Make getFile() return a const pointer and clean-up all uses of it.
svn-id: r44433
This commit is contained in:
parent
7ef17ba73e
commit
8a78e96838
6 changed files with 25 additions and 41 deletions
|
@ -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
|
// Check whether requested file exists
|
||||||
if (i >= _fileCount) {
|
if (i >= _fileCount) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
|
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
BAFile *getFile(unsigned int i) const;
|
const BAFile *getFile(unsigned int i) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Archive header data
|
// Archive header data
|
||||||
|
|
|
@ -155,7 +155,7 @@ int DraciEngine::init() {
|
||||||
debugC(2, kDraciGeneralDebugLevel, "Running archive tests...");
|
debugC(2, kDraciGeneralDebugLevel, "Running archive tests...");
|
||||||
Common::String path("INIT.DFW");
|
Common::String path("INIT.DFW");
|
||||||
BArchive ar(path);
|
BArchive ar(path);
|
||||||
BAFile *f;
|
const BAFile *f;
|
||||||
debugC(3, kDraciGeneralDebugLevel, "Number of file streams in archive: %d", ar.size());
|
debugC(3, kDraciGeneralDebugLevel, "Number of file streams in archive: %d", ar.size());
|
||||||
|
|
||||||
if(ar.isOpen()) {
|
if(ar.isOpen()) {
|
||||||
|
|
|
@ -43,10 +43,9 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
BArchive *initArchive = _vm->_initArchive;
|
BArchive *initArchive = _vm->_initArchive;
|
||||||
BAFile *file;
|
const BAFile *file;
|
||||||
|
|
||||||
// Read in persons
|
// Read in persons
|
||||||
|
|
||||||
file = initArchive->getFile(5);
|
file = initArchive->getFile(5);
|
||||||
Common::MemoryReadStream personData(file->_data, file->_length);
|
Common::MemoryReadStream personData(file->_data, file->_length);
|
||||||
|
|
||||||
|
@ -59,11 +58,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
|
||||||
_persons[i]._fontColour = personData.readByte();
|
_persons[i]._fontColour = personData.readByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close persons file
|
|
||||||
file->close();
|
|
||||||
|
|
||||||
// Read in dialogue offsets
|
// Read in dialogue offsets
|
||||||
|
|
||||||
file = initArchive->getFile(4);
|
file = initArchive->getFile(4);
|
||||||
Common::MemoryReadStream dialogueData(file->_data, file->_length);
|
Common::MemoryReadStream dialogueData(file->_data, file->_length);
|
||||||
|
|
||||||
|
@ -79,11 +74,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
|
||||||
_dialogueVars = new int[curOffset];
|
_dialogueVars = new int[curOffset];
|
||||||
memset(_dialogueVars, 0, sizeof (int) * curOffset);
|
memset(_dialogueVars, 0, sizeof (int) * curOffset);
|
||||||
|
|
||||||
// Close dialogues file
|
|
||||||
file->close();
|
|
||||||
|
|
||||||
// Read in game info
|
// Read in game info
|
||||||
|
|
||||||
file = initArchive->getFile(3);
|
file = initArchive->getFile(3);
|
||||||
Common::MemoryReadStream gameData(file->_data, file->_length);
|
Common::MemoryReadStream gameData(file->_data, file->_length);
|
||||||
|
|
||||||
|
@ -104,11 +95,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
|
||||||
|
|
||||||
_info._numDialogueBlocks = curOffset;
|
_info._numDialogueBlocks = curOffset;
|
||||||
|
|
||||||
// Close game info file
|
|
||||||
file->close();
|
|
||||||
|
|
||||||
// Read in variables
|
// Read in variables
|
||||||
|
|
||||||
file = initArchive->getFile(2);
|
file = initArchive->getFile(2);
|
||||||
unsigned int numVariables = file->_length / sizeof (int16);
|
unsigned int numVariables = file->_length / sizeof (int16);
|
||||||
|
|
||||||
|
@ -119,18 +106,14 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
|
||||||
_variables[i] = variableData.readUint16LE();
|
_variables[i] = variableData.readUint16LE();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close variables file
|
|
||||||
file->close();
|
|
||||||
|
|
||||||
// Read in item icon status
|
// Read in item icon status
|
||||||
|
|
||||||
file = initArchive->getFile(1);
|
file = initArchive->getFile(1);
|
||||||
_itemStatus = file->_data;
|
|
||||||
uint numItems = file->_length;
|
uint numItems = file->_length;
|
||||||
|
_itemStatus = new byte[numItems];
|
||||||
|
memcpy(_itemStatus, file->_data, numItems);
|
||||||
_items = new GameItem[numItems];
|
_items = new GameItem[numItems];
|
||||||
|
|
||||||
// Read in object status
|
// Read in object status
|
||||||
|
|
||||||
file = initArchive->getFile(0);
|
file = initArchive->getFile(0);
|
||||||
unsigned int numObjects = file->_length;
|
unsigned int numObjects = file->_length;
|
||||||
|
|
||||||
|
@ -147,14 +130,14 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
|
||||||
_objects[i]._location = (~(1 << 7) & tmp) - 1;
|
_objects[i]._location = (~(1 << 7) & tmp) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close object status file
|
|
||||||
file->close();
|
|
||||||
|
|
||||||
assert(numDialogues == _info._numDialogues);
|
assert(numDialogues == _info._numDialogues);
|
||||||
assert(numPersons == _info._numPersons);
|
assert(numPersons == _info._numPersons);
|
||||||
assert(numVariables == _info._numVariables);
|
assert(numVariables == _info._numVariables);
|
||||||
assert(numObjects == _info._numObjects);
|
assert(numObjects == _info._numObjects);
|
||||||
assert(numItems == _info._numItems);
|
assert(numItems == _info._numItems);
|
||||||
|
|
||||||
|
// Deallocate all cached files, because we have copied them into our own data structures.
|
||||||
|
initArchive->clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::start() {
|
void Game::start() {
|
||||||
|
@ -240,7 +223,7 @@ void Game::init() {
|
||||||
speechAnim->addFrame(speech);
|
speechAnim->addFrame(speech);
|
||||||
|
|
||||||
// Initialize inventory animation
|
// Initialize inventory animation
|
||||||
BAFile *f = _vm->_iconsArchive->getFile(13);
|
const BAFile *f = _vm->_iconsArchive->getFile(13);
|
||||||
Animation *inventoryAnim = _vm->_anims->addAnimation(kInventorySprite, 255, false);
|
Animation *inventoryAnim = _vm->_anims->addAnimation(kInventorySprite, 255, false);
|
||||||
Sprite *inventorySprite = new Sprite(f->_data, f->_length, 0, 0, true);
|
Sprite *inventorySprite = new Sprite(f->_data, f->_length, 0, 0, true);
|
||||||
inventoryAnim->addFrame(inventorySprite);
|
inventoryAnim->addFrame(inventorySprite);
|
||||||
|
@ -900,7 +883,7 @@ void Game::dialogueInit(int dialogID) {
|
||||||
_blockNum = _dialogueArchive->size() / 3;
|
_blockNum = _dialogueArchive->size() / 3;
|
||||||
_dialogueBlocks = new Dialogue[_blockNum];
|
_dialogueBlocks = new Dialogue[_blockNum];
|
||||||
|
|
||||||
BAFile *f;
|
const BAFile *f;
|
||||||
|
|
||||||
for (uint i = 0; i < kDialogueLines; ++i) {
|
for (uint i = 0; i < kDialogueLines; ++i) {
|
||||||
_lines[i] = 0;
|
_lines[i] = 0;
|
||||||
|
@ -1052,7 +1035,7 @@ void Game::walkHero(int x, int y) {
|
||||||
|
|
||||||
void Game::loadItem(int itemID) {
|
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);
|
Common::MemoryReadStream itemReader(f->_data, f->_length);
|
||||||
|
|
||||||
GameItem *item = _items + itemID;
|
GameItem *item = _items + itemID;
|
||||||
|
@ -1079,7 +1062,7 @@ void Game::loadItem(int itemID) {
|
||||||
|
|
||||||
void Game::loadRoom(int roomNum) {
|
void Game::loadRoom(int roomNum) {
|
||||||
|
|
||||||
BAFile *f;
|
const BAFile *f;
|
||||||
f = _vm->_roomsArchive->getFile(roomNum * 4);
|
f = _vm->_roomsArchive->getFile(roomNum * 4);
|
||||||
Common::MemoryReadStream roomReader(f->_data, f->_length);
|
Common::MemoryReadStream roomReader(f->_data, f->_length);
|
||||||
|
|
||||||
|
@ -1203,7 +1186,7 @@ void Game::loadRoom(int roomNum) {
|
||||||
|
|
||||||
int Game::loadAnimation(uint animNum, uint z) {
|
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);
|
Common::MemoryReadStream animationReader(animFile->_data, animFile->_length);
|
||||||
|
|
||||||
uint numFrames = animationReader.readByte();
|
uint numFrames = animationReader.readByte();
|
||||||
|
@ -1231,7 +1214,7 @@ int Game::loadAnimation(uint animNum, uint z) {
|
||||||
/* uint freq = */ animationReader.readUint16LE();
|
/* uint freq = */ animationReader.readUint16LE();
|
||||||
uint delay = 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);
|
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) {
|
void Game::loadObject(uint objNum) {
|
||||||
BAFile *file;
|
const BAFile *file;
|
||||||
|
|
||||||
file = _vm->_objectsArchive->getFile(objNum * 3);
|
file = _vm->_objectsArchive->getFile(objNum * 3);
|
||||||
Common::MemoryReadStream objReader(file->_data, file->_length);
|
Common::MemoryReadStream objReader(file->_data, file->_length);
|
||||||
|
@ -1301,7 +1284,7 @@ void Game::loadObject(uint objNum) {
|
||||||
|
|
||||||
void Game::loadWalkingMap(int mapID) {
|
void Game::loadWalkingMap(int mapID) {
|
||||||
|
|
||||||
BAFile *f;
|
const BAFile *f;
|
||||||
f = _vm->_walkingMapsArchive->getFile(mapID);
|
f = _vm->_walkingMapsArchive->getFile(mapID);
|
||||||
_currentRoom._walkingMap.load(f->_data, f->_length);
|
_currentRoom._walkingMap.load(f->_data, f->_length);
|
||||||
}
|
}
|
||||||
|
@ -1317,11 +1300,10 @@ uint Game::getNumObjects() const {
|
||||||
void Game::loadOverlays() {
|
void Game::loadOverlays() {
|
||||||
uint x, y, z, num;
|
uint x, y, z, num;
|
||||||
|
|
||||||
BAFile *overlayHeader;
|
const BAFile *overlayHeader;
|
||||||
|
|
||||||
overlayHeader = _vm->_roomsArchive->getFile(_currentRoom._roomNum * 4 + 2);
|
overlayHeader = _vm->_roomsArchive->getFile(_currentRoom._roomNum * 4 + 2);
|
||||||
Common::MemoryReadStream overlayReader(overlayHeader->_data, overlayHeader->_length);
|
Common::MemoryReadStream overlayReader(overlayHeader->_data, overlayHeader->_length);
|
||||||
BAFile *overlayFile;
|
|
||||||
|
|
||||||
for (int i = 0; i < _currentRoom._numOverlays; i++) {
|
for (int i = 0; i < _currentRoom._numOverlays; i++) {
|
||||||
|
|
||||||
|
@ -1330,6 +1312,7 @@ void Game::loadOverlays() {
|
||||||
y = overlayReader.readUint16LE();
|
y = overlayReader.readUint16LE();
|
||||||
z = overlayReader.readByte();
|
z = overlayReader.readByte();
|
||||||
|
|
||||||
|
const BAFile *overlayFile;
|
||||||
overlayFile = _vm->_overlaysArchive->getFile(num);
|
overlayFile = _vm->_overlaysArchive->getFile(num);
|
||||||
Sprite *sp = new Sprite(overlayFile->_data, overlayFile->_length, x, y, true);
|
Sprite *sp = new Sprite(overlayFile->_data, overlayFile->_length, x, y, true);
|
||||||
|
|
||||||
|
@ -1518,6 +1501,7 @@ Game::~Game() {
|
||||||
delete[] _variables;
|
delete[] _variables;
|
||||||
delete[] _dialogueOffsets;
|
delete[] _dialogueOffsets;
|
||||||
delete[] _objects;
|
delete[] _objects;
|
||||||
|
delete[] _itemStatus;
|
||||||
delete[] _items;
|
delete[] _items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ void Mouse::setPosition(uint16 x, uint16 y) {
|
||||||
void Mouse::setCursorType(CursorType cur) {
|
void Mouse::setCursorType(CursorType cur) {
|
||||||
_cursorType = cur;
|
_cursorType = cur;
|
||||||
|
|
||||||
BAFile *f;
|
const BAFile *f;
|
||||||
f = _vm->_iconsArchive->getFile(_cursorType);
|
f = _vm->_iconsArchive->getFile(_cursorType);
|
||||||
|
|
||||||
Sprite sp(f->_data, f->_length, 0, 0, true);
|
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) {
|
void Mouse::loadItemCursor(int itemID, bool highlighted) {
|
||||||
|
|
||||||
BAFile *f;
|
const BAFile *f;
|
||||||
f = _vm->_itemImagesArchive->getFile(2 * itemID + highlighted);
|
f = _vm->_itemImagesArchive->getFile(2 * itemID + highlighted);
|
||||||
|
|
||||||
Sprite sp(f->_data, f->_length, 0, 0, true);
|
Sprite sp(f->_data, f->_length, 0, 0, true);
|
||||||
|
|
|
@ -531,7 +531,7 @@ void Script::icoStat(Common::Queue<int> ¶ms) {
|
||||||
|
|
||||||
if (itemID != kNoItem) {
|
if (itemID != kNoItem) {
|
||||||
Animation *itemAnim = _vm->_anims->addItem(kInventoryItemsID - itemID);
|
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);
|
Sprite *sp = new Sprite(f->_data, f->_length, 0, 0, true);
|
||||||
itemAnim->addFrame(sp);
|
itemAnim->addFrame(sp);
|
||||||
}
|
}
|
||||||
|
@ -666,7 +666,7 @@ void Script::talk(Common::Queue<int> ¶ms) {
|
||||||
Surface *surface = _vm->_screen->getSurface();
|
Surface *surface = _vm->_screen->getSurface();
|
||||||
|
|
||||||
// Fetch string
|
// Fetch string
|
||||||
BAFile *f = _vm->_stringsArchive->getFile(sentenceID);
|
const BAFile *f = _vm->_stringsArchive->getFile(sentenceID);
|
||||||
|
|
||||||
// Fetch frame for the speech text
|
// Fetch frame for the speech text
|
||||||
Animation *speechAnim = _vm->_anims->getAnimation(kSpeechText);
|
Animation *speechAnim = _vm->_anims->getAnimation(kSpeechText);
|
||||||
|
@ -784,7 +784,7 @@ void Script::setPalette(Common::Queue<int> ¶ms) {
|
||||||
if (_vm->_game->getScheduledPalette() == -1) {
|
if (_vm->_game->getScheduledPalette() == -1) {
|
||||||
_vm->_screen->setPaletteEmpty();
|
_vm->_screen->setPaletteEmpty();
|
||||||
} else {
|
} else {
|
||||||
BAFile *f;
|
const BAFile *f;
|
||||||
f = _vm->_paletteArchive->getFile(_vm->_game->getScheduledPalette());
|
f = _vm->_paletteArchive->getFile(_vm->_game->getScheduledPalette());
|
||||||
_vm->_screen->setPalette(f->_data, 0, kNumColours);
|
_vm->_screen->setPalette(f->_data, 0, kNumColours);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue