GOB: Add some PreGob sound utility functions

This commit is contained in:
Sven Hesse 2012-07-01 03:45:09 +02:00
parent 233a3f54fc
commit 34cf81a4b6
4 changed files with 63 additions and 1 deletions

View File

@ -246,6 +246,10 @@ const OnceUpon::MenuButton OnceUpon::kIngameButtons[3] = {
{true, 180, 83, 211, 116, 72, 0, 103, 34, 180, 83, 2}
};
const char *OnceUpon::kSound[kSoundMAX] = {
"diamant.snd"
};
OnceUpon::OnceUpon(GobEngine *vm) : PreGob(vm), _jeudak(0), _lettre(0), _plettre(0), _glettre(0),
_openedArchives(false), _animalsButton(0) {
@ -286,6 +290,8 @@ void OnceUpon::init() {
"please contact the ScummVM team with details about this version.\n"
"Thanks", _vm->getLangDesc(_vm->_global->_language));
loadSounds(kSound, kSoundMAX);
initScreen();
_difficulty = kDifficultyMAX;
@ -293,6 +299,8 @@ void OnceUpon::init() {
}
void OnceUpon::deinit() {
freeSounds();
delete _jeudak;
delete _lettre;
delete _plettre;
@ -671,7 +679,7 @@ void OnceUpon::stopTitleMusic() {
_vm->_sound->blasterStopComposition();
_vm->_sound->protrackerStop();
for (int i = 0; i < Sound::kSoundsCount; i++)
for (int i = 0; i < ::Gob::Sound::kSoundsCount; i++)
_vm->_sound->sampleFree(_vm->_sound->sampleGetBySlot(i));
}

View File

@ -64,6 +64,11 @@ protected:
kDifficultyMAX
};
enum Sound {
kSoundClick = 0,
kSoundMAX
};
struct MenuButton {
bool needDraw;
int16 left, top, right, bottom;
@ -110,6 +115,9 @@ private:
static const MenuButton kSectionButtons[4];
static const MenuButton kIngameButtons[3];
static const char *kSound[kSoundMAX];
void setCopyProtectionPalette();
void setAnimState(ANIObject &ani, uint16 state, bool once, bool pause) const;

View File

@ -32,6 +32,8 @@
#include "gob/video.h"
#include "gob/aniobject.h"
#include "gob/sound/sound.h"
#include "gob/pregob/pregob.h"
static char kLanguageSuffix[5] = { 't', 'g', 'a', 'e', 'i' };
@ -141,6 +143,39 @@ bool PreGob::isCursorVisible() const {
return CursorMan.isVisible();
}
void PreGob::loadSounds(const char * const *sounds, uint soundCount) {
freeSounds();
_sounds.resize(soundCount);
for (uint i = 0; i < soundCount; i++) {
int32 size;
byte *data = _vm->_dataIO->getFile(sounds[i], size);
if (!data || !_sounds[i].load(SOUND_SND, data, size)) {
delete data;
warning("PreGob::loadSounds(): Failed to load sound \"%s\"", sounds[i]);
continue;
}
}
}
void PreGob::freeSounds() {
_sounds.clear();
}
void PreGob::playSound(uint sound, int16 frequency, int16 repCount) {
if (sound >= _sounds.size())
return;
_vm->_sound->blasterPlay(&_sounds[sound], repCount, frequency);
}
void PreGob::stopSound() {
_vm->_sound->blasterStop(0);
}
void PreGob::endFrame(bool doInput) {
_vm->_draw->blitInvalidated();
_vm->_util->waitEndFrame();

View File

@ -24,9 +24,12 @@
#define GOB_PREGOB_PREGOB_H
#include "common/str.h"
#include "common/array.h"
#include "gob/util.h"
#include "gob/sound/sounddesc.h"
#include "gob/pregob/txtfile.h"
namespace Gob {
@ -70,6 +73,12 @@ protected:
bool isCursorVisible() const;
void loadSounds(const char * const *sounds, uint soundCount);
void freeSounds();
void playSound(uint sound, int16 frequency = 0, int16 repCount = 0);
void stopSound();
void endFrame(bool doInput);
int16 checkInput(int16 &mouseX, int16 &mouseY, MouseButtons &mouseButtons);
@ -89,6 +98,8 @@ protected:
private:
bool _fadedOut; ///< Did we fade out?
Common::Array<SoundDesc> _sounds;
};
} // End of namespace Gob