[Scummvm-cvs-logs] scummvm master -> 267c6f1756c9582b8bd9534334c7f264a2400929

bluegr md5 at scummvm.org
Sat Nov 5 02:03:24 CET 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
267c6f1756 SCI: Made more fields of the Script class private. Some cleanup.


Commit: 267c6f1756c9582b8bd9534334c7f264a2400929
    https://github.com/scummvm/scummvm/commit/267c6f1756c9582b8bd9534334c7f264a2400929
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2011-11-04T18:00:42-07:00

Commit Message:
SCI: Made more fields of the Script class private. Some cleanup.

Changed paths:
    engines/sci/console.cpp
    engines/sci/engine/savegame.cpp
    engines/sci/engine/script.cpp
    engines/sci/engine/script.h
    engines/sci/engine/seg_manager.cpp
    engines/sci/engine/seg_manager.h
    engines/sci/engine/state.cpp
    engines/sci/engine/vm.cpp



diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index a44c661..664fa67 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 030c0f3..2f87137 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 01e1afe..8b26969 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 ff061e0..b6610aa 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 1510af8..4e822a5 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 ab5aeac..62e711e 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 4ea9f72..28818cd 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 c94fdac..6b3a319 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;
 			}






More information about the Scummvm-git-logs mailing list