diff options
author | Cameron Cawley | 2019-12-31 19:19:42 +0000 |
---|---|---|
committer | Filippos Karapetis | 2020-01-11 17:34:12 +0200 |
commit | 948c555ea616821ed7c2678ad406ed5bea392339 (patch) | |
tree | 000a4566cd70bdddff6d8f4d64edfc3db9119ac5 | |
parent | 395f707203e8f30add0b2f8e9d8616dd12468676 (diff) | |
download | scummvm-rg350-948c555ea616821ed7c2678ad406ed5bea392339.tar.gz scummvm-rg350-948c555ea616821ed7c2678ad406ed5bea392339.tar.bz2 scummvm-rg350-948c555ea616821ed7c2678ad406ed5bea392339.zip |
ALL: Create all instances of NEResources and PEResources using new instead of on the stack
Also adapted WinCursorGroup and MacMenu to reflect this.
-rw-r--r-- | engines/gnap/gnap.cpp | 2 | ||||
-rw-r--r-- | engines/gob/inter_v7.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/cursors.cpp | 4 | ||||
-rw-r--r-- | engines/pink/director.h | 4 | ||||
-rw-r--r-- | engines/pink/gui.cpp | 2 | ||||
-rw-r--r-- | engines/pink/pink.cpp | 13 | ||||
-rw-r--r-- | engines/pink/pink.h | 10 | ||||
-rw-r--r-- | engines/scumm/he/moonbase/moonbase.cpp | 3 | ||||
-rw-r--r-- | engines/scumm/he/moonbase/moonbase.h | 2 | ||||
-rw-r--r-- | engines/scumm/he/moonbase/moonbase_fow.cpp | 4 | ||||
-rw-r--r-- | engines/scumm/he/resource_he.cpp | 7 | ||||
-rw-r--r-- | engines/scumm/he/resource_he.h | 4 | ||||
-rw-r--r-- | graphics/fonts/winfont.cpp | 14 | ||||
-rw-r--r-- | graphics/macgui/macmenu.cpp | 5 | ||||
-rw-r--r-- | graphics/macgui/macmenu.h | 4 | ||||
-rw-r--r-- | graphics/wincursor.cpp | 12 | ||||
-rw-r--r-- | graphics/wincursor.h | 4 |
17 files changed, 57 insertions, 39 deletions
diff --git a/engines/gnap/gnap.cpp b/engines/gnap/gnap.cpp index a5434fb65f..abacd3e6b2 100644 --- a/engines/gnap/gnap.cpp +++ b/engines/gnap/gnap.cpp @@ -544,7 +544,7 @@ void GnapEngine::setVerbCursor(int verbCursor) { void GnapEngine::setCursor(int cursorIndex) { if (_cursorIndex != cursorIndex) { const char *cursorName = kCursorNames[cursorIndex]; - Graphics::WinCursorGroup *cursorGroup = Graphics::WinCursorGroup::createCursorGroup(*_exe, Common::WinResourceID(cursorName)); + Graphics::WinCursorGroup *cursorGroup = Graphics::WinCursorGroup::createCursorGroup(_exe, Common::WinResourceID(cursorName)); if (cursorGroup) { Graphics::Cursor *cursor = cursorGroup->cursors[0].cursor; CursorMan.replaceCursor(cursor); diff --git a/engines/gob/inter_v7.cpp b/engines/gob/inter_v7.cpp index fd9406054c..79a843f66e 100644 --- a/engines/gob/inter_v7.cpp +++ b/engines/gob/inter_v7.cpp @@ -181,7 +181,7 @@ void Inter_v7::o7_loadCursor() { // Load the cursor file and cursor group if (loadCursorFile()) - cursorGroup = Graphics::WinCursorGroup::createCursorGroup(*_cursors, Common::WinResourceID(cursorName)); + cursorGroup = Graphics::WinCursorGroup::createCursorGroup(_cursors, Common::WinResourceID(cursorName)); // If the requested cursor does not exist, create a default one const Graphics::Cursor *cursor = 0; diff --git a/engines/mohawk/cursors.cpp b/engines/mohawk/cursors.cpp index 12c3ebfffe..436b8ce266 100644 --- a/engines/mohawk/cursors.cpp +++ b/engines/mohawk/cursors.cpp @@ -157,7 +157,7 @@ NECursorManager::~NECursorManager() { void NECursorManager::setCursor(uint16 id) { if (_exe) { - Graphics::WinCursorGroup *cursorGroup = Graphics::WinCursorGroup::createCursorGroup(*_exe, id); + Graphics::WinCursorGroup *cursorGroup = Graphics::WinCursorGroup::createCursorGroup(_exe, id); if (cursorGroup) { Graphics::Cursor *cursor = cursorGroup->cursors[0].cursor; @@ -253,7 +253,7 @@ PECursorManager::PECursorManager(const Common::String &appName) { _cursors.resize(cursorGroups.size()); for (uint i = 0; i < cursorGroups.size(); i++) { _cursors[i].id = cursorGroups[i].getID(); - _cursors[i].cursorGroup = Graphics::WinCursorGroup::createCursorGroup(*exe, cursorGroups[i]); + _cursors[i].cursorGroup = Graphics::WinCursorGroup::createCursorGroup(exe, cursorGroups[i]); } delete exe; diff --git a/engines/pink/director.h b/engines/pink/director.h index 9dff49a271..a3255fc859 100644 --- a/engines/pink/director.h +++ b/engines/pink/director.h @@ -30,10 +30,6 @@ #include "graphics/macgui/macwindowmanager.h" #include "graphics/screen.h" -namespace Common { - class PEResources; -} - namespace Graphics { class MacMenu; } diff --git a/engines/pink/gui.cpp b/engines/pink/gui.cpp index 5267cbb540..9286747f63 100644 --- a/engines/pink/gui.cpp +++ b/engines/pink/gui.cpp @@ -129,7 +129,7 @@ static void menuCommandsCallback(int action, Common::U32String &, void *data) { engine->executeMenuCommand(action); } -void PinkEngine::initMenu(Common::PEResources &exeResources) { +void PinkEngine::initMenu(Common::PEResources *exeResources) { _director->getWndManager().setEnginePauseCallback(this, &pauseEngine); _menu = Graphics::MacMenu::createMenuFromPEexe(exeResources, &_director->getWndManager()); diff --git a/engines/pink/pink.cpp b/engines/pink/pink.cpp index 2852348a72..afff44d718 100644 --- a/engines/pink/pink.cpp +++ b/engines/pink/pink.cpp @@ -40,7 +40,7 @@ namespace Pink { PinkEngine::PinkEngine(OSystem *system, const ADGameDescription *desc) - : Engine(system), _console(nullptr), _rnd("pink"), + : Engine(system), _console(nullptr), _rnd("pink"), _exeResources(nullptr), _desc(desc), _bro(nullptr), _menu(nullptr), _actor(nullptr), _module(nullptr), _director(nullptr), _pdaMgr(this) { @@ -56,6 +56,7 @@ PinkEngine::PinkEngine(OSystem *system, const ADGameDescription *desc) PinkEngine::~PinkEngine() { delete _console; + delete _exeResources; delete _bro; _pdaMgr.close(); for (uint i = 0; i < _modules.size(); ++i) { @@ -72,16 +73,16 @@ Common::Error PinkEngine::init() { debugC(10, kPinkDebugGeneral, "PinkEngine init"); initGraphics(640, 480); - Common::PEResources exeResources; + _exeResources = new Common::PEResources(); Common::String fileName = isPeril() ? "pptp.exe" : "hpp.exe"; - if (!exeResources.loadFromEXE(fileName)) { + if (!_exeResources->loadFromEXE(fileName)) { return Common::kNoGameDataFoundError; } _console = new Console(this); _director = new Director(); - initMenu(exeResources); + initMenu(_exeResources); Common::String orbName; Common::String broName; @@ -96,7 +97,7 @@ Common::Error PinkEngine::init() { if (!_orb.open(orbName) || (_bro && !_bro->open(broName) && _orb.getTimestamp() == _bro->getTimestamp())) return Common::kNoGameDataFoundError; - if (!loadCursors(exeResources)) + if (!loadCursors(_exeResources)) return Common::kNoGameDataFoundError; setCursor(kLoadingCursor); @@ -233,7 +234,7 @@ bool PinkEngine::checkValueOfVariable(Common::String &variable, Common::String & return _variables[variable] == value; } -bool PinkEngine::loadCursors(Common::PEResources &exeResources) { +bool PinkEngine::loadCursors(Common::PEResources *exeResources) { bool isPokus = !isPeril(); _cursors.reserve(kCursorsCount); diff --git a/engines/pink/pink.h b/engines/pink/pink.h index cfc7190399..9c32abae08 100644 --- a/engines/pink/pink.h +++ b/engines/pink/pink.h @@ -62,6 +62,10 @@ struct ADGameDescription; +namespace Common { + class PEResources; +} + namespace Graphics { class MacMenu; } @@ -132,9 +136,9 @@ public: private: Common::Error init(); - void initMenu(Common::PEResources &exeResources); + void initMenu(Common::PEResources *exeResources); - bool loadCursors(Common::PEResources &exeResources); + bool loadCursors(Common::PEResources *exeResources); void initModule(const Common::String &moduleName, const Common::String &pageName, Archive *saveFile); void addModule(const Common::String &moduleName); @@ -148,6 +152,8 @@ private: Common::String _nextModule; Common::String _nextPage; + Common::PEResources *_exeResources; + OrbFile _orb; BroFile *_bro; diff --git a/engines/scumm/he/moonbase/moonbase.cpp b/engines/scumm/he/moonbase/moonbase.cpp index cb76c3f273..9b7ec9970e 100644 --- a/engines/scumm/he/moonbase/moonbase.cpp +++ b/engines/scumm/he/moonbase/moonbase.cpp @@ -30,6 +30,8 @@ namespace Scumm { Moonbase::Moonbase(ScummEngine_v100he *vm) : _vm(vm) { + _exe = new Common::PEResources(); + initFOW(); _ai = new AI(_vm); @@ -39,6 +41,7 @@ Moonbase::Moonbase(ScummEngine_v100he *vm) : _vm(vm) { } Moonbase::~Moonbase() { + delete _exe; delete _ai; #ifdef USE_LIBCURL delete _net; diff --git a/engines/scumm/he/moonbase/moonbase.h b/engines/scumm/he/moonbase/moonbase.h index d5fa4550ac..97ad6b7095 100644 --- a/engines/scumm/he/moonbase/moonbase.h +++ b/engines/scumm/he/moonbase/moonbase.h @@ -106,7 +106,7 @@ private: int32 _fowRenderTable[32768]; - Common::PEResources _exe; + Common::PEResources *_exe; Common::String _fileName; }; diff --git a/engines/scumm/he/moonbase/moonbase_fow.cpp b/engines/scumm/he/moonbase/moonbase_fow.cpp index 2e1265aff2..28d7e0cd55 100644 --- a/engines/scumm/he/moonbase/moonbase_fow.cpp +++ b/engines/scumm/he/moonbase/moonbase_fow.cpp @@ -99,11 +99,11 @@ bool Moonbase::setFOWImage(int image) { if (_fileName.empty()) { // We are running for the first time _fileName = _vm->generateFilename(-3); - if (!_exe.loadFromEXE(_fileName)) + if (!_exe->loadFromEXE(_fileName)) error("Cannot open file %s", _fileName.c_str()); } - Common::SeekableReadStream *stream = _exe.getResource(Common::kWinRCData, resId); + Common::SeekableReadStream *stream = _exe->getResource(Common::kWinRCData, resId); if (stream->size()) { _fowImage = (uint8 *)malloc(stream->size()); diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp index ddde352686..3de890f41b 100644 --- a/engines/scumm/he/resource_he.cpp +++ b/engines/scumm/he/resource_he.cpp @@ -114,13 +114,18 @@ void ResExtractor::setCursor(int id) { Win32ResExtractor::Win32ResExtractor(ScummEngine_v70he *scumm) : ResExtractor(scumm) { + _exe = new Common::PEResources(); +} + +Win32ResExtractor::~Win32ResExtractor() { + delete _exe; } bool Win32ResExtractor::extractResource(int id, CachedCursor *cc) { if (_fileName.empty()) { // We are running for the first time _fileName = _vm->generateFilename(-3); - if (!_exe.loadFromEXE(_fileName)) + if (!_exe->loadFromEXE(_fileName)) error("Cannot open file %s", _fileName.c_str()); } diff --git a/engines/scumm/he/resource_he.h b/engines/scumm/he/resource_he.h index 49175db8d4..617ed1f446 100644 --- a/engines/scumm/he/resource_he.h +++ b/engines/scumm/he/resource_he.h @@ -68,10 +68,10 @@ private: class Win32ResExtractor : public ResExtractor { public: Win32ResExtractor(ScummEngine_v70he *scumm); - ~Win32ResExtractor() {} + ~Win32ResExtractor(); private: - Common::PEResources _exe; + Common::PEResources *_exe; bool extractResource(int id, CachedCursor *cc); }; diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp index ec6ce6f89a..6ba0136a52 100644 --- a/graphics/fonts/winfont.cpp +++ b/graphics/fonts/winfont.cpp @@ -86,15 +86,18 @@ bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry } bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry) { - Common::NEResources exe; + Common::NEResources *exe = new Common::NEResources(); - if (!exe.loadFromEXE(fileName)) + if (!exe->loadFromEXE(fileName)) { + delete exe; return false; + } // Let's pull out the font directory - Common::SeekableReadStream *fontDirectory = exe.getResource(Common::kWinFontDir, Common::String("FONTDIR")); + Common::SeekableReadStream *fontDirectory = exe->getResource(Common::kWinFontDir, Common::String("FONTDIR")); if (!fontDirectory) { warning("No font directory in '%s'", fileName.c_str()); + delete exe; return false; } @@ -105,18 +108,21 @@ bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry & // Couldn't match the face name if (fontId == 0xffffffff) { warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str()); + delete exe; return false; } // Actually go get our font now... - Common::SeekableReadStream *fontStream = exe.getResource(Common::kWinFont, fontId); + Common::SeekableReadStream *fontStream = exe->getResource(Common::kWinFont, fontId); if (!fontStream) { warning("Could not find font %d in %s", fontId, fileName.c_str()); + delete exe; return false; } bool ok = loadFromFNT(*fontStream); delete fontStream; + delete exe; return ok; } diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp index 2c9b3f0902..b79ba8cfbc 100644 --- a/graphics/macgui/macmenu.cpp +++ b/graphics/macgui/macmenu.cpp @@ -24,6 +24,7 @@ #include "common/stack.h" #include "common/keyboard.h" #include "common/macresman.h" +#include "common/winexe_pe.h" #include "graphics/primitives.h" #include "graphics/font.h" @@ -200,8 +201,8 @@ static Common::U32String readUnicodeString(Common::SeekableReadStream *stream) { } -MacMenu *MacMenu::createMenuFromPEexe(Common::PEResources &exe, MacWindowManager *wm) { - Common::SeekableReadStream *menuData = exe.getResource(Common::kWinMenu, 128); +MacMenu *MacMenu::createMenuFromPEexe(Common::PEResources *exe, MacWindowManager *wm) { + Common::SeekableReadStream *menuData = exe->getResource(Common::kWinMenu, 128); if (!menuData) return nullptr; diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h index c8633c0cc7..13d374d084 100644 --- a/graphics/macgui/macmenu.h +++ b/graphics/macgui/macmenu.h @@ -24,11 +24,11 @@ #define GRAPHICS_MACGUI_MACMENU_H #include "common/str-array.h" -#include "common/winexe_pe.h" namespace Common { class U32String; class MacResManager; +class PEResources; } namespace Graphics { @@ -51,7 +51,7 @@ public: ~MacMenu(); static Common::StringArray *readMenuFromResource(Common::SeekableReadStream *res); - static MacMenu *createMenuFromPEexe(Common::PEResources &exe, MacWindowManager *wm); + static MacMenu *createMenuFromPEexe(Common::PEResources *exe, MacWindowManager *wm); void setCommandsCallback(void (*callback)(int, Common::String &, void *), void *data) { _ccallback = callback; _cdata = data; } void setCommandsCallback(void (*callback)(int, Common::U32String &, void *), void *data) { _unicodeccallback = callback; _cdata = data; } diff --git a/graphics/wincursor.cpp b/graphics/wincursor.cpp index 13d9bebfba..4cade1f5e2 100644 --- a/graphics/wincursor.cpp +++ b/graphics/wincursor.cpp @@ -242,8 +242,8 @@ WinCursorGroup::~WinCursorGroup() { delete cursors[i].cursor; } -WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, const Common::WinResourceID &id) { - Common::ScopedPtr<Common::SeekableReadStream> stream(exe.getResource(Common::kWinGroupCursor, id)); +WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id) { + Common::ScopedPtr<Common::SeekableReadStream> stream(exe->getResource(Common::kWinGroupCursor, id)); if (!stream || stream->size() <= 6) return 0; @@ -276,7 +276,7 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, cons stream->readUint32LE(); // data size uint32 cursorId = stream->readUint16LE(); - Common::ScopedPtr<Common::SeekableReadStream> cursorStream(exe.getResource(Common::kWinCursor, cursorId)); + Common::ScopedPtr<Common::SeekableReadStream> cursorStream(exe->getResource(Common::kWinCursor, cursorId)); if (!cursorStream) { delete group; return 0; @@ -298,8 +298,8 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, cons return group; } -WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, const Common::WinResourceID &id) { - Common::ScopedPtr<Common::SeekableReadStream> stream(exe.getResource(Common::kWinGroupCursor, id)); +WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id) { + Common::ScopedPtr<Common::SeekableReadStream> stream(exe->getResource(Common::kWinGroupCursor, id)); if (!stream || stream->size() <= 6) return 0; @@ -325,7 +325,7 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, cons stream->readUint32LE(); // data size uint32 cursorId = stream->readUint16LE(); - Common::ScopedPtr<Common::SeekableReadStream> cursorStream(exe.getResource(Common::kWinCursor, cursorId)); + Common::ScopedPtr<Common::SeekableReadStream> cursorStream(exe->getResource(Common::kWinCursor, cursorId)); if (!cursorStream) { delete group; return 0; diff --git a/graphics/wincursor.h b/graphics/wincursor.h index 2780b23a90..d77314458b 100644 --- a/graphics/wincursor.h +++ b/graphics/wincursor.h @@ -57,9 +57,9 @@ struct WinCursorGroup { Common::Array<CursorItem> cursors; /** Create a cursor group from an NE EXE, returns 0 on failure */ - static WinCursorGroup *createCursorGroup(Common::NEResources &exe, const Common::WinResourceID &id); + static WinCursorGroup *createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id); /** Create a cursor group from an PE EXE, returns 0 on failure */ - static WinCursorGroup *createCursorGroup(Common::PEResources &exe, const Common::WinResourceID &id); + static WinCursorGroup *createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id); }; /** |