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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Tue Jun 1 16:41:48 CEST 2010


Revision: 49372
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49372&view=rev
Author:   thebluegr
Date:     2010-06-01 14:41:48 +0000 (Tue, 01 Jun 2010)

Log Message:
-----------
The system strings segment is a fixed segment of the segment manager, which doesn't change during the game, thus move all the system strings code and variables inside the segment manager

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kernel32.cpp
    scummvm/trunk/engines/sci/engine/kfile.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.h
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/sci.cpp

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2010-06-01 14:41:48 UTC (rev 49372)
@@ -67,14 +67,8 @@
 
 	s->script_000 = s->_segMan->getScript(script_000_segment);
 
-	s->sys_strings = s->_segMan->allocateSysStrings(&s->sys_strings_segment);
+	s->_segMan->initSysStrings();
 
-	// Allocate static buffer for savegame and CWD directories
-	SystemString *str = &s->sys_strings->_strings[SYS_STRING_SAVEDIR];
-	str->_name = "savedir";
-	str->_maxSize = MAX_SAVE_DIR_SIZE;
-	str->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
-
 	s->r_acc = s->r_prev = NULL_REG;
 	s->restAdjust = 0;
 
@@ -108,7 +102,7 @@
 	if (s->_voc) {
 		s->_voc->parserIsValid = false; // Invalidate parser
 		s->_voc->parser_event = NULL_REG; // Invalidate parser event
-		s->_voc->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
+		s->_voc->parser_base = make_reg(s->_segMan->getSysStringsSegment(), SYS_STRING_PARSER_BASE);
 	}
 
 	// Initialize menu TODO: Actually this should be another init()
@@ -117,11 +111,6 @@
 
 	s->successor = NULL; // No successor
 
-	SystemString *str = &s->sys_strings->_strings[SYS_STRING_PARSER_BASE];
-	str->_name = "parser-base";
-	str->_maxSize = MAX_PARSER_BASE;
-	str->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
-
 	s->game_start_time = g_system->getMillis();
 	s->last_wait_time = s->game_start_time;
 

Modified: scummvm/trunk/engines/sci/engine/kernel32.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel32.cpp	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/kernel32.cpp	2010-06-01 14:41:48 UTC (rev 49372)
@@ -575,16 +575,16 @@
 		uint32 count = argv[5].toSint16() == -1 ? string2.size() - index2 + 1 : argv[5].toUint16();
 	
 		// We have a special case here for argv[1] being a system string
-		if (argv[1].segment == s->sys_strings_segment) {
+		if (argv[1].segment == s->_segMan->getSysStringsSegment()) {
 			// Resize if necessary
-			if ((uint32)s->sys_strings->_strings[argv[1].toUint16()]._maxSize < index1 + count) {
-				delete[] s->sys_strings->_strings[argv[1].toUint16()]._value;
-				s->sys_strings->_strings[argv[1].toUint16()]._maxSize = index1 + count;
-				s->sys_strings->_strings[argv[1].toUint16()]._value = new char[index1 + count];
-				memset(s->sys_strings->_strings[argv[1].toUint16()]._value, 0, index1 + count);
+			if ((uint32)s->_segMan->sysStrings->_strings[argv[1].toUint16()]._maxSize < index1 + count) {
+				delete[] s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value;
+				s->_segMan->sysStrings->_strings[argv[1].toUint16()]._maxSize = index1 + count;
+				s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value = new char[index1 + count];
+				memset(s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value, 0, index1 + count);
 			}
 
-			strncpy(s->sys_strings->_strings[argv[1].toUint16()]._value + index1, string2.c_str() + index2, count);
+			strncpy(s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value + index1, string2.c_str() + index2, count);
 		} else {
 			SciString *string1 = s->_segMan->lookupString(argv[1]);
 

Modified: scummvm/trunk/engines/sci/engine/kfile.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kfile.cpp	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/kfile.cpp	2010-06-01 14:41:48 UTC (rev 49372)
@@ -428,7 +428,7 @@
 		warning("kGetSaveDir called with %d parameter(s): %04x:%04x", argc, PRINT_REG(argv[0]));
 #endif
 
-	return make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR);
+	return make_reg(s->_segMan->getSysStringsSegment(), SYS_STRING_SAVEDIR);
 }
 
 reg_t kCheckFreeSpace(EngineState *s, int argc, reg_t *argv) {

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-01 14:41:48 UTC (rev 49372)
@@ -893,8 +893,6 @@
 	retval->_gameObj = s->_gameObj;
 	retval->script_000 = retval->_segMan->getScript(retval->_segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD));
 	retval->gc_countdown = GC_INTERVAL - 1;
-	retval->sys_strings_segment = retval->_segMan->findSegmentByType(SEG_TYPE_SYS_STRINGS);
-	retval->sys_strings = (SystemStrings *)(retval->_segMan->_heap[retval->sys_strings_segment]);
 
 	// Time state:
 	retval->last_wait_time = g_system->getMillis();
@@ -903,7 +901,7 @@
 	// static parser information:
 
 	if (retval->_voc)
-		retval->_voc->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
+		retval->_voc->parser_base = make_reg(s->_segMan->getSysStringsSegment(), SYS_STRING_PARSER_BASE);
 
 	retval->successor = NULL;
 

Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-06-01 14:41:48 UTC (rev 49372)
@@ -54,7 +54,6 @@
 	createClassTable();
 }
 
-// Destroy the object, free the memorys if allocated before
 SegManager::~SegManager() {
 	resetSegMan();
 }
@@ -81,6 +80,25 @@
 	createClassTable();
 }
 
+void SegManager::initSysStrings() {
+	sysStrings = (SystemStrings *)allocSegment(new SystemStrings(), &sysStringsSegment);
+
+	// Allocate static buffer for savegame and CWD directories
+	SystemString *strSaveDir = &sysStrings->_strings[SYS_STRING_SAVEDIR];
+	strSaveDir->_name = "savedir";
+	strSaveDir->_maxSize = MAX_SAVE_DIR_SIZE;
+	strSaveDir->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
+	// Set the savegame dir (actually, we set it to a fake value,
+	// since we cannot let the game control where saves are stored)
+	::strcpy(strSaveDir->_value, "");
+
+	// Allocate static buffer for the parser base
+	SystemString *strParserBase = &sysStrings->_strings[SYS_STRING_PARSER_BASE];
+	strParserBase->_name = "parser-base";
+	strParserBase->_maxSize = MAX_PARSER_BASE;
+	strParserBase->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
+}
+
 SegmentId SegManager::findFreeSegment() const {
 	// FIXME: This is a very crude approach: We find a free segment id by scanning
 	// from the start. This can be slow if the number of segments becomes large.
@@ -393,10 +411,6 @@
 	return retval;
 }
 
-SystemStrings *SegManager::allocateSysStrings(SegmentId *segid) {
-	return (SystemStrings *)allocSegment(new SystemStrings(), segid);
-}
-
 void SegManager::freeHunkEntry(reg_t addr) {
 	if (addr.isNull()) {
 		warning("Attempt to free a Hunk from a null address");

Modified: scummvm/trunk/engines/sci/engine/seg_manager.h
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.h	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/seg_manager.h	2010-06-01 14:41:48 UTC (rev 49372)
@@ -182,16 +182,11 @@
 	// 5. System Strings
 
 	/**
-	 * Allocates a system string table
-	 * See also sys_string_acquire();
-	 * @param[in] segid	Segment ID of the stack
-	 * @returns			The physical stack
+	 * Initializes the system string table.
 	 */
-	SystemStrings *allocateSysStrings(SegmentId *segid);
+	void initSysStrings();
 
 
-	// 5. System Strings
-
 	// 6, 7. Lists and Nodes
 
 	/**
@@ -441,6 +436,11 @@
 	void setClassOffset(int index, reg_t offset) { _classTable[index].reg = offset;	}
 	void resizeClassTable(uint32 size) { _classTable.resize(size); }
 
+	/**
+	 * Obtains the system strings segment ID
+	 */
+	SegmentId getSysStringsSegment() { return sysStringsSegment; }
+
 public: // TODO: make private
 	Common::Array<SegmentObj *> _heap;
 	// Only accessible from saveLoadWithSerializer()
@@ -467,6 +467,13 @@
 	SegmentId Nodes_seg_id; ///< ID of the (a) node segment
 	SegmentId Hunks_seg_id; ///< ID of the (a) hunk segment
 
+	/* System strings */
+	SegmentId sysStringsSegment;
+public:	// TODO: make private. Only kString() needs direct access
+	SystemStrings *sysStrings;
+
+private:
+
 #ifdef ENABLE_SCI32
 	SegmentId Arrays_seg_id;
 	SegmentId String_seg_id;

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2010-06-01 14:41:48 UTC (rev 49372)
@@ -94,9 +94,6 @@
 
 	script_000 = 0;
 
-	sys_strings_segment = 0;
-	sys_strings = 0;
-
 	_gameObj = NULL_REG;
 
 	gc_countdown = 0;

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/engine/state.h	2010-06-01 14:41:48 UTC (rev 49372)
@@ -160,10 +160,6 @@
 	 */
 	void shrinkStackToBase();
 
-	/* System strings */
-	SegmentId sys_strings_segment;
-	SystemStrings *sys_strings;
-
 	reg_t _gameObj; /**< Pointer to the game object */
 
 	int gc_countdown; /**< Number of kernel calls until next gc */

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-06-01 05:27:35 UTC (rev 49371)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-06-01 14:41:48 UTC (rev 49372)
@@ -233,11 +233,6 @@
 	script_adjust_opcode_formats(_gamestate);
 	_kernel->loadKernelNames(getGameID());
 
-	// Set the savegame dir (actually, we set it to a fake value,
-	// since we cannot let the game control where saves are stored)
-	assert(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value != 0);
-	strcpy(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value, "");
-
 	SciVersion soundVersion = _features->detectDoSoundType();
 
 	_gamestate->_soundCmd = new SoundCommandParser(_resMan, segMan, _kernel, _audio, soundVersion);


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