diff options
author | Joost Peters | 2004-08-01 19:53:29 +0000 |
---|---|---|
committer | Joost Peters | 2004-08-01 19:53:29 +0000 |
commit | 48cddda4b9728353317def35d0afd5e33f7a5bc1 (patch) | |
tree | 471de8ac2ffa0675a9863d6e3c58c9d3edfcf4fa /saga | |
parent | d60973b05e9c607b46edaa45b56b86953d7d079d (diff) | |
download | scummvm-rg350-48cddda4b9728353317def35d0afd5e33f7a5bc1.tar.gz scummvm-rg350-48cddda4b9728353317def35d0afd5e33f7a5bc1.tar.bz2 scummvm-rg350-48cddda4b9728353317def35d0afd5e33f7a5bc1.zip |
move SDATA_* into seperate class
svn-id: r14424
Diffstat (limited to 'saga')
-rw-r--r-- | saga/interface.cpp | 3 | ||||
-rw-r--r-- | saga/saga.cpp | 3 | ||||
-rw-r--r-- | saga/saga.h | 4 | ||||
-rw-r--r-- | saga/script.cpp | 5 | ||||
-rw-r--r-- | saga/script_mod.h | 6 | ||||
-rw-r--r-- | saga/sdata.cpp | 25 | ||||
-rw-r--r-- | saga/sdata.h | 13 | ||||
-rw-r--r-- | saga/sfuncs.cpp | 56 | ||||
-rw-r--r-- | saga/sthread.cpp | 20 |
9 files changed, 70 insertions, 65 deletions
diff --git a/saga/interface.cpp b/saga/interface.cpp index 380e9be04b..8c674b11dc 100644 --- a/saga/interface.cpp +++ b/saga/interface.cpp @@ -37,6 +37,7 @@ #include "interface_mod.h" #include "interface.h" +#include "sdata.h" namespace Saga { @@ -496,7 +497,7 @@ int HandlePlayfieldClick(R_SURFACE *ds, R_POINT *imouse_pt) { if (object_flags & R_OBJECT_NORMAL) { if (OBJECTMAP_GetEPNum(object_num, &script_num) == R_SUCCESS) { // Set active verb in script module - SDATA_PutWord(4, 4, I_VerbData[IfModule.active_verb].s_verb); + _vm->_sdata->putWord(4, 4, I_VerbData[IfModule.active_verb].s_verb); // Execute object script if present if (script_num != 0) { diff --git a/saga/saga.cpp b/saga/saga.cpp index e7a36a57f4..2c9d60c90d 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -49,6 +49,7 @@ #include "isomap_mod.h" #include "script_mod.h" #include "scene_mod.h" +#include "sdata.h" #include "sndres.h" #include "sprite_mod.h" #include "text_mod.h" @@ -159,6 +160,7 @@ void SagaEngine::go() { OBJECTMAP_Init(); ISOMAP_Init(); SCRIPT_Init(); + _sdata = new SData(); INTERFACE_Init(); // requires script module ACTOR_Init(); @@ -249,6 +251,7 @@ void SagaEngine::shutdown() { delete _render; delete _actionMap; delete _sndRes; + delete _sdata; // Shutdown system modules */ delete _music; delete _sound; diff --git a/saga/saga.h b/saga/saga.h index f93edeabcf..71315360a8 100644 --- a/saga/saga.h +++ b/saga/saga.h @@ -44,6 +44,7 @@ class Anim; class Render; class ActionMap; class Gfx; +class SData; using Common::MemoryReadStream; @@ -93,7 +94,8 @@ public: Render *_render; ActionMap *_actionMap; Gfx *_gfx; - + SData *_sdata; + private: int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len); int flipImage(byte *img_buf, int columns, int scanlines); diff --git a/saga/script.cpp b/saga/script.cpp index 3f268771f0..23fee26124 100644 --- a/saga/script.cpp +++ b/saga/script.cpp @@ -125,11 +125,6 @@ int SCRIPT_Init() { // Initialize script submodules ScriptModule.thread_list = ys_dll_create(); - if (SDATA_Init() != R_SUCCESS) { - free(ScriptModule.script_lut); - return R_FAILURE; - } - ScriptModule.initialized = 1; return R_SUCCESS; } diff --git a/saga/script_mod.h b/saga/script_mod.h index 834e6367c6..ee08bcbd2a 100644 --- a/saga/script_mod.h +++ b/saga/script_mod.h @@ -48,12 +48,6 @@ int SCRIPT_Init(); int SCRIPT_Shutdown(); int SCRIPT_Load(int script_num); int SCRIPT_Free(); -int SDATA_GetWord(int n_buf, int n_word, SDataWord_T *data); -int SDATA_PutWord(int n_buf, int n_word, SDataWord_T data); -int SDATA_SetBit(int n_buf, SDataWord_T n_bit, int bitstate); -int SDATA_GetBit(int n_buf, SDataWord_T n_bit, int *bitstate); -int SDATA_ReadWordS(SDataWord_T word); -uint16 SDATA_ReadWordU(SDataWord_T word); R_SCRIPT_THREAD *STHREAD_Create(); int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num); int STHREAD_ExecThreads(int msec); diff --git a/saga/sdata.cpp b/saga/sdata.cpp index 3374c398bb..35c87e26cc 100644 --- a/saga/sdata.cpp +++ b/saga/sdata.cpp @@ -31,34 +31,33 @@ namespace Saga { -int SDATA_Init() { +SData::SData() { unsigned int i; void *alloc_ptr; - debug(0, "Initializing script data buffers."); + debug(0, "Initializing script data buffers"); for (i = 0; i < R_SCRIPT_DATABUF_NUM; i++) { alloc_ptr = malloc(sizeof *ScriptModule.data_buf[0]); if (alloc_ptr == NULL) { - warning("Error allocating memory for script data buffer %d", i); - return R_MEM; + error("Couldn't allocate memory for script data buffer %d", i); } ScriptModule.data_buf[i] = (R_SCRIPT_DATABUF *)alloc_ptr; alloc_ptr = calloc(R_SCRIPT_DATABUF_LEN, sizeof(SDataWord_T)); if (alloc_ptr == NULL) { - warning("Error allocating memory for script data buffer %d", i); - return R_MEM; + error("Couldn't allocate memory for script data buffer %d", i); } ScriptModule.data_buf[i]->len = R_SCRIPT_DATABUF_LEN; ScriptModule.data_buf[i]->data = (SDataWord_T *)alloc_ptr; } +} - return R_SUCCESS; +SData::~SData() { } -int SDATA_GetWord(int n_buf, int n_word, SDataWord_T * data) { +int SData::getWord(int n_buf, int n_word, SDataWord_T *data) { if ((n_buf < 0) || (n_buf >= R_SCRIPT_DATABUF_NUM)) { return R_FAILURE; } @@ -76,7 +75,7 @@ int SDATA_GetWord(int n_buf, int n_word, SDataWord_T * data) { return R_SUCCESS; } -int SDATA_PutWord(int n_buf, int n_word, SDataWord_T data) { +int SData::putWord(int n_buf, int n_word, SDataWord_T data) { if ((n_buf < 0) || (n_buf >= R_SCRIPT_DATABUF_NUM)) { return R_FAILURE; } @@ -90,7 +89,7 @@ int SDATA_PutWord(int n_buf, int n_word, SDataWord_T data) { return R_SUCCESS; } -int SDATA_SetBit(int n_buf, SDataWord_T n_bit, int bitstate) { +int SData::setBit(int n_buf, SDataWord_T n_bit, int bitstate) { int n_word; int n_bitpos; @@ -118,7 +117,7 @@ int SDATA_SetBit(int n_buf, SDataWord_T n_bit, int bitstate) { return R_SUCCESS; } -int SDATA_GetBit(int n_buf, SDataWord_T n_bit, int *bitstate) { +int SData::getBit(int n_buf, SDataWord_T n_bit, int *bitstate) { int n_word; int n_bitpos; @@ -142,7 +141,7 @@ int SDATA_GetBit(int n_buf, SDataWord_T n_bit, int *bitstate) { return R_SUCCESS; } -int SDATA_ReadWordS(SDataWord_T word) { +int SData::readWordS(SDataWord_T word) { uint16 u_int = word; int s_int; @@ -155,7 +154,7 @@ int SDATA_ReadWordS(SDataWord_T word) { return s_int; } -uint16 SDATA_ReadWordU(SDataWord_T word) { +uint16 SData::readWordU(SDataWord_T word) { uint16 u_int = (uint16) word; return u_int; diff --git a/saga/sdata.h b/saga/sdata.h index a8a8470d3c..335d80e55b 100644 --- a/saga/sdata.h +++ b/saga/sdata.h @@ -31,7 +31,18 @@ namespace Saga { #define R_SCRIPT_DATABUF_NUM 5 #define R_SCRIPT_DATABUF_LEN 1024 -int SDATA_Init(); +class SData { +public: + SData(); + ~SData(); + + int getWord(int n_buf, int n_word, SDataWord_T *data); + int putWord(int n_buf, int n_word, SDataWord_T data); + int setBit(int n_buf, SDataWord_T n_bit, int bitstate); + int getBit(int n_buf, SDataWord_T n_bit, int *bitstate); + int readWordS(SDataWord_T word); + uint16 readWordU(SDataWord_T word); +}; } // End of namespace Saga diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp index 46a70974ad..065a769b9c 100644 --- a/saga/sfuncs.cpp +++ b/saga/sfuncs.cpp @@ -126,7 +126,7 @@ int SF_sleep(R_SCRIPTFUNC_PARAMS) { int time; SSTACK_Pop(thread->stack, &time_param); - time = SDATA_ReadWordU(time_param); + time = _vm->_sdata->readWordU(time_param); thread->sleep_time = time * 10; return R_SUCCESS; } @@ -173,15 +173,15 @@ int SF_actorWalkTo(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &x_parm); SSTACK_Pop(thread->stack, &y_parm); - actor_id = SDATA_ReadWordS(actor_parm); + actor_id = _vm->_sdata->readWordS(actor_parm); actor_idx = ACTOR_GetActorIndex(actor_id); if (actor_idx < 0) { CON_Print(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.", actor_id); return R_FAILURE; } - pt.x = SDATA_ReadWordS(x_parm); - pt.y = SDATA_ReadWordS(y_parm); + pt.x = _vm->_sdata->readWordS(x_parm); + pt.y = _vm->_sdata->readWordS(y_parm); ACTOR_WalkTo(actor_idx, &pt, 0, &thread->sem); @@ -207,8 +207,8 @@ int SF_setFacing(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &actor_parm); SSTACK_Pop(thread->stack, &orient_parm); - actor_id = SDATA_ReadWordS(actor_parm); - orientation = SDATA_ReadWordS(orient_parm); + actor_id = _vm->_sdata->readWordS(actor_parm); + orientation = _vm->_sdata->readWordS(orient_parm); actor_idx = ACTOR_GetActorIndex(actor_id); if (actor_idx < 0) { CON_Print(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.", actor_id); @@ -270,8 +270,8 @@ int SF_startAnim(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &frame_parm); SSTACK_Pop(thread->stack, &unk_parm); - frame_count = SDATA_ReadWordS(frame_parm); - anim_id = SDATA_ReadWordS(anim_id_parm); + frame_count = _vm->_sdata->readWordS(frame_parm); + anim_id = _vm->_sdata->readWordS(anim_id_parm); if (_vm->_anim->play(anim_id, 0) != R_SUCCESS) { CON_Print(S_WARN_PREFIX "SF.26: Anim::play() failed. Anim id: %u\n", anim_id); @@ -298,7 +298,7 @@ int SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &x_parm); SSTACK_Pop(thread->stack, &y_parm); - actor_id = SDATA_ReadWordS(actor_parm); + actor_id = _vm->_sdata->readWordS(actor_parm); actor_idx = ACTOR_GetActorIndex(actor_id); if (actor_idx < 0) { CON_Print(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.", @@ -306,8 +306,8 @@ int SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS) { return R_FAILURE; } - pt.x = SDATA_ReadWordS(x_parm); - pt.y = SDATA_ReadWordS(y_parm); + pt.x = _vm->_sdata->readWordS(x_parm); + pt.y = _vm->_sdata->readWordS(y_parm); ACTOR_WalkTo(actor_idx, &pt, 0, NULL); return R_SUCCESS; @@ -337,9 +337,9 @@ int SF_moveTo(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &x_parm); SSTACK_Pop(thread->stack, &y_parm); - actor_id = SDATA_ReadWordS(actor_parm); - pt.x = SDATA_ReadWordS(x_parm); - pt.y = SDATA_ReadWordS(y_parm); + actor_id = _vm->_sdata->readWordS(actor_parm); + pt.x = _vm->_sdata->readWordS(x_parm); + pt.y = _vm->_sdata->readWordS(y_parm); if (!ACTOR_ActorExists(actor_id)) { result = ACTOR_Create(actor_id, pt.x, pt.y); @@ -380,14 +380,14 @@ int SF_actorWalk(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &y_parm); SSTACK_Pop(thread->stack, &unk_parm); - actor_idx = ACTOR_GetActorIndex(SDATA_ReadWordS(actor_parm)); + actor_idx = ACTOR_GetActorIndex(_vm->_sdata->readWordS(actor_parm)); if (actor_idx < 0) { CON_Print(S_WARN_PREFIX "SF.36: Actor id 0x%X not found.", (int)actor_parm); return R_FAILURE; } - pt.x = SDATA_ReadWordS(x_parm); - pt.y = SDATA_ReadWordS(y_parm); + pt.x = _vm->_sdata->readWordS(x_parm); + pt.y = _vm->_sdata->readWordS(y_parm); #if 1 ACTOR_WalkTo(actor_idx, &pt, 0, NULL); @@ -419,8 +419,8 @@ int SF_cycleActorFrames(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &unk1_parm); SSTACK_Pop(thread->stack, &action_parm); SSTACK_Pop(thread->stack, &unk2_parm); - actor_id = SDATA_ReadWordS(actor_parm); - action = SDATA_ReadWordS(action_parm); + actor_id = _vm->_sdata->readWordS(actor_parm); + action = _vm->_sdata->readWordS(action_parm); actor_idx = ACTOR_GetActorIndex(actor_id); if (ACTOR_SetAction(actor_idx, action, ACTION_NONE) != R_SUCCESS) { @@ -452,8 +452,8 @@ int SF_setFrame(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &action_parm); SSTACK_Pop(thread->stack, &unk1_parm); - actor_id = SDATA_ReadWordS(actor_parm); - action = SDATA_ReadWordS(action_parm); + actor_id = _vm->_sdata->readWordS(actor_parm); + action = _vm->_sdata->readWordS(action_parm); actor_idx = ACTOR_GetActorIndex(actor_id); if (ACTOR_SetAction(actor_idx, action, ACTION_NONE) != R_SUCCESS) { @@ -484,9 +484,9 @@ int SF_linkAnim(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &anim2_parm); SSTACK_Pop(thread->stack, &tframes_parm); SSTACK_Pop(thread->stack, &unk_parm); - tframes = SDATA_ReadWordS(tframes_parm); - anim_id1 = SDATA_ReadWordU(anim1_parm); - anim_id2 = SDATA_ReadWordU(anim2_parm); + tframes = _vm->_sdata->readWordS(tframes_parm); + anim_id1 = _vm->_sdata->readWordU(anim1_parm); + anim_id2 = _vm->_sdata->readWordU(anim2_parm); if (_vm->_anim->link(anim_id1, anim_id2) != R_SUCCESS) { CON_Print(S_WARN_PREFIX "SF.41: Anim::link() failed. (%u->%u)\n", anim_id1, anim_id2); @@ -530,10 +530,10 @@ int SF_placeActor(R_SCRIPTFUNC_PARAMS) { SSTACK_Pop(thread->stack, &action_parm); SSTACK_Pop(thread->stack, &unknown_parm); - actor_id = SDATA_ReadWordS(actor_parm); - pt.x = SDATA_ReadWordS(x_parm); - pt.y = SDATA_ReadWordS(y_parm); - action_state = SDATA_ReadWordU(action_parm); + actor_id = _vm->_sdata->readWordS(actor_parm); + pt.x = _vm->_sdata->readWordS(x_parm); + pt.y = _vm->_sdata->readWordS(y_parm); + action_state = _vm->_sdata->readWordU(action_parm); if (!ACTOR_ActorExists(actor_id)) { result = ACTOR_Create(actor_id, pt.x, pt.y); diff --git a/saga/sthread.cpp b/saga/sthread.cpp index fdd633589b..6fbca7302a 100644 --- a/saga/sthread.cpp +++ b/saga/sthread.cpp @@ -265,26 +265,26 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { case 0x0B: n_buf = readS->readByte(); param1 = (SDataWord_T)readS->readUint16LE(); - SDATA_GetBit(n_buf, param1, &bitstate); + _vm->_sdata->getBit(n_buf, param1, &bitstate); SSTACK_Push(thread->stack, bitstate); break; // Get word (GETW) case 0x0C: n_buf = readS->readByte(); param1 = readS->readUint16LE(); - SDATA_GetWord(n_buf, param1, &data); + _vm->_sdata->getWord(n_buf, param1, &data); SSTACK_Push(thread->stack, data); break; // Modify flag (MODF) case 0x0F: n_buf = readS->readByte(); param1 = (SDataWord_T)readS->readUint16LE(); - bitstate = SDATA_ReadWordU(param1); + bitstate = _vm->_sdata->readWordU(param1); SSTACK_Top(thread->stack, &data); if (bitstate) { - SDATA_SetBit(n_buf, data, 1); + _vm->_sdata->setBit(n_buf, data, 1); } else { - SDATA_SetBit(n_buf, data, 0); + _vm->_sdata->setBit(n_buf, data, 0); } break; // Put word (PUTW) @@ -292,18 +292,18 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { n_buf = readS->readByte(); param1 = (SDataWord_T)readS->readUint16LE(); SSTACK_Top(thread->stack, &data); - SDATA_PutWord(n_buf, param1, data); + _vm->_sdata->putWord(n_buf, param1, data); break; // Modify flag and pop (MDFP) case 0x13: n_buf = readS->readByte(); param1 = (SDataWord_T)readS->readUint16LE(); SSTACK_Pop(thread->stack, ¶m1); - bitstate = SDATA_ReadWordU(param1); + bitstate = _vm->_sdata->readWordU(param1); if (bitstate) { - SDATA_SetBit(n_buf, param1, 1); + _vm->_sdata->setBit(n_buf, param1, 1); } else { - SDATA_SetBit(n_buf, param1, 0); + _vm->_sdata->setBit(n_buf, param1, 0); } break; // Put word and pop (PTWP) @@ -311,7 +311,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { n_buf = readS->readByte(); param1 = (SDataWord_T)readS->readUint16LE(); SSTACK_Top(thread->stack, &data); - SDATA_PutWord(n_buf, param1, data); + _vm->_sdata->putWord(n_buf, param1, data); break; // CONTROL INSTRUCTIONS |