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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Mar 24 13:46:50 CET 2009


Revision: 39663
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39663&view=rev
Author:   fingolfin
Date:     2009-03-24 12:46:48 +0000 (Tue, 24 Mar 2009)

Log Message:
-----------
SCI: Changed some char* into Common::String

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/engine/kmenu.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/gfx/sci_widgets.cpp
    scummvm/trunk/engines/sci/gfx/sci_widgets.h

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -603,7 +603,7 @@
 		return 1;
 
 	s->successor = NULL; // No successor
-	s->status_bar_text = NULL; // Status bar is blank
+	s->_statusBarText.clear(); // Status bar is blank
 	s->status_bar_foreground = 0;
 	s->status_bar_background = s->resmgr->_sciVersion >= SCI_VERSION_01_VGA ? 255 : 15;
 
@@ -628,21 +628,17 @@
 	game_obj = script_lookup_export(s, 0, 0);
 	// The first entry in the export table of script 0 points to the game object
 
-	s->game_name = sci_strdup(obj_get_name(s, game_obj));
+	const char *tmp = obj_get_name(s, game_obj);
 
-	if (!s->game_name) {
+	if (!tmp) {
 		sciprintf("Error: script.000, export 0 ("PREG") does not\n"
 		          " yield an object with a name -> sanity check failed\n", PRINT_REG(game_obj));
 		return 1;
 	}
+	s->_gameName = tmp;
 
-	sciprintf(" \"%s\" at "PREG"\n", s->game_name, PRINT_REG(game_obj));
+	sciprintf(" \"%s\" at "PREG"\n", s->_gameName.c_str(), PRINT_REG(game_obj));
 
-	if (strlen((char *)s->game_name) >= MAX_GAMEDIR_SIZE) {
-		s->game_name[MAX_GAMEDIR_SIZE - 1] = 0; // Fix length with brute force
-		sciprintf(" Designation too long; was truncated to \"%s\"\n", s->game_name);
-	}
-
 	s->game_obj = game_obj;
 
 	// Mark parse tree as unused
@@ -684,8 +680,6 @@
 
 	_free_graphics_input(s);
 
-	free(s->game_name);
-
 	return 0;
 }
 

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -1297,7 +1297,10 @@
 	int type = GET_SEL32V(obj, type);
 	int state = GET_SEL32V(obj, state);
 
-	if (type == K_CONTROL_BUTTON && text && !strcmp(s->game_name, "sq4") &&
+	// FIXME: This seems to be some kind of of game specific workaround.
+	// Therefore, a proper WORKAROUND comment should be added here which
+	// explains what this does.
+	if (type == K_CONTROL_BUTTON && text && (s->_gameName == "sq4") &&
 			s->version < SCI_VERSION(1, 001, 000) && !strcmp(text, " Delete ")) {
 		PUT_SEL32V(obj, state, (state | CONTROL_STATE_GRAY) & ~CONTROL_STATE_ENABLED);
 	}

Modified: scummvm/trunk/engines/sci/engine/kmenu.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmenu.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/kmenu.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -76,16 +76,13 @@
 	s->status_bar_foreground = fgcolor;
 	s->status_bar_background = bgcolor;
 
-	if (NULL != s->status_bar_text) {
-		free(s->status_bar_text);
-		s->status_bar_text = NULL;
+	if (text.segment) {
+		const char *tmp = sci_strdup(kernel_dereference_char_pointer(s, text, 0));
+		s->_statusBarText = tmp ? tmp : "";
 	}
 
-	if (text.segment)
-		s->status_bar_text = sci_strdup(kernel_dereference_char_pointer(s, text, 0));
+	sciw_set_status_bar(s, s->titlebar_port, s->_statusBarText, fgcolor, bgcolor);
 
-	sciw_set_status_bar(s, s->titlebar_port, s->status_bar_text, fgcolor, bgcolor);
-
 	gfxop_update(s->gfx_state);
 
 	return s->r_acc;
@@ -97,7 +94,7 @@
 	if (SKPV(0))
 		sciw_set_menubar(s, s->titlebar_port, s->_menubar, -1);
 	else
-		sciw_set_status_bar(s, s->titlebar_port, NULL, 0, 0);
+		sciw_set_status_bar(s, s->titlebar_port, "", 0, 0);
 
 	s->titlebar_port->draw(GFXW(s->titlebar_port), Common::Point(0, 0));
 	gfxop_update(s->gfx_state);
@@ -317,7 +314,7 @@
 			port->widfree(GFXW(port));
 			port = NULL;
 
-			sciw_set_status_bar(s, s->titlebar_port, s->status_bar_text, s->status_bar_foreground, s->status_bar_background);
+			sciw_set_status_bar(s, s->titlebar_port, s->_statusBarText, s->status_bar_foreground, s->status_bar_background);
 			gfxop_update(s->gfx_state);
 		}
 		FULL_REDRAW;

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -925,7 +925,7 @@
 
 	retval->successor = NULL;
 	retval->pic_priority_table = (int*)gfxop_get_pic_metainfo(retval->gfx_state);
-	retval->game_name = sci_strdup(obj_get_name(retval, retval->game_obj));
+	retval->_gameName = obj_get_name(retval, retval->game_obj);
 
 	retval->sound.it = NULL;
 	retval->sound.flags = s->sound.flags;

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -2781,7 +2781,7 @@
 	s->status_bar_foreground = cmd_params[0].val;
 	s->status_bar_background = cmd_params[1].val;
 
-	sciw_set_status_bar(s, s->titlebar_port, s->status_bar_text, s->status_bar_foreground, s->status_bar_background);
+	sciw_set_status_bar(s, s->titlebar_port, s->_statusBarText, s->status_bar_foreground, s->status_bar_background);
 	gfxop_update(s->gfx_state);
 
 	return 0;

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -34,7 +34,6 @@
 
 	resmgr = 0;
 
-	game_name = 0;
 	game_version = 0;
 
 	gfx_state = 0;
@@ -55,8 +54,6 @@
 
 	pic_priority_table = 0;
 
-	status_bar_text = 0;
-
 	status_bar_foreground = 0;
 	status_bar_background = 0;
 

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/state.h	2009-03-24 12:46:48 UTC (rev 39663)
@@ -76,7 +76,6 @@
 #define CURRENT_SAVEGAME_VERSION 8
 #define MINIMUM_SAVEGAME_VERSION 8
 
-#define MAX_GAMEDIR_SIZE 32 /* Used for subdirectory inside of "~/.freesci/" */
 #define MAX_SAVEGAME_NR 20 /* Maximum number of savegames */
 
 #define MAX_SAVE_DIR_SIZE MAXPATHLEN
@@ -119,7 +118,7 @@
 
 	ResourceManager *resmgr; /* The resource manager */
 
-	char *game_name; /* Designation of the primary object (which inherits from Game) */
+	Common::String _gameName; /* Designation of the primary object (which inherits from Game) */
 	char *game_version;
 
 	/* Non-VM information */
@@ -142,7 +141,8 @@
 
 	int *pic_priority_table; /* 16 entries with priorities or NULL if not present */
 
-	char *status_bar_text; /* Text on the status bar, or NULL if the title bar is blank */
+	/** Text on the status bar, or NULL if the title bar is blank */
+	Common::String _statusBarText;
 
 	int status_bar_foreground, status_bar_background;
 

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -2078,7 +2078,7 @@
 int game_run(EngineState **_s) {
 	EngineState *s = *_s;
 
-	sciprintf(" Calling %s::play()\n", s->game_name);
+	sciprintf(" Calling %s::play()\n", s->_gameName.c_str());
 	_init_stack_base_with_selector(s, s->selector_map.play); // Call the play selector
 
 	// Now: Register the first element on the execution stack-
@@ -2095,35 +2095,6 @@
 	return 0;
 }
 
-#if 0
-int game_restore(EngineState **_s, char *game_name) {
-	EngineState *s;
-	int debug_state = _debugstate_valid;
-
-	sciprintf("Restoring savegame '%s'...\n", game_name);
-	s = gamestate_restore(*_s, game_name);
-
-	if (!s) {
-		sciprintf("Restoring gamestate '%s' failed.\n", game_name);
-		return 1;
-	}
-	_debugstate_valid = debug_state;
-	script_abort_flag = 0;
-	s->restarting_flags = 0;
-
-	s->execution_stack_pos = -1; // Resatart with replay
-
-	_init_stack_base_with_selector(s, s->selector_map.replay);
-
-	send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base);
-
-	*_s = s = _game_run(s, 1);
-
-	sciprintf(" Game::play() finished.\n");
-	return 0;
-}
-#endif
-
 Object *obj_get(EngineState *s, reg_t offset) {
 	MemObject *memobj = GET_OBJECT_SEGMENT(*s->seg_manager, offset.segment);
 	Object *obj = NULL;

Modified: scummvm/trunk/engines/sci/gfx/sci_widgets.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/sci_widgets.cpp	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/gfx/sci_widgets.cpp	2009-03-24 12:46:48 UTC (rev 39663)
@@ -72,7 +72,7 @@
 	return list;
 }
 
-void sciw_set_status_bar(EngineState *s, gfxw_port_t *status_bar, const char *text, int fgcolor, int bgcolor) {
+void sciw_set_status_bar(EngineState *s, gfxw_port_t *status_bar, const Common::String &text, int fgcolor, int bgcolor) {
 	gfx_state_t *state;
 	gfxw_list_t *list;
 	gfx_color_t bg = status_bar->bgcolor;
@@ -93,9 +93,9 @@
 
 	clear_titlebar(status_bar);
 
-	if (text) {
+	if (!text.empty()) {
 		gfxw_text_t *textw = gfxw_new_text(state, gfx_rect(0, 0, status_bar->bounds.width, status_bar->bounds.height),
-		                                   status_bar->font_nr, text, ALIGN_LEFT, ALIGN_CENTER,
+		                                   status_bar->font_nr, text.c_str(), ALIGN_LEFT, ALIGN_CENTER,
 		                                   fg, fg, bg, GFXR_FONT_FLAG_NO_NEWLINES);
 
 		list = make_titlebar_list(s, status_bar->bounds, status_bar);

Modified: scummvm/trunk/engines/sci/gfx/sci_widgets.h
===================================================================
--- scummvm/trunk/engines/sci/gfx/sci_widgets.h	2009-03-24 12:14:41 UTC (rev 39662)
+++ scummvm/trunk/engines/sci/gfx/sci_widgets.h	2009-03-24 12:46:48 UTC (rev 39663)
@@ -62,7 +62,7 @@
 /* Used by the interpreter to flag buttons that are enabled */
 #define CONTROL_STATE_ENABLED 0x0001
 
-void sciw_set_status_bar(EngineState *s, gfxw_port_t *status_bar, const char *text, int fgcolor, int bgcolor);
+void sciw_set_status_bar(EngineState *s, gfxw_port_t *status_bar, const Common::String &text, int fgcolor, int bgcolor);
 /* Sets the contents of a port used as status bar
 ** Parmeters: (EngineState *) s: The affected game state
 **            (gfxw_port_t *) status_bar: The status bar port


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