aboutsummaryrefslogtreecommitdiff
path: root/engines/draci
diff options
context:
space:
mode:
authorRobert Špalek2009-09-28 03:51:23 +0000
committerRobert Špalek2009-09-28 03:51:23 +0000
commit8a78e968387ff001085bb6cec4ae6c8edba222db (patch)
tree19f85188e5e5a442670929dbff7de2f22b38b9f0 /engines/draci
parent7ef17ba73e26436e30689d14fda8153aadb3c347 (diff)
downloadscummvm-rg350-8a78e968387ff001085bb6cec4ae6c8edba222db.tar.gz
scummvm-rg350-8a78e968387ff001085bb6cec4ae6c8edba222db.tar.bz2
scummvm-rg350-8a78e968387ff001085bb6cec4ae6c8edba222db.zip
Make getFile() return a const pointer and clean-up all uses of it.
svn-id: r44433
Diffstat (limited to 'engines/draci')
-rw-r--r--engines/draci/barchive.cpp2
-rw-r--r--engines/draci/barchive.h2
-rw-r--r--engines/draci/draci.cpp2
-rw-r--r--engines/draci/game.cpp50
-rw-r--r--engines/draci/mouse.cpp4
-rw-r--r--engines/draci/script.cpp6
6 files changed, 25 insertions, 41 deletions
diff --git a/engines/draci/barchive.cpp b/engines/draci/barchive.cpp
index 2a27e6a383..12d0987262 100644
--- a/engines/draci/barchive.cpp
+++ b/engines/draci/barchive.cpp
@@ -393,7 +393,7 @@ void BArchive::clearCache() {
}
-BAFile *BArchive::getFile(unsigned int i) const {
+const BAFile *BArchive::getFile(unsigned int i) const {
// Check whether requested file exists
if (i >= _fileCount) {
diff --git a/engines/draci/barchive.h b/engines/draci/barchive.h
index 6766c3c1fd..2ac1a6aa7f 100644
--- a/engines/draci/barchive.h
+++ b/engines/draci/barchive.h
@@ -72,7 +72,7 @@ public:
void clearCache();
- BAFile *getFile(unsigned int i) const;
+ const BAFile *getFile(unsigned int i) const;
private:
// Archive header data
diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp
index 9f242261ea..d77712b586 100644
--- a/engines/draci/draci.cpp
+++ b/engines/draci/draci.cpp
@@ -155,7 +155,7 @@ int DraciEngine::init() {
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()) {
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp
index 12944ce210..98442a26ee 100644
--- a/engines/draci/game.cpp
+++ b/engines/draci/game.cpp
@@ -43,10 +43,9 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
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 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
_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 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
_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 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
_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 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
_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 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
_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 @@ void Game::init() {
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 @@ void Game::dialogueInit(int dialogID) {
_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::walkHero(int x, int y) {
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::loadItem(int itemID) {
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 @@ void Game::loadRoom(int roomNum) {
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 @@ int Game::loadAnimation(uint animNum, uint z) {
/* 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 @@ int Game::loadAnimation(uint animNum, uint z) {
}
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::loadObject(uint objNum) {
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 @@ uint Game::getNumObjects() const {
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 @@ void Game::loadOverlays() {
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 @@ Game::~Game() {
delete[] _variables;
delete[] _dialogueOffsets;
delete[] _objects;
+ delete[] _itemStatus;
delete[] _items;
}
diff --git a/engines/draci/mouse.cpp b/engines/draci/mouse.cpp
index e1b56a7961..054591931f 100644
--- a/engines/draci/mouse.cpp
+++ b/engines/draci/mouse.cpp
@@ -91,7 +91,7 @@ void Mouse::setPosition(uint16 x, uint16 y) {
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::setCursorType(CursorType cur) {
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);
diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp
index 44a89eedc0..ea9d14f31d 100644
--- a/engines/draci/script.cpp
+++ b/engines/draci/script.cpp
@@ -531,7 +531,7 @@ void Script::icoStat(Common::Queue<int> &params) {
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 @@ void Script::talk(Common::Queue<int> &params) {
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 @@ void Script::setPalette(Common::Queue<int> &params) {
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);
}