diff options
-rw-r--r-- | engines/cine/cine.cpp | 1 | ||||
-rw-r--r-- | engines/cine/object.cpp | 2 | ||||
-rw-r--r-- | engines/cine/object.h | 4 | ||||
-rw-r--r-- | engines/cine/prc.h | 2 | ||||
-rw-r--r-- | engines/cine/script.cpp | 84 | ||||
-rw-r--r-- | engines/cine/script.h | 24 | ||||
-rw-r--r-- | engines/cine/various.cpp | 27 |
7 files changed, 115 insertions, 29 deletions
diff --git a/engines/cine/cine.cpp b/engines/cine/cine.cpp index 9c7caa6562..5633df82af 100644 --- a/engines/cine/cine.cpp +++ b/engines/cine/cine.cpp @@ -129,7 +129,6 @@ void CineEngine::initialize() { } memset(objectTable, 0, sizeof(objectTable)); - memset(globalVars, 0, sizeof(globalVars)); memset(scriptTable, 0, sizeof(scriptTable)); memset(messageTable, 0, sizeof(messageTable)); memset(relTable, 0, sizeof(relTable)); diff --git a/engines/cine/object.cpp b/engines/cine/object.cpp index 23d00e7e16..59adae6fc9 100644 --- a/engines/cine/object.cpp +++ b/engines/cine/object.cpp @@ -36,7 +36,7 @@ namespace Cine { objectStruct objectTable[NUM_MAX_OBJECT]; -uint16 globalVars[NUM_MAX_VAR]; +ScriptVars globalVars(NUM_MAX_VAR); overlayHeadElement overlayHead; void unloadAllMasks(void) { diff --git a/engines/cine/object.h b/engines/cine/object.h index 9dc5dfc7e4..92b3111841 100644 --- a/engines/cine/object.h +++ b/engines/cine/object.h @@ -26,6 +26,8 @@ #ifndef CINE_OBJECT_H #define CINE_OBJECT_H +#include "script.h" + namespace Cine { struct objectStruct { @@ -53,7 +55,7 @@ struct overlayHeadElement { #define NUM_MAX_VAR 256 extern objectStruct objectTable[NUM_MAX_OBJECT]; -extern uint16 globalVars[NUM_MAX_VAR]; +extern ScriptVars globalVars; extern overlayHeadElement overlayHead; diff --git a/engines/cine/prc.h b/engines/cine/prc.h index 4bed589c0b..2ec4ed6f95 100644 --- a/engines/cine/prc.h +++ b/engines/cine/prc.h @@ -31,7 +31,7 @@ namespace Cine { struct prcLinkedListStruct { struct prcLinkedListStruct *next; int16 stack[SCRIPT_STACK_SIZE]; - int16 localVars[50]; + ScriptVars localVars; uint16 compareResult; uint16 scriptPosition; byte *scriptPtr; diff --git a/engines/cine/script.cpp b/engines/cine/script.cpp index f4579a1365..c1bfee317a 100644 --- a/engines/cine/script.cpp +++ b/engines/cine/script.cpp @@ -453,6 +453,86 @@ const char *getNextString() { return val; } +// empty array +ScriptVars::ScriptVars(unsigned int len) : _size(len), _vars(new int16[len]) { + assert(_vars); + reset(); +} + +// read game save, for later use +ScriptVars::ScriptVars(Common::InSaveFile &fHandle, unsigned int len) + : _size(len), _vars(new int16[len]) { + + assert(_vars); + + load(fHandle); +} + +// copy constructor +ScriptVars::ScriptVars(const ScriptVars &src) : _size(src._size), _vars(new int16[_size]) { + assert(_vars); + memcpy(_vars, src._vars, _size * sizeof(int16)); +} + +ScriptVars::~ScriptVars(void) { + delete[] _vars; +} + +ScriptVars &ScriptVars::operator=(const ScriptVars &src) { + ScriptVars tmp(src); + int16 *tmpvars = _vars; + + _vars = tmp._vars; + tmp._vars = tmpvars; + _size = src._size; + + return *this; +} + +// array access +int16 &ScriptVars::operator[](unsigned int idx) { + debugN(5, "assert(%d < %d)", idx, _size); + assert(idx < _size); + return _vars[idx]; +} + +int16 ScriptVars::operator[](unsigned int idx) const { + debugN(5, "assert(%d < %d)\n", idx, _size); + assert(idx < _size); + return _vars[idx]; +} + +// dump to savefile +void ScriptVars::save(Common::OutSaveFile &fHandle) { + save(fHandle, _size); +} + +// globalVars[255] is not written to savefiles... +void ScriptVars::save(Common::OutSaveFile &fHandle, unsigned int len) { + debugN(5, "assert(%d <= %d)\n", len, _size); + assert(len <= _size); + for (unsigned int i = 0; i < len; i++) { + fHandle.writeUint16BE(_vars[i]); + } +} + +// read from savefile +void ScriptVars::load(Common::InSaveFile &fHandle) { + load(fHandle, _size); +} + +void ScriptVars::load(Common::InSaveFile &fHandle, unsigned int len) { + debugN(5, "assert(%d <= %d)\n", len, _size); + assert(len <= _size); + for (unsigned int i = 0; i < len; i++) { + _vars[i] = fHandle.readUint16BE(); + } +} + +void ScriptVars::reset(void) { + memset( _vars, 0, _size * sizeof(int16)); +} + void addGfxElementA0(int16 param1, int16 param2) { overlayHeadElement *currentHead = &overlayHead; overlayHeadElement *tempHead = currentHead; @@ -661,10 +741,6 @@ void addScriptToList0(uint16 idx) { pNewElement->stack[i] = scriptTable[idx].stack[i]; } - for (i = 0; i < 50; i++) { - pNewElement->localVars[i] = 0; - } - pNewElement->compareResult = 0; pNewElement->scriptPosition = 0; diff --git a/engines/cine/script.h b/engines/cine/script.h index 2f39169a20..b6f3c79219 100644 --- a/engines/cine/script.h +++ b/engines/cine/script.h @@ -26,10 +26,34 @@ #ifndef CINE_SCRIPT_H #define CINE_SCRIPT_H +#include "common/savefile.h" + namespace Cine { #define SCRIPT_STACK_SIZE 50 +class ScriptVars { +private: + unsigned int _size; + int16 *_vars; + +public: + explicit ScriptVars(unsigned int len = 50); + ScriptVars(Common::InSaveFile &fHandle, unsigned int len = 50); + ScriptVars(const ScriptVars &src); + ~ScriptVars(void); + + ScriptVars &operator=(const ScriptVars &src); + int16 &operator[](unsigned int idx); + int16 operator[](unsigned int idx) const; + + void save(Common::OutSaveFile &fHandle); + void save(Common::OutSaveFile &fHandle, unsigned int len); + void load(Common::InSaveFile &fHandle); + void load(Common::InSaveFile &fHandle, unsigned int len); + void reset(void); +}; + struct ScriptStruct { byte *ptr; uint16 size; diff --git a/engines/cine/various.cpp b/engines/cine/various.cpp index ed12d0429f..f81aed92fd 100644 --- a/engines/cine/various.cpp +++ b/engines/cine/various.cpp @@ -170,10 +170,6 @@ void runObjectScript(int16 entryIdx) { pNewElement->stack[i] = 0; } - for (i = 0; i < 50; i++) { - pNewElement->localVars[i] = 0; - } - pNewElement->compareResult = 0; pNewElement->scriptPosition = 0; @@ -328,8 +324,7 @@ void loadScriptFromSave(Common::InSaveFile *fHandle, bool isGlobal) { for (i = 0; i < SCRIPT_STACK_SIZE; i++) newElement->stack[i] = fHandle->readUint16BE(); - for (i = 0; i < 50; i++) - newElement->localVars[i] = fHandle->readUint16BE(); + newElement->localVars.load(*fHandle); newElement->compareResult = fHandle->readUint16BE(); newElement->scriptPosition = fHandle->readUint16BE(); @@ -454,9 +449,7 @@ bool CineEngine::makeLoad(char *saveName) { objectTable[i].costume = 0; } - for (i = 0; i < 255; i++) { - globalVars[i] = 0; - } + globalVars.reset(); var2 = var3 = var4 = var5 = 0; @@ -519,9 +512,7 @@ bool CineEngine::makeLoad(char *saveName) { tempPalette[i] = fHandle->readUint16BE(); } - for (i = 0; i < 255; i++) { - globalVars[i] = fHandle->readUint16BE(); - } + globalVars.load(*fHandle, NUM_MAX_VAR - 1); for (i = 0; i < 16; i++) { zoneData[i] = fHandle->readUint16BE(); @@ -682,9 +673,7 @@ void makeSave(char *saveFileName) { fHandle->writeUint16BE(tempPalette[i]); } - for (i = 0; i < 255; i++) { - fHandle->writeUint16BE(globalVars[i]); - } + globalVars.save(*fHandle, NUM_MAX_VAR - 1); for (i = 0; i < 16; i++) { fHandle->writeUint16BE(zoneData[i]); @@ -756,9 +745,7 @@ void makeSave(char *saveFileName) { fHandle->writeUint16BE(currentHead->stack[i]); } - for (i = 0; i < 50; i++) { - fHandle->writeUint16BE(currentHead->localVars[i]); - } + currentHead->localVars.save(*fHandle); fHandle->writeUint16BE(currentHead->compareResult); fHandle->writeUint16BE(currentHead->scriptPosition); @@ -787,9 +774,7 @@ void makeSave(char *saveFileName) { fHandle->writeUint16BE(currentHead->stack[i]); } - for (i = 0; i < 50; i++) { - fHandle->writeUint16BE(currentHead->localVars[i]); - } + currentHead->localVars.save(*fHandle); fHandle->writeUint16BE(currentHead->compareResult); fHandle->writeUint16BE(currentHead->scriptPosition); |