[Scummvm-cvs-logs] SF.net SVN: scummvm: [23856] scummvm/trunk/engines/scumm

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Sep 9 20:20:33 CEST 2006


Revision: 23856
          http://svn.sourceforge.net/scummvm/?rev=23856&view=rev
Author:   fingolfin
Date:     2006-09-09 11:20:28 -0700 (Sat, 09 Sep 2006)

Log Message:
-----------
Moved allocResTypeData from ScummEngine to ResourceManager; removed friend declarations from ResourceManager, and performed other minor tweaks

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/resource.cpp
    scummvm/trunk/engines/scumm/scumm.cpp
    scummvm/trunk/engines/scumm/scumm.h

Modified: scummvm/trunk/engines/scumm/resource.cpp
===================================================================
--- scummvm/trunk/engines/scumm/resource.cpp	2006-09-09 17:31:44 UTC (rev 23855)
+++ scummvm/trunk/engines/scumm/resource.cpp	2006-09-09 18:20:28 UTC (rev 23856)
@@ -536,28 +536,28 @@
 	}
 }
 
-void ScummEngine::allocResTypeData(int id, uint32 tag, int num, const char *name, int mode) {
-	debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name, tag2str(TO_BE_32(tag)), num, mode);
-	assert(id >= 0 && id < (int)(ARRAYSIZE(res.mode)));
+void ResourceManager::allocResTypeData(int id, uint32 tag, int num_, const char *name_, int mode_) {
+	debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name_, tag2str(TO_BE_32(tag)), num_, mode_);
+	assert(id >= 0 && id < (int)(ARRAYSIZE(this->mode)));
 
-	if (num >= 8000)
-		error("Too many %ss (%d) in directory", name, num);
+	if (num_ >= 8000)
+		error("Too many %ss (%d) in directory", name_, num_);
 
-	res.mode[id] = mode;
-	res.num[id] = num;
-	res.tags[id] = tag;
-	res.name[id] = name;
-	res.address[id] = (byte **)calloc(num, sizeof(void *));
-	res.flags[id] = (byte *)calloc(num, sizeof(byte));
-	res.status[id] = (byte *)calloc(num, sizeof(byte));
+	mode[id] = mode_;
+	num[id] = num_;
+	tags[id] = tag;
+	name[id] = name_;
+	address[id] = (byte **)calloc(num_, sizeof(void *));
+	flags[id] = (byte *)calloc(num_, sizeof(byte));
+	status[id] = (byte *)calloc(num_, sizeof(byte));
 
-	if (mode) {
-		res.roomno[id] = (byte *)calloc(num, sizeof(byte));
-		res.roomoffs[id] = (uint32 *)calloc(num, sizeof(uint32));
+	if (mode_) {
+		roomno[id] = (byte *)calloc(num_, sizeof(byte));
+		roomoffs[id] = (uint32 *)calloc(num_, sizeof(uint32));
 	}
 
-	if (_game.heversion >= 70) {
-		res.globsize[id] = (uint32 *)calloc(num, sizeof(uint32));
+	if (_vm->_game.heversion >= 70) {
+		globsize[id] = (uint32 *)calloc(num_, sizeof(uint32));
 	}
 
 }
@@ -773,6 +773,12 @@
 	return getStringAddress(_scummVars[i]);
 }
 
+void ResourceManager::increaseExpireCounter() {
+	if (!(++_expireCounter)) {
+		increaseResourceCounter();
+	}
+}
+
 void ResourceManager::increaseResourceCounter() {
 	int i, j;
 	byte counter;
@@ -837,6 +843,17 @@
 //	_allocatedSize = 0;
 }
 
+ResourceManager::~ResourceManager() {
+	freeResources();
+}
+
+void ResourceManager::setHeapThreshold(int min, int max) {
+	assert(0 < max);
+	assert(min <= max);
+	_maxHeapThreshold = max;
+	_minHeapThreshold = min;
+}
+
 bool ResourceManager::validateResource(const char *str, int type, int idx) const {
 	if (type < rtFirst || type > rtLast || (uint) idx >= (uint)num[type]) {
 		error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
@@ -1275,28 +1292,28 @@
 		_storedFlObjects = (ObjectData *)calloc(100, sizeof(ObjectData));
 	}
 
-	allocResTypeData(rtCostume, (_game.features & GF_NEW_COSTUMES) ? MKID_BE('AKOS') : MKID_BE('COST'),
+	res.allocResTypeData(rtCostume, (_game.features & GF_NEW_COSTUMES) ? MKID_BE('AKOS') : MKID_BE('COST'),
 								_numCostumes, "costume", 1);
-	allocResTypeData(rtRoom, MKID_BE('ROOM'), _numRooms, "room", 1);
-	allocResTypeData(rtRoomImage, MKID_BE('RMIM'), _numRooms, "room image", 1);
-	allocResTypeData(rtRoomScripts, MKID_BE('RMSC'), _numRooms, "room script", 1);
-	allocResTypeData(rtSound, MKID_BE('SOUN'), _numSounds, "sound", 2);
-	allocResTypeData(rtScript, MKID_BE('SCRP'), _numScripts, "script", 1);
-	allocResTypeData(rtCharset, MKID_BE('CHAR'), _numCharsets, "charset", 1);
-	allocResTypeData(rtObjectName, 0, _numNewNames, "new name", 0);
-	allocResTypeData(rtInventory, 0, _numInventory, "inventory", 0);
-	allocResTypeData(rtTemp, 0, 10, "temp", 0);
-	allocResTypeData(rtScaleTable, 0, 5, "scale table", 0);
-	allocResTypeData(rtActorName, 0, _numActors, "actor name", 0);
-	allocResTypeData(rtVerb, 0, _numVerbs, "verb", 0);
-	allocResTypeData(rtString, 0, _numArray, "array", 0);
-	allocResTypeData(rtFlObject, 0, _numFlObject, "flobject", 0);
-	allocResTypeData(rtMatrix, 0, 10, "boxes", 0);
-	allocResTypeData(rtImage, MKID_BE('AWIZ'), _numImages, "images", 1);
-	allocResTypeData(rtTalkie, MKID_BE('TLKE'), _numTalkies, "talkie", 1);
+	res.allocResTypeData(rtRoom, MKID_BE('ROOM'), _numRooms, "room", 1);
+	res.allocResTypeData(rtRoomImage, MKID_BE('RMIM'), _numRooms, "room image", 1);
+	res.allocResTypeData(rtRoomScripts, MKID_BE('RMSC'), _numRooms, "room script", 1);
+	res.allocResTypeData(rtSound, MKID_BE('SOUN'), _numSounds, "sound", 2);
+	res.allocResTypeData(rtScript, MKID_BE('SCRP'), _numScripts, "script", 1);
+	res.allocResTypeData(rtCharset, MKID_BE('CHAR'), _numCharsets, "charset", 1);
+	res.allocResTypeData(rtObjectName, 0, _numNewNames, "new name", 0);
+	res.allocResTypeData(rtInventory, 0, _numInventory, "inventory", 0);
+	res.allocResTypeData(rtTemp, 0, 10, "temp", 0);
+	res.allocResTypeData(rtScaleTable, 0, 5, "scale table", 0);
+	res.allocResTypeData(rtActorName, 0, _numActors, "actor name", 0);
+	res.allocResTypeData(rtVerb, 0, _numVerbs, "verb", 0);
+	res.allocResTypeData(rtString, 0, _numArray, "array", 0);
+	res.allocResTypeData(rtFlObject, 0, _numFlObject, "flobject", 0);
+	res.allocResTypeData(rtMatrix, 0, 10, "boxes", 0);
+	res.allocResTypeData(rtImage, MKID_BE('AWIZ'), _numImages, "images", 1);
+	res.allocResTypeData(rtTalkie, MKID_BE('TLKE'), _numTalkies, "talkie", 1);
 
 	if (_game.heversion >= 70) {
-		allocResTypeData(rtSpoolBuffer, 0, 9, "spool buffer", 1);
+		res.allocResTypeData(rtSpoolBuffer, 0, 9, "spool buffer", 1);
 		_heV7RoomIntOffsets = (uint32 *)calloc(_numRooms, sizeof(uint32));
 	}
 }

Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp	2006-09-09 17:31:44 UTC (rev 23855)
+++ scummvm/trunk/engines/scumm/scumm.cpp	2006-09-09 18:20:28 UTC (rev 23856)
@@ -689,8 +689,6 @@
 	free(_palManipPalette);
 	free(_palManipIntermediatePal);
 
-	res.freeResources();
-
 	free(_objectStateTable);
 	free(_objectRoomTable);
 	free(_objectOwnerTable);
@@ -1029,7 +1027,7 @@
 		requestLoad(ConfMan.getInt("save_slot"));
 	}
 
-	allocResTypeData(rtBuffer, 0, 10, "buffer", 0);
+	res.allocResTypeData(rtBuffer, 0, 10, "buffer", 0);
 
 	setupScummVars();
 
@@ -1066,21 +1064,22 @@
 		_bootParam = -1;
 	}
 
+	int maxHeapThreshold = -1;
 #ifdef PALMOS_68K
 	if (_game.features & GF_NEW_COSTUMES)
-		res._maxHeapThreshold = gVars->memory[kMemScummNewCostGames];
+		maxHeapThreshold = gVars->memory[kMemScummNewCostGames];
 	else
-		res._maxHeapThreshold = gVars->memory[kMemScummOldCostGames];
+		maxHeapThreshold = gVars->memory[kMemScummOldCostGames];
 #else
 	if (_game.features & GF_NEW_COSTUMES) {
 		// Since the new costumes are very big, we increase the heap limit, to avoid having
 		// to constantly reload stuff from the data files.
-		res._maxHeapThreshold = 6 * 1024 * 1024;
+		maxHeapThreshold = 6 * 1024 * 1024;
 	} else {
-		res._maxHeapThreshold = 550000;
+		maxHeapThreshold = 550000;
 	}
 #endif
-	res._minHeapThreshold = 400000;
+	res.setHeapThreshold(400000, maxHeapThreshold);
 
 #if (defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
 	Graphics::initfonts();
@@ -1767,9 +1766,7 @@
 
 	camera._last = camera._cur;
 
-	if (!(++res._expireCounter)) {
-		res.increaseResourceCounter();
-	}
+	res.increaseExpireCounter();
 
 	animateCursor();
 

Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h	2006-09-09 17:31:44 UTC (rev 23855)
+++ scummvm/trunk/engines/scumm/scumm.h	2006-09-09 18:20:28 UTC (rev 23856)
@@ -350,8 +350,8 @@
  * a 'class', at least until somebody gets around to OOfying this more.
  */
 class ResourceManager {
-	friend class ScummDebugger;
-	friend class ScummEngine;
+	//friend class ScummDebugger;
+	//friend class ScummEngine;
 protected:
 	ScummEngine *_vm;
 
@@ -369,18 +369,23 @@
 	uint32 *roomoffs[rtNumTypes];
 	uint32 *globsize[rtNumTypes];
 
+protected:
 	uint32 _allocatedSize;
 	uint32 _maxHeapThreshold, _minHeapThreshold;
 	byte _expireCounter;
 
 public:
 	ResourceManager(ScummEngine *vm);
+	~ResourceManager();
 
+	void setHeapThreshold(int min, int max);
+
+	void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
+	void freeResources();
+
 	byte *createResource(int type, int index, uint32 size);
 	void nukeResource(int type, int i);
 
-	void freeResources();
-
 	bool isResourceLoaded(int type, int index) const;
 
 	void lock(int type, int i);
@@ -390,14 +395,16 @@
 	void setModified(int type, int i);
 	bool isModified(int type, int i) const;
 
+	void increaseExpireCounter();
 	void setResourceCounter(int type, int index, byte flag);
 	void increaseResourceCounter();
 
 	void resourceStats();
+	
+//protected:
+	bool validateResource(const char *str, int type, int index) const;
+protected:
 	void expireResources(uint32 size);
-
-protected:
-	bool validateResource(const char *str, int type, int index) const;
 };
 
 /**
@@ -770,7 +777,7 @@
 
 	void loadPtrToResource(int type, int i, const byte *ptr);
 	virtual void readResTypeList(int id, const char *name);
-	void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
+//	void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
 //	byte *createResource(int type, int index, uint32 size);
 	int loadResource(int type, int i);
 //	void nukeResource(int type, int i);


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