[Scummvm-cvs-logs] SF.net SVN: scummvm:[49683] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Tue Jun 15 09:20:54 CEST 2010


Revision: 49683
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49683&view=rev
Author:   thebluegr
Date:     2010-06-15 07:20:53 +0000 (Tue, 15 Jun 2010)

Log Message:
-----------
Cleanup of the savegame code:
- Added a saveLoadWithSerializer() method to the reg_t class
- Moved SegManager::reconstructClones() inside savegame.cpp
- Moved SoundCommandParser::syncPlayList() and SoundCommandParser::reconstructPlayList() inside savegame.cpp

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.cpp
    scummvm/trunk/engines/sci/engine/vm_types.h
    scummvm/trunk/engines/sci/sound/soundcmd.cpp

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-15 06:30:49 UTC (rev 49682)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-15 07:20:53 UTC (rev 49683)
@@ -36,6 +36,7 @@
 #include "sci/engine/state.h"
 #include "sci/engine/message.h"
 #include "sci/engine/savegame.h"
+#include "sci/engine/selector.h"
 #include "sci/engine/vm_types.h"
 #include "sci/engine/script.h"	// for SCI_OBJ_EXPORTS and SCI_OBJ_SYNONYMS
 #include "sci/graphics/gui.h"
@@ -77,11 +78,6 @@
 static void sync_songlib(Common::Serializer &s, SongLibrary &obj);
 #endif
 
-static void sync_reg_t(Common::Serializer &s, reg_t &obj) {
-	s.syncAsUint16LE(obj.segment);
-	s.syncAsUint16LE(obj.offset);
-}
-
 #ifdef USE_OLD_MUSIC_FUNCTIONS
 static void syncSong(Common::Serializer &s, Song &obj) {
 	s.syncAsSint32LE(obj._handle);
@@ -132,7 +128,7 @@
 		fadeTickerStep = 0;
 	} else {
 		// A bit more optimized saving
-		sync_reg_t(s, soundObj);
+		soundObj.saveLoadWithSerializer(s);
 		s.syncAsSint16LE(resourceId);
 		s.syncAsSint16LE(dataInc);
 		s.syncAsSint16LE(ticker);
@@ -217,7 +213,7 @@
 
 template <>
 void syncWithSerializer(Common::Serializer &s, reg_t &obj) {
-	sync_reg_t(s, obj);
+	obj.saveLoadWithSerializer(s);
 }
 
 void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
@@ -297,7 +293,7 @@
 template <>
 void syncWithSerializer(Common::Serializer &s, Class &obj) {
 	s.syncAsSint32LE(obj.script);
-	sync_reg_t(s, obj.reg);
+	obj.reg.saveLoadWithSerializer(s);
 }
 
 static void sync_SavegameMetadata(Common::Serializer &s, SavegameMetadata &obj) {
@@ -396,7 +392,7 @@
 
 void Object::saveLoadWithSerializer(Common::Serializer &s) {
 	s.syncAsSint32LE(_flags);
-	sync_reg_t(s, _pos);
+	_pos.saveLoadWithSerializer(s);
 	s.skip(4, VER(9), VER(12));			// OBSOLETE: Used to be variable_names_nr
 	s.syncAsSint32LE(_methodCount);		// that's actually a uint16
 
@@ -414,18 +410,18 @@
 void syncWithSerializer(Common::Serializer &s, Table<List>::Entry &obj) {
 	s.syncAsSint32LE(obj.next_free);
 
-	sync_reg_t(s, obj.first);
-	sync_reg_t(s, obj.last);
+	obj.first.saveLoadWithSerializer(s);
+	obj.last.saveLoadWithSerializer(s);
 }
 
 template <>
 void syncWithSerializer(Common::Serializer &s, Table<Node>::Entry &obj) {
 	s.syncAsSint32LE(obj.next_free);
 
-	sync_reg_t(s, obj.pred);
-	sync_reg_t(s, obj.succ);
-	sync_reg_t(s, obj.key);
-	sync_reg_t(s, obj.value);
+	obj.pred.saveLoadWithSerializer(s);
+	obj.succ.saveLoadWithSerializer(s);
+	obj.key.saveLoadWithSerializer(s);
+	obj.value.saveLoadWithSerializer(s);
 }
 
 #ifdef ENABLE_SCI32
@@ -459,7 +455,7 @@
 		if (s.isSaving())
 			value = obj.getValue(i);
 
-		sync_reg_t(s, value);
+		value.saveLoadWithSerializer(s);
 
 		if (s.isLoading())
 			obj.setValue(i, value);
@@ -692,6 +688,40 @@
 }
 #endif
 
+void SoundCommandParser::syncPlayList(Common::Serializer &s) {
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+	_music->saveLoadWithSerializer(s);
+#endif
+}
+
+void SoundCommandParser::reconstructPlayList(int savegame_version) {
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+	Common::StackLock lock(_music->_mutex);
+
+	const MusicList::iterator end = _music->getPlayListEnd();
+	for (MusicList::iterator i = _music->getPlayListStart(); i != end; ++i) {
+		if ((*i)->resourceId && _resMan->testResource(ResourceId(kResourceTypeSound, (*i)->resourceId))) {
+			(*i)->soundRes = new SoundResource((*i)->resourceId, _resMan, _soundVersion);
+			_music->soundInitSnd(*i);
+		} else {
+			(*i)->soundRes = 0;
+		}
+		if ((*i)->status == kSoundPlaying) {
+			if (savegame_version < 14) {
+				(*i)->dataInc = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(dataInc));
+				(*i)->signal = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(signal));
+
+				if (_soundVersion >= SCI_VERSION_1_LATE)
+					(*i)->volume = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(vol));
+			}
+
+			cmdPlaySound((*i)->soundObj, 0);
+		}
+	}
+
+#endif
+}
+
 #ifdef ENABLE_SCI32
 void ArrayTable::saveLoadWithSerializer(Common::Serializer &ser) {
 	if (ser.getVersion() < 18)
@@ -735,7 +765,13 @@
 	return 0;
 }
 
-// TODO: Move thie function to a more appropriate place, such as vm.cpp or script.cpp
+void SegManager::reconstructStack(EngineState *s) {
+	DataStack *stack = (DataStack *)(_heap[findSegmentByType(SEG_TYPE_STACK)]);
+	s->stack_base = stack->_entries;
+	s->stack_top = s->stack_base + stack->_capacity;
+}
+
+// TODO: Move this function to a more appropriate place, such as vm.cpp or script.cpp
 void SegManager::reconstructScripts(EngineState *s) {
 	uint i;
 
@@ -771,12 +807,35 @@
 	}
 }
 
-void SegManager::reconstructStack(EngineState *s) {
-	SegmentId stack_seg = findSegmentByType(SEG_TYPE_STACK);
-	DataStack *stack = (DataStack *)(_heap[stack_seg]);
+void SegManager::reconstructClones() {
+	for (uint i = 0; i < _heap.size(); i++) {
+		SegmentObj *mobj = _heap[i];
+		if (mobj && mobj->getType() == SEG_TYPE_CLONES) {
+			CloneTable *ct = (CloneTable *)mobj;
 
-	s->stack_base = stack->_entries;
-	s->stack_top = stack->_entries + stack->_capacity;
+			for (uint j = 0; j < ct->_table.size(); j++) {
+				// Check if the clone entry is used
+				uint entryNum = (uint)ct->first_free;
+				bool isUsed = true;
+				while (entryNum != ((uint) CloneTable::HEAPENTRY_INVALID)) {
+					if (entryNum == j) {
+						isUsed = false;
+						break;
+					}
+					entryNum = ct->_table[entryNum].next_free;
+				}
+
+				if (!isUsed)
+					continue;
+
+				CloneTable::Entry &seeker = ct->_table[j];
+				const Object *baseObj = getObject(seeker.getSpeciesSelector());
+				seeker.cloneFromObject(baseObj);
+				if (!baseObj)
+					warning("Clone entry without a base class: %d", j);
+			}	// end for
+			}	// end if
+	}	// end for
 }
 
 #ifdef USE_OLD_MUSIC_FUNCTIONS

Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-06-15 06:30:49 UTC (rev 49682)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-06-15 07:20:53 UTC (rev 49683)
@@ -476,39 +476,6 @@
 	return &(table->_table[offset]);
 }
 
-void SegManager::reconstructClones() {
-	for (uint i = 0; i < _heap.size(); i++) {
-		if (_heap[i]) {
-			SegmentObj *mobj = _heap[i];
-			if (mobj->getType() == SEG_TYPE_CLONES) {
-				CloneTable *ct = (CloneTable *)mobj;
-
-				for (uint j = 0; j < ct->_table.size(); j++) {
-					// Check if the clone entry is used
-					uint entryNum = (uint)ct->first_free;
-					bool isUsed = true;
-					while (entryNum != ((uint) CloneTable::HEAPENTRY_INVALID)) {
-						if (entryNum == j) {
-							isUsed = false;
-							break;
-						}
-						entryNum = ct->_table[entryNum].next_free;
-					}
-
-					if (!isUsed)
-						continue;
-
-					CloneTable::Entry &seeker = ct->_table[j];
-					const Object *baseObj = getObject(seeker.getSpeciesSelector());
-					seeker.cloneFromObject(baseObj);
-					if (!baseObj)
-						warning("Clone entry without a base class: %d", j);
-				}	// end for
-			}	// end if
-		}	// end if
-	}	// end for
-}
-
 List *SegManager::allocateList(reg_t *addr) {
 	ListTable *table;
 	int offset;

Modified: scummvm/trunk/engines/sci/engine/vm_types.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm_types.h	2010-06-15 06:30:49 UTC (rev 49682)
+++ scummvm/trunk/engines/sci/engine/vm_types.h	2010-06-15 07:20:53 UTC (rev 49683)
@@ -27,6 +27,7 @@
 #define SCI_ENGINE_VM_TYPES_H
 
 #include "common/scummsys.h"
+#include "common/serializer.h"
 
 namespace Sci {
 
@@ -56,6 +57,11 @@
 	int16 toSint16() const {
 		return (int16) offset;
 	}
+
+	void saveLoadWithSerializer(Common::Serializer &s) {
+		s.syncAsUint16LE(segment);
+		s.syncAsUint16LE(offset);
+	}
 };
 
 static inline reg_t make_reg(SegmentId segment, uint16 offset) {

Modified: scummvm/trunk/engines/sci/sound/soundcmd.cpp
===================================================================
--- scummvm/trunk/engines/sci/sound/soundcmd.cpp	2010-06-15 06:30:49 UTC (rev 49682)
+++ scummvm/trunk/engines/sci/sound/soundcmd.cpp	2010-06-15 07:20:53 UTC (rev 49683)
@@ -1088,40 +1088,6 @@
 #endif
 }
 
-void SoundCommandParser::syncPlayList(Common::Serializer &s) {
-#ifndef USE_OLD_MUSIC_FUNCTIONS
-	_music->saveLoadWithSerializer(s);
-#endif
-}
-
-void SoundCommandParser::reconstructPlayList(int savegame_version) {
-#ifndef USE_OLD_MUSIC_FUNCTIONS
-	Common::StackLock lock(_music->_mutex);
-
-	const MusicList::iterator end = _music->getPlayListEnd();
-	for (MusicList::iterator i = _music->getPlayListStart(); i != end; ++i) {
-		if ((*i)->resourceId && _resMan->testResource(ResourceId(kResourceTypeSound, (*i)->resourceId))) {
-			(*i)->soundRes = new SoundResource((*i)->resourceId, _resMan, _soundVersion);
-			_music->soundInitSnd(*i);
-		} else {
-			(*i)->soundRes = 0;
-		}
-		if ((*i)->status == kSoundPlaying) {
-			if (savegame_version < 14) {
-				(*i)->dataInc = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(dataInc));
-				(*i)->signal = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(signal));
-
-				if (_soundVersion >= SCI_VERSION_1_LATE)
-					(*i)->volume = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(vol));
-			}
-
-			cmdPlaySound((*i)->soundObj, 0);
-		}
-	}
-
-#endif
-}
-
 void SoundCommandParser::printPlayList(Console *con) {
 #ifndef USE_OLD_MUSIC_FUNCTIONS
 	_music->printPlayList(con);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list