diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/adl/adl.cpp | 7 | ||||
-rw-r--r-- | engines/adl/adl.h | 2 | ||||
-rw-r--r-- | engines/adl/hires1.cpp | 34 | ||||
-rw-r--r-- | engines/adl/hires2.cpp | 18 |
4 files changed, 19 insertions, 42 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index a17339f8ea..e25af25e32 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -85,12 +85,9 @@ Common::String AdlEngine::readStringAt(Common::SeekableReadStream &stream, uint return readString(stream, until); } -Common::File *AdlEngine::openFile(const Common::String &name) const { - Common::File *f = new Common::File(); - if (!f->open(name)) +void AdlEngine::openFile(Common::File &file, const Common::String &name) const { + if (!file.open(name)) error("Error opening '%s'", name.c_str()); - - return f; } void AdlEngine::printMessage(uint idx, bool wait) const { diff --git a/engines/adl/adl.h b/engines/adl/adl.h index d8c631ec48..c457291feb 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -143,7 +143,7 @@ protected: Common::String readString(Common::ReadStream &stream, byte until = 0) const; Common::String readStringAt(Common::SeekableReadStream &stream, uint offset, byte until = 0) const; - Common::File *openFile(const Common::String &name) const; + void openFile(Common::File &file, const Common::String &name) const; virtual void printMessage(uint idx, bool wait = true) const; void delay(uint32 ms) const; diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp index 735473864a..59a9e847cb 100644 --- a/engines/adl/hires1.cpp +++ b/engines/adl/hires1.cpp @@ -25,6 +25,7 @@ #include "common/error.h" #include "common/file.h" #include "common/stream.h" +#include "common/ptr.h" #include "adl/hires1.h" #include "adl/display.h" @@ -34,8 +35,7 @@ namespace Adl { void HiRes1Engine::runIntro() const { Common::File file; - if (!file.open(IDS_HR1_EXE_0)) - error("Failed to open file '" IDS_HR1_EXE_0 "'"); + openFile(file, IDS_HR1_EXE_0); file.seek(IDI_HR1_OFS_LOGO_0); _display->setMode(DISPLAY_MODE_HIRES); @@ -49,8 +49,7 @@ void HiRes1Engine::runIntro() const { _display->setMode(DISPLAY_MODE_TEXT); Common::File basic; - if (!basic.open(IDS_HR1_LOADER)) - error("Failed to open file '" IDS_HR1_LOADER "'"); + openFile(basic, IDS_HR1_LOADER); Common::String str; @@ -126,10 +125,8 @@ void HiRes1Engine::runIntro() const { _display->setMode(DISPLAY_MODE_MIXED); - if (!file.open(IDS_HR1_EXE_1)) - error("Failed to open file '" IDS_HR1_EXE_1 "'"); - // Title screen shown during loading + openFile(file, IDS_HR1_EXE_1); file.seek(IDI_HR1_OFS_LOGO_1); _display->loadFrameBuffer(file); _display->updateHiResScreen(); @@ -140,17 +137,13 @@ void HiRes1Engine::init() { _graphics = new Graphics_v1(*_display); Common::File f; - - if (!f.open(IDS_HR1_MESSAGES)) - error("Failed to open file '" IDS_HR1_MESSAGES "'"); + openFile(f, IDS_HR1_MESSAGES); for (uint i = 0; i < IDI_HR1_NUM_MESSAGES; ++i) _messages.push_back(readString(f, APPLECHAR('\r')) + APPLECHAR('\r')); f.close(); - - if (!f.open(IDS_HR1_EXE_1)) - error("Failed to open file '" IDS_HR1_EXE_1 "'"); + openFile(f, IDS_HR1_EXE_1); // Some messages have overrides inside the executable _messages[IDI_HR1_MSG_CANT_GO_THERE - 1] = readStringAt(f, IDI_HR1_OFS_STR_CANT_GO_THERE); @@ -223,8 +216,7 @@ void HiRes1Engine::initState() { _state.vars.clear(); _state.vars.resize(IDI_HR1_NUM_VARS); - if (!f.open(IDS_HR1_EXE_1)) - error("Failed to open file '" IDS_HR1_EXE_1 "'"); + openFile(f, IDS_HR1_EXE_1); // Load room data from executable _state.rooms.clear(); @@ -277,9 +269,7 @@ void HiRes1Engine::drawPic(byte pic, Common::Point pos) const { Common::File f; Common::String name = Common::String::format("BLOCK%i", _pictures[pic].block); - if (!f.open(name)) - error("Failed to open file '%s'", name.c_str()); - + openFile(f, name); f.seek(_pictures[pic].offset); _graphics->drawPic(f, pos, 0x7f); } @@ -305,10 +295,10 @@ void HiRes1Engine::printMessage(uint idx, bool wait) const { void HiRes1Engine::drawItem(const Item &item, const Common::Point &pos) const { if (item.isLineArt) { - Common::File *f = openFile(IDS_HR1_EXE_1); - f->seek(_corners[item.picture - 1]); - static_cast<Graphics_v1 *>(_graphics)->drawCorners(*f, pos); - delete f; + Common::File f; + openFile(f, IDS_HR1_EXE_1); + f.seek(_corners[item.picture - 1]); + static_cast<Graphics_v1 *>(_graphics)->drawCorners(f, pos); } else drawPic(item.picture, pos); } diff --git a/engines/adl/hires2.cpp b/engines/adl/hires2.cpp index 19f447e8be..3655b2afa8 100644 --- a/engines/adl/hires2.cpp +++ b/engines/adl/hires2.cpp @@ -34,10 +34,7 @@ namespace Adl { void HiRes2Engine::runIntro() const { Common::File f; - - if (!f.open(IDS_HR2_DISK_IMAGE)) - error("Failed to open file '" IDS_HR2_DISK_IMAGE "'"); - + openFile(f, IDS_HR2_DISK_IMAGE); f.seek(IDI_HR2_OFS_INTRO_TEXT); _display->setMode(DISPLAY_MODE_TEXT); @@ -55,9 +52,7 @@ void HiRes2Engine::init() { _graphics = new Graphics_v2(*_display); Common::File f; - - if (!f.open(IDS_HR2_DISK_IMAGE)) - error("Failed to open file '" IDS_HR2_DISK_IMAGE "'"); + openFile(f, IDS_HR2_DISK_IMAGE); for (uint i = 0; i < IDI_HR2_NUM_MESSAGES; ++i) { f.seek(IDI_HR2_OFS_MESSAGES + i * 4); @@ -97,9 +92,7 @@ void HiRes2Engine::init() { void HiRes2Engine::initState() { Common::File f; - - if (!f.open(IDS_HR2_DISK_IMAGE)) - error("Failed to open file '" IDS_HR2_DISK_IMAGE "'"); + openFile(f, IDS_HR2_DISK_IMAGE); _state.rooms.clear(); f.seek(IDI_HR2_OFS_ROOMS); @@ -127,10 +120,7 @@ void HiRes2Engine::drawPic(byte pic, Common::Point pos) const { // Temp hack to show a pic Common::File f; - - if (!f.open(IDS_HR2_DISK_IMAGE)) - error("Failed to open file '" IDS_HR2_DISK_IMAGE "'"); - + openFile(f, IDS_HR2_DISK_IMAGE); f.seek(0x1000); _graphics->drawPic(f, pos, 0); |