aboutsummaryrefslogtreecommitdiff
path: root/engines/gob
diff options
context:
space:
mode:
Diffstat (limited to 'engines/gob')
-rw-r--r--engines/gob/draw.cpp5
-rw-r--r--engines/gob/game.cpp13
-rw-r--r--engines/gob/game_v1.cpp50
-rw-r--r--engines/gob/game_v2.cpp4
-rw-r--r--engines/gob/inter_v1.cpp35
-rw-r--r--engines/gob/inter_v6.cpp4
-rw-r--r--engines/gob/script.cpp29
-rw-r--r--engines/gob/script.h14
8 files changed, 86 insertions, 68 deletions
diff --git a/engines/gob/draw.cpp b/engines/gob/draw.cpp
index 5c0cb47352..83266beb3a 100644
--- a/engines/gob/draw.cpp
+++ b/engines/gob/draw.cpp
@@ -391,9 +391,8 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right,
adjustCoords(1, &right, &bottom);
if (READ_LE_UINT16(_vm->_game->_script->getData() + 0x7E) != 0) {
- uint32 startPos = _vm->_game->_script->pos();
+ _vm->_game->_script->call(READ_LE_UINT16(_vm->_game->_script->getData() + 0x7E));
- _vm->_game->_script->seek(READ_LE_UINT16(_vm->_game->_script->getData() + 0x7E));
WRITE_VAR(17, (uint32) id);
WRITE_VAR(18, (uint32) left);
WRITE_VAR(19, (uint32) top);
@@ -401,7 +400,7 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right,
WRITE_VAR(21, (uint32) (bottom - top + 1));
_vm->_inter->funcBlock(0);
- _vm->_game->_script->seek(startPos);
+ _vm->_game->_script->pop();
}
if (str[0] == '\0')
diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp
index 8251219ed1..41cd6145a8 100644
--- a/engines/gob/game.cpp
+++ b/engines/gob/game.cpp
@@ -732,9 +732,7 @@ void Game::setCollisions(byte arg_0) {
if (((collArea->id & 0xC000) != 0x8000) || (collArea->funcSub == 0))
continue;
- uint32 startPos = _script->pos();
-
- _script->seek(collArea->funcSub);
+ _script->call(collArea->funcSub);
left = _script->readValExpr();
top = _script->readValExpr();
@@ -759,16 +757,14 @@ void Game::setCollisions(byte arg_0) {
collArea->right = left + width - 1;
collArea->bottom = top + height - 1;
- _script->seek(startPos);
+ _script->pop();
}
}
void Game::collSub(uint16 offset) {
int16 collStackSize;
- uint32 startPos = _script->pos();
-
- _script->seek(offset);
+ _script->call(offset);
_shouldPushColls = 1;
collStackSize = _collStackSize;
@@ -780,7 +776,8 @@ void Game::collSub(uint16 offset) {
_shouldPushColls = 0;
- _script->seek(startPos);
+ _script->pop();
+
setCollisions();
}
diff --git a/engines/gob/game_v1.cpp b/engines/gob/game_v1.cpp
index c4fbe49bcc..b456e5aaeb 100644
--- a/engines/gob/game_v1.cpp
+++ b/engines/gob/game_v1.cpp
@@ -55,7 +55,7 @@ void Game_v1::playTot(int16 skipPlay) {
int16 *oldBreakFrom = _vm->_inter->_breakFromLevel;
int16 *oldCaptureCounter = _vm->_scenery->_pCaptureCounter;
- uint32 startPos = _script->pos();
+ _script->push();
_vm->_inter->_nestLevel = &nestLevel;
_vm->_inter->_breakFromLevel = &breakFrom;
@@ -242,7 +242,7 @@ void Game_v1::playTot(int16 skipPlay) {
_vm->_inter->_breakFromLevel = oldBreakFrom;
_vm->_scenery->_pCaptureCounter = oldCaptureCounter;
- _script->seek(startPos);
+ _script->pop();
}
void Game_v1::clearCollisions() {
@@ -358,13 +358,9 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
_lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex);
if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) {
- uint32 startPos = _script->pos();
-
- _script->seek(_collisionAreas[_lastCollAreaIndex].funcEnter);
-
+ _script->call(_collisionAreas[_lastCollAreaIndex].funcEnter);
_vm->_inter->funcBlock(0);
-
- _script->seek(startPos);
+ _script->pop();
}
}
@@ -426,13 +422,9 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if ((_lastCollKey != 0) &&
(_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) {
- uint32 startPos = _script->pos();
-
- _script->seek(_collisionAreas[_lastCollAreaIndex].funcLeave);
-
+ _script->call(_collisionAreas[_lastCollAreaIndex].funcLeave);
_vm->_inter->funcBlock(0);
-
- _script->seek(startPos);
+ _script->pop();
}
_lastCollKey = 0;
@@ -467,13 +459,11 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if ((_lastCollKey != 0) &&
(_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) {
- uint32 startPos = _script->pos();
-
- _script->seek(_collisionAreas[_lastCollAreaIndex].funcLeave);
+ _script->call(_collisionAreas[_lastCollAreaIndex].funcLeave);
_vm->_inter->funcBlock(0);
+ _script->pop();
- _script->seek(startPos);
}
_lastCollKey = 0;
return key;
@@ -481,26 +471,22 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if ((_lastCollKey != 0) &&
(_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) {
- uint32 startPos = _script->pos();
-
- _script->seek(_collisionAreas[_lastCollAreaIndex].funcLeave);
+ _script->call(_collisionAreas[_lastCollAreaIndex].funcLeave);
_vm->_inter->funcBlock(0);
+ _script->pop();
- _script->seek(startPos);
}
_lastCollKey =
checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex);
if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) {
- uint32 startPos = _script->pos();
-
- _script->seek(_collisionAreas[_lastCollAreaIndex].funcEnter);
+ _script->call(_collisionAreas[_lastCollAreaIndex].funcEnter);
_vm->_inter->funcBlock(0);
+ _script->pop();
- _script->seek(startPos);
}
} else {
@@ -514,24 +500,20 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if (key != _lastCollKey) {
if ((_lastCollKey != 0) && ((oldId & 0x8000) != 0)) {
- uint32 startPos = _script->pos();
-
- _script->seek(_collisionAreas[oldIndex].funcLeave);
+ _script->call(_collisionAreas[oldIndex].funcLeave);
_vm->_inter->funcBlock(0);
+ _script->pop();
- _script->seek(startPos);
}
_lastCollKey = key;
if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) {
- uint32 startPos = _script->pos();
-
- _script->seek(_collisionAreas[_lastCollAreaIndex].funcEnter);
+ _script->call(_collisionAreas[_lastCollAreaIndex].funcEnter);
_vm->_inter->funcBlock(0);
+ _script->pop();
- _script->seek(startPos);
}
}
diff --git a/engines/gob/game_v2.cpp b/engines/gob/game_v2.cpp
index 4ed9a49e8c..b9cda4832a 100644
--- a/engines/gob/game_v2.cpp
+++ b/engines/gob/game_v2.cpp
@@ -62,7 +62,7 @@ void Game_v2::playTot(int16 skipPlay) {
oldBreakFrom = _vm->_inter->_breakFromLevel;
oldCaptureCounter = _vm->_scenery->_pCaptureCounter;
- uint32 startPos = _script->pos();
+ _script->push();
_vm->_inter->_nestLevel = &nestLevel;
_vm->_inter->_breakFromLevel = &breakFrom;
@@ -293,7 +293,7 @@ void Game_v2::playTot(int16 skipPlay) {
_vm->_inter->_breakFromLevel = oldBreakFrom;
_vm->_scenery->_pCaptureCounter = oldCaptureCounter;
- _script->seek(startPos);
+ _script->pop();
}
void Game_v2::clearCollisions() {
diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp
index bf24e8ef28..5cb74f2854 100644
--- a/engines/gob/inter_v1.cpp
+++ b/engines/gob/inter_v1.cpp
@@ -638,11 +638,7 @@ void Inter_v1::o1_freeFontToSprite() {
}
bool Inter_v1::o1_callSub(OpFuncParams &params) {
- uint16 offset;
-
- offset = _vm->_game->_script->readUint16();
-
- uint32 startPos = _vm->_game->_script->pos();
+ uint16 offset = _vm->_game->_script->readUint16();
debugC(5, kDebugGameFlow, "tot = \"%s\", offset = %d",
_vm->_game->_curTotFile, offset);
@@ -666,14 +662,16 @@ bool Inter_v1::o1_callSub(OpFuncParams &params) {
return false;
}
- _vm->_game->_script->seek(offset);
+ _vm->_game->_script->call(offset);
- if ((params.counter == params.cmdCount) && (params.retFlag == 2))
+ if ((params.counter == params.cmdCount) && (params.retFlag == 2)) {
+ _vm->_game->_script->pop(false);
return true;
+ }
callSub(2);
- _vm->_game->_script->seek(startPos);
+ _vm->_game->_script->pop();
return false;
}
@@ -714,17 +712,19 @@ bool Inter_v1::o1_switch(OpFuncParams &params) {
checkSwitchTable(offset);
- uint32 startPos = _vm->_game->_script->pos();
+ _vm->_game->_script->call(offset);
- _vm->_game->_script->seek(offset);
if (offset == 0)
_vm->_game->_script->setFinished(true);
- if ((params.counter == params.cmdCount) && (params.retFlag == 2))
+ if ((params.counter == params.cmdCount) && (params.retFlag == 2)) {
+ _vm->_game->_script->pop(false);
return true;
+ }
funcBlock(0);
- _vm->_game->_script->seek(startPos);
+
+ _vm->_game->_script->pop();
return false;
}
@@ -804,10 +804,9 @@ bool Inter_v1::o1_if(OpFuncParams &params) {
if ((params.counter == params.cmdCount) && (params.retFlag == 2))
return true;
- uint32 startPos = _vm->_game->_script->pos();
+ _vm->_game->_script->push();
funcBlock(0);
-
- _vm->_game->_script->seek(startPos);
+ _vm->_game->_script->pop();
_vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
@@ -830,11 +829,9 @@ bool Inter_v1::o1_if(OpFuncParams &params) {
if ((params.counter == params.cmdCount) && (params.retFlag == 2))
return true;
- uint32 startPos = _vm->_game->_script->pos();
-
+ _vm->_game->_script->push();
funcBlock(0);
-
- _vm->_game->_script->seek(startPos);
+ _vm->_game->_script->pop();
_vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
}
diff --git a/engines/gob/inter_v6.cpp b/engines/gob/inter_v6.cpp
index 1fc073d2ff..5b94fe91c4 100644
--- a/engines/gob/inter_v6.cpp
+++ b/engines/gob/inter_v6.cpp
@@ -263,14 +263,14 @@ bool Inter_v6::o6_assign(OpFuncParams &params) {
if (size != 0) {
int16 src;
- uint32 startPos = _vm->_game->_script->pos();
+ _vm->_game->_script->push();
src = _vm->_game->_script->readVarIndex(&size, 0);
memcpy(_vm->_inter->_variables->getAddressOff8(dest),
_vm->_inter->_variables->getAddressOff8(src), size * 4);
- _vm->_game->_script->seek(startPos);
+ _vm->_game->_script->pop();
evalExpr(&src);
diff --git a/engines/gob/script.cpp b/engines/gob/script.cpp
index f731ed33e9..e068ae5ff3 100644
--- a/engines/gob/script.cpp
+++ b/engines/gob/script.cpp
@@ -358,4 +358,33 @@ void Script::cuckoo(byte *totData, uint32 totSize) {
_totSize = totSize;
}
+void Script::push() {
+ CallEntry currentCall;
+
+ currentCall.totData = _totData;
+ currentCall.totPtr = _totPtr;
+ currentCall.totSize = _totSize;
+ currentCall.finished = _finished;
+
+ _callStack.push(currentCall);
+}
+
+void Script::pop(bool ret) {
+ assert(!_callStack.empty());
+
+ CallEntry lastCall = _callStack.pop();
+
+ if (ret) {
+ _totData = lastCall.totData;
+ _totPtr = lastCall.totPtr;
+ _totSize = lastCall.totSize;
+ _finished = lastCall.finished;
+ }
+}
+
+void Script::call(uint32 offset) {
+ push();
+ seek(offset);
+}
+
} // End of namespace Gob
diff --git a/engines/gob/script.h b/engines/gob/script.h
index c88d284e82..5c689bd991 100644
--- a/engines/gob/script.h
+++ b/engines/gob/script.h
@@ -27,6 +27,7 @@
#define GOB_SCRIPT_H
#include "common/str.h"
+#include "common/stack.h"
namespace Gob {
@@ -89,6 +90,10 @@ public:
void cuckoo(byte *totData, uint32 totSize);
+ void push();
+ void pop(bool ret = true);
+ void call(uint32 offset);
+
/* byte *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight, uint32 *dataSize = 0);
byte *loadTotResource(int16 id, int16 *dataSize = 0, int16 *width = 0, int16 *height = 0);
@@ -100,6 +105,13 @@ public:
int16 openLocTextFile(char *locTextFile, int language);*/
private:
+ struct CallEntry {
+ byte *totData;
+ byte *totPtr;
+ uint32 totSize;
+ bool finished;
+ };
+
GobEngine *_vm;
Parse *_parser;
@@ -115,6 +127,8 @@ private:
int16 _lomHandle;
+ Common::Stack<CallEntry> _callStack;
+
bool loadTOT(const Common::String &fileName);
bool loadLOM(const Common::String &fileName);