aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--saga/actor.cpp16
-rw-r--r--saga/input.cpp3
-rw-r--r--saga/interface.cpp6
-rw-r--r--saga/interface.h2
-rw-r--r--saga/saga.cpp5
-rw-r--r--saga/scene.cpp7
-rw-r--r--saga/script.cpp10
-rw-r--r--saga/script.h104
-rw-r--r--saga/script_mod.h56
-rw-r--r--saga/sdata.cpp1
-rw-r--r--saga/sdata.h3
-rw-r--r--saga/sdebug.cpp18
-rw-r--r--saga/sfuncs.cpp230
-rw-r--r--saga/sfuncs.h81
-rw-r--r--saga/sthread.cpp83
-rw-r--r--saga/sthread.h63
16 files changed, 293 insertions, 395 deletions
diff --git a/saga/actor.cpp b/saga/actor.cpp
index 69f29393bd..5e6530f50b 100644
--- a/saga/actor.cpp
+++ b/saga/actor.cpp
@@ -29,7 +29,7 @@
#include "saga/cvar_mod.h"
#include "saga/console.h"
#include "saga/rscfile_mod.h"
-#include "saga/script_mod.h"
+#include "saga/script.h"
#include "saga/sndres.h"
#include "saga/sprite.h"
#include "saga/font.h"
@@ -282,7 +282,7 @@ int Actor::skipDialogue() {
if (a_dnode != NULL) {
a_dialogue = (R_ACTORDIALOGUE *)ys_dll_get_data(a_dnode);
if (a_dialogue->d_sem != NULL) {
- STHREAD_ReleaseSem(a_dialogue->d_sem);
+ _vm->_script->SThreadReleaseSem(a_dialogue->d_sem);
}
ys_dll_delete(a_dnode);
// And stop any currently playing voices
@@ -471,7 +471,7 @@ int Actor::speak(int index, const char *d_string, uint16 d_voice_rn, R_SEMAPHORE
}
if (sem != NULL) {
- STHREAD_HoldSem(sem);
+ _vm->_script->SThreadHoldSem(sem);
}
return R_SUCCESS;
@@ -513,7 +513,7 @@ int Actor::handleSpeakIntent(R_ACTOR *actor, R_SPEAKINTENT *a_speakint, int *com
//actor->action = ACTION_IDLE;
if (a_dialogue->d_sem != NULL) {
- STHREAD_ReleaseSem(a_dialogue->d_sem);
+ _vm->_script->SThreadReleaseSem(a_dialogue->d_sem);
}
carry_time = a_dialogue->d_time;
@@ -770,7 +770,7 @@ int Actor::walkTo(int id, R_POINT *walk_pt, uint16 flags, R_SEMAPHORE *sem) {
ys_dll_add_tail(actor->a_intentlist, &actor_intent, sizeof actor_intent);
if (sem != NULL) {
- STHREAD_HoldSem(sem);
+ _vm->_script->SThreadHoldSem(sem);
}
return R_SUCCESS;
@@ -848,7 +848,7 @@ int Actor::handleWalkIntent(R_ACTOR *actor, R_WALKINTENT *a_walkint, int *comple
// Release path semaphore
if ((a_walkint->sem != NULL) && a_walkint->sem_held) {
- STHREAD_ReleaseSem(a_walkint->sem);
+ _vm->_script->SThreadReleaseSem(a_walkint->sem);
}
*complete_p = 1;
@@ -915,7 +915,7 @@ int Actor::handleWalkIntent(R_ACTOR *actor, R_WALKINTENT *a_walkint, int *comple
// Release path semaphore
if (a_walkint->sem != NULL) {
- STHREAD_ReleaseSem(a_walkint->sem);
+ _vm->_script->SThreadReleaseSem(a_walkint->sem);
}
actor->action_frame = 0;
@@ -931,7 +931,7 @@ int Actor::handleWalkIntent(R_ACTOR *actor, R_WALKINTENT *a_walkint, int *comple
// Release path semaphore
if (a_walkint->sem != NULL) {
- STHREAD_ReleaseSem(a_walkint->sem);
+ _vm->_script->SThreadReleaseSem(a_walkint->sem);
}
actor->action_frame = 0;
diff --git a/saga/input.cpp b/saga/input.cpp
index 9a4188849d..cc1db9bd45 100644
--- a/saga/input.cpp
+++ b/saga/input.cpp
@@ -28,6 +28,7 @@
#include "saga/interface.h"
#include "saga/render.h"
#include "saga/scene.h"
+#include "saga/script.h"
namespace Saga {
@@ -90,7 +91,7 @@ int SagaEngine::processInput() {
_vm->_render->toggleFlag(RF_OBJECTMAP_TEST);
break;
case 9: // Tab
- STHREAD_DebugStep();
+ _vm->_script->SThreadDebugStep();
break;
// Actual game keys
diff --git a/saga/interface.cpp b/saga/interface.cpp
index a87957b818..f16dd19e50 100644
--- a/saga/interface.cpp
+++ b/saga/interface.cpp
@@ -32,7 +32,7 @@
#include "saga/font.h"
#include "saga/objectmap.h"
#include "saga/rscfile_mod.h"
-#include "saga/script_mod.h"
+#include "saga/script.h"
#include "saga/sprite.h"
#include "saga/interface.h"
@@ -142,7 +142,7 @@ Interface::Interface(SagaEngine *vm) : _vm(vm), _initialized(false) {
return;
}
- _iThread = STHREAD_Create();
+ _iThread = _vm->_script->SThreadCreate();
if (_iThread == NULL) {
warning("Interface::Interface(): Error creating script thread for game interface module");
return;
@@ -504,7 +504,7 @@ int Interface::handlePlayfieldClick(R_SURFACE *ds, R_POINT *imouse_pt) {
// Execute object script if present
if (script_num != 0) {
- STHREAD_Execute(_iThread, script_num);
+ _vm->_script->SThreadExecute(_iThread, script_num);
}
}
} else {
diff --git a/saga/interface.h b/saga/interface.h
index 83a9df85ee..3876396b04 100644
--- a/saga/interface.h
+++ b/saga/interface.h
@@ -27,7 +27,7 @@
#define SAGA_INTERFACE_H__
#include "saga/sprite.h"
-#include "saga/script_mod.h"
+#include "saga/script.h"
namespace Saga {
diff --git a/saga/saga.cpp b/saga/saga.cpp
index a8987af35c..df755caf3d 100644
--- a/saga/saga.cpp
+++ b/saga/saga.cpp
@@ -47,7 +47,6 @@
#include "saga/interface.h"
#include "saga/isomap.h"
#include "saga/script.h"
-#include "saga/script_mod.h"
#include "saga/scene.h"
#include "saga/sdata.h"
#include "saga/sndres.h"
@@ -228,8 +227,8 @@ void SagaEngine::go() {
msec = R_MAX_TIME_DELTA;
}
_actor->direct(msec);
- _vm->_events->handleEvents(msec);
- STHREAD_ExecThreads(msec);
+ _events->handleEvents(msec);
+ _script->SThreadExecThreads(msec);
}
// Per frame processing
_render->drawScene();
diff --git a/saga/scene.cpp b/saga/scene.cpp
index 35cfa99066..66bf9faaff 100644
--- a/saga/scene.cpp
+++ b/saga/scene.cpp
@@ -33,7 +33,6 @@
#include "saga/events.h"
#include "saga/actionmap.h"
#include "saga/isomap.h"
-#include "saga/script_mod.h"
#include "saga/objectmap.h"
#include "saga/palanim.h"
#include "saga/render.h"
@@ -953,13 +952,13 @@ int Scene::defaultScene(int param, R_SCENE_INFO *scene_info) {
debug(0, "Starting start script #%d", _desc.startScriptNum);
- _startScriptThread= STHREAD_Create();
+ _startScriptThread = _vm->_script->SThreadCreate();
if (_startScriptThread == NULL) {
_vm->_console->print("Thread creation failed.");
break;
}
- STHREAD_Execute(_startScriptThread, _desc.startScriptNum);
- STHREAD_completeThread();
+ _vm->_script->SThreadExecute(_startScriptThread, _desc.startScriptNum);
+ _vm->_script->SThreadCompleteThread();
}
debug(0, "Scene started");
diff --git a/saga/script.cpp b/saga/script.cpp
index f87fedc72b..bcb2170f63 100644
--- a/saga/script.cpp
+++ b/saga/script.cpp
@@ -31,9 +31,7 @@
#include "saga/console.h"
#include "saga/cvar_mod.h"
-#include "saga/script_mod.h"
#include "saga/script.h"
-#include "saga/sthread.h"
namespace Saga {
@@ -129,6 +127,8 @@ Script::Script() {
// Initialize script submodules
_threadList = ys_dll_create();
+ setupScriptFuncList();
+
_initialized = true;
}
@@ -151,7 +151,7 @@ Script::~Script() {
for (thread_node = ys_dll_head(_threadList); thread_node != NULL;
thread_node = ys_dll_next(thread_node)) {
thread = (R_SCRIPT_THREAD *)ys_dll_get_data(thread_node);
- STHREAD_Destroy(thread);
+ SThreadDestroy(thread);
}
_initialized = false;
@@ -520,7 +520,7 @@ void Script::scriptExec(int argc, char *argv[]) {
if (_dbg_thread == NULL) {
_vm->_console->print("Creating debug thread...");
- _dbg_thread = STHREAD_Create();
+ _dbg_thread = SThreadCreate();
if (_dbg_thread == NULL) {
_vm->_console->print("Thread creation failed.");
return;
@@ -532,7 +532,7 @@ void Script::scriptExec(int argc, char *argv[]) {
return;
}
- STHREAD_Execute(_dbg_thread, ep_num);
+ SThreadExecute(_dbg_thread, ep_num);
}
void CF_script_info(int argc, char *argv[], void *refCon) {
diff --git a/saga/script.h b/saga/script.h
index 69a2788285..46ef3b5f9b 100644
--- a/saga/script.h
+++ b/saga/script.h
@@ -26,12 +26,15 @@
#ifndef SAGA_SCRIPT_H
#define SAGA_SCRIPT_H
-#include "saga/sdata.h"
#include "saga/text.h"
#include "saga/yslib.h"
+#include "common/stack.h"
namespace Saga {
+#define R_SCRIPT_DATABUF_NUM 5
+#define R_SCRIPT_DATABUF_LEN 1024
+
#define R_S_LUT_ENTRYLEN_ITECD 22
#define R_S_LUT_ENTRYLEN_ITEDISK 16
@@ -47,6 +50,41 @@ namespace Saga {
#define S_ERROR_PREFIX "SError: "
#define S_WARN_PREFIX "SWarning: "
+#define R_SFUNC_NUM 78
+
+typedef unsigned int SDataWord_T;
+
+enum R_SCRIPT_VERBS {
+ S_VERB_WALKTO = 0,
+ S_VERB_LOOKAT = 2,
+ S_VERB_PICKUP = 1,
+ S_VERB_TALKTO,
+ S_VERB_OPEN = 5,
+ S_VERB_CLOSE = 6,
+ S_VERB_USE = 8,
+ S_VERB_GIVE
+};
+
+#define STHREAD_DEF_INSTR_COUNT 8
+
+struct R_SEMAPHORE {
+ int hold_count;
+};
+
+struct R_SCRIPT_THREAD_tag {
+ int executing;
+
+ int sleep_time;
+ int ep_num; // Entrypoint number
+ unsigned long ep_offset; // Entrypoint offset
+ unsigned long i_offset; // Instruction offset
+
+ R_SEMAPHORE sem;
+ Common::Stack<SDataWord_T> *stack;
+};
+
+typedef struct R_SCRIPT_THREAD_tag R_SCRIPT_THREAD;
+
struct R_PROC_TBLENTRY {
size_t name_offset;
size_t offset;
@@ -89,6 +127,7 @@ struct R_SCRIPT_DATABUF {
int len;
};
+#define R_SCRIPTFUNC_PARAMS R_SCRIPT_THREAD *thread
class Script {
public:
@@ -129,6 +168,69 @@ public:
int _dbg_dostep;
R_SCRIPT_THREAD *_dbg_thread;
R_TEXTLIST_ENTRY *_dbg_txtentry;
+
+public:
+ R_SCRIPT_THREAD *SThreadCreate();
+ int SThreadExecute(R_SCRIPT_THREAD *thread, int ep_num);
+ int SThreadExecThreads(int msec);
+ int SThreadHoldSem(R_SEMAPHORE *sem);
+ int SThreadReleaseSem(R_SEMAPHORE *sem);
+ int SThreadDebugStep();
+ void SThreadCompleteThread(void);
+ int SThreadDestroy(R_SCRIPT_THREAD *thread);
+
+private:
+ unsigned char *SThreadGetReadPtr(R_SCRIPT_THREAD *thread);
+ unsigned long SThreadGetReadOffset(const byte *read_p);
+ size_t SThreadGetReadLen(R_SCRIPT_THREAD *thread);
+ int SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec);
+ int SThreadSetEntrypoint(R_SCRIPT_THREAD *thread, int ep_num);
+
+private:
+ typedef int (Script::*SFunc_T)(R_SCRIPTFUNC_PARAMS);
+
+ struct R_SFUNC_ENTRY {
+ int sfunc_num;
+ int sfunc_argc;
+ SFunc_T sfunc_fp;
+ };
+
+ const R_SFUNC_ENTRY *_SFuncList;
+
+ void setupScriptFuncList(void);
+ int SDebugPrintInstr(R_SCRIPT_THREAD *thread);
+
+ int SF_sleep(R_SCRIPTFUNC_PARAMS);
+ int SF_3(R_SCRIPTFUNC_PARAMS);
+ int SF_setCommandText(R_SCRIPTFUNC_PARAMS);
+ int SF_actorWalkTo(R_SCRIPTFUNC_PARAMS);
+ int SF_setFacing(R_SCRIPTFUNC_PARAMS);
+ int SF_freezeInterface(R_SCRIPTFUNC_PARAMS);
+ int SF_startAnim(R_SCRIPTFUNC_PARAMS);
+ int SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS);
+ int SF_moveTo(R_SCRIPTFUNC_PARAMS);
+ int SF_actorWalk(R_SCRIPTFUNC_PARAMS);
+ int SF_cycleActorFrames(R_SCRIPTFUNC_PARAMS);
+ int SF_setFrame(R_SCRIPTFUNC_PARAMS);
+ int SF_linkAnim(R_SCRIPTFUNC_PARAMS);
+ int SF_placeActor(R_SCRIPTFUNC_PARAMS);
+ int SF_checkUserInterrupt(R_SCRIPTFUNC_PARAMS);
+ int SF_moveRelative(R_SCRIPTFUNC_PARAMS);
+ int SF_doAction(R_SCRIPTFUNC_PARAMS);
+ int SF_faceTowards(R_SCRIPTFUNC_PARAMS);
+ int SF_setFollower(R_SCRIPTFUNC_PARAMS);
+ int SF_centerActor(R_SCRIPTFUNC_PARAMS);
+ int SF_setActorState(R_SCRIPTFUNC_PARAMS);
+ int SF_swapActors(R_SCRIPTFUNC_PARAMS);
+ int SF_scriptSpecialWalk(R_SCRIPTFUNC_PARAMS);
+ int SF_walkRelative(R_SCRIPTFUNC_PARAMS);
+ int SF_throwActor(R_SCRIPTFUNC_PARAMS);
+ int SF_waitWalk(R_SCRIPTFUNC_PARAMS);
+ int SF_changeActorScene(R_SCRIPTFUNC_PARAMS);
+ int SF_climb(R_SCRIPTFUNC_PARAMS);
+ int SF_setActorZ(R_SCRIPTFUNC_PARAMS);
+ int SF_getActorX(R_SCRIPTFUNC_PARAMS);
+ int SF_getActorY(R_SCRIPTFUNC_PARAMS);
};
} // End of namespace Saga
diff --git a/saga/script_mod.h b/saga/script_mod.h
deleted file mode 100644
index 8a7e907c50..0000000000
--- a/saga/script_mod.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2004 The ScummVM project
- *
- * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- *
- */
-
-// Scripting module public header
-
-#ifndef SAGA_SCRIPT_MOD_H
-#define SAGA_SCRIPT_MOD_H
-
-namespace Saga {
-
-typedef unsigned int SDataWord_T;
-
-typedef struct R_SCRIPT_THREAD_tag R_SCRIPT_THREAD;
-
-enum R_SCRIPT_VERBS {
- S_VERB_WALKTO = 0,
- S_VERB_LOOKAT = 2,
- S_VERB_PICKUP = 1,
- S_VERB_TALKTO,
- S_VERB_OPEN = 5,
- S_VERB_CLOSE = 6,
- S_VERB_USE = 8,
- S_VERB_GIVE
-};
-
-R_SCRIPT_THREAD *STHREAD_Create();
-int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num);
-int STHREAD_ExecThreads(int msec);
-int STHREAD_HoldSem(R_SEMAPHORE *sem);
-int STHREAD_ReleaseSem(R_SEMAPHORE *sem);
-int STHREAD_DebugStep();
-void STHREAD_completeThread(void);
-
-} // End of namespace Saga
-
-#endif
diff --git a/saga/sdata.cpp b/saga/sdata.cpp
index c316208582..bcdaa9d99b 100644
--- a/saga/sdata.cpp
+++ b/saga/sdata.cpp
@@ -24,7 +24,6 @@
#include "saga/saga.h"
#include "saga/gfx.h"
-#include "saga/script_mod.h"
#include "saga/script.h"
#include "saga/sdata.h"
diff --git a/saga/sdata.h b/saga/sdata.h
index 335d80e55b..bcd67b4886 100644
--- a/saga/sdata.h
+++ b/saga/sdata.h
@@ -28,9 +28,6 @@
namespace Saga {
-#define R_SCRIPT_DATABUF_NUM 5
-#define R_SCRIPT_DATABUF_LEN 1024
-
class SData {
public:
SData();
diff --git a/saga/sdebug.cpp b/saga/sdebug.cpp
index e68f8cdd82..107dcc1198 100644
--- a/saga/sdebug.cpp
+++ b/saga/sdebug.cpp
@@ -29,16 +29,14 @@
#include "saga/scene.h"
#include "saga/font.h"
-#include "saga/script_mod.h"
#include "saga/script.h"
-#include "saga/sthread.h"
namespace Saga {
#define SD_DISPLAY_LEN 128
#define SD_ADDTXT( x ) strncat( disp_buf, x, SD_DISPLAY_LEN );
-int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
+int Script::SDebugPrintInstr(R_SCRIPT_THREAD *thread) {
R_TEXTLIST_ENTRY tl_e;
char tmp_buf[80] = { 0 };
static char disp_buf[SD_DISPLAY_LEN] = { 0 };
@@ -52,9 +50,9 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
disp_buf[0] = 0;
- if (_vm->_script->_dbg_txtentry != NULL) {
- _vm->textDeleteEntry(si.text_list, _vm->_script->_dbg_txtentry);
- _vm->_script->_dbg_txtentry = NULL;
+ if (_dbg_txtentry != NULL) {
+ _vm->textDeleteEntry(si.text_list, _dbg_txtentry);
+ _dbg_txtentry = NULL;
}
tl_e.color = 1;
@@ -66,9 +64,9 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
tl_e.string = disp_buf;
tl_e.display = 1;
- MemoryReadStream readS(_vm->_script->currentScript()->bytecode->bytecode_p
+ MemoryReadStream readS(currentScript()->bytecode->bytecode_p
+ thread->i_offset,
- _vm->_script->currentScript()->bytecode->bytecode_len
+ currentScript()->bytecode->bytecode_len
- thread->i_offset);
in_char = readS.readByte();
sprintf(tmp_buf, "%04lX | %02X | ", thread->i_offset, in_char);
@@ -514,8 +512,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
break;
}
- _vm->_script->_dbg_txtentry = _vm->textAddEntry(si.text_list, &tl_e);
- _vm->textSetDisplay(_vm->_script->_dbg_txtentry, 1);
+ _dbg_txtentry = _vm->textAddEntry(si.text_list, &tl_e);
+ _vm->textSetDisplay(_dbg_txtentry, 1);
return R_SUCCESS;
}
diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp
index c2a3e02dbf..65f9822ee6 100644
--- a/saga/sfuncs.cpp
+++ b/saga/sfuncs.cpp
@@ -32,96 +32,102 @@
#include "saga/interface.h"
#include "saga/script.h"
-#include "saga/sfuncs.h"
+#include "saga/sdata.h"
+
#include "common/stack.h"
namespace Saga {
-R_SFUNC_ENTRY SFuncList[R_SFUNC_NUM] = {
- {0, 0, NULL},
- {1, 1, SF_sleep},
- {2, 0, NULL},
- {3, 1, SF_3},
- {4, 1, SF_setCommandText},
- {5, 0, NULL},
- {6, 3, SF_actorWalkTo},
- {7, 0, SF_doAction},
- {8, 2, SF_setFacing},
- {9, 0, NULL},
- {10, 0, NULL},
- {11, 1, SF_freezeInterface},
- {12, 0, NULL},
- {13, 0, NULL},
- {14, 0, SF_faceTowards},
- {15, 0, SF_setFollower},
- {16, 0, NULL},
- {17, 0, NULL},
- {18, 0, NULL},
- {19, 0, NULL},
- {20, 0, NULL},
- {21, 0, NULL},
- {22, 0, NULL},
- {23, 0, NULL},
- {24, 0, NULL},
- {25, 0, SF_centerActor},
- {26, 3, SF_startAnim},
- {27, 3, SF_actorWalkToAsync},
- {28, 0, NULL},
- {29, 0, SF_setActorState},
- {30, 3, SF_moveTo},
- {31, 0, NULL},
- {32, 0, NULL},
- {33, 0, NULL},
- {34, 0, SF_swapActors},
- {35, 0, NULL},
- {36, 4, SF_actorWalk},
- {37, 4, SF_cycleActorFrames},
- {38, 3, SF_setFrame},
- {39, 0, NULL},
- {40, 0, NULL},
- {41, 4, SF_linkAnim},
- {42, 0, SF_scriptSpecialWalk},
- {43, 6, SF_placeActor},
- {44, 0, SF_checkUserInterrupt},
- {45, 0, SF_walkRelative},
- {46, 0, SF_moveRelative},
- {47, 0, NULL},
- {48, 0, NULL},
- {49, 0, NULL},
- {50, 0, NULL},
- {51, 0, NULL},
- {52, 0, SF_throwActor},
- {53, 0, SF_waitWalk},
- {54, 0, NULL},
- {55, 0, SF_changeActorScene},
- {56, 0, SF_climb},
- {57, 0, NULL},
- {58, 0, SF_setActorZ},
- {59, 0, NULL},
- {60, 0, SF_getActorX},
- {61, 0, SF_getActorY},
- {62, 0, NULL},
- {63, 0, NULL},
- {64, 0, NULL},
- {65, 0, NULL},
- {66, 0, NULL},
- {67, 0, NULL},
- {68, 0, NULL},
- {69, 0, NULL},
- {70, 0, NULL},
- {71, 0, NULL},
- {72, 0, NULL},
- {73, 0, NULL},
- {74, 0, NULL},
- {75, 0, NULL},
- {76, 0, NULL},
- {77, 0, NULL}
-};
+#define OPCODE(x) &Script::x
+
+void Script::setupScriptFuncList(void) {
+ static const R_SFUNC_ENTRY SFuncList[R_SFUNC_NUM] = {
+ {0, 0, NULL},
+ {1, 1, OPCODE(SF_sleep)},
+ {2, 0, NULL},
+ {3, 1, OPCODE(SF_3)},
+ {4, 1, OPCODE(SF_setCommandText)},
+ {5, 0, NULL},
+ {6, 3, OPCODE(SF_actorWalkTo)},
+ {7, 0, OPCODE(SF_doAction)},
+ {8, 2, OPCODE(SF_setFacing)},
+ {9, 0, NULL},
+ {10, 0, NULL},
+ {11, 1, OPCODE(SF_freezeInterface)},
+ {12, 0, NULL},
+ {13, 0, NULL},
+ {14, 0, OPCODE(SF_faceTowards)},
+ {15, 0, OPCODE(SF_setFollower)},
+ {16, 0, NULL},
+ {17, 0, NULL},
+ {18, 0, NULL},
+ {19, 0, NULL},
+ {20, 0, NULL},
+ {21, 0, NULL},
+ {22, 0, NULL},
+ {23, 0, NULL},
+ {24, 0, NULL},
+ {25, 0, OPCODE(SF_centerActor)},
+ {26, 3, OPCODE(SF_startAnim)},
+ {27, 3, OPCODE(SF_actorWalkToAsync)},
+ {28, 0, NULL},
+ {29, 0, OPCODE(SF_setActorState)},
+ {30, 3, OPCODE(SF_moveTo)},
+ {31, 0, NULL},
+ {32, 0, NULL},
+ {33, 0, NULL},
+ {34, 0, OPCODE(SF_swapActors)},
+ {35, 0, NULL},
+ {36, 4, OPCODE(SF_actorWalk)},
+ {37, 4, OPCODE(SF_cycleActorFrames)},
+ {38, 3, OPCODE(SF_setFrame)},
+ {39, 0, NULL},
+ {40, 0, NULL},
+ {41, 4, OPCODE(SF_linkAnim)},
+ {42, 0, OPCODE(SF_scriptSpecialWalk)},
+ {43, 6, OPCODE(SF_placeActor)},
+ {44, 0, OPCODE(SF_checkUserInterrupt)},
+ {45, 0, OPCODE(SF_walkRelative)},
+ {46, 0, OPCODE(SF_moveRelative)},
+ {47, 0, NULL},
+ {48, 0, NULL},
+ {49, 0, NULL},
+ {50, 0, NULL},
+ {51, 0, NULL},
+ {52, 0, OPCODE(SF_throwActor)},
+ {53, 0, OPCODE(SF_waitWalk)},
+ {54, 0, NULL},
+ {55, 0, OPCODE(SF_changeActorScene)},
+ {56, 0, OPCODE(SF_climb)},
+ {57, 0, NULL},
+ {58, 0, OPCODE(SF_setActorZ)},
+ {59, 0, NULL},
+ {60, 0, OPCODE(SF_getActorX)},
+ {61, 0, OPCODE(SF_getActorY)},
+ {62, 0, NULL},
+ {63, 0, NULL},
+ {64, 0, NULL},
+ {65, 0, NULL},
+ {66, 0, NULL},
+ {67, 0, NULL},
+ {68, 0, NULL},
+ {69, 0, NULL},
+ {70, 0, NULL},
+ {71, 0, NULL},
+ {72, 0, NULL},
+ {73, 0, NULL},
+ {74, 0, NULL},
+ {75, 0, NULL},
+ {76, 0, NULL},
+ {77, 0, NULL}
+ };
+ _SFuncList = SFuncList;
+}
// Script function #1 (0x01) blocking
// Suspends thread execution for the specified time period
// Param1: time to suspend ( units? )
-int SF_sleep(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_sleep(R_SCRIPTFUNC_PARAMS) {
SDataWord_T time_param;
int time;
@@ -134,7 +140,7 @@ int SF_sleep(R_SCRIPTFUNC_PARAMS) {
// Script function #3 (0x03)
// Unknown function; pops a parameter and pushes a return value
// Param1: unknown
-int SF_3(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_3(R_SCRIPTFUNC_PARAMS) {
// INCOMPLETE
SDataWord_T param1;
param1 = thread->stack->pop();
@@ -147,7 +153,7 @@ int SF_3(R_SCRIPTFUNC_PARAMS) {
// Script function #4 (0x04) nonblocking
// Set the command display to the specified text string
// Param1: dialogue index of string
-int SF_setCommandText(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_setCommandText(R_SCRIPTFUNC_PARAMS) {
SDataWord_T s_idx_parm;
s_idx_parm = thread->stack->pop();
@@ -161,7 +167,7 @@ int SF_setCommandText(R_SCRIPTFUNC_PARAMS) {
// Param1: actor id
// Param2: actor destination x
// Param3: actor destination y
-int SF_actorWalkTo(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_actorWalkTo(R_SCRIPTFUNC_PARAMS) {
SDataWord_T actor_parm;
SDataWord_T x_parm;
SDataWord_T y_parm;
@@ -189,7 +195,7 @@ int SF_actorWalkTo(R_SCRIPTFUNC_PARAMS) {
}
// Script function #7
-int SF_doAction(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_doAction(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
@@ -197,7 +203,7 @@ int SF_doAction(R_SCRIPTFUNC_PARAMS) {
// Sets the orientation of the specified actor.
// Param1: actor id
// Param2: actor orientation
-int SF_setFacing(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_setFacing(R_SCRIPTFUNC_PARAMS) {
SDataWord_T actor_parm;
SDataWord_T orient_parm;
int actor_id;
@@ -224,7 +230,7 @@ int SF_setFacing(R_SCRIPTFUNC_PARAMS) {
// continues to run. If the parameter is false, the user interface is
// reenabled.
// Param1: boolean
-int SF_freezeInterface(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_freezeInterface(R_SCRIPTFUNC_PARAMS) {
SDataWord_T b_param;
b_param = thread->stack->pop();
@@ -239,17 +245,17 @@ int SF_freezeInterface(R_SCRIPTFUNC_PARAMS) {
}
// Script function #14
-int SF_faceTowards(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_faceTowards(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #15
-int SF_setFollower(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_setFollower(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #25
-int SF_centerActor(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_centerActor(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
@@ -258,7 +264,7 @@ int SF_centerActor(R_SCRIPTFUNC_PARAMS) {
// Param1: ?
// Param2: frames of animation to play or -1 to loop
// Param3: animation id
-int SF_startAnim(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_startAnim(R_SCRIPTFUNC_PARAMS) {
// FIXME: implementation is wrong. Should link animation
SDataWord_T unk_parm;
SDataWord_T frame_parm;
@@ -286,7 +292,7 @@ int SF_startAnim(R_SCRIPTFUNC_PARAMS) {
// Param1: actor id
// Param2: actor destination x
// Param3: actor destination y
-int SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS) {
SDataWord_T actor_parm;
SDataWord_T x_parm;
SDataWord_T y_parm;
@@ -314,7 +320,7 @@ int SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS) {
}
// Script function #29
-int SF_setActorState(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_setActorState(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
@@ -324,7 +330,7 @@ int SF_setActorState(R_SCRIPTFUNC_PARAMS) {
// Param1: actor id
// Param2: actor pos x
// Param3: actor pos y
-int SF_moveTo(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_moveTo(R_SCRIPTFUNC_PARAMS) {
SDataWord_T actor_parm;
SDataWord_T x_parm;
SDataWord_T y_parm;
@@ -356,7 +362,7 @@ int SF_moveTo(R_SCRIPTFUNC_PARAMS) {
}
// Script function #34
-int SF_swapActors(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_swapActors(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
@@ -366,7 +372,7 @@ int SF_swapActors(R_SCRIPTFUNC_PARAMS) {
// Param2: actor destination x
// Param3: actor destination y
// Param4: unknown
-int SF_actorWalk(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_actorWalk(R_SCRIPTFUNC_PARAMS) {
// INCOMPLETE
SDataWord_T actor_parm;
SDataWord_T x_parm;
@@ -404,7 +410,7 @@ int SF_actorWalk(R_SCRIPTFUNC_PARAMS) {
// Param2: unknown
// Param3: actor action state
// Param4: unknown
-int SF_cycleActorFrames(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_cycleActorFrames(R_SCRIPTFUNC_PARAMS) {
// INCOMPLETE
SDataWord_T actor_parm;
SDataWord_T unk1_parm;
@@ -436,7 +442,7 @@ int SF_cycleActorFrames(R_SCRIPTFUNC_PARAMS) {
// Param1: actor id
// Param2: actor action state
// Param3: unknown
-int SF_setFrame(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_setFrame(R_SCRIPTFUNC_PARAMS) {
// INCOMPLETE
SDataWord_T actor_parm;
@@ -471,7 +477,7 @@ int SF_setFrame(R_SCRIPTFUNC_PARAMS) {
// Param2: total linked frame count
// Param3: animation id link target
// Param4: animation id link source
-int SF_linkAnim(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_linkAnim(R_SCRIPTFUNC_PARAMS) {
SDataWord_T unk_parm;
SDataWord_T tframes_parm;
SDataWord_T anim1_parm;
@@ -497,7 +503,7 @@ int SF_linkAnim(R_SCRIPTFUNC_PARAMS) {
}
// Script function #42
-int SF_scriptSpecialWalk(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_scriptSpecialWalk(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
@@ -510,7 +516,7 @@ int SF_scriptSpecialWalk(R_SCRIPTFUNC_PARAMS) {
// Param4: ?
// Param5: actor action
// Param6: ?
-int SF_placeActor(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_placeActor(R_SCRIPTFUNC_PARAMS) {
// INCOMPLETE
SDataWord_T actor_parm;
SDataWord_T x_parm;
@@ -557,7 +563,7 @@ int SF_placeActor(R_SCRIPTFUNC_PARAMS) {
// Checks to see if the user has interrupted a currently playing
// game cinematic. Pushes a zero or positive value if the game
// has not been interrupted.
-int SF_checkUserInterrupt(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_checkUserInterrupt(R_SCRIPTFUNC_PARAMS) {
thread->stack->push(0);
// INCOMPLETE
@@ -566,47 +572,47 @@ int SF_checkUserInterrupt(R_SCRIPTFUNC_PARAMS) {
}
// Script function #45
-int SF_walkRelative(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_walkRelative(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #46
-int SF_moveRelative(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_moveRelative(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #52
-int SF_throwActor(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_throwActor(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #53
-int SF_waitWalk(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_waitWalk(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #55
-int SF_changeActorScene(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_changeActorScene(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #56
-int SF_climb(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_climb(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #58
-int SF_setActorZ(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_setActorZ(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #60
-int SF_getActorX(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_getActorX(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
// Script function #61
-int SF_getActorY(R_SCRIPTFUNC_PARAMS) {
+int Script::SF_getActorY(R_SCRIPTFUNC_PARAMS) {
return R_SUCCESS;
}
diff --git a/saga/sfuncs.h b/saga/sfuncs.h
deleted file mode 100644
index bd9d75d319..0000000000
--- a/saga/sfuncs.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2004 The ScummVM project
- *
- * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- *
- */
-
-// Scripting module script function component header file
-
-#ifndef SAGA_SFUNCS_H
-#define SAGA_SFUNCS_H
-
-#include "saga/sthread.h"
-
-namespace Saga {
-
-#define R_SFUNC_NUM 78
-
-#define R_SCRIPTFUNC_PARAMS R_SCRIPT_THREAD *thread
-
-typedef int (*SFunc_T) (R_SCRIPTFUNC_PARAMS);
-
-struct R_SFUNC_ENTRY {
- int sfunc_num;
- int sfunc_argc;
- SFunc_T sfunc_fp;
-};
-
-extern R_SFUNC_ENTRY SFuncList[];
-
-int SF_sleep(R_SCRIPTFUNC_PARAMS);
-int SF_3(R_SCRIPTFUNC_PARAMS);
-int SF_setCommandText(R_SCRIPTFUNC_PARAMS);
-int SF_actorWalkTo(R_SCRIPTFUNC_PARAMS);
-int SF_setFacing(R_SCRIPTFUNC_PARAMS);
-int SF_freezeInterface(R_SCRIPTFUNC_PARAMS);
-int SF_startAnim(R_SCRIPTFUNC_PARAMS);
-int SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS);
-int SF_moveTo(R_SCRIPTFUNC_PARAMS);
-int SF_actorWalk(R_SCRIPTFUNC_PARAMS);
-int SF_cycleActorFrames(R_SCRIPTFUNC_PARAMS);
-int SF_setFrame(R_SCRIPTFUNC_PARAMS);
-int SF_linkAnim(R_SCRIPTFUNC_PARAMS);
-int SF_placeActor(R_SCRIPTFUNC_PARAMS);
-int SF_checkUserInterrupt(R_SCRIPTFUNC_PARAMS);
-int SF_moveRelative(R_SCRIPTFUNC_PARAMS);
-int SF_doAction(R_SCRIPTFUNC_PARAMS);
-int SF_faceTowards(R_SCRIPTFUNC_PARAMS);
-int SF_setFollower(R_SCRIPTFUNC_PARAMS);
-int SF_centerActor(R_SCRIPTFUNC_PARAMS);
-int SF_setActorState(R_SCRIPTFUNC_PARAMS);
-int SF_swapActors(R_SCRIPTFUNC_PARAMS);
-int SF_scriptSpecialWalk(R_SCRIPTFUNC_PARAMS);
-int SF_walkRelative(R_SCRIPTFUNC_PARAMS);
-int SF_throwActor(R_SCRIPTFUNC_PARAMS);
-int SF_waitWalk(R_SCRIPTFUNC_PARAMS);
-int SF_changeActorScene(R_SCRIPTFUNC_PARAMS);
-int SF_climb(R_SCRIPTFUNC_PARAMS);
-int SF_setActorZ(R_SCRIPTFUNC_PARAMS);
-int SF_getActorX(R_SCRIPTFUNC_PARAMS);
-int SF_getActorY(R_SCRIPTFUNC_PARAMS);
-
-}
-
-#endif
diff --git a/saga/sthread.cpp b/saga/sthread.cpp
index 7423969eaa..07da1786eb 100644
--- a/saga/sthread.cpp
+++ b/saga/sthread.cpp
@@ -29,22 +29,19 @@
#include "saga/actor.h"
#include "saga/console.h"
-#include "saga/script_mod.h"
#include "saga/script.h"
#include "saga/sdata.h"
-#include "saga/sthread.h"
-#include "saga/sfuncs.h"
#include "common/stack.h"
namespace Saga {
-R_SCRIPT_THREAD *STHREAD_Create() {
+R_SCRIPT_THREAD *Script::SThreadCreate() {
YS_DL_NODE *new_node;
R_SCRIPT_THREAD *new_thread;
- if (!_vm->_script->isInitialized()) {
+ if (!isInitialized()) {
return NULL;
}
@@ -55,14 +52,14 @@ R_SCRIPT_THREAD *STHREAD_Create() {
new_thread->stack = new Common::Stack<SDataWord_T>();
- new_node = ys_dll_add_head(_vm->_script->threadList(), new_thread, sizeof *new_thread);
+ new_node = ys_dll_add_head(threadList(), new_thread, sizeof *new_thread);
free(new_thread);
return (R_SCRIPT_THREAD *)ys_dll_get_data(new_node);
}
-int STHREAD_Destroy(R_SCRIPT_THREAD *thread) {
+int Script::SThreadDestroy(R_SCRIPT_THREAD *thread) {
if (thread == NULL) {
return R_FAILURE;
}
@@ -72,36 +69,36 @@ int STHREAD_Destroy(R_SCRIPT_THREAD *thread) {
return R_SUCCESS;
}
-int STHREAD_ExecThreads(int msec) {
+int Script::SThreadExecThreads(int msec) {
YS_DL_NODE *walk_p;
R_SCRIPT_THREAD *thread;
- if (!_vm->_script->isInitialized()) {
+ if (!isInitialized()) {
return R_FAILURE;
}
- for (walk_p = ys_dll_head(_vm->_script->threadList()); walk_p != NULL; walk_p = ys_dll_next(walk_p)) {
+ for (walk_p = ys_dll_head(threadList()); walk_p != NULL; walk_p = ys_dll_next(walk_p)) {
thread = (R_SCRIPT_THREAD *)ys_dll_get_data(walk_p);
if (thread->executing) {
- STHREAD_Run(thread, STHREAD_DEF_INSTR_COUNT, msec);
+ SThreadRun(thread, STHREAD_DEF_INSTR_COUNT, msec);
}
}
return R_SUCCESS;
}
-void STHREAD_completeThread(void) {
- for (int i = 0; i < 40 && (ys_dll_head(_vm->_script->threadList()) != NULL); i++)
- STHREAD_ExecThreads(0);
+void Script::SThreadCompleteThread(void) {
+ for (int i = 0; i < 40 && (ys_dll_head(threadList()) != NULL); i++)
+ SThreadExecThreads(0);
}
-int STHREAD_SetEntrypoint(R_SCRIPT_THREAD *thread, int ep_num) {
+int Script::SThreadSetEntrypoint(R_SCRIPT_THREAD *thread, int ep_num) {
R_SCRIPT_BYTECODE *bytecode;
int max_entrypoint;
- assert(_vm->_script->isInitialized());
+ assert(isInitialized());
- bytecode = _vm->_script->currentScript()->bytecode;
+ bytecode = currentScript()->bytecode;
max_entrypoint = bytecode->n_entrypoints;
if ((ep_num < 0) || (ep_num >= max_entrypoint)) {
@@ -114,14 +111,14 @@ int STHREAD_SetEntrypoint(R_SCRIPT_THREAD *thread, int ep_num) {
return R_SUCCESS;
}
-int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num) {
- assert(_vm->_script->isInitialized());
+int Script::SThreadExecute(R_SCRIPT_THREAD *thread, int ep_num) {
+ assert(isInitialized());
- if ((_vm->_script->currentScript() == NULL) || (!_vm->_script->currentScript()->loaded)) {
+ if ((currentScript() == NULL) || (!currentScript()->loaded)) {
return R_FAILURE;
}
- STHREAD_SetEntrypoint(thread, ep_num);
+ SThreadSetEntrypoint(thread, ep_num);
thread->i_offset = thread->ep_offset;
thread->executing = 1;
@@ -129,20 +126,20 @@ int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num) {
return R_SUCCESS;
}
-unsigned char *GetReadPtr(R_SCRIPT_THREAD *thread) {
- return _vm->_script->currentScript()->bytecode->bytecode_p + thread->i_offset;
+unsigned char *Script::SThreadGetReadPtr(R_SCRIPT_THREAD *thread) {
+ return currentScript()->bytecode->bytecode_p + thread->i_offset;
}
-unsigned long GetReadOffset(const byte *read_p) {
- return (unsigned long)(read_p - (unsigned char *)_vm->_script->currentScript()->bytecode->bytecode_p);
+unsigned long Script::SThreadGetReadOffset(const byte *read_p) {
+ return (unsigned long)(read_p - (unsigned char *)currentScript()->bytecode->bytecode_p);
}
-size_t GetReadLen(R_SCRIPT_THREAD *thread) {
- return _vm->_script->currentScript()->bytecode->bytecode_len - thread->i_offset;
+size_t Script::SThreadGetReadLen(R_SCRIPT_THREAD *thread) {
+ return currentScript()->bytecode->bytecode_len - thread->i_offset;
}
-int STHREAD_HoldSem(R_SEMAPHORE *sem) {
+int Script::SThreadHoldSem(R_SEMAPHORE *sem) {
if (sem == NULL) {
return R_FAILURE;
}
@@ -152,7 +149,7 @@ int STHREAD_HoldSem(R_SEMAPHORE *sem) {
return R_SUCCESS;
}
-int STHREAD_ReleaseSem(R_SEMAPHORE *sem) {
+int Script::SThreadReleaseSem(R_SEMAPHORE *sem) {
if (sem == NULL) {
return R_FAILURE;
}
@@ -165,15 +162,15 @@ int STHREAD_ReleaseSem(R_SEMAPHORE *sem) {
return R_SUCCESS;
}
-int STHREAD_DebugStep() {
- if (_vm->_script->_dbg_singlestep) {
- _vm->_script->_dbg_dostep = 1;
+int Script::SThreadDebugStep() {
+ if (_dbg_singlestep) {
+ _dbg_dostep = 1;
}
return R_SUCCESS;
}
-int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
+int Script::SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int instr_count;
uint32 saved_offset;
SDataWord_T param1;
@@ -191,12 +188,12 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int unhandled = 0;
// Handle debug single-stepping
- if ((thread == _vm->_script->_dbg_thread) && _vm->_script->_dbg_singlestep) {
- if (_vm->_script->_dbg_dostep) {
+ if ((thread == _dbg_thread) && _dbg_singlestep) {
+ if (_dbg_dostep) {
debug_print = 1;
thread->sleep_time = 0;
instr_limit = 1;
- _vm->_script->_dbg_dostep = 0;
+ _dbg_dostep = 0;
} else {
return R_SUCCESS;
}
@@ -218,7 +215,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
saved_offset = thread->i_offset;
- MemoryReadStream readS(GetReadPtr(thread), GetReadLen(thread));
+ MemoryReadStream readS(SThreadGetReadPtr(thread), SThreadGetReadLen(thread));
in_char = readS.readByte();
@@ -347,7 +344,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
}
- sfunc = SFuncList[func_num].sfunc_fp;
+ sfunc = _SFuncList[func_num].sfunc_fp;
if (sfunc == NULL) {
_vm->_console->print(S_WARN_PREFIX "%X: Undefined script function number: (%X)\n",
thread->i_offset, func_num);
@@ -356,7 +353,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
thread->stack->pop();
}
} else {
- FIXME_SHADOWED_result = sfunc(thread);
+ FIXME_SHADOWED_result = (this->*sfunc)(thread);
if (FIXME_SHADOWED_result != R_SUCCESS) {
_vm->_console->print(S_WARN_PREFIX "%X: Script function %d failed.\n", thread->i_offset, func_num);
}
@@ -732,12 +729,12 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
data = thread->stack->pop();
if (a_index < 0)
continue;
- if (!_vm->_script->isVoiceLUTPresent()) {
+ if (!isVoiceLUTPresent()) {
voice_rn = -1;
} else {
- voice_rn = _vm->_script->currentScript()->voice->voices[data];
+ voice_rn = currentScript()->voice->voices[data];
}
- _vm->_actor->speak(a_index, _vm->_script->currentScript()->diag-> str[data], voice_rn, &thread->sem);
+ _vm->_actor->speak(a_index, currentScript()->diag-> str[data], voice_rn, &thread->sem);
}
}
break;
@@ -784,7 +781,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
thread->executing = 0;
}
if (thread->executing && debug_print) {
- SDEBUG_PrintInstr(thread);
+ SDebugPrintInstr(thread);
}
}
diff --git a/saga/sthread.h b/saga/sthread.h
deleted file mode 100644
index cadd8a3f18..0000000000
--- a/saga/sthread.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2004 The ScummVM project
- *
- * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- *
- */
-
-// Scripting module thread management component header file
-
-#ifndef SAGA_STHREAD_H__
-#define SAGA_STHREAD_H__
-
-#include "common/stack.h"
-
-namespace Saga {
-
-#define STHREAD_DEF_INSTR_COUNT 8
-
-struct R_SEMAPHORE {
- int hold_count;
-};
-
-struct R_SCRIPT_THREAD_tag {
- int executing;
-
- int sleep_time;
- int ep_num; // Entrypoint number
- unsigned long ep_offset; // Entrypoint offset
- unsigned long i_offset; // Instruction offset
-
- R_SEMAPHORE sem;
- Common::Stack<SDataWord_T> *stack;
-};
-
-R_SCRIPT_THREAD *STHREAD_Create();
-int STHREAD_Destroy(R_SCRIPT_THREAD *thread);
-int STHREAD_SetEntrypoint(R_SCRIPT_THREAD *thread, int ep_num);
-int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num);
-int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec);
-unsigned long GetReadOffset(const byte *read_p);
-unsigned char *GetReadPtr(R_SCRIPT_THREAD *thread);
-size_t GetReadLen(R_SCRIPT_THREAD *thread);
-int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread);
-
-} // End of namespace Saga
-
-#endif