mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 12:39:56 +00:00
Implemented a call stack
svn-id: r41754
This commit is contained in:
parent
962fc19b57
commit
7fbad08fd1
@ -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')
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -638,11 +638,7 @@ void Inter_v1::o1_freeFontToSprite() {
|
||||
}
|
||||
|
||||
bool Inter_v1::o1_callSub(OpFuncParams ¶ms) {
|
||||
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 ¶ms) {
|
||||
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 ¶ms) {
|
||||
|
||||
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 ¶ms) {
|
||||
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 ¶ms) {
|
||||
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);
|
||||
}
|
||||
|
@ -263,14 +263,14 @@ bool Inter_v6::o6_assign(OpFuncParams ¶ms) {
|
||||
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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user