aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2011-11-05 02:53:08 +0200
committerFilippos Karapetis2011-11-05 03:00:42 +0200
commit267c6f1756c9582b8bd9534334c7f264a2400929 (patch)
tree3371fa3b24dc20abb4145f6e87291cdcf0e4b955
parentd70d6c4c50942ec3679fce07ff6045b5d18ed9a1 (diff)
downloadscummvm-rg350-267c6f1756c9582b8bd9534334c7f264a2400929.tar.gz
scummvm-rg350-267c6f1756c9582b8bd9534334c7f264a2400929.tar.bz2
scummvm-rg350-267c6f1756c9582b8bd9534334c7f264a2400929.zip
SCI: Made more fields of the Script class private. Some cleanup.
-rw-r--r--engines/sci/console.cpp4
-rw-r--r--engines/sci/engine/savegame.cpp2
-rw-r--r--engines/sci/engine/script.cpp27
-rw-r--r--engines/sci/engine/script.h9
-rw-r--r--engines/sci/engine/seg_manager.cpp27
-rw-r--r--engines/sci/engine/seg_manager.h7
-rw-r--r--engines/sci/engine/state.cpp8
-rw-r--r--engines/sci/engine/vm.cpp12
8 files changed, 48 insertions, 48 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index a44c661561..664fa6747b 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -1876,8 +1876,8 @@ bool Console::segmentInfo(int nr) {
DebugPrintf(" Synonyms: %4d\n", scr->getSynonymsNr());
- if (scr->_localsBlock)
- DebugPrintf(" Locals : %4d in segment 0x%x\n", scr->_localsBlock->_locals.size(), scr->_localsSegment);
+ if (scr->getLocalsCount() > 0)
+ DebugPrintf(" Locals : %4d in segment 0x%x\n", scr->getLocalsCount(), scr->getLocalsSegment());
else
DebugPrintf(" Locals : none\n");
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 030c0f3f54..2f87137d7f 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -226,7 +226,7 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
continue;
Script *scr = (Script *)_heap[i];
- scr->_localsBlock = (scr->_localsSegment == 0) ? NULL : (LocalVariables *)(_heap[scr->_localsSegment]);
+ scr->syncLocalsBlock(this);
for (ObjMap::iterator it = scr->_objects.begin(); it != scr->_objects.end(); ++it) {
reg_t addr = it->_value.getPos();
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index 01e1afe5ea..8b26969f4a 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -492,8 +492,29 @@ SegmentRef Script::dereference(reg_t pointer) {
return ret;
}
+LocalVariables *Script::allocLocalsSegment(SegManager *segMan) {
+ if (!getLocalsCount()) { // No locals
+ return NULL;
+ } else {
+ LocalVariables *locals;
+
+ if (_localsSegment) {
+ locals = (LocalVariables *)segMan->getSegment(_localsSegment, SEG_TYPE_LOCALS);
+ if (!locals || locals->getType() != SEG_TYPE_LOCALS || locals->script_id != getScriptNumber())
+ error("Invalid script locals segment while allocating locals");
+ } else
+ locals = (LocalVariables *)segMan->allocSegment(new LocalVariables(), &_localsSegment);
+
+ _localsBlock = locals;
+ locals->script_id = getScriptNumber();
+ locals->_locals.resize(getLocalsCount());
+
+ return locals;
+ }
+}
+
void Script::initializeLocals(SegManager *segMan) {
- LocalVariables *locals = segMan->allocLocalsSegment(this);
+ LocalVariables *locals = allocLocalsSegment(segMan);
if (locals) {
if (getSciVersion() > SCI_VERSION_0_EARLY) {
const byte *base = (const byte *)(_buf + getLocalsOffset());
@@ -508,6 +529,10 @@ void Script::initializeLocals(SegManager *segMan) {
}
}
+void Script::syncLocalsBlock(SegManager *segMan) {
+ _localsBlock = (_localsSegment == 0) ? NULL : (LocalVariables *)(segMan->getSegment(_localsSegment, SEG_TYPE_LOCALS));
+}
+
void Script::initializeClasses(SegManager *segMan) {
const byte *seeker = 0;
uint16 mult = 0;
diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h
index ff061e0e36..b6610aadea 100644
--- a/engines/sci/engine/script.h
+++ b/engines/sci/engine/script.h
@@ -69,6 +69,8 @@ private:
uint16 _localsCount;
bool _markedAsDeleted;
+ SegmentId _localsSegment; /**< The local variable segment */
+ LocalVariables *_localsBlock;
public:
/**
@@ -76,8 +78,6 @@ public:
* Indexed by the TODO offset.
*/
ObjMap _objects;
- SegmentId _localsSegment; /**< The local variable segment */
- LocalVariables *_localsBlock;
public:
int getLocalsOffset() const { return _localsOffset; }
@@ -89,6 +89,9 @@ public:
const byte *getBuf(uint offset = 0) const { return _buf + offset; }
int getScriptNumber() const { return _nr; }
+ SegmentId getLocalsSegment() const { return _localsSegment; }
+ reg_t *getLocalsBegin() { return _localsBlock ? _localsBlock->_locals.begin() : NULL; }
+ void syncLocalsBlock(SegManager *segMan);
public:
Script();
@@ -295,6 +298,8 @@ private:
* @param segmentId The script's segment id
*/
void initializeObjectsSci3(SegManager *segMan, SegmentId segmentId);
+
+ LocalVariables *allocLocalsSegment(SegManager *segMan);
};
} // End of namespace Sci
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 1510af8508..4e822a5a1e 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -151,8 +151,8 @@ void SegManager::deallocate(SegmentId seg) {
if (mobj->getType() == SEG_TYPE_SCRIPT) {
Script *scr = (Script *)mobj;
_scriptSegMap.erase(scr->getScriptNumber());
- if (scr->_localsSegment)
- deallocate(scr->_localsSegment);
+ if (scr->getLocalsSegment())
+ deallocate(scr->getLocalsSegment());
}
delete mobj;
@@ -341,29 +341,6 @@ SegmentId SegManager::getScriptSegment(int script_nr, ScriptLoadType load) {
return segment;
}
-LocalVariables *SegManager::allocLocalsSegment(Script *scr) {
- if (!scr->getLocalsCount()) { // No locals
- scr->_localsSegment = 0;
- scr->_localsBlock = NULL;
- return NULL;
- } else {
- LocalVariables *locals;
-
- if (scr->_localsSegment) {
- locals = (LocalVariables *)_heap[scr->_localsSegment];
- if (!locals || locals->getType() != SEG_TYPE_LOCALS || locals->script_id != scr->getScriptNumber())
- error("Invalid script locals segment while allocating locals");
- } else
- locals = (LocalVariables *)allocSegment(new LocalVariables(), &scr->_localsSegment);
-
- scr->_localsBlock = locals;
- locals->script_id = scr->getScriptNumber();
- locals->_locals.resize(scr->getLocalsCount());
-
- return locals;
- }
-}
-
DataStack *SegManager::allocateStack(int size, SegmentId *segid) {
SegmentObj *mobj = allocSegment(new DataStack(), segid);
DataStack *retval = (DataStack *)mobj;
diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h
index ab5aeacabf..62e711e686 100644
--- a/engines/sci/engine/seg_manager.h
+++ b/engines/sci/engine/seg_manager.h
@@ -463,8 +463,10 @@ private:
SegmentId _stringSegId;
#endif
-private:
+public:
SegmentObj *allocSegment(SegmentObj *mem, SegmentId *segid);
+
+private:
void deallocate(SegmentId seg);
void createClassTable();
@@ -477,9 +479,6 @@ private:
* 'seg' is a valid segment
*/
bool check(SegmentId seg);
-
-public:
- LocalVariables *allocLocalsSegment(Script *scr);
};
} // End of namespace Sci
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index 4ea9f72054..28818cddef 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -145,12 +145,12 @@ void EngineState::wait(int16 ticks) {
void EngineState::initGlobals() {
Script *script_000 = _segMan->getScript(1);
- if (!script_000->_localsBlock)
+ if (script_000->getLocalsCount() == 0)
error("Script 0 has no locals block");
- variablesSegment[VAR_GLOBAL] = script_000->_localsSegment;
- variablesBase[VAR_GLOBAL] = variables[VAR_GLOBAL] = script_000->_localsBlock->_locals.begin();
- variablesMax[VAR_GLOBAL] = script_000->_localsBlock->_locals.size();
+ variablesSegment[VAR_GLOBAL] = script_000->getLocalsSegment();
+ variablesBase[VAR_GLOBAL] = variables[VAR_GLOBAL] = script_000->getLocalsBegin();
+ variablesMax[VAR_GLOBAL] = script_000->getLocalsCount();
}
uint16 EngineState::currentRoomNumber() const {
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index c94fdac034..6b3a3198ea 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -593,15 +593,9 @@ void run_vm(EngineState *s) {
if (!local_script) {
error("Could not find local script from segment %x", s->xs->local_segment);
} else {
- s->variablesSegment[VAR_LOCAL] = local_script->_localsSegment;
- if (local_script->_localsBlock)
- s->variablesBase[VAR_LOCAL] = s->variables[VAR_LOCAL] = local_script->_localsBlock->_locals.begin();
- else
- s->variablesBase[VAR_LOCAL] = s->variables[VAR_LOCAL] = NULL;
- if (local_script->_localsBlock)
- s->variablesMax[VAR_LOCAL] = local_script->_localsBlock->_locals.size();
- else
- s->variablesMax[VAR_LOCAL] = 0;
+ s->variablesSegment[VAR_LOCAL] = local_script->getLocalsSegment();
+ s->variablesBase[VAR_LOCAL] = s->variables[VAR_LOCAL] = local_script->getLocalsBegin();
+ s->variablesMax[VAR_LOCAL] = local_script->getLocalsCount();
s->variablesMax[VAR_TEMP] = s->xs->sp - s->xs->fp;
s->variablesMax[VAR_PARAM] = s->xs->argc + 1;
}