From 8ee283d921ec88bad61469e136a31aef0ff5b9ca Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 23 Feb 2014 21:34:20 -0500 Subject: MADS: Implemented sound player logic and outer game loop --- engines/mads/sound.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 10 deletions(-) (limited to 'engines/mads/sound.cpp') diff --git a/engines/mads/sound.cpp b/engines/mads/sound.cpp index 46ba997198..8608abf4e7 100644 --- a/engines/mads/sound.cpp +++ b/engines/mads/sound.cpp @@ -24,29 +24,89 @@ #include "audio/decoders/raw.h" #include "common/memstream.h" #include "mads/sound.h" +#include "mads/mads.h" +#include "mads/nebular/sound_nebular.h" namespace MADS { SoundManager::SoundManager(MADSEngine *vm, Audio::Mixer *mixer) { _vm = vm; _mixer = mixer; - _asound = nullptr; + _driver = nullptr; + _pollSoundEnabled = false; + _soundPollFlag = false; + _newSoundsPaused = false; } SoundManager::~SoundManager() { - delete _asound; + delete _driver; } -void SoundManager::test() { - _asound = new Nebular::ASound1(_mixer); - _asound->command(5); - _asound->command(28); - _asound->command(19); +void SoundManager::init(int sectionNumber) { + assert(sectionNumber > 0 && sectionNumber < 10); + + switch (_vm->getGameID()) { + case GType_RexNebular: + // TODO: Other Rex Adlib section drivers + assert(sectionNumber == 1); + _driver = new Nebular::ASound1(_mixer); + break; + + default: + error("Unknown game"); + } +} + +void SoundManager::closeDriver() { + if (_driver) { + command(0); + setEnabled(false); + stop(); + + removeDriver(); + } +} + +void SoundManager::removeDriver() { + delete _driver; + _driver = nullptr; +} + +void SoundManager::setEnabled(bool flag) { + _pollSoundEnabled = flag; + _soundPollFlag = false; +} + +void SoundManager::queueNewCommands() { + _newSoundsPaused = true; +} + +void SoundManager::startQueuedCommands() { + _newSoundsPaused = false; + + while (!_queuedCommands.empty()) { + int commandId = _queuedCommands.front(); + command(commandId); + } +} + +void SoundManager::command(int commandId, int param) { + if (_newSoundsPaused) { + if (_queuedCommands.size() < 8) + _queuedCommands.push(commandId); + } else if (_driver) { + _driver->command(commandId, param); + } +} + +void SoundManager::stop() { + if (_driver) + _driver->stop(); } -void SoundManager::poll() { - if (_asound) - _asound->poll(); +void SoundManager::noise() { + if (_driver) + _driver->noise(); } } // End of namespace MADS -- cgit v1.2.3