ASYLUM: Implement Encounter::messageHandler()

- Add Sound::getMusicVolume()
- Update AsylumEvent
- Add stubs for mouse, key, update and init events handlers

git-svn-id: http://asylumengine.googlecode.com/svn/trunk@576 0bfb4aae-4ea4-11de-8d8d-752d95cf3e3c
This commit is contained in:
Julien Templier 2010-11-27 00:03:53 +00:00 committed by Eugene Sandulenko
parent a07548e605
commit 01b0ea4915
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
6 changed files with 69 additions and 15 deletions

View File

@ -356,7 +356,7 @@ void AsylumEngine::switchMessageHandler(MessageHandler *handler) {
// De-init previous handler
if (_handler != NULL) {
AsylumEvent deinit(EVENT_ASYLUM, AsylumMessageDeInit);
AsylumEvent deinit(EVENT_ASYLUM_DEINIT);
(*_handler)(deinit);
}
@ -364,7 +364,7 @@ void AsylumEngine::switchMessageHandler(MessageHandler *handler) {
_handler = handler;
// Init new handler
AsylumEvent init(EVENT_ASYLUM, AsylumMessageInit);
AsylumEvent init(EVENT_ASYLUM_INIT);
(*_handler)(init);
}

View File

@ -31,23 +31,17 @@
namespace Asylum {
#define EVENT_ASYLUM 0xFFF0
enum AsylumMessages {
AsylumMessageUpdate,
AsylumMessageInit,
AsylumMessageDeInit,
enum AsylumEventType {
EVENT_ASYLUM_INIT = 0xFFF0,
EVENT_ASYLUM_DEINIT = 0xFFF1,
EVENT_ASYLUM_UPDATE = 0xFFF2
};
struct AsylumEvent : public Common::Event {
// For events of type EVENT_ASYLUM, we check our custom event value
// Since we don't feed any custom message into the event manager,
// we can safely use our own custom event type.
AsylumMessages extra;
AsylumEvent(uint32 msgType, AsylumMessages customMessage) {
AsylumEvent(AsylumEventType msgType) {
type = (Common::EventType)msgType;
extra = customMessage;
}
};

View File

@ -156,7 +156,51 @@ void Encounter::run(int32 encounterIndex, ObjectId objectId1, ObjectId objectId2
// Message handler
//////////////////////////////////////////////////////////////////////////
void Encounter::messageHandler(const AsylumEvent &evt) {
error("[Encounter::messageHandler] Not implemented!");
switch ((uint32)evt.type) {
default:
break;
case EVENT_ASYLUM_INIT:
init();
break;
case EVENT_ASYLUM_UPDATE:
update();
break;
case Common::EVENT_KEYDOWN:
key(evt);
break;
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
mouse(evt);
break;
}
}
void Encounter::init() {
if (getSound()->getMusicVolume() != Config.musicVolume - 500)
getSound()->setMusicVolume(Config.musicVolume - 500);
error("[Encounter::init] Not implemented!");
}
void Encounter::update() {
if (getSound()->getMusicVolume() != Config.musicVolume - 500)
getSound()->setMusicVolume(Config.musicVolume - 500);
error("[Encounter::update] Not implemented!");
}
void Encounter::key(const AsylumEvent &evt) {
error("[Encounter::key] Not implemented!");
}
void Encounter::mouse(const AsylumEvent &evt) {
error("[Encounter::mouse] Not implemented!");
}
//////////////////////////////////////////////////////////////////////////

View File

@ -107,6 +107,10 @@ private:
// Message handling
Common::Functor1Mem<const AsylumEvent &, void, Encounter> *_messageHandler;
void messageHandler(const AsylumEvent &evt);
void init();
void update();
void key(const AsylumEvent &evt);
void mouse(const AsylumEvent &evt);
//////////////////////////////////////////////////////////////////////////
// Variables

View File

@ -43,7 +43,7 @@
namespace Asylum {
Sound::Sound(AsylumEngine *engine, Audio::Mixer *mixer) : _vm(engine), _mixer(mixer) {
Sound::Sound(AsylumEngine *engine, Audio::Mixer *mixer) : _vm(engine), _mixer(mixer), _musicVolume(-10000) {
}
Sound::~Sound() {
@ -126,6 +126,9 @@ void Sound::setMusicVolume(int32 volume) {
if (volume < -10000)
return;
// Save music volume (we need to be able to return it to the logic code
_musicVolume = volume;
convertVolume(volume);
_mixer->setChannelVolume(_musicHandle, (byte)volume);

View File

@ -165,6 +165,13 @@ public:
*/
void setMusicVolume(int32 volume);
/**
* Gets the music volume.
*
* @return The music volume.
*/
int32 getMusicVolume() { return _musicVolume; }
/**
* Sets the panning for a buffered sound resource
*
@ -240,6 +247,8 @@ private:
Audio::SoundHandle _musicHandle;
Audio::SoundHandle _soundHandle;
int32 _musicVolume;
Common::Array<SoundBufferItem> _soundBuffer;
/**