diff options
author | johndoe123 | 2014-03-13 19:55:25 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-07-20 06:43:33 +0000 |
commit | 9d35f807ecc0cbc7a98a987c02d58d795706ed1f (patch) | |
tree | d92c9e062265b56d2c2797d39f950494b83530ac /engines/illusions/scriptman.cpp | |
parent | 9696eb9a546891bf7ff601d94f7a8a2ff6730349 (diff) | |
download | scummvm-rg350-9d35f807ecc0cbc7a98a987c02d58d795706ed1f.tar.gz scummvm-rg350-9d35f807ecc0cbc7a98a987c02d58d795706ed1f.tar.bz2 scummvm-rg350-9d35f807ecc0cbc7a98a987c02d58d795706ed1f.zip |
ILLUSIONS: More work on the script system
Diffstat (limited to 'engines/illusions/scriptman.cpp')
-rw-r--r-- | engines/illusions/scriptman.cpp | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/engines/illusions/scriptman.cpp b/engines/illusions/scriptman.cpp index 922ce605bb..25b8d2e902 100644 --- a/engines/illusions/scriptman.cpp +++ b/engines/illusions/scriptman.cpp @@ -22,11 +22,17 @@ #include "illusions/illusions.h" #include "illusions/scriptman.h" +#include "illusions/scriptthread.h" +#include "illusions/scriptopcodes.h" namespace Illusions { // ActiveScenes +ActiveScenes::ActiveScenes() { + clear(); +} + void ActiveScenes::clear() { _stack.clear(); } @@ -112,10 +118,14 @@ int16 ScriptStack::peek() { // ScriptMan ScriptMan::ScriptMan(IllusionsEngine *vm) - : _vm(vm) { + : _vm(vm), _pauseCtr(0), _doScriptThreadInit(false) { + _threads = new ThreadList(vm); + _scriptOpcodes = new ScriptOpcodes(vm); } ScriptMan::~ScriptMan() { + delete _threads; + delete _scriptOpcodes; } void ScriptMan::setSceneIdThreadId(uint32 theSceneId, uint32 theThreadId) { @@ -123,4 +133,52 @@ void ScriptMan::setSceneIdThreadId(uint32 theSceneId, uint32 theThreadId) { _theThreadId = theThreadId; } +void ScriptMan::startScriptThread(uint32 threadId, uint32 callingThreadId, + uint32 value8, uint32 valueC, uint32 value10) { + debug("Starting script thread %08X", threadId); + byte *scriptCodeIp = _scriptResource->getThreadCode(threadId); + newScriptThread(threadId, callingThreadId, 0, scriptCodeIp, value8, valueC, value10); +} + +void ScriptMan::startAnonScriptThread(int32 threadId, uint32 callingThreadId, + uint32 value8, uint32 valueC, uint32 value10) { + debug("Starting anonymous script thread %08X", threadId); + uint32 tempThreadId = newTempThreadId(); + byte *scriptCodeIp = _scriptResource->getThreadCode(threadId); + scriptCodeIp = _scriptResource->getThreadCode(threadId); + newScriptThread(tempThreadId, callingThreadId, 0, scriptCodeIp, value8, valueC, value10); +} + +uint32 ScriptMan::startTempScriptThread(byte *scriptCodeIp, uint32 callingThreadId, + uint32 value8, uint32 valueC, uint32 value10) { + debug("Starting temp script thread"); + uint32 tempThreadId = newTempThreadId(); + newScriptThread(tempThreadId, callingThreadId, 0, scriptCodeIp, value8, valueC, value10); + return tempThreadId; +} + +void ScriptMan::newScriptThread(uint32 threadId, uint32 callingThreadId, uint notifyFlags, + byte *scriptCodeIp, uint32 value8, uint32 valueC, uint32 value10) { + ScriptThread *scriptThread = new ScriptThread(_vm, threadId, callingThreadId, + notifyFlags, scriptCodeIp, value8, valueC, value10); + _threads->startThread(scriptThread); + if (_pauseCtr > 0) + scriptThread->pause(); + if (_doScriptThreadInit) { + int updateResult = 4; + while (scriptThread->_pauseCtr <= 0 && updateResult != 1 && updateResult != 2) + updateResult = scriptThread->update(); + } +} + +uint32 ScriptMan::newTempThreadId() { + uint32 threadId = _nextTempThreadId + 2 * _scriptResource->_codeCount; + if (threadId > 65535) { + _nextTempThreadId = 0; + threadId = 2 * _scriptResource->_codeCount; + } + ++_nextTempThreadId; + return 0x00020000 | threadId; +} + } // End of namespace Illusions |