diff options
author | Torbjörn Andersson | 2004-05-07 19:56:19 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2004-05-07 19:56:19 +0000 |
commit | afb91fc184a141e23445368a7493e1d4ae19562d (patch) | |
tree | 118c3f78f1d9120cd7132d754fdec48dea219d4e /sword2 | |
parent | 8d86693893a8a7492f4cf613792768139ab226d8 (diff) | |
download | scummvm-rg350-afb91fc184a141e23445368a7493e1d4ae19562d.tar.gz scummvm-rg350-afb91fc184a141e23445368a7493e1d4ae19562d.tar.bz2 scummvm-rg350-afb91fc184a141e23445368a7493e1d4ae19562d.zip |
Cleanup.
svn-id: r13806
Diffstat (limited to 'sword2')
-rw-r--r-- | sword2/anims.cpp | 2 | ||||
-rw-r--r-- | sword2/logic.h | 2 | ||||
-rw-r--r-- | sword2/sync.cpp | 76 |
3 files changed, 37 insertions, 43 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp index 98a2913527..52b4a2c258 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -147,7 +147,7 @@ int32 Logic::animate(int32 *params, bool reverse) { ob_graphic->anim_pc = anim_head->noAnimFrames - 1; else ob_graphic->anim_pc = 0; - } else if (getSync()) { + } else if (getSync() != -1) { // We've received a sync - return to script immediately debug(5, "**sync stopped %d**", _scriptVars[ID]); diff --git a/sword2/logic.h b/sword2/logic.h index df7d7a560d..90992c7a6a 100644 --- a/sword2/logic.h +++ b/sword2/logic.h @@ -221,7 +221,7 @@ public: SyncUnit _syncList[MAX_syncs]; void clearSyncs(uint32 id); - bool getSync(void); + int getSync(void); Router *_router; diff --git a/sword2/sync.cpp b/sword2/sync.cpp index c7011a185b..3bed7d56fd 100644 --- a/sword2/sync.cpp +++ b/sword2/sync.cpp @@ -22,7 +22,6 @@ #include "sword2/defs.h" #include "sword2/interpreter.h" #include "sword2/logic.h" -#include "sword2/resman.h" namespace Sword2 { @@ -32,7 +31,7 @@ int32 Logic::fnSendSync(int32 *params) { for (int i = 0; i < MAX_syncs; i++) { if (_syncList[i].id == 0) { - debug(5, " %d sending sync %d to %d", _scriptVars[ID], params[1], params[0]); + debug(5, "%d sends sync %d to %d", _scriptVars[ID], params[1], params[0]); _syncList[i].id = params[0]; _syncList[i].sync = params[1]; return IR_CONT; @@ -46,12 +45,13 @@ int32 Logic::fnSendSync(int32 *params) { return IR_CONT; } -void Logic::clearSyncs(uint32 id) { - // clear any syncs registered for this id - // call this just after the id has been processed - // there could in theory be more than one sync waiting for us so - // clear the lot +/** + * Clear any syncs registered for this id. Call this just after the id has been + * processed. Theoretically there could be more than one sync waiting for us, + * so clear the lot. + */ +void Logic::clearSyncs(uint32 id) { for (int i = 0; i < MAX_syncs; i++) { if (_syncList[i].id == id) { debug(5, "removing sync %d for %d", i, id); @@ -60,58 +60,52 @@ void Logic::clearSyncs(uint32 id) { } } -bool Logic::getSync(void) { - // check for a sync waiting for this character - // - called from system code eg. from inside fnAnim(), to see if - // animation to be quit +/** + * Check for a sync waiting for this character. Called from fnAnim() to see if + * animation is to be finished. Returns an index into _syncList[], or -1. + */ +int Logic::getSync(void) { for (int i = 0; i < MAX_syncs; i++) { - if (_syncList[i].id == _scriptVars[ID]) { - // means sync found - return true; - } + if (_syncList[i].id == _scriptVars[ID]) + return i; } - // no sync found - return false; + return -1; } -int32 Logic::fnGetSync(int32 *params) { - // check for a sync waiting for this character - // - called from script +/** + * Like getSync(), but called from scripts. Sets the RESULT variable to + * the sync value, or 0 if none is found. + */ +int32 Logic::fnGetSync(int32 *params) { // params: none - for (int i = 0; i < MAX_syncs; i++) { - if (_syncList[i].id == _scriptVars[ID]) { - // return sync value waiting - _scriptVars[RESULT] = _syncList[i].sync; - return IR_CONT; - } - } + int slot = getSync(); - // no sync found - _scriptVars[RESULT] = 0; + _scriptVars[RESULT] = (slot != -1) ? _syncList[slot].sync : 0; return IR_CONT; } -int32 Logic::fnWaitSync(int32 *params) { - // keep calling until a sync received +/** + * Wait for sync to happen. Sets the RESULT variable to the sync value, once + * it has been found. + */ +int32 Logic::fnWaitSync(int32 *params) { // params: none - debug(5, "fnWaitSync: %d waits", _scriptVars[ID]); + debug(6, "fnWaitSync: %d waits", _scriptVars[ID]); - for (int i = 0; i < MAX_syncs; i++) { - if (_syncList[i].id == _scriptVars[ID]) { - // return sync value waiting - debug(5, "fnWaitSync: go"); - _scriptVars[RESULT] = _syncList[i].sync; - return IR_CONT; - } - } + int slot = getSync(); - return IR_REPEAT; + if (slot == -1) + return IR_REPEAT; + + debug(5, "fnWaitSync: %d got sync %d", _scriptVars[ID], _syncList[slot].sync); + _scriptVars[RESULT] = _syncList[slot].sync; + return IR_CONT; } } // End of namespace Sword2 |