diff options
author | johndoe123 | 2014-04-01 12:34:27 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-07-20 06:43:33 +0000 |
commit | d67021b32cf96388291135b19060d6dba8b7fbd4 (patch) | |
tree | e76ba048e62e679e54be1faaca26af565a4f80bb /engines/illusions | |
parent | d77d4ed4a61d79ffc75bb9dbdab01157da387a13 (diff) | |
download | scummvm-rg350-d67021b32cf96388291135b19060d6dba8b7fbd4.tar.gz scummvm-rg350-d67021b32cf96388291135b19060d6dba8b7fbd4.tar.bz2 scummvm-rg350-d67021b32cf96388291135b19060d6dba8b7fbd4.zip |
ILLUSIONS: Implement talkitem pausing/unpausing
- Fix isActiveThread to check only non-paused and non-terminated threads
Diffstat (limited to 'engines/illusions')
-rw-r--r-- | engines/illusions/scriptopcodes.cpp | 5 | ||||
-rw-r--r-- | engines/illusions/talkresource.cpp | 74 | ||||
-rw-r--r-- | engines/illusions/talkresource.h | 13 | ||||
-rw-r--r-- | engines/illusions/thread.cpp | 7 |
4 files changed, 73 insertions, 26 deletions
diff --git a/engines/illusions/scriptopcodes.cpp b/engines/illusions/scriptopcodes.cpp index 0a96f9c587..aa63512142 100644 --- a/engines/illusions/scriptopcodes.cpp +++ b/engines/illusions/scriptopcodes.cpp @@ -31,6 +31,7 @@ #include "illusions/scriptresource.h" #include "illusions/scriptthread.h" #include "illusions/specialcode.h" +#include "illusions/talkresource.h" namespace Illusions { @@ -296,7 +297,7 @@ void ScriptOpcodes::opStartModalScene(ScriptThread *scriptThread, OpCall &opCall // NOTE Skipped checking for stalled resources _vm->_input->discardButtons(0xFFFF); _vm->_scriptMan->enterPause(opCall._callerThreadId); - // TODO _vm->_talkItems->pauseByTag(_vm->getCurrentScene()); + _vm->_talkItems->pauseByTag(_vm->getCurrentScene()); _vm->_scriptMan->enterScene(sceneId, opCall._callerThreadId); _vm->_scriptMan->startScriptThread(threadId, 0, scriptThread->_value8, scriptThread->_valueC, scriptThread->_value10); @@ -308,7 +309,7 @@ void ScriptOpcodes::opExitModalScene(ScriptThread *scriptThread, OpCall &opCall) _vm->_input->discardButtons(0xFFFF); _vm->_scriptMan->exitScene(opCall._callerThreadId); _vm->_scriptMan->leavePause(opCall._callerThreadId); - // TODO _vm->_talkItems->unpauseByTag(_vm->getCurrentScene()); + _vm->_talkItems->unpauseByTag(_vm->getCurrentScene()); } void ScriptOpcodes::opEnterCloseUpScene(ScriptThread *scriptThread, OpCall &opCall) { diff --git a/engines/illusions/talkresource.cpp b/engines/illusions/talkresource.cpp index 0c1108ea27..2487d61afa 100644 --- a/engines/illusions/talkresource.cpp +++ b/engines/illusions/talkresource.cpp @@ -35,26 +35,14 @@ void TalkResourceLoader::load(Resource *resource) { talkResource->load(resource->_data, resource->_dataSize); resource->_refId = talkResource; - _vm->_talkItems->newTalkItem(resource->_resId, talkResource); - - for (uint i = 0; i < talkResource->_talkEntriesCount; ++i) { - TalkEntry *talkEntry = &talkResource->_talkEntries[i]; - _vm->_dict->addTalkEntry(talkEntry->_talkId, talkEntry); - } - + TalkItem *talkItem = _vm->_talkItems->newTalkItem(resource->_resId, resource->_tag, talkResource); + talkItem->registerResources(); } void TalkResourceLoader::unload(Resource *resource) { TalkItem *talkItem = _vm->_talkItems->findTalkItem(resource->_resId); - TalkResource *talkResource = talkItem->_talkRes; - - for (uint i = 0; i < talkResource->_talkEntriesCount; ++i) { - TalkEntry *talkEntry = &talkResource->_talkEntries[i]; - _vm->_dict->removeTalkEntry(talkEntry->_talkId); - } - + talkItem->unregisterResources(); _vm->_talkItems->freeTalkItem(talkItem); - } void TalkResourceLoader::buildFilename(Resource *resource) { @@ -109,23 +97,50 @@ void TalkResource::load(byte *data, uint32 dataSize) { // TalkItem -TalkItem::TalkItem(uint32 talkId, TalkResource *talkResource) - : _talkId(talkId), _talkRes(talkResource), _pauseCtr(0) { +TalkItem::TalkItem(IllusionsEngine *vm, uint32 talkId, uint32 tag, TalkResource *talkResource) + : _vm(vm), _talkId(talkId), _tag(tag), _talkRes(talkResource), _pauseCtr(0) { } TalkItem::~TalkItem() { } +void TalkItem::registerResources() { + for (uint i = 0; i < _talkRes->_talkEntriesCount; ++i) { + TalkEntry *talkEntry = &_talkRes->_talkEntries[i]; + _vm->_dict->addTalkEntry(talkEntry->_talkId, talkEntry); + } +} + +void TalkItem::unregisterResources() { + for (uint i = 0; i < _talkRes->_talkEntriesCount; ++i) { + TalkEntry *talkEntry = &_talkRes->_talkEntries[i]; + _vm->_dict->removeTalkEntry(talkEntry->_talkId); + } +} + +void TalkItem::pause() { + ++_pauseCtr; + if (_pauseCtr == 1) + unregisterResources(); +} + +void TalkItem::unpause() { + --_pauseCtr; + if (_pauseCtr == 0) + registerResources(); +} + // TalkItems -TalkItems::TalkItems(IllusionsEngine *vm) { +TalkItems::TalkItems(IllusionsEngine *vm) + : _vm(vm) { } TalkItems::~TalkItems() { } -TalkItem *TalkItems::newTalkItem(uint32 talkId, TalkResource *talkResource) { - TalkItem *talkItem = new TalkItem(talkId, talkResource); +TalkItem *TalkItems::newTalkItem(uint32 talkId, uint32 tag, TalkResource *talkResource) { + TalkItem *talkItem = new TalkItem(_vm, talkId, tag, talkResource); _items.push_back(talkItem); return talkItem; } @@ -142,4 +157,23 @@ TalkItem *TalkItems::findTalkItem(uint32 talkId) { return 0; } +TalkItem *TalkItems::findTalkItemByTag(uint32 tag) { + for (ItemsIterator it = _items.begin(); it != _items.end(); ++it) + if ((*it)->_tag == tag) + return (*it); + return 0; +} + +void TalkItems::pauseByTag(uint32 tag) { + TalkItem *talkItem = findTalkItemByTag(tag); + if (talkItem) + talkItem->pause(); +} + +void TalkItems::unpauseByTag(uint32 tag) { + TalkItem *talkItem = findTalkItemByTag(tag); + if (talkItem) + talkItem->unpause(); +} + } // End of namespace Illusions diff --git a/engines/illusions/talkresource.h b/engines/illusions/talkresource.h index beb859c108..ff82645508 100644 --- a/engines/illusions/talkresource.h +++ b/engines/illusions/talkresource.h @@ -63,10 +63,16 @@ public: class TalkItem { public: - TalkItem(uint32 talkId, TalkResource *talkResource); + TalkItem(IllusionsEngine *vm, uint32 talkId, uint32 tag, TalkResource *talkResource); ~TalkItem(); + void registerResources(); + void unregisterResources(); + void pause(); + void unpause(); public: + IllusionsEngine *_vm; uint32 _talkId; + uint32 _tag; TalkResource *_talkRes; int _pauseCtr; }; @@ -75,9 +81,12 @@ class TalkItems { public: TalkItems(IllusionsEngine *vm); ~TalkItems(); - TalkItem *newTalkItem(uint32 talkId, TalkResource *talkResource); + TalkItem *newTalkItem(uint32 talkId, uint32 tag, TalkResource *talkResource); void freeTalkItem(TalkItem *talkItem); TalkItem *findTalkItem(uint32 talkId); + TalkItem *findTalkItemByTag(uint32 tag); + void pauseByTag(uint32 tag); + void unpauseByTag(uint32 tag); //protected: public: typedef Common::List<TalkItem*> Items; diff --git a/engines/illusions/thread.cpp b/engines/illusions/thread.cpp index 980a8afc4b..cac13d9760 100644 --- a/engines/illusions/thread.cpp +++ b/engines/illusions/thread.cpp @@ -286,9 +286,12 @@ uint32 ThreadList::getThreadSceneId(uint32 threadId) { bool ThreadList::isActiveThread(int msgNum) { // Check if at least one thread returns a non-null value for the message - for (Iterator it = _threads.begin(); it != _threads.end(); ++it) - if ((*it)->sendMessage(msgNum, 0) != 0) + for (Iterator it = _threads.begin(); it != _threads.end(); ++it) { + Thread *thread = *it; + if (!thread->_terminated && thread->_pauseCtr <= 0 && + thread->sendMessage(msgNum, 0) != 0) return true; + } return false; } |