From 297996a0900acca177ecfd3ffa51907ad8d284fa Mon Sep 17 00:00:00 2001 From: johndoe123 Date: Fri, 1 Aug 2014 22:53:07 +0200 Subject: ILLUSIONS: Add sound effects (still buggy) --- engines/illusions/actorresource.cpp | 7 --- engines/illusions/backgroundresource.cpp | 9 ---- engines/illusions/bbdou/bbdou_inventory.cpp | 2 +- engines/illusions/bbdou/bbdou_specialcode.cpp | 1 + engines/illusions/fontresource.cpp | 4 -- engines/illusions/graphics.cpp | 1 - engines/illusions/illusions_bbdou.cpp | 5 +-- engines/illusions/illusions_duckman.cpp | 62 ++++++++++++++++++++++++++- engines/illusions/input.cpp | 1 - engines/illusions/scriptopcodes_bbdou.cpp | 4 +- engines/illusions/scriptopcodes_duckman.cpp | 7 ++- engines/illusions/scriptthread.cpp | 5 --- engines/illusions/sound.cpp | 24 ++++++----- engines/illusions/soundresource.cpp | 7 ++- engines/illusions/talkresource.cpp | 4 -- engines/illusions/textdrawer.cpp | 5 --- engines/illusions/thread.cpp | 3 +- 17 files changed, 86 insertions(+), 65 deletions(-) (limited to 'engines/illusions') diff --git a/engines/illusions/actorresource.cpp b/engines/illusions/actorresource.cpp index d3762f96b6..f1276c0aa7 100644 --- a/engines/illusions/actorresource.cpp +++ b/engines/illusions/actorresource.cpp @@ -94,7 +94,6 @@ void Frame::load(byte *dataStart, Common::SeekableReadStream &stream) { uint32 compressedPixelsOffs = stream.readUint32LE(); _compressedPixels = dataStart + compressedPixelsOffs; _pointsConfig = dataStart + pointsConfigOffs; - debug(5, "Frame::load() compressedPixelsOffs: %08X", compressedPixelsOffs); } @@ -104,10 +103,8 @@ void Sequence::load(byte *dataStart, Common::SeekableReadStream &stream) { _unk4 = stream.readUint32LE(); uint32 sequenceCodeOffs = stream.readUint32LE(); _sequenceCode = dataStart + sequenceCodeOffs; - debug(5, "Sequence::load() _sequenceId: %08X; _unk4: %d; sequenceCodeOffs: %08X", _sequenceId, _unk4, sequenceCodeOffs); - } void ActorType::load(byte *dataStart, Common::SeekableReadStream &stream) { @@ -133,14 +130,12 @@ void ActorType::load(byte *dataStart, Common::SeekableReadStream &stream) { _pointsConfig = dataStart + pointsConfigOffs; stream.seek(namedPointsOffs); _namedPoints.load(namedPointsCount, stream); - debug(5, "ActorType::load() _actorTypeId: %08X; _color(%d,%d,%d); _scale: %d; _priority: %d; _value1E: %d", _actorTypeId, _color.r, _color.g, _color.b, _scale, _priority, _value1E); debug(5, "ActorType::load() _pathWalkPointsIndex: %d; _scaleLayerIndex: %d; _pathWalkRectIndex: %d", _pathWalkPointsIndex, _scaleLayerIndex, _pathWalkRectIndex); debug(5, "ActorType::load() _priorityLayerIndex: %d; _regionLayerIndex: %d; _flags: %04X", _priorityLayerIndex, _regionLayerIndex,_flags); - } // ActorResource @@ -154,7 +149,6 @@ ActorResource::~ActorResource() { void ActorResource::load(Resource *resource) { byte *data = resource->_data; uint32 dataSize = resource->_dataSize; - Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO); _totalSize = stream.readUint32LE(); @@ -207,7 +201,6 @@ void ActorResource::load(Resource *resource) { } debug("ActorResource(%08X) framesCount: %d", resource->_resId, framesCount); - } bool ActorResource::containsSequence(Sequence *sequence) { diff --git a/engines/illusions/backgroundresource.cpp b/engines/illusions/backgroundresource.cpp index a39412c5be..818f704342 100644 --- a/engines/illusions/backgroundresource.cpp +++ b/engines/illusions/backgroundresource.cpp @@ -99,7 +99,6 @@ void TileMap::load(byte *dataStart, Common::SeekableReadStream &stream) { stream.skip(4); // Unknown uint32 mapOffs = stream.pos(); _map = dataStart + mapOffs; - debug(0, "TileMap::load() _width: %d; _height: %d", _width, _height); } @@ -117,7 +116,6 @@ void BgInfo::load(byte *dataStart, Common::SeekableReadStream &stream) { stream.seek(tileMapOffs); _tileMap.load(dataStart, stream); _tilePixels = dataStart + tilePixelsOffs; - debug(0, "BgInfo::load() _flags: %08X; _priorityBase: %d; tileMapOffs: %08X; tilePixelsOffs: %08X", _flags, _priorityBase, tileMapOffs, tilePixelsOffs); } @@ -134,7 +132,6 @@ void PriorityLayer::load(byte *dataStart, Common::SeekableReadStream &stream) { _mapHeight = READ_LE_UINT16(_map + 2); _map += 8; _values = dataStart + valuesOffs; - debug(0, "PriorityLayer::load() _width: %d; _height: %d; mapOffs: %08X; valuesOffs: %08X; _mapWidth: %d; _mapHeight: %d", _width, _height, mapOffs, valuesOffs, _mapWidth, _mapHeight); } @@ -153,7 +150,6 @@ void ScaleLayer::load(byte *dataStart, Common::SeekableReadStream &stream) { stream.skip(2); uint32 valuesOffs = stream.readUint32LE(); _values = dataStart + valuesOffs; - debug(0, "ScaleLayer::load() _height: %d; valuesOffs: %08X", _height, valuesOffs); } @@ -178,7 +174,6 @@ void RegionLayer::load(byte *dataStart, Common::SeekableReadStream &stream) { _mapWidth = READ_LE_UINT16(_map + 0); _mapHeight = READ_LE_UINT16(_map + 2); _map += 8; - debug("RegionLayer::load() %d; regionSequenceIdsOffs: %08X; _width: %d; _height: %d; mapOffs: %08X; valuesOffs: %08X", _unk, regionSequenceIdsOffs, _width, _height, mapOffs, valuesOffs); } @@ -213,7 +208,6 @@ void BackgroundObject::load(byte *dataStart, Common::SeekableReadStream &stream) _priority = stream.readUint16LE(); uint32 pointsConfigOffs = stream.readUint32LE(); _pointsConfig = dataStart + pointsConfigOffs; - debug(0, "BackgroundObject::load() _objectId: %08X; _flags: %04X; _priority: %d; pointsConfigOffs: %08X", _objectId, _flags, _priority, pointsConfigOffs); } @@ -264,7 +258,6 @@ BackgroundResource::~BackgroundResource() { void BackgroundResource::load(byte *data, uint32 dataSize) { Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO); - // TODO A lot stream.seek(8); _paletteIndex = stream.readUint16LE(); @@ -510,7 +503,6 @@ void BackgroundItem::drawTiles16(Graphics::Surface *surface, TileMap &tileMap, b } void BackgroundItem::pause() { - // TODO ++_pauseCtr; if (_pauseCtr <= 1) { for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) { @@ -526,7 +518,6 @@ void BackgroundItem::pause() { } void BackgroundItem::unpause() { - // TODO --_pauseCtr; if (_pauseCtr <= 0) { for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) { diff --git a/engines/illusions/bbdou/bbdou_inventory.cpp b/engines/illusions/bbdou/bbdou_inventory.cpp index c2ffd99e3e..3c4e37cc9b 100644 --- a/engines/illusions/bbdou/bbdou_inventory.cpp +++ b/engines/illusions/bbdou/bbdou_inventory.cpp @@ -117,7 +117,7 @@ InventorySlot *InventoryBag::findClosestSlot(Common::Point putPos, int index) { // BbdouInventory BbdouInventory::BbdouInventory(IllusionsEngine_BBDOU *vm, BbdouSpecialCode *bbdou) - : _vm(vm), _bbdou(bbdou) { + : _vm(vm), _bbdou(bbdou), _activeInventorySceneId(0) { } void BbdouInventory::registerInventoryBag(uint32 sceneId) { diff --git a/engines/illusions/bbdou/bbdou_specialcode.cpp b/engines/illusions/bbdou/bbdou_specialcode.cpp index cb4f32aeae..eba37a8b88 100644 --- a/engines/illusions/bbdou/bbdou_specialcode.cpp +++ b/engines/illusions/bbdou/bbdou_specialcode.cpp @@ -69,6 +69,7 @@ void CauseThread::onTerminated() { } // RadarMicrophoneThread + RadarMicrophoneThread::RadarMicrophoneThread(IllusionsEngine_BBDOU *vm, uint32 threadId, uint32 callingThreadId, uint32 cursorObjectId) : Thread(vm, threadId, callingThreadId, 0), _cursorObjectId(cursorObjectId), _zonesCount(0) { diff --git a/engines/illusions/fontresource.cpp b/engines/illusions/fontresource.cpp index 9f7a075895..c2c66ac528 100644 --- a/engines/illusions/fontresource.cpp +++ b/engines/illusions/fontresource.cpp @@ -31,13 +31,10 @@ namespace Illusions { void FontResourceLoader::load(Resource *resource) { debug("FontResourceLoader::load() Loading font %08X from %s...", resource->_resId, resource->_filename.c_str()); - // TODO FontResource *fontResource = new FontResource(); fontResource->load(resource); resource->_refId = fontResource; - _vm->_dict->addFont(resource->_resId, fontResource); - } void FontResourceLoader::unload(Resource *resource) { @@ -102,7 +99,6 @@ void FontResource::load(Resource *resource) { byte *data = resource->_data; uint32 dataSize = resource->_dataSize; Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO); - _totalSize = stream.readUint32LE(); _charHeight = stream.readUint16LE(); _field_6 = stream.readUint16LE(); diff --git a/engines/illusions/graphics.cpp b/engines/illusions/graphics.cpp index a4fa0e6cfe..eae605641e 100644 --- a/engines/illusions/graphics.cpp +++ b/engines/illusions/graphics.cpp @@ -75,7 +75,6 @@ void NamedPoints::load(uint count, Common::SeekableReadStream &stream) { void loadPoint(Common::SeekableReadStream &stream, Common::Point &pt) { pt.x = stream.readSint16LE(); pt.y = stream.readSint16LE(); - debug(0, "loadPoint() x: %d; y: %d", pt.x, pt.y); } diff --git a/engines/illusions/illusions_bbdou.cpp b/engines/illusions/illusions_bbdou.cpp index 658732de3f..41a6be6c8c 100644 --- a/engines/illusions/illusions_bbdou.cpp +++ b/engines/illusions/illusions_bbdou.cpp @@ -65,8 +65,6 @@ namespace Illusions { -//typedef Common::Functor2Mem UpdateFunctionI; - // TriggerFunction TriggerFunction::TriggerFunction(uint32 sceneId, uint32 verbId, uint32 objectId2, uint32 objectId, TriggerFunctionCallback *callback) @@ -188,7 +186,7 @@ Common::Error IllusionsEngine_BBDOU::run() { SearchMan.addSubDirectoryMatching(gameDataDir, "resource"); SearchMan.addSubDirectoryMatching(gameDataDir, "resrem"); SearchMan.addSubDirectoryMatching(gameDataDir, "savegame"); - SearchMan.addSubDirectoryMatching(gameDataDir, "sfx"); + SearchMan.addSubDirectoryMatching(gameDataDir, "sfx", 0, 2); SearchMan.addSubDirectoryMatching(gameDataDir, "video"); SearchMan.addSubDirectoryMatching(gameDataDir, "voice"); @@ -250,7 +248,6 @@ Common::Error IllusionsEngine_BBDOU::run() { runUpdateFunctions(); _system->updateScreen(); updateEvents(); - _system->delayMillis(10); } delete _stack; diff --git a/engines/illusions/illusions_duckman.cpp b/engines/illusions/illusions_duckman.cpp index 1bbaf06a77..aee847e39f 100644 --- a/engines/illusions/illusions_duckman.cpp +++ b/engines/illusions/illusions_duckman.cpp @@ -162,7 +162,6 @@ Common::Error IllusionsEngine_Duckman::run() { runUpdateFunctions(); _system->updateScreen(); updateEvents(); - _system->delayMillis(10); } delete _stack; @@ -897,7 +896,66 @@ void IllusionsEngine_Duckman::updateGameState2() { } void IllusionsEngine_Duckman::playSoundEffect(int index) { - // TODO + uint32 soundEffectId = 0; + uint32 *soundIds = _scriptResource->_soundIds; + switch (index) { + case 1: + soundEffectId = soundIds[0]; + break; + case 2: + soundEffectId = soundIds[1]; + break; + case 3: + soundEffectId = soundIds[2]; + break; + case 4: + soundEffectId = soundIds[3]; + break; + case 5: + soundEffectId = soundIds[4]; + break; + case 6: + soundEffectId = soundIds[getRandom(4) + 5]; + break; + case 7: + soundEffectId = soundIds[getRandom(4) + 9]; + break; + case 8: + soundEffectId = soundIds[13]; + break; + case 9: + soundEffectId = soundIds[14]; + break; + case 10: + soundEffectId = soundIds[15]; + break; + case 11: + soundEffectId = soundIds[16]; + break; + case 12: + soundEffectId = soundIds[getRandom(4) + 17]; + break; + case 13: + soundEffectId = soundIds[21]; + break; + case 14: + soundEffectId = soundIds[22]; + break; + case 15: + soundEffectId = soundIds[23]; + break; + case 16: + soundEffectId = soundIds[24]; + break; + case 17: + soundEffectId = soundIds[25]; + break; + case 18: + soundEffectId = soundIds[26]; + break; + } + if (soundEffectId) + _soundMan->playSound(soundEffectId, 255, 0); } bool IllusionsEngine_Duckman::getTriggerCause(uint32 verbId, uint32 objectId2, uint32 objectId, uint32 &outThreadId) { diff --git a/engines/illusions/input.cpp b/engines/illusions/input.cpp index 53b3291a59..e9bf25fb1a 100644 --- a/engines/illusions/input.cpp +++ b/engines/illusions/input.cpp @@ -34,7 +34,6 @@ Input::Input() { _cursorPos.y = 0; _prevCursorPos.x = 0; _prevCursorPos.y = 0; - // TODO Not sure if this is still needed newTimer(40, 0, 0, Input_onTimer); initKeys(); } diff --git a/engines/illusions/scriptopcodes_bbdou.cpp b/engines/illusions/scriptopcodes_bbdou.cpp index 30cd023974..32350cd69e 100644 --- a/engines/illusions/scriptopcodes_bbdou.cpp +++ b/engines/illusions/scriptopcodes_bbdou.cpp @@ -513,12 +513,12 @@ void ScriptOpcodes_BBDOU::opStartSound(ScriptThread *scriptThread, OpCall &opCal ARG_INT16(volume); ARG_INT16(pan); ARG_UINT32(soundEffectId); - // TODO _vm->startSound(soundEffectId, volume, pan); + _vm->_soundMan->playSound(soundEffectId, volume, pan); } void ScriptOpcodes_BBDOU::opStopSound(ScriptThread *scriptThread, OpCall &opCall) { ARG_SKIP(2); ARG_UINT32(soundEffectId); - // TODO _vm->stopSound(soundEffectId); + _vm->_soundMan->stopSound(soundEffectId); } void ScriptOpcodes_BBDOU::opStartMusic(ScriptThread *scriptThread, OpCall &opCall) { diff --git a/engines/illusions/scriptopcodes_duckman.cpp b/engines/illusions/scriptopcodes_duckman.cpp index e8daf6a999..541ad18e11 100644 --- a/engines/illusions/scriptopcodes_duckman.cpp +++ b/engines/illusions/scriptopcodes_duckman.cpp @@ -30,6 +30,7 @@ #include "illusions/scriptman.h" #include "illusions/scriptresource.h" #include "illusions/scriptthread.h" +#include "illusions/sound.h" #include "illusions/specialcode.h" #include "illusions/talkresource.h" @@ -369,8 +370,6 @@ void ScriptOpcodes_Duckman::opStartFade(ScriptThread *scriptThread, OpCall &opCa ARG_INT16(firstIndex); ARG_INT16(lastIndex); _vm->startFader(duration, minValue, maxValue, firstIndex, lastIndex, opCall._threadId); - //DEBUG Resume calling thread, later done when the fading is finished - //_vm->notifyThreadId(opCall._threadId); } void ScriptOpcodes_Duckman::opSetDisplay(ScriptThread *scriptThread, OpCall &opCall) { @@ -560,13 +559,13 @@ void ScriptOpcodes_Duckman::opRunSpecialCode(ScriptThread *scriptThread, OpCall void ScriptOpcodes_Duckman::opStartSound(ScriptThread *scriptThread, OpCall &opCall) { ARG_INT16(volume); ARG_UINT32(soundEffectId); - // TODO _vm->startSound(soundEffectId, volume, pan); + _vm->_soundMan->playSound(soundEffectId, volume, 0); } void ScriptOpcodes_Duckman::opStopSound(ScriptThread *scriptThread, OpCall &opCall) { ARG_SKIP(2); ARG_UINT32(soundEffectId); - // TODO _vm->stopSound(soundEffectId); + _vm->_soundMan->stopSound(soundEffectId); } void ScriptOpcodes_Duckman::opStartMidiMusic(ScriptThread *scriptThread, OpCall &opCall) { diff --git a/engines/illusions/scriptthread.cpp b/engines/illusions/scriptthread.cpp index 73ef8ecd67..ba072e9407 100644 --- a/engines/illusions/scriptthread.cpp +++ b/engines/illusions/scriptthread.cpp @@ -52,11 +52,6 @@ int ScriptThread::onUpdate() { } void ScriptThread::loadOpcode(OpCall &opCall) { -#if 0 - for (uint i = 0; i < 16; ++i) - debugN("%02X ", _scriptCodeIp[i]); - debug("."); -#endif if (_vm->getGameId() == kGameIdDuckman) { opCall._op = _scriptCodeIp[0] & 0x7F; opCall._opSize = _scriptCodeIp[1]; diff --git a/engines/illusions/sound.cpp b/engines/illusions/sound.cpp index 23caf7ebb0..3a0f5ef3f2 100644 --- a/engines/illusions/sound.cpp +++ b/engines/illusions/sound.cpp @@ -82,7 +82,7 @@ VoicePlayer::~VoicePlayer() { } bool VoicePlayer::cue(const char *voiceName) { -debug("VoicePlayer::cue(%s)", voiceName); + debug("VoicePlayer::cue(%s)", voiceName); _voiceName = voiceName; _voiceStatus = 2; if (!isEnabled()) { @@ -161,7 +161,7 @@ void Sound::play(int16 volume, int16 pan) { } void Sound::stop() { - if (g_system->getMixer()->isSoundHandleActive(_soundHandle)) + if (isPlaying()) g_system->getMixer()->stopHandle(_soundHandle); } @@ -228,26 +228,28 @@ bool SoundMan::isVoiceCued() { } void SoundMan::loadSound(uint32 soundEffectId, uint32 soundGroupId, bool looping) { - Sound *soundEffect = new Sound(soundEffectId, soundGroupId, looping); - _sounds.push_front(soundEffect); + Sound *sound = new Sound(soundEffectId, soundGroupId, looping); + _sounds.push_front(sound); } void SoundMan::playSound(uint32 soundEffectId, int16 volume, int16 pan) { - Sound *soundEffect = getSound(soundEffectId); - soundEffect->play(volume, pan); + Sound *sound = getSound(soundEffectId); + if (sound) + sound->play(volume, pan); } void SoundMan::stopSound(uint32 soundEffectId) { - Sound *soundEffect = getSound(soundEffectId); - soundEffect->stop(); + Sound *sound = getSound(soundEffectId); + if (sound) + sound->stop(); } void SoundMan::unloadSounds(uint32 soundGroupId) { SoundListIterator it = _sounds.begin(); while (it != _sounds.end()) { - Sound *soundEffect = *it; - if (soundGroupId == 0 || soundEffect->_soundGroupId == soundGroupId) { - delete soundEffect; + Sound *sound = *it; + if (soundGroupId == 0 || sound->_soundGroupId == soundGroupId) { + delete sound; it = _sounds.erase(it); } else ++it; diff --git a/engines/illusions/soundresource.cpp b/engines/illusions/soundresource.cpp index 8dbe798905..2e658431f5 100644 --- a/engines/illusions/soundresource.cpp +++ b/engines/illusions/soundresource.cpp @@ -30,7 +30,6 @@ namespace Illusions { void SoundGroupResourceLoader::load(Resource *resource) { debug("SoundGroupResourceLoader::load() Loading sound group %08X...", resource->_resId); - SoundGroupResource *soundGroupResource = new SoundGroupResource(); soundGroupResource->load(resource->_data, resource->_dataSize); resource->_refId = soundGroupResource; @@ -39,10 +38,10 @@ void SoundGroupResourceLoader::load(Resource *resource) { SoundEffect *soundEffect = &soundGroupResource->_soundEffects[i]; _vm->_soundMan->loadSound(soundEffect->_soundEffectId, resource->_resId, soundEffect->_looping); } - } void SoundGroupResourceLoader::unload(Resource *resource) { + debug("SoundGroupResourceLoader::unload() Unloading sound group %08X...", resource->_resId); _vm->_soundMan->unloadSounds(resource->_resId); delete (SoundGroupResource*)resource->_refId; } @@ -53,8 +52,8 @@ void SoundGroupResourceLoader::buildFilename(Resource *resource) { bool SoundGroupResourceLoader::isFlag(int flag) { return - flag == kRlfLoadFile || - flag == kRlfFreeDataAfterUse; + flag == kRlfLoadFile/* || + flag == kRlfFreeDataAfterUse*/; } // SoundEffect diff --git a/engines/illusions/talkresource.cpp b/engines/illusions/talkresource.cpp index 2487d61afa..f100aebcc8 100644 --- a/engines/illusions/talkresource.cpp +++ b/engines/illusions/talkresource.cpp @@ -65,7 +65,6 @@ void TalkEntry::load(byte *dataStart, Common::SeekableReadStream &stream) { _text = dataStart + textOffs; _tblPtr = dataStart + tblOffs; _voiceName = dataStart + voiceNameOffs; - debug(0, "TalkEntry::load() _talkId: %08X; textOffs: %08X; tblOffs: %08X; voiceNameOffs: %08X", _talkId, textOffs, tblOffs, voiceNameOffs); } @@ -82,17 +81,14 @@ TalkResource::~TalkResource() { void TalkResource::load(byte *data, uint32 dataSize) { Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO); - stream.skip(4); // Skip size _talkEntriesCount = stream.readUint16LE(); stream.skip(2); // Skip padding - _talkEntries = new TalkEntry[_talkEntriesCount]; for (uint i = 0; i < _talkEntriesCount; ++i) { stream.seek(8 + i * 0x14); _talkEntries[i].load(data, stream); } - } // TalkItem diff --git a/engines/illusions/textdrawer.cpp b/engines/illusions/textdrawer.cpp index d3f9379aa9..61c4455150 100644 --- a/engines/illusions/textdrawer.cpp +++ b/engines/illusions/textdrawer.cpp @@ -186,10 +186,5 @@ int16 TextDrawer::getCharWidth(uint16 c) { int16 offsX = (int16)(offsPt.x * 0.75); int16 offsY = (int16)(offsPt.y * 1.5); */ -/* -if (_surface) - drawChar(textPosX, textPosY, c); -textPosX += getCharWidth(c); -*/ } // End of namespace Illusions diff --git a/engines/illusions/thread.cpp b/engines/illusions/thread.cpp index 6c6a7d6fa2..941706abfd 100644 --- a/engines/illusions/thread.cpp +++ b/engines/illusions/thread.cpp @@ -131,13 +131,14 @@ void ThreadList::startThread(Thread *thread) { } void ThreadList::updateThreads() { + // TODO Move outer loop to caller while (1) { Iterator it = _threads.begin(); while (it != _threads.end()) { Thread *thread = *it; if (thread->_terminated) { - it = _threads.erase(it); delete thread; + it = _threads.erase(it); } else { int status = kTSRun; while (!thread->_terminated && status != kTSTerminate && status != kTSYield) -- cgit v1.2.3