[Scummvm-cvs-logs] SF.net SVN: scummvm:[44433] scummvm/trunk/engines/draci

spalek at users.sourceforge.net spalek at users.sourceforge.net
Mon Sep 28 05:51:24 CEST 2009


Revision: 44433
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44433&view=rev
Author:   spalek
Date:     2009-09-28 03:51:23 +0000 (Mon, 28 Sep 2009)

Log Message:
-----------
Make getFile() return a const pointer and clean-up all uses of it.

Modified Paths:
--------------
    scummvm/trunk/engines/draci/barchive.cpp
    scummvm/trunk/engines/draci/barchive.h
    scummvm/trunk/engines/draci/draci.cpp
    scummvm/trunk/engines/draci/game.cpp
    scummvm/trunk/engines/draci/mouse.cpp
    scummvm/trunk/engines/draci/script.cpp

Modified: scummvm/trunk/engines/draci/barchive.cpp
===================================================================
--- scummvm/trunk/engines/draci/barchive.cpp	2009-09-28 03:06:43 UTC (rev 44432)
+++ scummvm/trunk/engines/draci/barchive.cpp	2009-09-28 03:51:23 UTC (rev 44433)
@@ -393,7 +393,7 @@
 }
 	
 
-BAFile *BArchive::getFile(unsigned int i) const {
+const BAFile *BArchive::getFile(unsigned int i) const {
 
 	// Check whether requested file exists
 	if (i >= _fileCount) {

Modified: scummvm/trunk/engines/draci/barchive.h
===================================================================
--- scummvm/trunk/engines/draci/barchive.h	2009-09-28 03:06:43 UTC (rev 44432)
+++ scummvm/trunk/engines/draci/barchive.h	2009-09-28 03:51:23 UTC (rev 44433)
@@ -72,7 +72,7 @@
 
 	void clearCache();
 
-	BAFile *getFile(unsigned int i) const;
+	const BAFile *getFile(unsigned int i) const;
 
 private:
 	// Archive header data

Modified: scummvm/trunk/engines/draci/draci.cpp
===================================================================
--- scummvm/trunk/engines/draci/draci.cpp	2009-09-28 03:06:43 UTC (rev 44432)
+++ scummvm/trunk/engines/draci/draci.cpp	2009-09-28 03:51:23 UTC (rev 44433)
@@ -155,7 +155,7 @@
 	debugC(2, kDraciGeneralDebugLevel, "Running archive tests...");	
 	Common::String path("INIT.DFW");	
 	BArchive ar(path);
-	BAFile *f;
+	const BAFile *f;
 	debugC(3, kDraciGeneralDebugLevel, "Number of file streams in archive: %d", ar.size());	
 	
 	if(ar.isOpen()) {

Modified: scummvm/trunk/engines/draci/game.cpp
===================================================================
--- scummvm/trunk/engines/draci/game.cpp	2009-09-28 03:06:43 UTC (rev 44432)
+++ scummvm/trunk/engines/draci/game.cpp	2009-09-28 03:51:23 UTC (rev 44433)
@@ -43,10 +43,9 @@
 	unsigned int i;
 	
 	BArchive *initArchive = _vm->_initArchive;
-	BAFile *file;
+	const BAFile *file;
 	
 	// Read in persons
-	
 	file = initArchive->getFile(5);
 	Common::MemoryReadStream personData(file->_data, file->_length);
 	
@@ -59,11 +58,7 @@
 		_persons[i]._fontColour = personData.readByte();
 	}
 
-	// Close persons file
-	file->close();
-	
 	// Read in dialogue offsets
-	
 	file = initArchive->getFile(4);
 	Common::MemoryReadStream dialogueData(file->_data, file->_length);
 	
@@ -79,11 +74,7 @@
 	_dialogueVars = new int[curOffset];
 	memset(_dialogueVars, 0, sizeof (int) * curOffset);
 	
-	// Close dialogues file
-	file->close();	
-
 	// Read in game info
-	
 	file = initArchive->getFile(3);
 	Common::MemoryReadStream gameData(file->_data, file->_length);
 	
@@ -104,11 +95,7 @@
 
 	_info._numDialogueBlocks = curOffset;
 
-	// Close game info file
-	file->close();
-
 	// Read in variables
-	
 	file = initArchive->getFile(2);
 	unsigned int numVariables = file->_length / sizeof (int16);
 
@@ -119,18 +106,14 @@
 		_variables[i] = variableData.readUint16LE();
 	}
 
-	// Close variables file
-	file->close();
-
 	// Read in item icon status
-	
 	file = initArchive->getFile(1);
-	_itemStatus = file->_data;
 	uint numItems = file->_length;
+	_itemStatus = new byte[numItems];
+	memcpy(_itemStatus, file->_data, numItems);
 	_items = new GameItem[numItems];
 	
 	// Read in object status
-	
 	file = initArchive->getFile(0);
 	unsigned int numObjects = file->_length;
 	
@@ -147,14 +130,14 @@
 		_objects[i]._location = (~(1 << 7) & tmp) - 1;
  	}
 	
-	// Close object status file
-	file->close();
-
 	assert(numDialogues == _info._numDialogues);
 	assert(numPersons == _info._numPersons);
 	assert(numVariables == _info._numVariables);
 	assert(numObjects == _info._numObjects);
 	assert(numItems == _info._numItems);	
+
+	// Deallocate all cached files, because we have copied them into our own data structures.
+	initArchive->clearCache();
 }
 
 void Game::start() {
@@ -240,7 +223,7 @@
 	speechAnim->addFrame(speech);
 
 	// Initialize inventory animation
-	BAFile *f = _vm->_iconsArchive->getFile(13);
+	const BAFile *f = _vm->_iconsArchive->getFile(13);
 	Animation *inventoryAnim = _vm->_anims->addAnimation(kInventorySprite, 255, false);
 	Sprite *inventorySprite = new Sprite(f->_data, f->_length, 0, 0, true);
 	inventoryAnim->addFrame(inventorySprite);
@@ -900,7 +883,7 @@
 	_blockNum = _dialogueArchive->size() / 3;
 	_dialogueBlocks = new Dialogue[_blockNum];
 
-	BAFile *f;
+	const BAFile *f;
 
 	for (uint i = 0; i < kDialogueLines; ++i) {
 		_lines[i] = 0;
@@ -1052,7 +1035,7 @@
 
 void Game::loadItem(int itemID) {
 	
-	BAFile *f = _vm->_itemsArchive->getFile(itemID * 3);
+	const BAFile *f = _vm->_itemsArchive->getFile(itemID * 3);
 	Common::MemoryReadStream itemReader(f->_data, f->_length);
 	
 	GameItem *item = _items + itemID;
@@ -1079,7 +1062,7 @@
 
 void Game::loadRoom(int roomNum) {
 
-	BAFile *f;
+	const BAFile *f;
 	f = _vm->_roomsArchive->getFile(roomNum * 4);
 	Common::MemoryReadStream roomReader(f->_data, f->_length);
 
@@ -1203,7 +1186,7 @@
 
 int Game::loadAnimation(uint animNum, uint z) {
 
-	BAFile *animFile = _vm->_animationsArchive->getFile(animNum);
+	const BAFile *animFile = _vm->_animationsArchive->getFile(animNum);
 	Common::MemoryReadStream animationReader(animFile->_data, animFile->_length);	
 
 	uint numFrames = animationReader.readByte();
@@ -1231,7 +1214,7 @@
 		/* uint freq = */ animationReader.readUint16LE();
 		uint delay = animationReader.readUint16LE();
 
-		BAFile *spriteFile = _vm->_spritesArchive->getFile(spriteNum);
+		const BAFile *spriteFile = _vm->_spritesArchive->getFile(spriteNum);
 
 		Sprite *sp = new Sprite(spriteFile->_data, spriteFile->_length, x, y, true);
 
@@ -1260,7 +1243,7 @@
 }
 
 void Game::loadObject(uint objNum) {
-	BAFile *file;
+	const BAFile *file;
 	
 	file = _vm->_objectsArchive->getFile(objNum * 3);
 	Common::MemoryReadStream objReader(file->_data, file->_length);
@@ -1301,7 +1284,7 @@
 
 void Game::loadWalkingMap(int mapID) {
 
-	BAFile *f;
+	const BAFile *f;
 	f = _vm->_walkingMapsArchive->getFile(mapID);
 	_currentRoom._walkingMap.load(f->_data, f->_length);
 }
@@ -1317,11 +1300,10 @@
 void Game::loadOverlays() {
  	uint x, y, z, num;
  
-	BAFile *overlayHeader;
+	const BAFile *overlayHeader;
 
 	overlayHeader = _vm->_roomsArchive->getFile(_currentRoom._roomNum * 4 + 2);
 	Common::MemoryReadStream overlayReader(overlayHeader->_data, overlayHeader->_length);
- 	BAFile *overlayFile;
  
  	for (int i = 0; i < _currentRoom._numOverlays; i++) {
  
@@ -1330,6 +1312,7 @@
  		y = overlayReader.readUint16LE();
  		z = overlayReader.readByte();
  
+		const BAFile *overlayFile;
 		overlayFile = _vm->_overlaysArchive->getFile(num);
  		Sprite *sp = new Sprite(overlayFile->_data, overlayFile->_length, x, y, true);
  
@@ -1518,6 +1501,7 @@
 	delete[] _variables;
 	delete[] _dialogueOffsets;
 	delete[] _objects;
+	delete[] _itemStatus;
 	delete[] _items;
 }
 

Modified: scummvm/trunk/engines/draci/mouse.cpp
===================================================================
--- scummvm/trunk/engines/draci/mouse.cpp	2009-09-28 03:06:43 UTC (rev 44432)
+++ scummvm/trunk/engines/draci/mouse.cpp	2009-09-28 03:51:23 UTC (rev 44433)
@@ -91,7 +91,7 @@
 void Mouse::setCursorType(CursorType cur) {
 	_cursorType = cur;
 
-	BAFile *f;
+	const BAFile *f;
 	f = _vm->_iconsArchive->getFile(_cursorType);
 
 	Sprite sp(f->_data, f->_length, 0, 0, true);
@@ -102,7 +102,7 @@
 
 void Mouse::loadItemCursor(int itemID, bool highlighted) {
 	
-	BAFile *f;
+	const BAFile *f;
 	f = _vm->_itemImagesArchive->getFile(2 * itemID + highlighted);
 
 	Sprite sp(f->_data, f->_length, 0, 0, true);

Modified: scummvm/trunk/engines/draci/script.cpp
===================================================================
--- scummvm/trunk/engines/draci/script.cpp	2009-09-28 03:06:43 UTC (rev 44432)
+++ scummvm/trunk/engines/draci/script.cpp	2009-09-28 03:51:23 UTC (rev 44433)
@@ -531,7 +531,7 @@
 
 		if (itemID != kNoItem) {
 			Animation *itemAnim = _vm->_anims->addItem(kInventoryItemsID - itemID);
-			BAFile *f = _vm->_itemImagesArchive->getFile(2 * itemID);
+			const BAFile *f = _vm->_itemImagesArchive->getFile(2 * itemID);
 			Sprite *sp = new Sprite(f->_data, f->_length, 0, 0, true);
 			itemAnim->addFrame(sp);
 		}
@@ -666,7 +666,7 @@
 	Surface *surface = _vm->_screen->getSurface();
 
 	// Fetch string
-	BAFile *f = _vm->_stringsArchive->getFile(sentenceID);
+	const BAFile *f = _vm->_stringsArchive->getFile(sentenceID);
 
 	// Fetch frame for the speech text
 	Animation *speechAnim = _vm->_anims->getAnimation(kSpeechText);
@@ -784,7 +784,7 @@
 	if (_vm->_game->getScheduledPalette() == -1) {
 		_vm->_screen->setPaletteEmpty();
 	} else {
-		BAFile *f;		
+		const BAFile *f;		
 		f = _vm->_paletteArchive->getFile(_vm->_game->getScheduledPalette());
 		_vm->_screen->setPalette(f->_data, 0, kNumColours);
 	}


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