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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Sep 22 03:08:43 CEST 2009


Revision: 44246
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44246&view=rev
Author:   fingolfin
Date:     2009-09-22 01:08:42 +0000 (Tue, 22 Sep 2009)

Log Message:
-----------
SCI: Change SystemStrings to use RAW storage consistenly

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/segment.cpp
    scummvm/trunk/engines/sci/engine/segment.h
    scummvm/trunk/engines/sci/engine/vm.h
    scummvm/trunk/engines/sci/sci.cpp

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-09-22 00:51:55 UTC (rev 44245)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-09-22 01:08:42 UTC (rev 44246)
@@ -334,12 +334,10 @@
 	s->string_frag_segment = s->segMan->allocateStringFrags();
 
 	// Allocate static buffer for savegame and CWD directories
-	SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
+	SystemString *str = &s->sys_strings->_strings[SYS_STRING_SAVEDIR];
 	str->_name = "savedir";
-	str->max_size = MAX_SAVE_DIR_SIZE;
-	str->value = (reg_t *)calloc(MAX_SAVE_DIR_SIZE, sizeof(reg_t));	// FIXME -- sizeof(char) or sizeof(reg_t) ??
-	str->value[0].segment = s->string_frag_segment; // Set to empty string
-	str->value[0].offset = 0;
+	str->_maxSize = MAX_SAVE_DIR_SIZE;
+	str->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
 
 
 	s->r_acc = s->r_prev = NULL_REG;
@@ -365,16 +363,6 @@
 	return 0;
 }
 
-void script_set_gamestate_save_dir(EngineState *s, const char *path) {
-	SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
-
-	strncpy((char *)str->value, path, str->max_size);		// FIXME -- strncpy or internal_stringfrag_strncpy ?
-	str->value[str->max_size - 1].segment = s->string_frag_segment; // Make sure to terminate
-	str->value[str->max_size - 1].offset &= 0xff00; // Make sure to terminate
-}
-
-void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int len);
-
 void script_free_vm_memory(EngineState *s) {
 	debug(2, "Freeing VM memory");
 
@@ -438,12 +426,10 @@
 	s->status_bar_foreground = 0;
 	s->status_bar_background = !s->resMan->isVGA() ? 15 : 255;
 
-	SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE];
+	SystemString *str = &s->sys_strings->_strings[SYS_STRING_PARSER_BASE];
 	str->_name = "parser-base";
-	str->max_size = MAX_PARSER_BASE;
-	str->value = (reg_t *)calloc(MAX_PARSER_BASE + 1, sizeof(char));	// FIXME -- sizeof(char) or sizeof(reg_t) ??
-	str->value[0].segment = s->string_frag_segment; // Set to empty string
-	str->value[0].offset = 0; // Set to empty string
+	str->_maxSize = MAX_PARSER_BASE;
+	str->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
 
 	s->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
 

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-09-22 00:51:55 UTC (rev 44245)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-09-22 01:08:42 UTC (rev 44246)
@@ -438,16 +438,24 @@
 
 static void sync_SystemString(Common::Serializer &s, SystemString &obj) {
 	s.syncString(obj._name);
-	s.syncAsSint32LE(obj.max_size);
+	s.syncAsSint32LE(obj._maxSize);
 
-	// FIXME: This is a *WEIRD* hack: We sync a reg_t* as if it was a string.
-	// No idea why, but this mimicks what the old save/load code used to do.
-	syncCStr(s, (char **)&obj.value);
+	// Sync obj._value. We cannot use syncCStr as we must make sure that
+	// the allocated buffer has the correct size, i.e., obj._maxSize
+	Common::String tmp;
+	if (s.isSaving() && obj._value)
+		tmp = obj._value;
+	s.syncString(tmp);
+	if (s.isLoading()) {
+		//free(*str);
+		obj._value = (char *)calloc(obj._maxSize, sizeof(char));
+		strncpy(obj._value, tmp.c_str(), obj._maxSize);
+	}
 }
 
 void SystemStrings::saveLoadWithSerializer(Common::Serializer &s) {
 	for (int i = 0; i < SYS_STRINGS_MAX; ++i)
-		sync_SystemString(s, strings[i]);
+		sync_SystemString(s, _strings[i]);
 }
 
 void DynMem::saveLoadWithSerializer(Common::Serializer &s) {
@@ -776,25 +784,6 @@
 	retval->sys_strings_segment = retval->segMan->findSegmentByType(SEG_TYPE_SYS_STRINGS);
 	retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->segMan, retval->sys_strings_segment, SEG_TYPE_SYS_STRINGS);
 
-	// Restore system strings
-	SystemString *str;
-
-	// First, pad memory
-	for (int i = 0; i < SYS_STRINGS_MAX; i++) {
-		str = &retval->sys_strings->strings[i];
-		char *data = (char *)str->value;
-		if (data) {
-			str->value = (reg_t *)calloc(str->max_size + 1, sizeof(reg_t));
-			strncpy((char *)str->value, data, str->max_size + 1);		// FIXME -- strncpy or internal_stringfrag_strncpy ?
-			free(data);
-		}
-	}
-
-	str = &retval->sys_strings->strings[SYS_STRING_SAVEDIR];
-	internal_stringfrag_strncpy(s, str->value, s->sys_strings->strings[SYS_STRING_SAVEDIR].value, str->max_size);
-	str->value[str->max_size - 1].segment = s->string_frag_segment; // Make sure to terminate
-	str->value[str->max_size - 1].offset &= 0xff00; // Make sure to terminate
-
 	// Time state:
 	retval->last_wait_time = g_system->getMillis();
 	retval->game_start_time = g_system->getMillis() - retval->game_time * 1000;

Modified: scummvm/trunk/engines/sci/engine/segment.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.cpp	2009-09-22 00:51:55 UTC (rev 44245)
+++ scummvm/trunk/engines/sci/engine/segment.cpp	2009-09-22 01:08:42 UTC (rev 44246)
@@ -294,15 +294,15 @@
 }
 
 bool SystemStrings::isValidOffset(uint16 offset) const {
-	return offset < SYS_STRINGS_MAX && !strings[offset]._name.empty();
+	return offset < SYS_STRINGS_MAX && !_strings[offset]._name.empty();
 }
 
 SegmentRef SystemStrings::dereference(reg_t pointer) {
 	SegmentRef ret;
-	ret.isRaw = false;	// FIXME: Raw or not raw? the sys strings code is totally incoherent in this regard
-	ret.maxSize = strings[pointer.offset].max_size;
+	ret.isRaw = true;	// FIXME: Raw or not raw? the sys strings code is totally incoherent in this regard
+	ret.maxSize = _strings[pointer.offset]._maxSize;
 	if (isValidOffset(pointer.offset))
-		ret.raw = (byte *)(strings[pointer.offset].value);
+		ret.raw = (byte *)(_strings[pointer.offset]._value);
 	else {
 		// This occurs in KQ5CD when interacting with certain objects
 		warning("Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(pointer));

Modified: scummvm/trunk/engines/sci/engine/segment.h
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.h	2009-09-22 00:51:55 UTC (rev 44245)
+++ scummvm/trunk/engines/sci/engine/segment.h	2009-09-22 01:08:42 UTC (rev 44246)
@@ -150,28 +150,28 @@
 
 struct SystemString {
 	Common::String _name;
-	int max_size;
-	reg_t *value;
+	int _maxSize;
+	char *_value;
 };
 
 struct SystemStrings : public SegmentObj {
-	SystemString strings[SYS_STRINGS_MAX];
+	SystemString _strings[SYS_STRINGS_MAX];
 
 public:
 	SystemStrings() : SegmentObj(SEG_TYPE_SYS_STRINGS) {
 		for (int i = 0; i < SYS_STRINGS_MAX; i++) {
-			strings[i].max_size = 0;
-			strings[i].value = 0;
+			_strings[i]._maxSize = 0;
+			_strings[i]._value = 0;
 		}
 	}
 	~SystemStrings() {
 		for (int i = 0; i < SYS_STRINGS_MAX; i++) {
-			SystemString *str = &strings[i];
+			SystemString *str = &_strings[i];
 			if (!str->_name.empty()) {
-				free(str->value);
-				str->value = NULL;
+				free(str->_value);
+				str->_value = NULL;
 
-				str->max_size = 0;
+				str->_maxSize = 0;
 			}
 		}
 	}

Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h	2009-09-22 00:51:55 UTC (rev 44245)
+++ scummvm/trunk/engines/sci/engine/vm.h	2009-09-22 01:08:42 UTC (rev 44246)
@@ -418,13 +418,6 @@
 int script_init_engine(EngineState *);
 
 /**
- * Sets the gamestate's save_dir to the parameter path
- * @param[in] s		The state to set
- * @param[in] path	Path where save_dir will point to
- */
-void script_set_gamestate_save_dir(EngineState *s, const char *path);
-
-/**
  * Frees all additional memory associated with a EngineState block
  * @param[in] s	The EngineState whose elements should be cleared
  */

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2009-09-22 00:51:55 UTC (rev 44245)
+++ scummvm/trunk/engines/sci/sci.cpp	2009-09-22 01:08:42 UTC (rev 44246)
@@ -153,7 +153,7 @@
 
 	// Set the savegame dir (actually, we set it to a fake value,
 	// since we cannot let the game control where saves are stored)
-	script_set_gamestate_save_dir(_gamestate, "/");
+	strcpy(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value, "/");
 
 	GfxState gfx_state;
 	_gamestate->gfx_state = &gfx_state;


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