aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorFilippos Karapetis2010-06-09 09:17:48 +0000
committerFilippos Karapetis2010-06-09 09:17:48 +0000
commit536b2614e8bd7c3c6e47e686a90596460c5448d1 (patch)
tree55eb2235bf58831e2397ce39004fc10267675ffe /engines/sci
parent95b080f60b74fe9b83d71abc9a80038f025845c6 (diff)
downloadscummvm-rg350-536b2614e8bd7c3c6e47e686a90596460c5448d1.tar.gz
scummvm-rg350-536b2614e8bd7c3c6e47e686a90596460c5448d1.tar.bz2
scummvm-rg350-536b2614e8bd7c3c6e47e686a90596460c5448d1.zip
Globals from script 0 are now initialized in script_init_engine(), and are accessed from the relevant variables pointer. Removed direct reference to script 0 from the engine state
svn-id: r49536
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/game.cpp7
-rw-r--r--engines/sci/engine/savegame.cpp2
-rw-r--r--engines/sci/engine/state.cpp16
-rw-r--r--engines/sci/engine/state.h16
-rw-r--r--engines/sci/engine/vm.cpp15
-rw-r--r--engines/sci/graphics/animate.cpp6
6 files changed, 25 insertions, 37 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 4f4ae774e0..9e5b9b8990 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -58,14 +58,13 @@ int script_init_engine(EngineState *s) {
s->_msgState = new MessageState(s->_segMan);
s->gc_countdown = GC_INTERVAL - 1;
- SegmentId script_000_segment = s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK);
-
- if (script_000_segment <= 0) {
+ // Script 0 should always be at segment 1
+ if (s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK) != 1) {
debug(2, "Failed to instantiate script.000");
return 1;
}
- s->script_000 = s->_segMan->getScript(script_000_segment);
+ s->initGlobals();
s->_segMan->initSysStrings();
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 815ffa32a9..255e2700ee 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -870,7 +870,7 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
s->_segMan->reconstructStack(s);
s->_segMan->reconstructScripts(s);
s->_segMan->reconstructClones();
- s->script_000 = s->_segMan->getScript(s->_segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD));
+ s->initGlobals();
s->gc_countdown = GC_INTERVAL - 1;
// Time state:
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index e94be73077..8860666bef 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -85,7 +85,6 @@ void EngineState::reset(bool isRestoring) {
#endif
if (!isRestoring) {
- script_000 = 0;
_gameObj = NULL_REG;
_memorySegmentSize = 0;
@@ -127,12 +126,23 @@ void EngineState::wait(int16 ticks) {
g_sci->getEventManager()->sleep(ticks * 1000 / 60);
}
+void EngineState::initGlobals() {
+ Script *script_000 = _segMan->getScript(1);
+
+ if (!script_000->_localsBlock)
+ error("Script 0 has no locals block");
+
+ variables_seg[VAR_GLOBAL] = script_000->_localsSegment;
+ variables_base[VAR_GLOBAL] = variables[VAR_GLOBAL] = script_000->_localsBlock->_locals.begin();
+ variables_max[VAR_GLOBAL] = script_000->_localsBlock->_locals.size();
+}
+
uint16 EngineState::currentRoomNumber() const {
- return script_000->_localsBlock->_locals[13].toUint16();
+ return variables[VAR_GLOBAL][13].toUint16();
}
void EngineState::setRoomNumber(uint16 roomNumber) {
- script_000->_localsBlock->_locals[13] = make_reg(0, roomNumber);
+ variables[VAR_GLOBAL][13] = make_reg(0, roomNumber);
}
void EngineState::shrinkStackToBase() {
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index ae81e9393d..aaeb8c49ee 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -79,13 +79,6 @@ enum {
MAX_SAVE_DIR_SIZE = MAXPATHLEN
};
-/** values for EngineState.restarting_flag */
-enum {
- SCI_GAME_IS_NOT_RESTARTING = 0,
- SCI_GAME_WAS_RESTARTED = 1,
- SCI_GAME_IS_RESTARTING_NOW = 2
-};
-
class FileHandle {
public:
Common::String _name;
@@ -145,7 +138,7 @@ public:
bool _executionStackPosChanged; /**< Set to true if the execution stack position should be re-evaluated by the vm */
reg_t r_acc; /**< Accumulator */
- int16 restAdjust; /**< current &rest register (only used for save games) */
+ int16 restAdjust; /**< current &rest register */
reg_t r_prev; /**< previous comparison result */
StackPtr stack_base; /**< Pointer to the least stack element */
@@ -158,8 +151,6 @@ public:
SegmentId variables_seg[4]; ///< Same as above, contains segment IDs
int variables_max[4]; ///< Max. values for all variables
- Script *script_000; /**< script 000, e.g. for globals */
-
int loadFromLauncher;
AbortGameState abortScriptProcessing;
@@ -172,6 +163,11 @@ public:
void setRoomNumber(uint16 roomNumber);
/**
+ * Sets global variables from script 0
+ */
+ void initGlobals();
+
+ /**
* Shrink execution stack to size.
* Contains an assert it is not already smaller.
*/
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 71d6672eb4..851f301a75 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -736,24 +736,9 @@ void run_vm(EngineState *s, bool restoring) {
if (!restoring)
s->execution_stack_base = s->_executionStack.size() - 1;
-#ifndef DISABLE_VALIDATIONS
- // Initialize maximum variable count
- if (s->script_000->_localsBlock)
- s->variables_max[VAR_GLOBAL] = s->script_000->_localsBlock->_locals.size();
- else
- s->variables_max[VAR_GLOBAL] = 0;
-#endif
-
- s->variables_seg[VAR_GLOBAL] = s->script_000->_localsSegment;
s->variables_seg[VAR_TEMP] = s->variables_seg[VAR_PARAM] = s->_segMan->findSegmentByType(SEG_TYPE_STACK);
s->variables_base[VAR_TEMP] = s->variables_base[VAR_PARAM] = s->stack_base;
- // SCI code reads the zeroth argument to determine argc
- if (s->script_000->_localsBlock)
- s->variables_base[VAR_GLOBAL] = s->variables[VAR_GLOBAL] = s->script_000->_localsBlock->_locals.begin();
- else
- s->variables_base[VAR_GLOBAL] = s->variables[VAR_GLOBAL] = NULL;
-
s->_executionStackPosChanged = true; // Force initialization
while (1) {
diff --git a/engines/sci/graphics/animate.cpp b/engines/sci/graphics/animate.cpp
index c201b2cfb7..d4def39ebf 100644
--- a/engines/sci/graphics/animate.cpp
+++ b/engines/sci/graphics/animate.cpp
@@ -84,10 +84,8 @@ bool GfxAnimate::invoke(List *list, int argc, reg_t *argv) {
if (!_ignoreFastCast) {
// Check if the game has a fastCast object set
// if we don't abort kAnimate processing, at least in kq5 there will be animation cels drawn into speech boxes.
- reg_t global84 = _s->script_000->_localsBlock->_locals[84];
-
- if (!global84.isNull()) {
- if (!strcmp(_s->_segMan->getObjectName(global84), "fastCast"))
+ if (!_s->variables[VAR_GLOBAL][84].isNull()) {
+ if (!strcmp(_s->_segMan->getObjectName(_s->variables[VAR_GLOBAL][84]), "fastCast"))
return false;
}
}