Skip to content

Commit

Permalink
SLUDGE: change global Common::String to public var of SludgeEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
yinsimei authored and sev- committed Jul 13, 2017
1 parent d6308b9 commit 91fcdda
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 48 deletions.
40 changes: 18 additions & 22 deletions engines/sludge/builtin.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions engines/sludge/main_loop.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 7 additions & 10 deletions engines/sludge/newfatal.cpp
Expand Up @@ -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 /*= ""*/;

Expand All @@ -52,21 +49,21 @@ 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
}
}

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) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions engines/sludge/savedata.cpp
Expand Up @@ -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();

Expand Down
10 changes: 10 additions & 0 deletions engines/sludge/sludge.cpp
Expand Up @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions engines/sludge/sludge.h
Expand Up @@ -53,6 +53,15 @@ class SludgeEngine: public Engine {
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();

Expand Down
16 changes: 7 additions & 9 deletions engines/sludge/sludger.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 91fcdda

Please sign in to comment.