From 948c555ea616821ed7c2678ad406ed5bea392339 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Tue, 31 Dec 2019 19:19:42 +0000 Subject: ALL: Create all instances of NEResources and PEResources using new instead of on the stack Also adapted WinCursorGroup and MacMenu to reflect this. --- engines/gnap/gnap.cpp | 2 +- engines/gob/inter_v7.cpp | 2 +- engines/mohawk/cursors.cpp | 4 ++-- engines/pink/director.h | 4 ---- engines/pink/gui.cpp | 2 +- engines/pink/pink.cpp | 13 +++++++------ engines/pink/pink.h | 10 ++++++++-- engines/scumm/he/moonbase/moonbase.cpp | 3 +++ engines/scumm/he/moonbase/moonbase.h | 2 +- engines/scumm/he/moonbase/moonbase_fow.cpp | 4 ++-- engines/scumm/he/resource_he.cpp | 7 ++++++- engines/scumm/he/resource_he.h | 4 ++-- 12 files changed, 34 insertions(+), 23 deletions(-) (limited to 'engines') 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); }; -- cgit v1.2.3