diff options
| author | Max Horn | 2006-09-09 18:20:28 +0000 | 
|---|---|---|
| committer | Max Horn | 2006-09-09 18:20:28 +0000 | 
| commit | 94bd9ef05de9d14ab3fd8895a6fcf681b59646b4 (patch) | |
| tree | 1d5dca6ec6b4f1d1c9f9c45217ac18c6ac695915 | |
| parent | b3ee442693d6947a99921055add45eea55d5471b (diff) | |
| download | scummvm-rg350-94bd9ef05de9d14ab3fd8895a6fcf681b59646b4.tar.gz scummvm-rg350-94bd9ef05de9d14ab3fd8895a6fcf681b59646b4.tar.bz2 scummvm-rg350-94bd9ef05de9d14ab3fd8895a6fcf681b59646b4.zip | |
Moved allocResTypeData from ScummEngine to ResourceManager; removed friend declarations from ResourceManager, and performed other minor tweaks
svn-id: r23856
| -rw-r--r-- | engines/scumm/resource.cpp | 95 | ||||
| -rw-r--r-- | engines/scumm/scumm.cpp | 19 | ||||
| -rw-r--r-- | engines/scumm/scumm.h | 23 | 
3 files changed, 79 insertions, 58 deletions
| diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp index d71adec75e..3dfc68071a 100644 --- a/engines/scumm/resource.cpp +++ b/engines/scumm/resource.cpp @@ -536,28 +536,28 @@ void ScummEngine::readResTypeList(int id, const char *name) {  	}  } -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))); - -	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)); - -	if (mode) { -		res.roomno[id] = (byte *)calloc(num, sizeof(byte)); -		res.roomoffs[id] = (uint32 *)calloc(num, sizeof(uint32)); +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_); + +	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_) { +		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 @@ byte *ScummEngine::getStringAddressVar(int i) {  	return getStringAddress(_scummVars[i]);  } +void ResourceManager::increaseExpireCounter() { +	if (!(++_expireCounter)) { +		increaseResourceCounter(); +	} +} +  void ResourceManager::increaseResourceCounter() {  	int i, j;  	byte counter; @@ -837,6 +843,17 @@ ResourceManager::ResourceManager(ScummEngine *vm) {  //	_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 @@ void ScummEngine::allocateArrays() {  		_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));  	}  } diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index a7add0ef84..912bcb9ff3 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -689,8 +689,6 @@ ScummEngine::~ScummEngine() {  	free(_palManipPalette);  	free(_palManipIntermediatePal); -	res.freeResources(); -  	free(_objectStateTable);  	free(_objectRoomTable);  	free(_objectOwnerTable); @@ -1029,7 +1027,7 @@ void ScummEngine::setupScumm() {  		requestLoad(ConfMan.getInt("save_slot"));  	} -	allocResTypeData(rtBuffer, 0, 10, "buffer", 0); +	res.allocResTypeData(rtBuffer, 0, 10, "buffer", 0);  	setupScummVars(); @@ -1066,21 +1064,22 @@ void ScummEngine::setupScumm() {  		_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 @@ load_game:  	camera._last = camera._cur; -	if (!(++res._expireCounter)) { -		res.increaseResourceCounter(); -	} +	res.increaseExpireCounter();  	animateCursor(); diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h index d1baf2b770..d9ae984bda 100644 --- a/engines/scumm/scumm.h +++ b/engines/scumm/scumm.h @@ -350,8 +350,8 @@ enum ResTypes {   * 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 @@ public:  	uint32 *roomoffs[rtNumTypes];  	uint32 *globsize[rtNumTypes]; +protected:  	uint32 _allocatedSize;  	uint32 _maxHeapThreshold, _minHeapThreshold;  	byte _expireCounter;  public:  	ResourceManager(ScummEngine *vm); +	~ResourceManager(); -	byte *createResource(int type, int index, uint32 size); -	void nukeResource(int type, int i); +	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); +  	bool isResourceLoaded(int type, int index) const;  	void lock(int type, int i); @@ -390,14 +395,16 @@ public:  	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(); -	void expireResources(uint32 size); - -protected: +	 +//protected:  	bool validateResource(const char *str, int type, int index) const; +protected: +	void expireResources(uint32 size);  };  /** @@ -770,7 +777,7 @@ protected:  	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); | 
