diff options
-rw-r--r-- | engines/sludge/newfatal.cpp | 84 | ||||
-rw-r--r-- | engines/sludge/newfatal.h | 41 | ||||
-rw-r--r-- | engines/sludge/sludge.cpp | 9 | ||||
-rw-r--r-- | engines/sludge/sludge.h | 5 |
4 files changed, 92 insertions, 47 deletions
diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp index edd4a88073..820b497e8e 100644 --- a/engines/sludge/newfatal.cpp +++ b/engines/sludge/newfatal.cpp @@ -24,74 +24,88 @@ #include "sludge/allfiles.h" #include "sludge/errors.h" +#include "sludge/newfatal.h" #include "sludge/sludge.h" #include "sludge/sound.h" #include "sludge/version.h" -namespace Sludge { +namespace Common { +DECLARE_SINGLETON(Sludge::FatalMsgManager); +} -const char emergencyMemoryMessage[] = "Out of memory displaying error message!"; +namespace Sludge { extern int numResourceNames /* = 0*/; extern Common::String *allResourceNames /*= ""*/; -int resourceForFatal = -1; +int inFatal(const Common::String &str) { + g_sludge->_soundMan->killSoundStuff(); + error("%s", str.c_str()); + return true; +} -const Common::String resourceNameFromNum(int i) { - if (i == -1) - return NULL; - if (numResourceNames == 0) - return "RESOURCE"; - if (i < numResourceNames) - return allResourceNames[i]; - return "Unknown resource"; +FatalMsgManager::FatalMsgManager() { + reset(); } -bool hasFatal() { - if (!g_sludge->fatalMessage.empty()) - return true; - return false; +FatalMsgManager::~FatalMsgManager() { } -int inFatal(const Common::String &str) { - g_sludge->_soundMan->killSoundStuff(); - error("%s", str.c_str()); - return true; +void FatalMsgManager::reset() { + _fatalMessage = ""; + _fatalInfo = "Initialisation error! Something went wrong before we even got started!"; + _resourceForFatal = -1; } -int checkNew(const void *mem) { - if (mem == NULL) { - inFatal(ERROR_OUT_OF_MEMORY); - return 0; - } - return 1; +bool FatalMsgManager::hasFatal() { + if (!_fatalMessage.empty()) + return true; + return false; } -void setFatalInfo(const Common::String &userFunc, const Common::String &BIF) { - g_sludge->fatalInfo = "Currently in this sub: " + userFunc + "\nCalling: " + BIF; - debugC(0, kSludgeDebugFatal, "%s", g_sludge->fatalInfo.c_str()); +void FatalMsgManager::setFatalInfo(const Common::String &userFunc, const Common::String &BIF) { + _fatalInfo = "Currently in this sub: " + userFunc + "\nCalling: " + BIF; + debugC(0, kSludgeDebugFatal, "%s", _fatalInfo.c_str()); } -void setResourceForFatal(int n) { - resourceForFatal = n; +void FatalMsgManager::setResourceForFatal(int n) { + _resourceForFatal = n; } -int fatal(const Common::String &str1) { - if (numResourceNames && resourceForFatal != -1) { - Common::String r = resourceNameFromNum(resourceForFatal); - Common::String newStr = g_sludge->fatalInfo + "\nResource: " + r + "\n\n" + str1; +int FatalMsgManager::fatal(const Common::String &str1) { + if (numResourceNames && _resourceForFatal != -1) { + Common::String r = resourceNameFromNum(_resourceForFatal); + Common::String newStr = _fatalInfo + "\nResource: " + r + "\n\n" + str1; inFatal(newStr); } else { - Common::String newStr = g_sludge->fatalInfo + "\n\n" + str1; + Common::String newStr = _fatalInfo + "\n\n" + str1; inFatal(newStr); } return 0; } +int checkNew(const void *mem) { + if (mem == NULL) { + inFatal(ERROR_OUT_OF_MEMORY); + return 0; + } + return 1; +} + int fatal(const Common::String &str1, const Common::String &str2) { Common::String newStr = str1 + " " + str2; fatal(newStr); return 0; } +const Common::String resourceNameFromNum(int i) { + if (i == -1) + return NULL; + if (numResourceNames == 0) + return "RESOURCE"; + if (i < numResourceNames) + return allResourceNames[i]; + return "Unknown resource"; +} + } // End of namespace Sludge diff --git a/engines/sludge/newfatal.h b/engines/sludge/newfatal.h index fc91110758..08a26db4e7 100644 --- a/engines/sludge/newfatal.h +++ b/engines/sludge/newfatal.h @@ -23,18 +23,49 @@ #define SLUDGE_NEWFATAL_H #include "common/str.h" +#include "common/singleton.h" #include "sludge/errors.h" namespace Sludge { -bool hasFatal(); +class FatalMsgManager : public Common::Singleton<Sludge::FatalMsgManager>{ +public: + FatalMsgManager(); + ~FatalMsgManager(); + + void reset(); + + bool hasFatal(); + int fatal(const Common::String &str); + void setFatalInfo(const Common::String &userFunc, const Common::String &BIF); + void setResourceForFatal(int n); + +private: + Common::String _fatalMessage; + Common::String _fatalInfo; + + int _resourceForFatal; +}; + +inline bool hasFatal() { + return FatalMsgManager::instance().hasFatal(); +} + +inline int fatal(const Common::String &str) { + return FatalMsgManager::instance().fatal(str); +} + +inline void setFatalInfo(const Common::String &userFunc, const Common::String &BIF) { + FatalMsgManager::instance().setFatalInfo(userFunc, BIF); +} + +inline void setResourceForFatal(int n) { + FatalMsgManager::instance().setResourceForFatal(n); +} -int fatal(const Common::String &str); -int fatal(const Common::String &str1, const Common::String &str2); int checkNew(const void *mem); -void setFatalInfo(const Common::String &userFunc, const Common::String &BIF); -void setResourceForFatal(int n); +int fatal(const Common::String &str1, const Common::String &str2); const Common::String resourceNameFromNum(int i); } // End of namespace Sludge diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index a864a61ae9..821539d877 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -30,12 +30,13 @@ #include "sludge/fonttext.h" #include "sludge/floor.h" #include "sludge/graphics.h" +#include "sludge/main_loop.h" +#include "sludge/newfatal.h" #include "sludge/people.h" #include "sludge/region.h" #include "sludge/sludge.h" #include "sludge/sound.h" #include "sludge/speech.h" -#include "sludge/main_loop.h" namespace Sludge { @@ -71,11 +72,9 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) launchNext = ""; loadNow = ""; gamePath = ""; - bundleFolder = ""; - fatalMessage = ""; - fatalInfo = "Initialisation error! Something went wrong before we even got started!"; // Init managers + _fatalMan = new FatalMsgManager(); _peopleMan = new PeopleManager(this); _resMan = new ResourceManager(); _languageMan = new LanguageManager(); @@ -134,6 +133,8 @@ SludgeEngine::~SludgeEngine() { _peopleMan = nullptr; delete _floorMan; _floorMan = nullptr; + delete _fatalMan; + _fatalMan = nullptr; } Common::Error SludgeEngine::run() { diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h index 6a0848a26d..692af64071 100644 --- a/engines/sludge/sludge.h +++ b/engines/sludge/sludge.h @@ -40,6 +40,7 @@ extern SludgeEngine *g_sludge; class CursorManager; class EventManager; +class FatalMsgManager; class FloorManager; class GraphicsManager; class PeopleManager; @@ -74,9 +75,6 @@ public: Common::String launchNext; Common::String loadNow; Common::String gamePath; - Common::String bundleFolder; - Common::String fatalMessage; - Common::String fatalInfo; // timer Timer _timer; @@ -94,6 +92,7 @@ public: RegionManager *_regionMan; PeopleManager *_peopleMan; FloorManager *_floorMan; + FatalMsgManager *_fatalMan; SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc); virtual ~SludgeEngine(); |