diff options
author | Filippos Karapetis | 2015-12-04 22:06:47 +0200 |
---|---|---|
committer | Willem Jan Palenstijn | 2015-12-23 21:33:50 +0100 |
commit | 3ac02c1196875ff28e4aa9d2804bef811f8decb6 (patch) | |
tree | 52a30bbdf2900a0e47e24ab693661d3eaa6d311d /engines | |
parent | 9ba30835a290c0e6fb10472149477d19e94e00b3 (diff) | |
download | scummvm-rg350-3ac02c1196875ff28e4aa9d2804bef811f8decb6.tar.gz scummvm-rg350-3ac02c1196875ff28e4aa9d2804bef811f8decb6.tar.bz2 scummvm-rg350-3ac02c1196875ff28e4aa9d2804bef811f8decb6.zip |
LAB: Simplify file handling code
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lab/labsets.cpp | 16 | ||||
-rw-r--r-- | engines/lab/map.cpp | 2 | ||||
-rw-r--r-- | engines/lab/music.cpp | 24 | ||||
-rw-r--r-- | engines/lab/resource.cpp | 26 |
4 files changed, 22 insertions, 46 deletions
diff --git a/engines/lab/labsets.cpp b/engines/lab/labsets.cpp index 21c495d246..259858763e 100644 --- a/engines/lab/labsets.cpp +++ b/engines/lab/labsets.cpp @@ -58,19 +58,15 @@ void LargeSet::exclElement(uint16 element) { } bool LargeSet::readInitialConditions(const char *fileName) { - Common::File *file; + Common::File *file = _vm->_resource->openDataFile(fileName, MKTAG('C', 'O', 'N', '0')); - if ((file = _vm->_resource->openDataFile(fileName, MKTAG('C', 'O', 'N', '0')))) { - uint16 conditions = file->readUint16LE(); - for (int i = 0; i < conditions; i++) { - inclElement(file->readUint16LE()); - } - - delete file; - return true; + uint16 conditions = file->readUint16LE(); + for (int i = 0; i < conditions; i++) { + inclElement(file->readUint16LE()); } - return false; + delete file; + return true; } diff --git a/engines/lab/map.cpp b/engines/lab/map.cpp index f5746baa42..36591d759b 100644 --- a/engines/lab/map.cpp +++ b/engines/lab/map.cpp @@ -171,8 +171,6 @@ static bool loadMapData() { } Common::File *mapFile = g_lab->_resource->openDataFile("Lab:Maps", MKTAG('M', 'A', 'P', '0')); - if (!mapFile) - error("Corrupt map file"); g_lab->_music->updateMusic(); if (!g_lab->_music->_doNotFilestopSoundEffect) g_lab->_music->stopSoundEffect(); diff --git a/engines/lab/music.cpp b/engines/lab/music.cpp index b6b00cb23c..0f42064a5c 100644 --- a/engines/lab/music.cpp +++ b/engines/lab/music.cpp @@ -176,14 +176,8 @@ bool Music::initMusic() { filename = "Music:BackGrou"; _file = g_lab->_resource->openDataFile(filename); - - if (_file) { - startMusic(true); - return true; - } - - _musicOn = false; - return false; + startMusic(true); + return true; } /*****************************************************************************/ @@ -278,16 +272,10 @@ void Music::changeMusic(const char *newmusic) { } _file = g_lab->_resource->openDataFile(newmusic); - - if (_file) { - _musicOn = true; /* turn it off */ - setMusic(false); - _musicOn = false; /* turn it back on */ - setMusic(true); - } else { - _file = _tFile; - _tFile = 0; - } + _musicOn = true; /* turn it off */ + setMusic(false); + _musicOn = false; /* turn it back on */ + setMusic(true); } /*****************************************************************************/ diff --git a/engines/lab/resource.cpp b/engines/lab/resource.cpp index 5b4c0c101e..aaac1cd261 100644 --- a/engines/lab/resource.cpp +++ b/engines/lab/resource.cpp @@ -34,7 +34,6 @@ namespace Lab { -static uint16 allocroom; extern RoomData *_rooms; extern uint16 NumInv, ManyRooms, HighestCondition; @@ -91,9 +90,7 @@ char *Resource::getText(const char *fileName) { } bool Resource::readRoomData(const char *fileName) { - Common::File *dataFile; - if (!(dataFile = openDataFile(fileName, MKTAG('D', 'O', 'R', '1')))) - return false; + Common::File *dataFile = openDataFile(fileName, MKTAG('D', 'O', 'R', '1')); ManyRooms = dataFile->readUint16LE(); HighestCondition = dataFile->readUint16LE(); @@ -120,9 +117,7 @@ bool Resource::readRoomData(const char *fileName) { } InventoryData *Resource::readInventory(const char *fileName) { - Common::File *dataFile; - if (!(dataFile = openDataFile(fileName, MKTAG('I', 'N', 'V', '1')))) - return nullptr; + Common::File *dataFile = openDataFile(fileName, MKTAG('I', 'N', 'V', '1')); NumInv = dataFile->readUint16LE(); InventoryData *inventory = (InventoryData *)malloc((NumInv + 1) * sizeof(InventoryData)); @@ -140,11 +135,7 @@ InventoryData *Resource::readInventory(const char *fileName) { bool Resource::readViews(uint16 roomNum) { Common::String fileName = "LAB:Rooms/" + Common::String::format("%d", roomNum); - Common::File *dataFile; - if (!(dataFile = openDataFile(fileName.c_str(), MKTAG('R', 'O', 'M', '4')))) - return false; - - allocroom = roomNum; + Common::File *dataFile = openDataFile(fileName.c_str(), MKTAG('R', 'O', 'M', '4')); _rooms[roomNum]._roomMsg = readString(dataFile); _rooms[roomNum]._view[NORTH] = readView(dataFile); @@ -191,11 +182,14 @@ Common::File *Resource::openDataFile(const char *fileName, uint32 fileHeader) { Common::File *dataFile = new Common::File(); dataFile->open(translateFileName(fileName)); if (!dataFile->isOpen()) - error("openDataFile couldn't open %s (%s)", translateFileName(fileName), fileName); + error("openDataFile: Couldn't open %s (%s)", translateFileName(fileName), fileName); - if (fileHeader > 0 && dataFile->readUint32BE() != fileHeader) { - dataFile->close(); - return nullptr; + if (fileHeader > 0) { + uint32 headerTag = dataFile->readUint32BE(); + if (headerTag != fileHeader) { + dataFile->close(); + error("openDataFile: Unexpected header in %s (%s) - expected: %d, got: %d", translateFileName(fileName), fileName, fileHeader, headerTag); + } } return dataFile; |