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/talkresource.cpp | |
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/talkresource.cpp')
-rw-r--r-- | engines/illusions/talkresource.cpp | 74 |
1 files changed, 54 insertions, 20 deletions
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 |