From 91fcdda2d188602a376f4369d375a74117f93ae7 Mon Sep 17 00:00:00 2001 From: yinsimei Date: Tue, 11 Jul 2017 15:39:22 +0200 Subject: SLUDGE: change global Common::String to public var of SludgeEngine --- engines/sludge/builtin.cpp | 40 ++++++++++++++++++---------------------- engines/sludge/main_loop.cpp | 6 +----- engines/sludge/newfatal.cpp | 17 +++++++---------- engines/sludge/savedata.cpp | 2 -- engines/sludge/sludge.cpp | 10 ++++++++++ engines/sludge/sludge.h | 9 +++++++++ engines/sludge/sludger.cpp | 16 +++++++--------- 7 files changed, 52 insertions(+), 48 deletions(-) (limited to 'engines/sludge') diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 6d7ee428d8..4adbe93482 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -54,14 +54,11 @@ namespace Sludge { -extern Common::String gamePath; - int speechMode = 0; int cameraX, cameraY; float cameraZoom = 1.0; spritePalette pastePalette; -Common::String launchMe = NULL; variable *launchResult = NULL; extern int lastFramesPerSecond, thumbWidth, thumbHeight; @@ -80,7 +77,6 @@ extern char builtInFunctionNames[][25]; extern Common::String *allUserFunc; extern Common::String *allBIFNames; extern inputType input; -extern Common::String loadNow; #if 0 extern GLuint backdropTextureName; @@ -280,15 +276,15 @@ builtIn(saveGame) { fatal("Can't save game state while the engine is frozen"); } - loadNow = getTextFromAnyVar(fun->stack->thisVar); + g_sludge->loadNow = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); - Common::String aaaaa = encodeFilename(loadNow); - loadNow.clear(); + Common::String aaaaa = encodeFilename(g_sludge->loadNow); + g_sludge->loadNow.clear(); if (failSecurityCheck(aaaaa)) return BR_ERROR; // Won't fail if encoded, how cool is that? OK, not very. - loadNow = ":" + aaaaa; + g_sludge->loadNow = ":" + aaaaa; setVariable(fun->reg, SVT_INT, 0); saverFunc = fun; @@ -297,10 +293,10 @@ builtIn(saveGame) { builtIn(fileExists) { UNUSEDALL - loadNow = getTextFromAnyVar(fun->stack->thisVar); + g_sludge->loadNow = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); - Common::String aaaaa = encodeFilename(loadNow); - loadNow.clear(); + Common::String aaaaa = encodeFilename(g_sludge->loadNow); + g_sludge->loadNow.clear(); if (failSecurityCheck(aaaaa)) return BR_ERROR; #if 0 @@ -334,22 +330,22 @@ builtIn(loadGame) { UNUSEDALL Common::String aaaaa = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); - loadNow.clear(); - loadNow = encodeFilename(aaaaa); + g_sludge->loadNow.clear(); + g_sludge->loadNow = encodeFilename(aaaaa); if (frozenStuff) { fatal("Can't load a saved game while the engine is frozen"); } - if (failSecurityCheck(loadNow)) + if (failSecurityCheck(g_sludge->loadNow)) return BR_ERROR; - Common::InSaveFile *fp = g_system->getSavefileManager()->openForLoading(loadNow); + Common::InSaveFile *fp = g_system->getSavefileManager()->openForLoading(g_sludge->loadNow); if (fp) { delete fp; return BR_KEEP_AND_PAUSE; } debug("not find sav file"); - loadNow.clear(); + g_sludge->loadNow.clear(); return BR_CONTINUE; } @@ -961,14 +957,14 @@ builtIn(launch) { if (newTextA[0] == 'h' && newTextA[1] == 't' && newTextA[2] == 't' && newTextA[3] == 'p' && (newTextA[4] == ':' || (newTextA[4] == 's' && newTextA[5] == ':'))) { // IT'S A WEBSITE! - launchMe.clear(); - launchMe = newTextA; + g_sludge->launchMe.clear(); + g_sludge->launchMe = newTextA; } else { - Common::String gameDir = gamePath; + Common::String gameDir = g_sludge->gamePath; gameDir += "/"; - launchMe.clear(); - launchMe = gameDir + newText; - if (launchMe.empty()) + g_sludge->launchMe.clear(); + g_sludge->launchMe = gameDir + newText; + if (g_sludge->launchMe.empty()) return BR_ERROR; } setGraphicsWindow(false); diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp index 04d38f5831..d888059481 100644 --- a/engines/sludge/main_loop.cpp +++ b/engines/sludge/main_loop.cpp @@ -70,10 +70,6 @@ Graphics::Surface renderSurface; int dialogValue = 0; -Common::String gameName = ""; -Common::String gamePath = ""; -Common::String bundleFolder = ""; - void setGameFilePath(char *f) { char currentDir[1000]; #if 0 @@ -295,7 +291,7 @@ int main_loop(const char *filename) initStatusBar(); resetRandW(); - gameName = getNumberedString(1); + g_sludge->gameName = getNumberedString(1); #if 0 SDL_WM_SetCaption(gameName, gameName); diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp index e9cd860d8a..0f847bdda8 100644 --- a/engines/sludge/newfatal.cpp +++ b/engines/sludge/newfatal.cpp @@ -33,9 +33,6 @@ namespace Sludge { const char emergencyMemoryMessage[] = "Out of memory displaying error message!"; -static Common::String fatalMessage; -static Common::String fatalInfo = "Initialisation error! Something went wrong before we even got started!"; - extern int numResourceNames /* = 0*/; extern Common::String *allResourceNames /*= ""*/; @@ -52,13 +49,13 @@ const Common::String &resourceNameFromNum(int i) { } bool hasFatal() { - if (!fatalMessage.empty()) + if (!g_sludge->fatalMessage.empty()) return true; return false; } void displayFatal() { - if (!fatalMessage.empty()) { + if (!g_sludge->fatalMessage.empty()) { #if 0 msgBox("SLUDGE v" TEXT_VERSION " fatal error!", fatalMessage); #endif @@ -66,7 +63,7 @@ void displayFatal() { } void registerWindowForFatal() { - fatalInfo = "There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured."; + g_sludge->fatalInfo = "There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured."; } int inFatal(const Common::String &str) { @@ -84,8 +81,8 @@ int checkNew(const void *mem) { } void setFatalInfo(const Common::String &userFunc, const Common::String &BIF) { - fatalInfo = "Currently in this sub: " + userFunc + "\nCalling: " + BIF; - debug(kSludgeDebugFatal, "%s", fatalInfo.c_str()); + g_sludge->fatalInfo = "Currently in this sub: " + userFunc + "\nCalling: " + BIF; + debug(kSludgeDebugFatal, "%s", g_sludge->fatalInfo.c_str()); } void setResourceForFatal(int n) { @@ -95,10 +92,10 @@ void setResourceForFatal(int n) { int fatal(const Common::String &str1) { if (numResourceNames && resourceForFatal != -1) { Common::String r = resourceNameFromNum(resourceForFatal); - Common::String newStr = fatalInfo + "\nResource: " + r + "\n\n" + str1; + Common::String newStr = g_sludge->fatalInfo + "\nResource: " + r + "\n\n" + str1; inFatal(newStr); } else { - Common::String newStr = fatalInfo + "\n\n" + str1; + Common::String newStr = g_sludge->fatalInfo + "\n\n" + str1; inFatal(newStr); } return 0; diff --git a/engines/sludge/savedata.cpp b/engines/sludge/savedata.cpp index 77328db34e..1757798385 100644 --- a/engines/sludge/savedata.cpp +++ b/engines/sludge/savedata.cpp @@ -36,8 +36,6 @@ uint16 saveEncoding = false; char encode1 = 0; char encode2 = 0; -extern Common::String gamePath; - void writeStringEncoded(const Common::String &s, Common::WriteStream *stream) { int len = s.size(); diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index ab1eb868a2..e3754a7b57 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -50,6 +50,16 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) // check init debug("SludgeEngine::SludgeEngine"); + + // Init Strings + launchMe = ""; + loadNow = ""; + gameName = ""; + gamePath = ""; + bundleFolder = ""; + + fatalMessage = ""; + fatalInfo = "Initialisation error! Something went wrong before we even got started!"; } SludgeEngine::~SludgeEngine() { diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h index 03297ffffd..6ed1380b2d 100644 --- a/engines/sludge/sludge.h +++ b/engines/sludge/sludge.h @@ -53,6 +53,15 @@ protected: virtual Common::Error run(); public: + // global String variables + Common::String launchMe; + Common::String loadNow; + Common::String gameName; + Common::String gamePath; + Common::String bundleFolder; + Common::String fatalMessage; + Common::String fatalInfo; + SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc); virtual ~SludgeEngine(); diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index bbec72f3f6..c1b9af8865 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -57,7 +57,6 @@ extern personaAnimation *mouseCursorAnim; extern spritePalette pastePalette; extern int dialogValue; extern uint sceneWidth, sceneHeight; -extern Common::String launchMe; extern variable *launchResult; extern bool reallyWantToQuit; @@ -98,7 +97,6 @@ extern loadedFunction *saverFunc; loadedFunction *allRunningFunctions = NULL; screenRegion *lastRegion = NULL; variableStack *noStack = NULL; -Common::String loadNow; inputType input; variable *globalVars; int numGlobals; @@ -1194,15 +1192,15 @@ bool runSludge() { thisFunction = nextFunction; } - if (!loadNow.empty()) { - if (loadNow[0] == ':') { - saveGame(loadNow.c_str() + 1); + if (!g_sludge->loadNow.empty()) { + if (g_sludge->loadNow[0] == ':') { + saveGame(g_sludge->loadNow.c_str() + 1); setVariable(saverFunc->reg, SVT_INT, 1); } else { - if (!loadGame(loadNow)) + if (!loadGame(g_sludge->loadNow)) return false; } - loadNow.clear(); + g_sludge->loadNow.clear(); } return true; @@ -1307,14 +1305,14 @@ bool handleInput() { } // lastFramesPerSecond = theTime.wSecond; #endif - if (!launchMe.empty()) { + if (!g_sludge->launchMe.empty()) { if (l) { // Still paused because of spawned thingy... } else { l = 1; setVariable(*launchResult, SVT_INT, 0/*launch(launchMe) > 31*/); //TODO:false value - launchMe.clear(); + g_sludge->launchMe.clear(); launchResult = NULL; } return true; -- cgit v1.2.3