diff options
Diffstat (limited to 'engines/saga/script.h')
-rw-r--r-- | engines/saga/script.h | 92 |
1 files changed, 28 insertions, 64 deletions
diff --git a/engines/saga/script.h b/engines/saga/script.h index 21afeb5c44..e5054d5f4e 100644 --- a/engines/saga/script.h +++ b/engines/saga/script.h @@ -129,16 +129,7 @@ struct EntryPoint { uint16 offset; }; -struct VoiceLUT { - uint16 voicesCount; - uint16 *voices; - void freeMem() { - voicesCount = 0; - free(voices); - } - VoiceLUT() { - memset(this, 0, sizeof(*this)); - } +class VoiceLUT : public Common::Array<uint16> { }; struct ModuleData { @@ -147,28 +138,29 @@ struct ModuleData { int stringsResourceId; int voicesResourceId; - byte *moduleBase; // all base module - uint16 moduleBaseSize; // base module size + ByteArray moduleBase; // all base module uint16 staticSize; // size of static data uint staticOffset; // offset of static data begining in _commonBuffer - - uint16 entryPointsTableOffset; // offset of entrypoint table in moduleBase - uint16 entryPointsCount; - EntryPoint *entryPoints; + Common::Array<EntryPoint> entryPoints; StringsTable strings; VoiceLUT voiceLUT; - void freeMem() { - strings.freeMem(); - voiceLUT.freeMem(); - free(moduleBase); - free(entryPoints); + + void clear() { + loaded = false; + strings.clear(); + voiceLUT.clear(); + moduleBase.clear(); + entryPoints.clear(); + } + + ModuleData() : loaded(false), scriptResourceId(0), stringsResourceId(0), voicesResourceId(0), staticSize(0), staticOffset(0) { } }; class ScriptThread { public: - int16 *_stackBuf; + Common::Array<int16> _stackBuf; uint16 _stackTopIndex; uint16 _frameIndex; @@ -264,41 +256,15 @@ public: } ScriptThread() { - memset(this, 0xFE, sizeof(*this)); - _flags = kTFlagNone; - _stackBuf = 0; - } - - // copy constructor - ScriptThread(const ScriptThread& s) { - // Verify that s doesn't have a non-zero _stackBuf, for else - // we would have to clone that buffer, too, which we currently - // don't do. This case should never occur anyway, though (at - // least as long as the thread handling code does not change). - assert(!s._stackBuf); + memset(&_frameIndex, 0xFE, sizeof(_frameIndex)); + memset(_threadVars, 0xFE, sizeof(_threadVars)); + memset(&_waitType, 0xFE, sizeof(_waitType)); + memset(&_sleepTime, 0xFE, sizeof(_sleepTime)); + memset(&_threadObj, 0xFE, sizeof(_threadObj)); + memset(&_returnValue, 0xFE, sizeof(_threadObj)); + memset(&_frameWait, 0xFE, sizeof(_frameWait)); - memcpy(this, &s, sizeof(*this)); - } - - // assignment operator - ScriptThread& operator=(const ScriptThread &s) { - if (this == &s) - return *this; - - // Verify that s doesn't have a non-zero _stackBuf, for else - // we would have to clone that buffer, too, which we currently - // don't do. This case should never occur anyway, though (at - // least as long as the thread handling code does not change). - assert(!s._stackBuf); - - free(_stackBuf); - memcpy(this, &s, sizeof(*this)); - - return *this; - } - - ~ScriptThread() { - free(_stackBuf); + _flags = kTFlagNone; } }; @@ -315,8 +281,8 @@ public: Script(SagaEngine *vm); virtual ~Script(); - void loadModule(int scriptModuleNumber); - void freeModules(); + void loadModule(uint scriptModuleNumber); + void clearModules(); void doVerb(); void showVerb(int statusColor = -1); @@ -384,13 +350,11 @@ protected: ResourceContext *_dataContext; uint16 _modulesLUTEntryLen; - ModuleData *_modules; - int _modulesCount; + Common::Array<ModuleData> _modules; TextListEntry *_placardTextEntry; friend class SagaEngine; - byte *_commonBuffer; - uint _commonBufferSize; + ByteArray _commonBuffer; uint _staticSize; ScriptThreadList _threadList; @@ -428,10 +392,10 @@ public: void wakeUpThreads(int waitType); void wakeUpThreadsDelayed(int waitType, int sleepTime); - void loadVoiceLUT(VoiceLUT &voiceLUT, const byte *resourcePointer, size_t resourceLength); + void loadVoiceLUT(VoiceLUT &voiceLUT, const ByteArray &resourceData); protected: - void loadModuleBase(ModuleData &module, const byte *resourcePointer, size_t resourceLength); + void loadModuleBase(ModuleData &module, const ByteArray &resourceData); // runThread returns true if we should break running of other threads bool runThread(ScriptThread &thread); |