[Scummvm-cvs-logs] CVS: scummvm/sword2 console.cpp,1.46,1.47 console.h,1.21,1.22 controls.cpp,1.71,1.72 layers.cpp,1.29,1.30 logic.cpp,1.43,1.44 logic.h,1.36,1.37 resman.cpp,1.96,1.97 resman.h,1.20,1.21 startup.cpp,1.42,1.43 sword2.cpp,1.113,1.114 sword2.h,1.64,1.65

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Wed Sep 8 00:12:01 CEST 2004


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

Modified Files:
	console.cpp console.h controls.cpp layers.cpp logic.cpp 
	logic.h resman.cpp resman.h startup.cpp sword2.cpp sword2.h 
Log Message:
Fixed evil regression #2. Restarting the game, or using the "start" debug
command, would close the global script variables and player object
resources, without reopening them again. This made them fair game for the
resource expiration mechanism. The player object is probably referenced
often enough to stay alive, but the variables died on me pretty quickly,
causing ScummVM to crash.

I've also added a "reslist" debug command to make this sort of things
easier to spot. By default it only lists resources with refCount > 0. Use
"reslist 0" to see all the cached resources as well.


Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- console.cpp	9 May 2004 13:32:03 -0000	1.46
+++ console.cpp	8 Sep 2004 07:10:53 -0000	1.47
@@ -80,6 +80,7 @@
 	DCmd_Register("mem", &Debugger::Cmd_Mem);
 	DCmd_Register("tony", &Debugger::Cmd_Tony);
 	DCmd_Register("res", &Debugger::Cmd_Res);
+	DCmd_Register("reslist", &Debugger::Cmd_ResList);
 	DCmd_Register("starts", &Debugger::Cmd_Starts);
 	DCmd_Register("start", &Debugger::Cmd_Start);
 	DCmd_Register("s", &Debugger::Cmd_Start);
@@ -191,6 +192,17 @@
 	return true;
 }
 
+bool Debugger::Cmd_ResList(int argc, const char **argv) {
+	// By default, list only resources that are being held open.
+	uint minCount = 1;
+
+	if (argc > 1)
+		minCount = atoi(argv[1]);
+
+	_vm->_resman->listResources(minCount);
+	return true;
+}
+
 bool Debugger::Cmd_Starts(int argc, const char **argv) {
 	_vm->_logic->conPrintStartMenu();
 	return true;

Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- console.h	5 May 2004 07:06:17 -0000	1.21
+++ console.h	8 Sep 2004 07:10:54 -0000	1.22
@@ -87,6 +87,7 @@
 	bool Cmd_Mem(int argc, const char **argv);
 	bool Cmd_Tony(int argc, const char **argv);
 	bool Cmd_Res(int argc, const char **argv);
+	bool Cmd_ResList(int argc, const char **argv);
 	bool Cmd_Starts(int argc, const char **argv);
 	bool Cmd_Start(int argc, const char **argv);
 	bool Cmd_Info(int argc, const char **argv);

Index: controls.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/controls.cpp,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- controls.cpp	1 Aug 2004 06:52:56 -0000	1.71
+++ controls.cpp	8 Sep 2004 07:10:54 -0000	1.72
@@ -1598,9 +1598,8 @@
 	// global variables
 	_vm->_resman->removeAll();
 
-	// Reopen global variables resource & send address to interpreter -
-	// it won't be moving
-	_vm->_logic->resetScriptVars();
+	// Reopen global variables resource and player object
+	_vm->setupPersistentResources();
 
 	Logic::_scriptVars[DEMO] = temp_demo_flag;
 

Index: layers.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/layers.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- layers.cpp	24 Apr 2004 12:29:35 -0000	1.29
+++ layers.cpp	8 Sep 2004 07:10:54 -0000	1.30
@@ -58,7 +58,7 @@
 
 	// The resources age every time a new room is entered.
 	_resman->passTime();
-	_resman->expelOldResources();
+	_resman->expireOldResources();
 
 	clearFxQueue();
 	_graphics->waitForFade();

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- logic.cpp	7 Apr 2004 14:18:26 -0000	1.43
+++ logic.cpp	8 Sep 2004 07:10:54 -0000	1.44
@@ -32,16 +32,6 @@
 namespace Sword2 {
 
 /**
- * Reset the script variables. If the resource is already open, this won't do
- * anything, I beleive.
- */
-
-void Logic::resetScriptVars(void) {
-	_scriptVars = (uint32 *) (_vm->_resman->openResource(1) + sizeof(StandardHeader));
-	_vm->_resman->closeResource(1);
-}
-    
-/**
  * Do one cycle of the current session.
  */
 

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- logic.h	7 May 2004 19:56:19 -0000	1.36
+++ logic.h	8 Sep 2004 07:10:54 -0000	1.37
@@ -197,8 +197,6 @@
 	// could alternately use logic->looping of course
 	bool _choosing;
 
-	void resetScriptVars(void);
-
 	void conPrintStartMenu(void);
 	void conStart(int start);
 

Index: resman.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.cpp,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- resman.cpp	27 Jun 2004 22:14:32 -0000	1.96
+++ resman.cpp	8 Sep 2004 07:10:54 -0000	1.97
@@ -633,7 +633,7 @@
 	return file.readUint32LE();
 }
 
-void ResourceManager::expelOldResources() {
+void ResourceManager::expireOldResources() {
 	int nuked = 0;
 
 	for (uint i = 0; i < _totalResFiles; i++) {
@@ -673,6 +673,15 @@
 		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 age: %-2d\n", i, head->name, _resList[i].refCount, _resTime - _resList[i].refTime);
+		}
+	}
+}
+
 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);

Index: resman.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- resman.h	23 Apr 2004 07:02:04 -0000	1.20
+++ resman.h	8 Sep 2004 07:10:54 -0000	1.21
@@ -44,7 +44,7 @@
 	bool checkValid(uint32 res);
 	uint32 fetchLen(uint32 res);
 
-	void expelOldResources(void);
+	void expireOldResources(void);
 
 	void passTime(void);
 
@@ -60,6 +60,7 @@
 	// ----console commands
 
 	void printConsoleClusters(void);
+	void listResources(uint minCount);
 	void examine(int res);
 	void kill(int res);
 	void killAll(bool wantInfo);

Index: startup.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/startup.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- startup.cpp	27 Apr 2004 08:59:58 -0000	1.42
+++ startup.cpp	8 Sep 2004 07:10:54 -0000	1.43
@@ -21,6 +21,7 @@
 #include "common/file.h"
 #include "sword2/sword2.h"
 #include "sword2/console.h"
+#include "sword2/defs.h"
 #include "sword2/interpreter.h"
 #include "sword2/logic.h"
 #include "sword2/maketext.h"
@@ -188,8 +189,8 @@
 
 	_vm->_resman->removeAll();
 
-	// Reopen global variables resource and send address to interpreter
-	_vm->_logic->resetScriptVars();
+	// Reopen global variables resource and player object
+	_vm->setupPersistentResources();
 
 	// Free all the route memory blocks from previous game
 	_router->freeAllRouteMem();
@@ -201,7 +202,7 @@
 	}
 
 	// Open George
-	char *raw_data_ad = (char *) _vm->_resman->openResource(8);
+	char *raw_data_ad = (char *) _vm->_resman->openResource(CUR_PLAYER_ID);
 	char *raw_script = (char *) _vm->_resman->openResource(_startList[start].start_res_id);
 
 	// Denotes script to run
@@ -211,7 +212,7 @@
 	runScript(raw_script, raw_data_ad, &null_pc);
 
 	_vm->_resman->closeResource(_startList[start].start_res_id);
-	_vm->_resman->closeResource(8);
+	_vm->_resman->closeResource(CUR_PLAYER_ID);
 
 	// Make sure there's a mouse, in case restarting while mouse not
 	// available

Index: sword2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.cpp,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- sword2.cpp	28 Jun 2004 00:06:31 -0000	1.113
+++ sword2.cpp	8 Sep 2004 07:10:54 -0000	1.114
@@ -232,22 +232,23 @@
 	}
 }
 
+/**
+ * The global script variables and player object should be kept open throughout
+ * the game, so that they are never expelled by the resource manager.
+ */
+
+void Sword2Engine::setupPersistentResources(void) {
+	Logic::_scriptVars = (uint32 *) (_resman->openResource(1) + sizeof(StandardHeader));
+	_resman->openResource(CUR_PLAYER_ID);
+}
+    
 int32 Sword2Engine::initialiseGame(void) {
 	// During normal gameplay, we care neither about mouse button releases
 	// nor the scroll wheel.
 	setEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN);
 
-	// initialise global script variables
-	// res 1 is the globals list
-	Logic::_scriptVars = (uint32 *) (_resman->openResource(1) + sizeof(StandardHeader));
-
-	// DON'T CLOSE VARIABLES RESOURCE - KEEP IT OPEN AT VERY START OF
-	// MEMORY SO IT CAN'T MOVE!
-
-	// DON'T CLOSE PLAYER OBJECT RESOURCE - KEEP IT OPEN IN MEMORY SO IT
-	// CAN'T MOVE!
-
-	_resman->openResource(8);
+	// Initialise global script variables and player object
+	setupPersistentResources();
 
 	// Set up font resource variables for this language version
 
@@ -555,7 +556,7 @@
 	uint32 null_pc = 1;
 
 	// open george object, ready for start script to reference
-	raw_data_ad = (char *) _resman->openResource(8);
+	raw_data_ad = (char *) _resman->openResource(CUR_PLAYER_ID);
 
 	// open the ScreenManager object
 	raw_script = (char *) _resman->openResource(screen_manager_id);
@@ -567,7 +568,7 @@
 	_resman->closeResource(screen_manager_id);
 
 	// close george
-	_resman->closeResource(8);
+	_resman->closeResource(CUR_PLAYER_ID);
 
 	debug(5, "startGame() DONE.");
 }

Index: sword2.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- sword2.h	10 Jun 2004 06:48:50 -0000	1.64
+++ sword2.h	8 Sep 2004 07:10:54 -0000	1.65
@@ -173,6 +173,7 @@
 	Sword2Engine(GameDetector *detector, OSystem *syst);
 	~Sword2Engine();
 	void go(void);
+	void setupPersistentResources(void);
 	int32 initialiseGame(void);
 
 	bool _quit;





More information about the Scummvm-git-logs mailing list