[Scummvm-cvs-logs] CVS: scummvm/sword2 console.cpp,1.53,1.54 console.h,1.25,1.26 debug.cpp,1.48,1.49 events.cpp,1.35,1.36 logic.cpp,1.51,1.52 logic.h,1.42,1.43 memory.cpp,1.34,1.35 memory.h,1.17,1.18 resman.cpp,1.107,1.108 resman.h,1.25,1.26 startup.cpp,1.47,1.48 sword2.h,1.77,1.78

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Mon Feb 21 23:38:37 CET 2005


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8257

Modified Files:
	console.cpp console.h debug.cpp events.cpp logic.cpp logic.h 
	memory.cpp memory.h resman.cpp resman.h startup.cpp sword2.h 
Log Message:
Moved some debugging stuff into the debugger class.


Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- console.cpp	19 Feb 2005 14:02:10 -0000	1.53
+++ console.cpp	22 Feb 2005 07:37:49 -0000	1.54
@@ -179,8 +179,92 @@
 	return true;
 }
 
+static int compare_blocks(const void *p1, const void *p2) {
+	const MemBlock *m1 = *(const MemBlock * const *) p1;
+	const MemBlock *m2 = *(const MemBlock * const *) p2;
+
+	if (m1->size < m2->size)
+		return 1;
+	if (m1->size > m2->size)
+		return -1;
+	return 0;
+}
+
 bool Debugger::Cmd_Mem(int argc, const char **argv) {
-	_vm->_memory->memDisplay();
+	int16 numBlocks = _vm->_memory->getNumBlocks();
+	MemBlock *memBlocks = _vm->_memory->getMemBlocks();
+
+	MemBlock **blocks = (MemBlock **) malloc(numBlocks * sizeof(MemBlock));
+
+	int i, j;
+
+	for (i = 0, j = 0; i < MAX_MEMORY_BLOCKS; i++) {
+		if (memBlocks[i].ptr)
+			blocks[j++] = &memBlocks[i];
+	}
+
+	qsort(blocks, numBlocks, sizeof(MemBlock *), compare_blocks);
+
+	DebugPrintf("     size id  res  type                 name\n");
+	DebugPrintf("---------------------------------------------------------------------------\n");
+
+	for (i = 0; i < numBlocks; i++) {
+		StandardHeader *head = (StandardHeader *) blocks[i]->ptr;
+		const char *type;
+
+		switch (head->fileType) {
+		case ANIMATION_FILE:
+			type = "ANIMATION_FILE";
+			break;
+		case SCREEN_FILE:
+			type = "SCREEN_FILE";
+			break;
+		case GAME_OBJECT:
+			type  = "GAME_OBJECT";
+			break;
+		case WALK_GRID_FILE:
+			type = "WALK_GRID_FILE";
+			break;
+		case GLOBAL_VAR_FILE:
+			type = "GLOBAL_VAR_FILE";
+			break;
+		case PARALLAX_FILE_null:
+			type = "PARALLAX_FILE_null";
+			break;
+		case RUN_LIST:
+			type = "RUN_LIST";
+			break;
+		case TEXT_FILE:
+			type = "TEXT_FILE";
+			break;
+		case SCREEN_MANAGER:
+			type = "SCREEN_MANAGER";
+			break;
+		case MOUSE_FILE:
+			type = "MOUSE_FILE";
+			break;
+		case WAV_FILE:
+			type = "WAV_FILE";
+			break;
+		case ICON_FILE:
+			type = "ICON_FILE";
+			break;
+		case PALETTE_FILE:
+			type = "PALETTE_FILE";
+			break;
+		default:
+			type = "<unknown>";
+			break;
+		}
+
+		DebugPrintf("%9ld %-3d %-4d %-20s %s\n", blocks[i]->size, blocks[i]->id, blocks[i]->uid, type, head->name);
+	}
+		
+	free(blocks);
+
+	DebugPrintf("---------------------------------------------------------------------------\n");
+	DebugPrintf("%9ld\n", _vm->_memory->getTotAlloc());
+
 	return true;
 }
 
@@ -190,7 +274,37 @@
 }
 
 bool Debugger::Cmd_Res(int argc, const char **argv) {
-	_vm->_resman->printConsoleClusters();
+	uint32 numClusters = _vm->_resman->getNumClusters();
+
+	if (!numClusters) {
+		DebugPrintf("Argh! No resources!\n");
+		return true;
+	}
+
+	ResourceFile *resFiles = _vm->_resman->getResFiles();
+
+	for (uint i = 0; i < numClusters; i++) {
+		DebugPrintf("%-20s ", resFiles[i].fileName);
+		if (!(resFiles[i].cd & LOCAL_PERM)) {			
+			switch (resFiles[i].cd & 3) {
+			case BOTH:
+				DebugPrintf("CD 1 & 2\n");
+				break;
+			case CD1:
+				DebugPrintf("CD 1\n");
+				break;
+			case CD2:
+				DebugPrintf("CD 2\n");
+				break;
+			default:
+				DebugPrintf("CD 3? Huh?!\n");
+				break;
+			}
+		} else
+			DebugPrintf("HD\n");
+	}
+
+	DebugPrintf("%d resources\n", _vm->_resman->getNumResFiles());
 	return true;
 }
 
@@ -201,12 +315,39 @@
 	if (argc > 1)
 		minCount = atoi(argv[1]);
 
-	_vm->_resman->listResources(minCount);
+	uint32 numResFiles = _vm->_resman->getNumResFiles();
+	Resource *resList = _vm->_resman->getResList();
+
+	for (uint i = 0; i < numResFiles; i++) {
+		if (resList[i].ptr && resList[i].refCount >= minCount) {
+			StandardHeader *head = (StandardHeader *) resList[i].ptr;
+			DebugPrintf("%-4d: %-35s refCount: %-3d\n", i, head->name, resList[i].refCount);
+		}
+	}
+
 	return true;
 }
 
 bool Debugger::Cmd_Starts(int argc, const char **argv) {
-	_vm->conPrintStartMenu();
+	uint32 numStarts = _vm->getNumStarts();
+
+	if (!numStarts) {
+		DebugPrintf("Sorry - no startup positions registered?\n");
+
+		uint32 numScreenManagers = _vm->getNumScreenManagers();
+
+		if (!numScreenManagers)
+			DebugPrintf("There is a problem with startup.inf\n");
+		else
+			DebugPrintf(" (%d screen managers found in startup.inf)\n", numScreenManagers);
+		return true;
+	}
+
+	StartUp *startList = _vm->getStartList();
+
+	for (uint i = 0; i < numStarts; i++)
+		DebugPrintf("%d  (%s)\n", i, startList[i].description);
+
 	return true;
 }
 
@@ -218,7 +359,23 @@
 		return true;
 	}
 
-	_vm->conStart(atoi(argv[1]));
+	uint32 numStarts = _vm->getNumStarts();
+
+	if (!numStarts) {
+		DebugPrintf("Sorry - there are no startups!\n");
+		return true;
+	}
+
+	int start = atoi(argv[1]);
+	
+	if (start < 0 || start >= (int) numStarts) {
+		DebugPrintf("Not a legal start position\n");
+		return true;
+	}
+
+	DebugPrintf("Running start %d\n", start);
+
+	_vm->runStart(start);
 	_vm->_screen->setPalette(187, 1, pal, RDPAL_INSTANT);
 	return true;
 }
@@ -268,28 +425,139 @@
 }
 
 bool Debugger::Cmd_ResLook(int argc, const char **argv) {
-	if (argc != 2)
+	if (argc != 2) {
 		DebugPrintf("Usage: %s number\n", argv[0]);
-	else
-		_vm->_resman->examine(atoi(argv[1]));
+		return true;
+	}
+
+	int res = atoi(argv[1]);
+	uint32 numResFiles = _vm->_resman->getNumResFiles();
+
+	if (res < 0 || res >= (int) numResFiles) {
+		DebugPrintf("Illegal resource %d. There are %d resources, 0-%d.\n",
+			res, numResFiles, numResFiles - 1);
+		return true;
+	}
+
+	if (!_vm->_resman->checkValid(res)) {
+		DebugPrintf("%d is a null & void resource number\n", res);
+		return true;
+	}
+
+	// Open up the resource and take a look inside!
+	StandardHeader *file_header = (StandardHeader *) _vm->_resman->openResource(res);
+
+	switch (file_header->fileType) {
+	case ANIMATION_FILE:
+		DebugPrintf("<anim> %s\n", file_header->name);
+		break;
+	case SCREEN_FILE:
+		DebugPrintf("<layer> %s\n", file_header->name);
+		break;
+	case GAME_OBJECT:
+		DebugPrintf("<game object> %s\n", file_header->name);
+		break;
+	case WALK_GRID_FILE:
+		DebugPrintf("<walk grid> %s\n", file_header->name);
+		break;
+	case GLOBAL_VAR_FILE:
+		DebugPrintf("<global variables> %s\n", file_header->name);
+		break;
+	case PARALLAX_FILE_null:
+		DebugPrintf("<parallax file NOT USED!> %s\n", file_header->name);
+		break;
+	case RUN_LIST:
+		DebugPrintf("<run list> %s\n", file_header->name);
+		break;
+	case TEXT_FILE:
+		DebugPrintf("<text file> %s\n", file_header->name);
+		break;
+	case SCREEN_MANAGER:
+		DebugPrintf("<screen manager> %s\n", file_header->name);
+		break;
+	case MOUSE_FILE:
+		DebugPrintf("<mouse pointer> %s\n", file_header->name);
+		break;
+	case ICON_FILE:
+		DebugPrintf("<menu icon> %s\n", file_header->name);
+		break;
+	default:
+		DebugPrintf("unrecognised fileType %d\n", file_header->fileType);
+		break;
+	}
+
+	_vm->_resman->closeResource(res);
 	return true;
 }
 
 bool Debugger::Cmd_CurrentInfo(int argc, const char **argv) {
-	printCurrentInfo();
+	// prints general stuff about the screen, etc.
+	ScreenInfo *screenInfo = _vm->_screen->getScreenInfo();
+
+	if (screenInfo->background_layer_id) {
+		DebugPrintf("background layer id %d\n", screenInfo->background_layer_id);
+		DebugPrintf("%d wide, %d high\n", screenInfo->screen_wide, screenInfo->screen_deep);
+		DebugPrintf("%d normal layers\n", screenInfo->number_of_layers);
+
+		Cmd_RunList(argc, argv);
+	} else
+		DebugPrintf("No screen\n");
 	return true;
 }
 
 bool Debugger::Cmd_RunList(int argc, const char **argv) {
-	_vm->_logic->examineRunList();
+	uint32 *game_object_list;
+	StandardHeader *file_header;
+
+	uint32 runList = _vm->_logic->getRunList();
+
+	if (runList) {
+		game_object_list = (uint32 *) (_vm->_resman->openResource(runList) + sizeof(StandardHeader));
+
+		DebugPrintf("Runlist number %d\n", runList);
+
+		for (int i = 0; game_object_list[i]; i++) {
+			file_header = (StandardHeader *) _vm->_resman->openResource(game_object_list[i]);
+			DebugPrintf("%d %s\n", game_object_list[i], file_header->name);
+			_vm->_resman->closeResource(game_object_list[i]);
+		}
+
+		_vm->_resman->closeResource(runList);
+	} else
+		DebugPrintf("No run list set\n");
+
 	return true;
 }
 
 bool Debugger::Cmd_Kill(int argc, const char **argv) {
-	if (argc != 2)
+	if (argc != 2) {
 		DebugPrintf("Usage: %s number\n", argv[0]);
-	else
-		_vm->_resman->kill(atoi(argv[1]));
+		return true;
+	}
+
+	int res = atoi(argv[1]);
+	uint32 numResFiles = _vm->_resman->getNumResFiles();
+
+	if (res < 0 || res >= (int) numResFiles) {
+		DebugPrintf("Illegal resource %d. There are %d resources, 0-%d.\n",
+			res, numResFiles, numResFiles - 1);
+		return true;
+	}
+
+	Resource *resList = _vm->_resman->getResList();
+
+	if (!resList[res].ptr) {
+		DebugPrintf("Resource %d is not in memory\n", res);
+		return true;
+	}
+
+	if (resList[res].refCount) {
+		DebugPrintf("Resource %d is open - cannot remove\n", res);
+		return true;
+	}
+
+	_vm->_resman->remove(res);
+	DebugPrintf("Trashed %d\n", res);
 	return true;
 }
 
@@ -466,7 +734,7 @@
 	}
 
 	// Automatically do "s 32" to run the animation testing start script
-	_vm->conStart(32);
+	_vm->runStart(32);
 
 	// Same as typing "VAR 912 <value>" at the console
 	varSet(912, atoi(argv[1]));
@@ -482,7 +750,7 @@
 	}
 
 	// Automatically do "s 33" to run the text/speech testing start script
-	_vm->conStart(33);
+	_vm->runStart(33);
 
 	// Same as typing "VAR 1230 <value>" at the console
 	varSet(1230, atoi(argv[1]));
@@ -501,7 +769,7 @@
 	}
 
 	// Automatically do "s 33" to run the text/speech testing start script
-	_vm->conStart(33);
+	_vm->runStart(33);
 
 	// Same as typing "VAR 1230 <value>" at the console
 	varSet(1230, atoi(argv[1]));
@@ -518,7 +786,21 @@
 }
 
 bool Debugger::Cmd_Events(int argc, const char **argv) {
-	_vm->_logic->printEventList();
+	EventUnit *eventList = _vm->_logic->getEventList();
+
+	DebugPrintf("EVENT LIST:\n");
+
+	for (uint32 i = 0; i < MAX_events; i++) {
+		if (eventList[i].id) {
+			byte buf[NAME_LEN];
+			uint32 target = eventList[i].id;
+			uint32 script = eventList[i].interact_id;
+
+			DebugPrintf("slot %2d: id = %s (%d)\n", i, _vm->fetchObjectName(target, buf), target);
+			DebugPrintf("         script = %s (%d) pos %d\n", _vm->fetchObjectName(script / 65536, buf), script / 65536, script % 65536);
+		}
+	}
+
 	return true;
 }
 

Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- console.h	17 Jan 2005 10:57:10 -0000	1.25
+++ console.h	22 Feb 2005 07:37:49 -0000	1.26
@@ -46,11 +46,9 @@
 
 	byte _debugTextBlocks[MAX_DEBUG_TEXTS];
 
-	void clearDebugTextBlocks(void);
+	void clearDebugTextBlocks();
 	void makeDebugTextBlock(char *text, int16 x, int16 y);
 
-	void printCurrentInfo(void);
-
 	void plotCrossHair(int16 x, int16 y, uint8 pen);
 	void drawRect(int16 x, int16 y, int16 x2, int16 y2, uint8 pen);
 
@@ -72,8 +70,8 @@
 	ObjectGraphic _playerGraphic;
 	uint32 _playerGraphicNoFrames;
 
-	void buildDebugText(void);
-	void drawDebugGraphics(void);
+	void buildDebugText();
+	void drawDebugGraphics();
 
 protected:
 	Sword2Engine *_vm;

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/debug.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- debug.cpp	19 Feb 2005 14:02:10 -0000	1.48
+++ debug.cpp	22 Feb 2005 07:37:49 -0000	1.49
@@ -31,7 +31,7 @@
 
 namespace Sword2 {
 
-void Debugger::clearDebugTextBlocks(void) {
+void Debugger::clearDebugTextBlocks() {
 	uint8 blockNo = 0;
 
 	while (blockNo < MAX_DEBUG_TEXTS && _debugTextBlocks[blockNo] > 0) {
@@ -56,7 +56,7 @@
 	_debugTextBlocks[blockNo] = _vm->_fontRenderer->buildNewBloc((byte *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION);
 }
 
-void Debugger::buildDebugText(void) {
+void Debugger::buildDebugText() {
 	char buf[128];
 
 	int32 showVarNo;		// for variable watching
@@ -307,12 +307,21 @@
 		// memory indicator - this should come last, to show all the
 		// sprite blocks above!
 
-		_vm->_memory->memStatusStr(buf);
+		uint32 totAlloc = _vm->_memory->getTotAlloc();
+		int16 numBlocks = _vm->_memory->getNumBlocks();
+
+		if (totAlloc < 1024)
+			sprintf(buf, "%u bytes in %d memory blocks", totAlloc, numBlocks);
+		else if (totAlloc < 1024 * 1024)
+			sprintf(buf, "%uK in %d memory blocks", totAlloc / 1024, numBlocks);
+		else
+			sprintf(buf, "%.02fM in %d memory blocks", totAlloc / 1048576., numBlocks);
+
 		makeDebugTextBlock(buf, 0, 0);
 	}
 }
 
-void Debugger::drawDebugGraphics(void) {
+void Debugger::drawDebugGraphics() {
 	ScreenInfo *screenInfo = _vm->_screen->getScreenInfo();
 	// walk-grid
 
@@ -364,18 +373,4 @@
 	_vm->_screen->drawLine(x2, y1, x2, y2, pen);	// right edge
 }
 
-void Debugger::printCurrentInfo(void) {
-	// prints general stuff about the screen, etc.
-	ScreenInfo *screenInfo = _vm->_screen->getScreenInfo();
-
-	if (screenInfo->background_layer_id) {
-		DebugPrintf("background layer id %d\n", screenInfo->background_layer_id);
-		DebugPrintf("%d wide, %d high\n", screenInfo->screen_wide, screenInfo->screen_deep);
-		DebugPrintf("%d normal layers\n", screenInfo->number_of_layers);
-
-		_vm->_logic->examineRunList();
-	} else
-		DebugPrintf("No screen\n");
-}
-
 } // End of namespace Sword2

Index: events.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/events.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- events.cpp	28 Jan 2005 16:33:09 -0000	1.35
+++ events.cpp	22 Feb 2005 07:37:49 -0000	1.36
@@ -21,14 +21,11 @@
 #include "common/stdafx.h"
 #include "sword2/sword2.h"
 #include "sword2/defs.h"
-#include "sword2/console.h"
 #include "sword2/interpreter.h"
 #include "sword2/logic.h"
 #include "sword2/memory.h"
 #include "sword2/resman.h"
 
-#define Debug_Printf _vm->_debugger->DebugPrintf
-
 namespace Sword2 {
 
 void Logic::sendEvent(uint32 id, uint32 interact_id) {
@@ -48,7 +45,7 @@
 	sendEvent(id, (interact_id << 16) | 2);
 }
 
-int Logic::checkEventWaiting(void) {
+int Logic::checkEventWaiting() {
 	for (int i = 0; i < MAX_events; i++) {
 		if (_eventList[i].id == _scriptVars[ID])
 			return 1;
@@ -57,7 +54,7 @@
 	return 0;
 }
 
-void Logic::startEvent(void) {
+void Logic::startEvent() {
 	// call this from stuff like fnWalk
 	// you must follow with a return IR_TERMINATE
 
@@ -90,7 +87,7 @@
 
 // For the debugger
 
-uint32 Logic::countEvents(void) {
+uint32 Logic::countEvents() {
 	uint32 count = 0;
 
 	for (int i = 0; i < MAX_events; i++) {
@@ -101,19 +98,4 @@
 	return count;
 }
 
-void Logic::printEventList(void) {
-	Debug_Printf("EVENT LIST:\n");
-
-	for (uint32 i = 0; i < MAX_events; i++) {
-		if (_eventList[i].id) {
-			byte buf[NAME_LEN];
-			uint32 target = _eventList[i].id;
-			uint32 script = _eventList[i].interact_id;
-
-			Debug_Printf("slot %2d: id = %s (%d)\n", i, _vm->fetchObjectName(target, buf), target);
-			Debug_Printf("         script = %s (%d) pos %d\n", _vm->fetchObjectName(script / 65536, buf), script / 65536, script % 65536);
-		}
-	}
-}
-
 } // End of namespace Sword2

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- logic.cpp	19 Feb 2005 14:02:11 -0000	1.51
+++ logic.cpp	22 Feb 2005 07:37:49 -0000	1.52
@@ -21,7 +21,6 @@
 #include "common/stdafx.h"
 #include "sword2/sword2.h"
 #include "sword2/defs.h"
-#include "sword2/console.h"
 #include "sword2/interpreter.h"
 #include "sword2/logic.h"
 #include "sword2/resman.h"
@@ -30,8 +29,6 @@
 
 #define LEVEL (_curObjectHub->logic_level)
 
-#define Debug_Printf _vm->_debugger->DebugPrintf
-
 namespace Sword2 {
 
 Logic::Logic(Sword2Engine *vm) :
@@ -54,7 +51,7 @@
  * Do one cycle of the current session.
  */
 
-int Logic::processSession(void) {
+int Logic::processSession() {
 	// might change during the session, so take a copy here
 	uint32 run_list = _currentRunList;
 
@@ -219,7 +216,7 @@
  * @return The private _currentRunList variable.
  */
 
-uint32 Logic::getRunList(void) {
+uint32 Logic::getRunList() {
 	return _currentRunList;
 }
 
@@ -257,28 +254,7 @@
 	_curObjectHub->script_pc[LEVEL] = new_script & 0xffff;
 }
 
-void Logic::examineRunList(void) {
-	uint32 *game_object_list;
-	StandardHeader *file_header;
-
-	if (_currentRunList) {
-		// open and lock in place
-		game_object_list = (uint32 *) (_vm->_resman->openResource(_currentRunList) + sizeof(StandardHeader));
-
-		Debug_Printf("Runlist number %d\n", _currentRunList);
-
-		for (int i = 0; game_object_list[i]; i++) {
-			file_header = (StandardHeader *) _vm->_resman->openResource(game_object_list[i]);
-			Debug_Printf("%d %s\n", game_object_list[i], file_header->name);
-			_vm->_resman->closeResource(game_object_list[i]);
-		}
-
-		_vm->_resman->closeResource(_currentRunList);
-	} else
-		Debug_Printf("No run list set\n");
-}
-
-void Logic::resetKillList(void) {
+void Logic::resetKillList() {
 	_kills = 0;
 }
 

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- logic.h	19 Feb 2005 14:02:11 -0000	1.42
+++ logic.h	22 Feb 2005 07:37:49 -0000	1.43
@@ -44,6 +44,11 @@
 class Sword2Engine;
 class Router;
 
+struct EventUnit {
+	uint32 id;
+	uint32 interact_id;
+};
+
 class Logic {
 private:
 	Sword2Engine *_vm;
@@ -62,11 +67,6 @@
 	// each object has one of these tacked onto the beginning
 	ObjectHub *_curObjectHub;
 
-	struct EventUnit {
-		uint32 id;
-		uint32 interact_id;
-	};
-
 	EventUnit _eventList[MAX_events];
 
 	// Resource id of the wav to use as lead-in/lead-out from smacker
@@ -148,6 +148,8 @@
 	Logic(Sword2Engine *vm);
 	~Logic();
 
+	EventUnit *getEventList() { return _eventList; }
+
 	// Point to the global variable data
 	static uint32 *_scriptVars;
 
@@ -166,12 +168,12 @@
 
 	void sendEvent(uint32 id, uint32 interact_id);
 	void setPlayerActionEvent(uint32 id, uint32 interact_id);
-	void startEvent(void);
-	int checkEventWaiting(void);
+	void startEvent();
+	int checkEventWaiting();
 	void clearEvent(uint32 id);
 	void killAllIdsEvents(uint32 id);
 
-	uint32 countEvents(void);
+	uint32 countEvents();
 
 	struct SyncUnit {
 		uint32 id;
@@ -181,7 +183,7 @@
 	SyncUnit _syncList[MAX_syncs];
 
 	void clearSyncs(uint32 id);
-	int getSync(void);
+	int getSync();
 
 	Router *_router;
 
@@ -304,22 +306,19 @@
 	int32 fnChangeShadows(int32 *params);
 
 	// do one cycle of the current session
-	int processSession(void);
+	int processSession();
 
 	// cause the logic loop to terminate and drop out
 	void expressChangeSession(uint32 sesh_id);
 
-	uint32 getRunList(void);
+	uint32 getRunList();
 
 	// setup script_id and script_pc in _curObjectHub - called by fnGosub()
 	void logicUp(uint32 new_script);
 
 	void logicReplace(uint32 new_script);
 	void logicOne(uint32 new_script);
-	void examineRunList(void);
-	void resetKillList(void);
-
-	void printEventList(void);
+	void resetKillList();
 };
 
 } // End of namespace Sword2

Index: memory.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/memory.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- memory.cpp	17 Jan 2005 10:57:11 -0000	1.34
+++ memory.cpp	22 Feb 2005 07:37:49 -0000	1.35
@@ -43,15 +43,10 @@
 
 #include "common/stdafx.h"
 #include "sword2/sword2.h"
-#include "sword2/console.h"
 #include "sword2/memory.h"
 
 namespace Sword2 {
 
-#define MAX_BLOCKS 999
-
-#define Debug_Printf _vm->_debugger->DebugPrintf
-
 MemoryManager::MemoryManager(Sword2Engine *vm) : _vm(vm) {
 	// The id stack contains all the possible ids for the memory blocks.
 	// We use this to ensure that no two blocks ever have the same id.
@@ -71,24 +66,24 @@
 	// encoding or decoding pointers any faster, and these are by far the
 	// most common operations.
 
-	_idStack = (int16 *) malloc(MAX_BLOCKS * sizeof(int16));
-	_memBlocks = (MemBlock *) malloc(MAX_BLOCKS * sizeof(MemBlock));
-	_memBlockIndex = (MemBlock **) malloc(MAX_BLOCKS * sizeof(MemBlock *));
+	_idStack = (int16 *) malloc(MAX_MEMORY_BLOCKS * sizeof(int16));
+	_memBlocks = (MemBlock *) malloc(MAX_MEMORY_BLOCKS * sizeof(MemBlock));
+	_memBlockIndex = (MemBlock **) malloc(MAX_MEMORY_BLOCKS * sizeof(MemBlock *));
 
 	_totAlloc = 0;
 	_numBlocks = 0;
 
-	for (int i = 0; i < MAX_BLOCKS; i++) {
-		_idStack[i] = MAX_BLOCKS - i - 1;
+	for (int i = 0; i < MAX_MEMORY_BLOCKS; i++) {
+		_idStack[i] = MAX_MEMORY_BLOCKS - i - 1;
 		_memBlocks[i].ptr = NULL;
 		_memBlockIndex[i] = NULL;
 	}
 
-	_idStackPtr = MAX_BLOCKS;
+	_idStackPtr = MAX_MEMORY_BLOCKS;
 }
 
 MemoryManager::~MemoryManager() {
-	for (int i = 0; i < MAX_BLOCKS; i++)
+	for (int i = 0; i < MAX_MEMORY_BLOCKS; i++)
 		free(_memBlocks[i].ptr);
 	free(_memBlocks);
 	free(_memBlockIndex);
@@ -245,96 +240,4 @@
 		_memBlockIndex[i] = _memBlockIndex[i + 1];
 }
 
-static int compare_blocks(const void *p1, const void *p2) {
-	const MemBlock *m1 = *(const MemBlock * const *) p1;
-	const MemBlock *m2 = *(const MemBlock * const *) p2;
-
-	if (m1->size < m2->size)
-		return 1;
-	if (m1->size > m2->size)
-		return -1;
-	return 0;
-}
-
-void MemoryManager::memDisplay() {
-	MemBlock **blocks = (MemBlock **) malloc(_numBlocks * sizeof(MemBlock));
-	int i, j;
-
-	for (i = 0, j = 0; i < MAX_BLOCKS; i++) {
-		if (_memBlocks[i].ptr)
-			blocks[j++] = &_memBlocks[i];
-	}
-
-	qsort(blocks, _numBlocks, sizeof(MemBlock *), compare_blocks);
-
-	Debug_Printf("     size id  res  type                 name\n");
-	Debug_Printf("---------------------------------------------------------------------------\n");
-
-	for (i = 0; i < _numBlocks; i++) {
-		StandardHeader *head = (StandardHeader *) blocks[i]->ptr;
-		const char *type;
-
-		switch (head->fileType) {
-		case ANIMATION_FILE:
-			type = "ANIMATION_FILE";
-			break;
-		case SCREEN_FILE:
-			type = "SCREEN_FILE";
-			break;
-		case GAME_OBJECT:
-			type  = "GAME_OBJECT";
-			break;
-		case WALK_GRID_FILE:
-			type = "WALK_GRID_FILE";
-			break;
-		case GLOBAL_VAR_FILE:
-			type = "GLOBAL_VAR_FILE";
-			break;
-		case PARALLAX_FILE_null:
-			type = "PARALLAX_FILE_null";
-			break;
-		case RUN_LIST:
-			type = "RUN_LIST";
-			break;
-		case TEXT_FILE:
-			type = "TEXT_FILE";
-			break;
-		case SCREEN_MANAGER:
-			type = "SCREEN_MANAGER";
-			break;
-		case MOUSE_FILE:
-			type = "MOUSE_FILE";
-			break;
-		case WAV_FILE:
-			type = "WAV_FILE";
-			break;
-		case ICON_FILE:
-			type = "ICON_FILE";
-			break;
-		case PALETTE_FILE:
-			type = "PALETTE_FILE";
-			break;
-		default:
-			type = "<unknown>";
-			break;
-		}
-
-		Debug_Printf("%9ld %-3d %-4d %-20s %s\n", blocks[i]->size, blocks[i]->id, blocks[i]->uid, type, head->name);
-	}
-		
-	free(blocks);
-
-	Debug_Printf("---------------------------------------------------------------------------\n");
-	Debug_Printf("%9ld\n", _totAlloc);
-}
-
-void MemoryManager::memStatusStr(char *buf) {
-	if (_totAlloc < 1024)
-		sprintf(buf, "%u bytes in %d memory blocks", _totAlloc, _numBlocks);
-	else if (_totAlloc < 1024 * 1024)
-		sprintf(buf, "%uK in %d memory blocks", _totAlloc / 1024, _numBlocks);
-	else
-		sprintf(buf, "%.02fM in %d memory blocks", _totAlloc / 1048576., _numBlocks);
-}
-
 } // End of namespace Sword2

Index: memory.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/memory.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- memory.h	17 Jan 2005 10:57:11 -0000	1.17
+++ memory.h	22 Feb 2005 07:37:49 -0000	1.18
@@ -21,6 +21,8 @@
 #ifndef	MEMORY_H
 #define	MEMORY_H
 
+#define MAX_MEMORY_BLOCKS 999
+
 namespace Sword2 {
 
 struct MemBlock {
@@ -51,14 +53,15 @@
 	MemoryManager(Sword2Engine *vm);
 	~MemoryManager();
 
+	int16 getNumBlocks() { return _numBlocks; }
+	uint32 getTotAlloc() { return _totAlloc; }
+	MemBlock *getMemBlocks() { return _memBlocks; }
+
 	int32 encodePtr(byte *ptr);
 	byte *decodePtr(int32 n);
 
 	byte *memAlloc(uint32 size, int16 uid);
 	void memFree(byte *ptr);
-
-	void memDisplay();
-	void memStatusStr(char *buf);
 };
 
 } // End of namespace Sword2

Index: resman.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.cpp,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- resman.cpp	21 Feb 2005 02:29:15 -0000	1.107
+++ resman.cpp	22 Feb 2005 07:37:49 -0000	1.108
@@ -21,8 +21,8 @@
 #include "common/stdafx.h"
 #include "common/file.h"
 #include "sword2/sword2.h"
-#include "sword2/console.h"
 #include "sword2/defs.h"
+#include "sword2/console.h"
 #include "sword2/logic.h"
 #include "sword2/memory.h"
 #include "sword2/resman.h"
@@ -42,14 +42,6 @@
 //	resource.tab which is a table which tells us which cluster a resource
 //      is located in and the number within the cluster
 
-enum {
-	BOTH		= 0x0,		// Cluster is on both CDs
-	CD1		= 0x1,		// Cluster is on CD1 only
-	CD2		= 0x2,		// Cluster is on CD2 only
-	LOCAL_CACHE	= 0x4,		// Cluster is cached on HDD
-	LOCAL_PERM	= 0x8		// Cluster is on HDD.
-};
-
 #if !defined(__GNUC__)
 	#pragma START_PACK_STRUCTS
 #endif
@@ -198,7 +190,7 @@
 	_usedMem = 0;
 }
 
-ResourceManager::~ResourceManager(void) {
+ResourceManager::~ResourceManager() {
 	Resource *res = _cacheStart;
 	while (res) {
 		_vm->_memory->memFree(res->ptr);
@@ -659,7 +651,7 @@
 	return _resFiles[parent_res_file].entryTab[actual_res * 2 + 1];
 }
 
-void ResourceManager::checkMemUsage(void) {
+void ResourceManager::checkMemUsage() {
 	while (_usedMem > MAX_MEM_CACHE) {
 		// we're using up more memory than we wanted to. free some old stuff.
 		// Newly loaded objects are added to the start of the list,
@@ -679,113 +671,6 @@
 	}
 }
 
-void ResourceManager::printConsoleClusters(void) {
-	if (_totalClusters) {
-		for (uint i = 0; i < _totalClusters; i++) {
-			Debug_Printf("%-20s ", _resFiles[i].fileName);
-			if (!(_resFiles[i].cd & LOCAL_PERM)) {			
-				switch (_resFiles[i].cd & 3) {
-				case BOTH:
-					Debug_Printf("CD 1 & 2\n");
-					break;
-				case CD1:
-					Debug_Printf("CD 1\n");
-					break;
-				case CD2:
-					Debug_Printf("CD 2\n");
-					break;
-				default:
-					Debug_Printf("CD 3? Huh?!\n");
-					break;
-				}
-			} else
-				Debug_Printf("HD\n");
-		}
-		Debug_Printf("%d resources\n", _totalResFiles);
-	} else
-		Debug_Printf("Argh! No resources!\n");
-}
-
-void ResourceManager::listResources(uint minCount) {
-	for (uint i = 0; i < _totalResFiles; i++) {
-		if (_resList[i].ptr && _resList[i].refCount >= minCount) {
-			StandardHeader *head = (StandardHeader *) _resList[i].ptr;
-			Debug_Printf("%-4d: %-35s refCount: %-3d\n", i, head->name, _resList[i].refCount);
-		}
-	}
-}
-
-void ResourceManager::examine(int res) {
-	if (res < 0 || res >= (int) _totalResFiles)
-		Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
-	else if (_resConvTable[res * 2] == 0xffff)
-		Debug_Printf("%d is a null & void resource number\n", res);
-	else {
-		// open up the resource and take a look inside!
-		StandardHeader *file_header = (StandardHeader *) openResource(res);
-
-		switch (file_header->fileType) {
-		case ANIMATION_FILE:
-			Debug_Printf("<anim> %s\n", file_header->name);
-			break;
-		case SCREEN_FILE:
-			Debug_Printf("<layer> %s\n", file_header->name);
-			break;
-		case GAME_OBJECT:
-			Debug_Printf("<game object> %s\n", file_header->name);
-			break;
-		case WALK_GRID_FILE:
-			Debug_Printf("<walk grid> %s\n", file_header->name);
-			break;
-		case GLOBAL_VAR_FILE:
-			Debug_Printf("<global variables> %s\n", file_header->name);
-			break;
-		case PARALLAX_FILE_null:
-			Debug_Printf("<parallax file NOT USED!> %s\n", file_header->name);
-			break;
-		case RUN_LIST:
-			Debug_Printf("<run list> %s\n", file_header->name);
-			break;
-		case TEXT_FILE:
-			Debug_Printf("<text file> %s\n", file_header->name);
-			break;
-		case SCREEN_MANAGER:
-			Debug_Printf("<screen manager> %s\n", file_header->name);
-			break;
-		case MOUSE_FILE:
-			Debug_Printf("<mouse pointer> %s\n", file_header->name);
-			break;
-		case ICON_FILE:
-			Debug_Printf("<menu icon> %s\n", file_header->name);
-			break;
-		default:
-			Debug_Printf("unrecognised fileType %d\n", file_header->fileType);
-			break;
-		}
-		closeResource(res);
-	}
-}
-
-void ResourceManager::kill(int res) {
-	if (res < 0 || res >= (int) _totalResFiles) {
-		Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
-		return;
-	}
-
-	if (!_resList[res].ptr) {
-		Debug_Printf("Resource %d is not in memory\n", res);
-		return;
-	}
-
-	if (_resList[res].refCount) {
-		Debug_Printf("Resource %d is open - cannot remove\n", res);
-		return;
-	}
-
-	remove(res);
-	Debug_Printf("Trashed %d\n", res);
-}
-
 void ResourceManager::remove(int res) {
 	if (_resList[res].ptr) {
 		removeFromCacheList(_resList + res);
@@ -802,7 +687,7 @@
  * the player object and global variables resource.
  */
 
-void ResourceManager::removeAll(void) {
+void ResourceManager::removeAll() {
 	// We need to clear the FX queue, because otherwise the sound system
 	// will still believe that the sound resources are in memory, and that
 	// it's ok to close them.
@@ -880,7 +765,7 @@
 		Debug_Printf("Expelled %d resources\n", nuked);
 }
 
-int ResourceManager::whichCd(void)  {
+int ResourceManager::whichCd()  {
 	return _curCd;
 }
 

Index: resman.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- resman.h	21 Feb 2005 08:16:49 -0000	1.25
+++ resman.h	22 Feb 2005 07:37:50 -0000	1.26
@@ -23,13 +23,21 @@
 
 class File;
 
-namespace Sword2 {
-
 #define MAX_MEM_CACHE (8 * 1024 * 1024) // we keep up to 8 megs of resource data files in memory
 #define	MAX_res_files 20
 
+namespace Sword2 {
+
 class Sword2Engine;
 
+enum {
+	BOTH		= 0x0,		// Cluster is on both CDs
+	CD1		= 0x1,		// Cluster is on CD1 only
+	CD2		= 0x2,		// Cluster is on CD2 only
+	LOCAL_CACHE	= 0x4,		// Cluster is cached on HDD
+	LOCAL_PERM	= 0x8		// Cluster is on HDD.
+};
+
 struct Resource {
 	byte *ptr;
 	uint32 size;
@@ -45,38 +53,12 @@
 };
 
 class ResourceManager {
-public:
-	ResourceManager(Sword2Engine *vm);	// read in the config file
-	~ResourceManager(void);
-
-	byte *openResource(uint32 res, bool dump = false);
-	void closeResource(uint32 res);
-
-	bool checkValid(uint32 res);
-	uint32 fetchLen(uint32 res);
-
-	// Prompts the user for the specified CD.
-	void getCd(int cd);
-
-	int whichCd();
-
-	void remove(int res);
-
-	// ----console commands
-
-	void printConsoleClusters(void);
-	void listResources(uint minCount);
-	void examine(int res);
-	void kill(int res);
-	void killAll(bool wantInfo);
-	void killAllObjects(bool wantInfo);
-	void removeAll(void);
 private:
 	File *openCluFile(uint16 fileNum);
 	void readCluIndex(uint16 fileNum, File *file = NULL);
 	void removeFromCacheList(Resource *res);
 	void addToCacheList(Resource *res);
-	void checkMemUsage(void);
+	void checkMemUsage();
 
 	Sword2Engine *_vm;
 
@@ -92,6 +74,34 @@
 
 	Resource *_cacheStart, *_cacheEnd;
 	uint32 _usedMem; // amount of used memory in bytes
+
+public:
+	ResourceManager(Sword2Engine *vm);	// read in the config file
+	~ResourceManager();
+
+	uint32 getNumResFiles() { return _totalResFiles; }
+	uint32 getNumClusters() { return _totalClusters; }
+	ResourceFile *getResFiles() { return _resFiles; }
+	Resource *getResList() { return _resList; }
+
+	byte *openResource(uint32 res, bool dump = false);
+	void closeResource(uint32 res);
+
+	bool checkValid(uint32 res);
+	uint32 fetchLen(uint32 res);
+
+	// Prompts the user for the specified CD.
+	void getCd(int cd);
+
+	int whichCd();
+
+	void remove(int res);
+	void removeAll();
+
+	// ----console commands
+
+	void killAll(bool wantInfo);
+	void killAllObjects(bool wantInfo);
 };
 
 } // End of namespace Sword2

Index: startup.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/startup.cpp,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- startup.cpp	28 Jan 2005 16:33:12 -0000	1.47
+++ startup.cpp	22 Feb 2005 07:37:50 -0000	1.48
@@ -22,7 +22,6 @@
 #include "common/file.h"
 
 #include "sword2/sword2.h"
-#include "sword2/console.h"
 #include "sword2/defs.h"
 #include "sword2/interpreter.h"
 #include "sword2/logic.h"
@@ -32,8 +31,6 @@
 #include "sword2/router.h"
 #include "sword2/sound.h"
 
-#define Debug_Printf _debugger->DebugPrintf
-
 namespace Sword2 {
 
 bool Sword2Engine::initStartMenu() {
@@ -145,37 +142,7 @@
 	_totalStartups++;
 }
 
-/**
- * The console 'starts' (or 's') command which lists out all the registered
- * start points in the game.
- */
-
-void Sword2Engine::conPrintStartMenu() {
-	if (!_totalStartups) {
-		Debug_Printf("Sorry - no startup positions registered?\n");
-
-		if (!_totalScreenManagers)
-			Debug_Printf("There is a problem with startup.inf\n");
-		else
-			Debug_Printf(" (%d screen managers found in startup.inf)\n", _totalScreenManagers);
-		return;
-	}
-
-	for (uint i = 0; i < _totalStartups; i++)
-		Debug_Printf("%d  (%s)\n", i, _startList[i].description);
-}
-
-void Sword2Engine::conStart(int start) {
-	if (!_totalStartups) {
-		Debug_Printf("Sorry - there are no startups!\n");
-		return;
-	}
-
-	if (start < 0 || start >= (int) _totalStartups) {
-		Debug_Printf("Not a legal start position\n");
-		return;
-	}
-
+void Sword2Engine::runStart(int start) {
 	// Restarting - stop sfx, music & speech!
 
 	_sound->clearFxQueue();
@@ -207,7 +174,6 @@
 	// Denotes script to run
 	uint32 null_pc = _startList[start].key & 0xffff;
 
-	Debug_Printf("Running start %d\n", start);
 	_logic->runScript(raw_script, raw_data_ad, &null_pc);
 
 	_resman->closeResource(_startList[start].start_res_id);

Index: sword2.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.h,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- sword2.h	20 Feb 2005 15:38:48 -0000	1.77
+++ sword2.h	22 Feb 2005 07:37:50 -0000	1.78
@@ -85,6 +85,17 @@
 	int modifiers;
 };
 
+struct StartUp {
+	char description[MAX_description];
+
+	// id of screen manager object
+	uint32 start_res_id;
+
+	// Tell the manager which startup you want (if there are more than 1)
+	// (i.e more than 1 entrance to a screen and/or separate game boots)
+	uint32 key;
+};
+
 class Sword2Engine : public Engine {
 private:
 	uint32 _eventFilter;
@@ -113,18 +124,6 @@
 
 	bool _useSubtitles;
 
-	struct StartUp {
-		char description[MAX_description];
-
-		// id of screen manager object
-		uint32 start_res_id;
-
-		// tell the manager which startup you want (if there are more
-		// than 1) (i.e more than 1 entrance to a screen and/or
-		// separate game boots)
-		uint32 key;
-	};
-
 	StartUp _startList[MAX_starts];
 
 public:
@@ -256,8 +255,12 @@
 
 	bool initStartMenu();
 	void registerStartPoint(int32 key, char *name);
-	void conPrintStartMenu();
-	void conStart(int start);
+
+	uint32 getNumStarts() { return _totalStartups; }
+	uint32 getNumScreenManagers() { return _totalScreenManagers; }
+	StartUp *getStartList() { return _startList; }
+
+	void runStart(int start);
 
 	// Convenience alias for OSystem::getMillis().
 	// This is a bit hackish, of course :-).





More information about the Scummvm-git-logs mailing list