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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Feb 2 23:52:44 CET 2010


Revision: 47824
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47824&view=rev
Author:   fingolfin
Date:     2010-02-02 22:52:41 +0000 (Tue, 02 Feb 2010)

Log Message:
-----------
SCI: Use Common::List and Common::String to simplify breakpoint handling (untested)

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/script.h
    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/engine/vm.h
    scummvm/trunk/engines/sci/sci.cpp

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/console.cpp	2010-02-02 22:52:41 UTC (rev 47824)
@@ -205,8 +205,8 @@
 	if (_vm->_gamestate)
 		_vm->_gamestate->_sound.sfx_suspend(true);
 #endif
-	if (_vm->getEngineState() && _vm->getEngineState()->_soundCmd)
-		_vm->getEngineState()->_soundCmd->pauseAll(true);
+	if (_vm->_gamestate && _vm->_gamestate->_soundCmd)
+		_vm->_gamestate->_soundCmd->pauseAll(true);
 }
 
 void Console::postEnter() {
@@ -214,8 +214,8 @@
 	if (_vm->_gamestate)
 		_vm->_gamestate->_sound.sfx_suspend(false);
 #endif
-	if (_vm->getEngineState() && _vm->getEngineState()->_soundCmd)
-		_vm->getEngineState()->_soundCmd->pauseAll(false);
+	if (_vm->_gamestate && _vm->_gamestate->_soundCmd)
+		_vm->_gamestate->_soundCmd->pauseAll(false);
 
 	if (!_videoFile.empty()) {
 		_vm->_gamestate->_gui->hideCursor();
@@ -409,7 +409,7 @@
 bool Console::cmdGetVersion(int argc, const char **argv) {
 	const char *viewTypeDesc[] = { "Unknown", "EGA", "VGA", "VGA SCI1.1", "Amiga" };
 
-	EngineState *s = _vm->getEngineState();
+	EngineState *s = _vm->_gamestate;
 	bool hasVocab997 = s->resMan->testResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SELECTORS)) ? true : false;
 
 	DebugPrintf("Game ID: %s\n", s->_gameId.c_str());
@@ -693,7 +693,7 @@
 	} else {
 		Common::String roomNumberStr = argv[1];
 		int roomNumber = strtol(roomNumberStr.c_str(), NULL, roomNumberStr.hasSuffix("h") ? 16 : 10);
-		_vm->getEngineState()->setRoomNumber(roomNumber);
+		_vm->_gamestate->setRoomNumber(roomNumber);
 		DebugPrintf("Room number changed to %d (%x in hex)\n", roomNumber, roomNumber);
 	}
 
@@ -1446,7 +1446,7 @@
 	} while (seeker);
 	DebugPrintf("\n");
 #else
-	_vm->getEngineState()->_soundCmd->printPlayList(this);
+	_vm->_gamestate->_soundCmd->printPlayList(this);
 #endif
 
 	return true;
@@ -1467,7 +1467,7 @@
 		return true;
 	}
 
-	_vm->getEngineState()->_soundCmd->printSongInfo(addr, this);
+	_vm->_gamestate->_soundCmd->printSongInfo(addr, this);
 
 	return true;
 }
@@ -1486,7 +1486,7 @@
 		return true;
 	}
 
-	_vm->getEngineState()->_soundCmd->startNewSound(number);
+	_vm->_gamestate->_soundCmd->startNewSound(number);
 
 	return false;
 }
@@ -1590,7 +1590,7 @@
 		return true;
 	}
 
-	SoundResource *soundRes = new SoundResource(number, _vm->getResourceManager(), _vm->getEngineState()->detectDoSoundType());
+	SoundResource *soundRes = new SoundResource(number, _vm->getResourceManager(), _vm->_gamestate->detectDoSoundType());
 
 	if (!soundRes) {
 		DebugPrintf("Not a sound resource!\n");
@@ -2367,25 +2367,25 @@
 }
 
 bool Console::cmdBreakpointList(int argc, const char **argv) {
-	Breakpoint *bp = _vm->_gamestate->bp_list;
 	int i = 0;
 	int bpdata;
 
 	DebugPrintf("Breakpoint list:\n");
 
-	while (bp) {
+	Common::List<Breakpoint>::const_iterator bp = _vm->_gamestate->_breakpoints.begin();
+	Common::List<Breakpoint>::const_iterator end = _vm->_gamestate->_breakpoints.end();
+	for (; bp != end; ++bp) {
 		DebugPrintf("  #%i: ", i);
 		switch (bp->type) {
 		case BREAK_SELECTOR:
-			DebugPrintf("Execute %s\n", bp->data.name);
+			DebugPrintf("Execute %s\n", bp->name.c_str());
 			break;
 		case BREAK_EXPORT:
-			bpdata = bp->data.address;
+			bpdata = bp->address;
 			DebugPrintf("Execute script %d, export %d\n", bpdata >> 16, bpdata & 0xFFFF);
 			break;
 		}
 
-		bp = bp->next;
 		i++;
 	}
 
@@ -2399,45 +2399,30 @@
 		return true;
 	}
 
-	Breakpoint *bp, *bp_next, *bp_prev;
-	int i = 0, found = 0;
-	int type;
-	int idx = atoi(argv[1]);
+	const int idx = atoi(argv[1]);
 
-	// Find breakpoint with given index
-	bp_prev = NULL;
-	bp = _vm->_gamestate->bp_list;
-	while (bp && i < idx) {
-		bp_prev = bp;
-		bp = bp->next;
-		i++;
+	// Find the breakpoint at index idx.
+	Common::List<Breakpoint>::iterator bp = _vm->_gamestate->_breakpoints.begin();
+	const Common::List<Breakpoint>::iterator end = _vm->_gamestate->_breakpoints.end();
+	for (int i = 0; bp != end && i < idx; ++bp, ++i) {
+		// do nothing
 	}
-	if (!bp) {
+
+	if (bp == end) {
 		DebugPrintf("Invalid breakpoint index %i\n", idx);
 		return true;
 	}
 
 	// Delete it
-	bp_next = bp->next;
-	type = bp->type;
-	if (type == BREAK_SELECTOR) free(bp->data.name);
-	free(bp);
-	if (bp_prev)
-		bp_prev->next = bp_next;
-	else
-		_vm->_gamestate->bp_list = bp_next;
+	_vm->_gamestate->_breakpoints.erase(bp);
 
-	// Check if there are more breakpoints of the same type. If not, clear
-	// the respective bit in s->have_bp.
-	for (bp = _vm->_gamestate->bp_list; bp; bp = bp->next) {
-		if (bp->type == type) {
-			found = 1;
-			break;
-		}
+	// Update EngineState::_activeBreakpointTypes.
+	int type = 0;
+	for (bp = _vm->_gamestate->_breakpoints.begin(); bp != end; ++bp) {
+		type |= bp->type;
 	}
 
-	if (!found)
-		_vm->_gamestate->have_bp &= ~type;
+	_vm->_gamestate->_activeBreakpointTypes = type;
 
 	return true;
 }
@@ -2455,25 +2440,13 @@
 	/* Note: We can set a breakpoint on a method that has not been loaded yet.
 	   Thus, we can't check whether the command argument is a valid method name.
 	   A breakpoint set on an invalid method name will just never trigger. */
-	Breakpoint *bp;
-	if (_vm->_gamestate->bp_list) {
-		// List exists, append the breakpoint to the end
-		bp = _vm->_gamestate->bp_list;
-		while (bp->next)
-			bp = bp->next;
-		bp->next = (Breakpoint *)malloc(sizeof(Breakpoint));
-		bp = bp->next;
-	} else {
-		// No list, so create the list head
-		_vm->_gamestate->bp_list = (Breakpoint *)malloc(sizeof(Breakpoint));
-		bp = _vm->_gamestate->bp_list;
-	}
-	bp->next = NULL;
-	bp->type = BREAK_SELECTOR;
-	bp->data.name = (char *)malloc(strlen(argv[1]) + 1);
-	strcpy(bp->data.name, argv[1]);
-	_vm->_gamestate->have_bp |= BREAK_SELECTOR;
+	Breakpoint bp;
+	bp.type = BREAK_SELECTOR;
+	bp.name = argv[1];
 
+	_vm->_gamestate->_breakpoints.push_back(bp);
+	_vm->_gamestate->_activeBreakpointTypes |= BREAK_SELECTOR;
+
 	return true;
 }
 
@@ -2488,24 +2461,13 @@
 	/* Note: We can set a breakpoint on a method that has not been loaded yet.
 	   Thus, we can't check whether the command argument is a valid method name.
 	   A breakpoint set on an invalid method name will just never trigger. */
-	Breakpoint *bp;
-	if (_vm->_gamestate->bp_list) {
-		// List exists, append the breakpoint to the end
-		bp = _vm->_gamestate->bp_list;
-		while (bp->next)
-			bp = bp->next;
-		bp->next = (Breakpoint *)malloc(sizeof(Breakpoint));
-		bp = bp->next;
-	} else {
-		// No list, so create the list head
-		_vm->_gamestate->bp_list = (Breakpoint *)malloc(sizeof(Breakpoint));
-		bp = _vm->_gamestate->bp_list;
-	}
-	bp->next = NULL;
-	bp->type = BREAK_EXPORT;
-	bp->data.address = (atoi(argv[1]) << 16 | atoi(argv[2]));
-	_vm->_gamestate->have_bp |= BREAK_EXPORT;
+	Breakpoint bp;
+	bp.type = BREAK_EXPORT;
+	bp.address = (atoi(argv[1]) << 16 | atoi(argv[2]));
 
+	_vm->_gamestate->_breakpoints.push_back(bp);
+	_vm->_gamestate->_activeBreakpointTypes |= BREAK_EXPORT;
+
 	return true;
 }
 

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2010-02-02 22:52:41 UTC (rev 47824)
@@ -218,8 +218,8 @@
 
 	s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING;
 
-	s->bp_list = NULL; // No breakpoints defined
-	s->have_bp = 0;
+	s->_breakpoints.clear(); // No breakpoints defined
+	s->_activeBreakpointTypes = 0;
 
 	if (s->detectLofsType() == SCI_VERSION_1_MIDDLE)
 		s->_segMan->setExportAreWide(true);
@@ -231,22 +231,6 @@
 	return 0;
 }
 
-void script_free_breakpoints(EngineState *s) {
-	Breakpoint *bp, *bp_next;
-
-	// Free breakpoint list
-	bp = s->bp_list;
-	while (bp) {
-		bp_next = bp->next;
-		if (bp->type == BREAK_SELECTOR)
-			free(bp->data.name);
-		free(bp);
-		bp = bp_next;
-	}
-
-	s->bp_list = NULL;
-}
-
 /*************************************************************/
 /* Game instance stuff: Init/Unitialize state-dependant data */
 /*************************************************************/

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-02-02 22:52:41 UTC (rev 47824)
@@ -1003,8 +1003,8 @@
 		retval->_voc->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
 
 	// Copy breakpoint information from current game instance
-	retval->have_bp = s->have_bp;
-	retval->bp_list = s->bp_list;
+	retval->_breakpoints = s->_breakpoints;
+	retval->_activeBreakpointTypes = s->_activeBreakpointTypes;
 
 	retval->successor = NULL;
 	retval->_gameId = s->_gameId;

Modified: scummvm/trunk/engines/sci/engine/script.h
===================================================================
--- scummvm/trunk/engines/sci/engine/script.h	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/engine/script.h	2010-02-02 22:52:41 UTC (rev 47824)
@@ -204,8 +204,6 @@
 
 void script_adjust_opcode_formats(EngineState *s);
 
-void script_free_breakpoints(EngineState *s);
-
 } // End of namespace Sci
 
 #endif // SCI_ENGINE_SCRIPT_H

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2010-02-02 22:52:41 UTC (rev 47824)
@@ -59,8 +59,7 @@
 
 	script_000 = 0;
 
-	bp_list = 0;
-	have_bp = 0;
+	_activeBreakpointTypes = 0;
 	sys_strings_segment = 0;
 	sys_strings = 0;
 

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/engine/state.h	2010-02-02 22:52:41 UTC (rev 47824)
@@ -280,8 +280,8 @@
 	bool usesCdTrack() { return _usesCdTrack; }
 
 	/* Debugger data: */
-	Breakpoint *bp_list;   /**< List of breakpoints */
-	int have_bp;  /**< Bit mask specifying which types of breakpoints are used in bp_list */
+	Common::List<Breakpoint> _breakpoints;   /**< List of breakpoints */
+	int _activeBreakpointTypes;  /**< Bit mask specifying which types of breakpoints are active */
 
 	/* System strings */
 	SegmentId sys_strings_segment;

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2010-02-02 22:52:41 UTC (rev 47824)
@@ -52,7 +52,7 @@
 int script_step_counter = 0; // Counts the number of steps executed	// FIXME: Avoid non-const global vars
 int script_gc_interval = GC_INTERVAL; // Number of steps in between gcs	// FIXME: Avoid non-const global vars
 
-static bool breakpointFlag = false;	// FIXME: Avoid non-const global vars
+static bool breakpointWasHit = false;	// FIXME: Avoid non-const global vars
 
 // validation functionality
 
@@ -241,22 +241,20 @@
 	}
 
 	// Check if a breakpoint is set on this method
-	if (s->have_bp & BREAK_EXPORT) {
-		Breakpoint *bp;
+	if (s->_activeBreakpointTypes & BREAK_EXPORT) {
 		uint32 bpaddress;
 
 		bpaddress = (script << 16 | pubfunct);
 
-		bp = s->bp_list;
-		while (bp) {
-			if (bp->type == BREAK_EXPORT && bp->data.address == bpaddress) {
+		Common::List<Breakpoint>::const_iterator bp;
+		for (bp = s->_breakpoints.begin(); bp != s->_breakpoints.end(); ++bp) {
+			if (bp->type == BREAK_EXPORT && bp->address == bpaddress) {
 				Console *con = ((SciEngine *)g_engine)->getSciDebugger();
 				con->DebugPrintf("Break on script %d, export %d\n", script, pubfunct);
 				g_debugState.debugging = true;
-				breakpointFlag = true;
+				breakpointWasHit = true;
 				break;
 			}
-			bp = bp->next;
 		}
 	}
 
@@ -322,32 +320,30 @@
 		}
 
 		// Check if a breakpoint is set on this method
-		if (s->have_bp & BREAK_SELECTOR) {
-			Breakpoint *bp;
-			char method_name [256];
+		if (s->_activeBreakpointTypes & BREAK_SELECTOR) {
+			char method_name[256];
 
 			sprintf(method_name, "%s::%s", s->_segMan->getObjectName(send_obj), s->_kernel->getSelectorName(selector).c_str());
 
-			bp = s->bp_list;
-			while (bp) {
-				int cmplen = strlen(bp->data.name);
-				if (bp->data.name[cmplen - 1] != ':')
+			Common::List<Breakpoint>::const_iterator bp;
+			for (bp = s->_breakpoints.begin(); bp != s->_breakpoints.end(); ++bp) {
+				int cmplen = bp->name.size();
+				if (bp->name.lastChar() != ':')
 					cmplen = 256;
 
-				if (bp->type == BREAK_SELECTOR && !strncmp(bp->data.name, method_name, cmplen)) {
+				if (bp->type == BREAK_SELECTOR && !strncmp(bp->name.c_str(), method_name, cmplen)) {
 					Console *con = ((SciEngine *)g_engine)->getSciDebugger();
 					con->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj));
 					print_send_action = 1;
-					breakpointFlag = true;
+					breakpointWasHit = true;
 					g_debugState.debugging = true;
 					break;
 				}
-				bp = bp->next;
 			}
 		}
 
 #ifdef VM_DEBUG_SEND
-		printf("Send to %04x:%04x, selector %04x (%s):", PRINT_REG(send_obj), selector, ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str());
+		printf("Send to %04x:%04x, selector %04x (%s):", PRINT_REG(send_obj), selector, ((SciEngine *)g_engine)->getKernel()->getSelectorName(selector).c_str());
 #endif // VM_DEBUG_SEND
 
 		ObjVarRef varp;
@@ -651,8 +647,8 @@
 		// Debug if this has been requested:
 		// TODO: re-implement sci_debug_flags
 		if (g_debugState.debugging /* sci_debug_flags*/) {
-			script_debug(s, breakpointFlag);
-			breakpointFlag = false;
+			script_debug(s, breakpointWasHit);
+			breakpointWasHit = false;
 		}
 		Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
 		if (con->isAttached()) {

Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/engine/vm.h	2010-02-02 22:52:41 UTC (rev 47824)
@@ -287,11 +287,8 @@
 
 struct Breakpoint {
 	BreakpointType type;
-	union {
-		uint32 address;  ///< Breakpoints on exports
-		char *name; ///< Breakpoints on selector names
-	} data;
-	Breakpoint *next;
+	uint32 address;  ///< Breakpoints on exports
+	Common::String name; ///< Breakpoints on selector names
 };
 
 /**

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-02-02 22:50:32 UTC (rev 47823)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-02-02 22:52:41 UTC (rev 47824)
@@ -35,7 +35,7 @@
 
 #include "sci/engine/state.h"
 #include "sci/engine/kernel.h"
-#include "sci/engine/script.h"	// for script_adjust_opcode_formats & script_free_breakpoints
+#include "sci/engine/script.h"	// for script_adjust_opcode_formats
 
 #include "sci/sound/audio.h"
 #include "sci/sound/soundcmd.h"
@@ -242,7 +242,6 @@
 	game_run(&_gamestate); // Run the game
 
 	game_exit(_gamestate);
-	script_free_breakpoints(_gamestate);
 
 	ConfMan.flushToDisk();
 


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