[Scummvm-cvs-logs] scummvm master -> 562a8a980c22eab85144558050e5fa5e425612c4

bluegr md5 at scummvm.org
Fri Jun 15 11:55:05 CEST 2012


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:
562a8a980c SCI: Further cleanup of the script code


Commit: 562a8a980c22eab85144558050e5fa5e425612c4
    https://github.com/scummvm/scummvm/commit/562a8a980c22eab85144558050e5fa5e425612c4
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-06-15T02:53:17-07:00

Commit Message:
SCI: Further cleanup of the script code

Merge the init() and load() Script methods and reset the script when
necessary

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



diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 7c41e18..cabe5f4 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -189,7 +189,7 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
 
 		assert(mobj);
 
-		// Let the object sync custom data
+		// Let the object sync custom data. Scripts are loaded at this point.
 		mobj->saveLoadWithSerializer(s);
 
 		if (type == SEG_TYPE_SCRIPT) {
@@ -200,9 +200,6 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
 				// Hook the script up in the script->segment map
 				_scriptSegMap[scr->getScriptNumber()] = i;
 
-				// Now, load the script itself
-				scr->load(g_sci->getResMan());
-
 				ObjMap objects = scr->getObjectMap();
 				for (ObjMap::iterator it = objects.begin(); it != objects.end(); ++it)
 					it->_value.syncBaseObject(scr->getBuf(it->_value.getPos().offset));
@@ -486,7 +483,7 @@ void Script::saveLoadWithSerializer(Common::Serializer &s) {
 	s.syncAsSint32LE(_nr);
 
 	if (s.isLoading())
-		init(_nr, g_sci->getResMan());
+		load(_nr, g_sci->getResMan());
 	s.skip(4, VER(14), VER(22));		// OBSOLETE: Used to be _bufSize
 	s.skip(4, VER(14), VER(22));		// OBSOLETE: Used to be _scriptSize
 	s.skip(4, VER(14), VER(22));		// OBSOLETE: Used to be _heapSize
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index 18e23f3..7714983 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -32,12 +32,21 @@
 
 namespace Sci {
 
-Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) {
+Script::Script() : SegmentObj(SEG_TYPE_SCRIPT), _buf(NULL) {
+	freeScript();
+}
+
+Script::~Script() {
+	freeScript();
+}
+
+void Script::freeScript() {
 	_nr = 0;
+
+	free(_buf);
 	_buf = NULL;
 	_bufSize = 0;
 	_scriptSize = 0;
-
 	_heapStart = NULL;
 	_heapSize = 0;
 
@@ -52,23 +61,13 @@ Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) {
 	_localsCount = 0;
 
 	_lockers = 1;
-
 	_markedAsDeleted = false;
+	_objects.clear();
 }
 
-Script::~Script() {
+void Script::load(int script_nr, ResourceManager *resMan) {
 	freeScript();
-}
-
-void Script::freeScript() {
-	free(_buf);
-	_buf = NULL;
-	_bufSize = 0;
-
-	_objects.clear();
-}
 
-void Script::init(int script_nr, ResourceManager *resMan) {
 	Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0);
 	if (!script)
 		error("Script %d not found", script_nr);
@@ -118,11 +117,6 @@ void Script::init(int script_nr, ResourceManager *resMan) {
 			error("TODO: SCI script %d is over 64KB - it's %d bytes long. This can't "
 			      "be handled at the moment, thus stopping", script_nr, script->size);
 	}
-}
-
-void Script::load(ResourceManager *resMan) {
-	Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, _nr), 0);
-	assert(script != 0);
 
 	uint extraLocalsWorkaround = 0;
 	if (g_sci->getGameId() == GID_FANMADE && _nr == 1 && script->size == 11140) {
diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h
index 06a7f08..4d23ffb 100644
--- a/engines/sci/engine/script.h
+++ b/engines/sci/engine/script.h
@@ -95,8 +95,7 @@ public:
 	~Script();
 
 	void freeScript();
-	void init(int script_nr, ResourceManager *resMan);
-	void load(ResourceManager *resMan);
+	void load(int script_nr, ResourceManager *resMan);
 
 	void matchSignatureAndPatch(uint16 scriptNr, byte *scriptData, const uint32 scriptSize);
 	int32 findSignature(const SciScriptSignature *signature, const byte *scriptData, const uint32 scriptSize);
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index cfa83a7..8f85577 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -977,8 +977,7 @@ int SegManager::instantiateScript(int scriptNum) {
 		scr = allocateScript(scriptNum, &segmentId);
 	}
 
-	scr->init(scriptNum, _resMan);
-	scr->load(_resMan);
+	scr->load(scriptNum, _resMan);
 	scr->initializeLocals(this);
 	scr->initializeClasses(this);
 	scr->initializeObjects(this, segmentId);






More information about the Scummvm-git-logs mailing list