diff options
Diffstat (limited to 'engines/sludge/sludger.cpp')
-rw-r--r-- | engines/sludge/sludger.cpp | 96 |
1 files changed, 80 insertions, 16 deletions
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index 8e49b32465..69e6966e74 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -20,12 +20,14 @@ * */ +#include "common/config-manager.h" #include "common/debug.h" #include "sludge/allfiles.h" #include "sludge/backdrop.h" #include "sludge/builtin.h" #include "sludge/cursors.h" +#include "sludge/event.h" #include "sludge/fonttext.h" #include "sludge/freeze.h" #include "sludge/floor.h" @@ -54,7 +56,6 @@ namespace Sludge { extern int dialogValue; -extern Variable *launchResult; int numBIFNames = 0; Common::String *allBIFNames; @@ -74,11 +75,20 @@ extern SpeechStruct *speech; extern LoadedFunction *saverFunc; LoadedFunction *allRunningFunctions = NULL; -ScreenRegion *lastRegion = NULL; VariableStack *noStack = NULL; Variable *globalVars; -int numGlobals; +int numGlobals = 0; + +extern SpritePalette pastePalette; +extern int speechMode; +extern float speechSpeed; +extern Variable *launchResult; +extern int lastFramesPerSecond, thumbWidth, thumbHeight; + +extern bool allowAnyFilename; +extern byte fadeMode; +extern uint16 saveEncoding; const char *sludgeText[] = { "?????", "RETURN", "BRANCH", "BR_ZERO", "SET_GLOBAL", "SET_LOCAL", "LOAD_GLOBAL", "LOAD_LOCAL", "PLUS", "MINUS", @@ -138,9 +148,69 @@ Common::File *openAndVerify(const Common::String &filename, char extra1, char ex return fp; } +void initSludge() { + g_sludge->_languageMan->init(); + g_sludge->_gfxMan->init(); + g_sludge->_resMan->init(); + initPeople(); + initFloor(); + g_sludge->_objMan->init(); + initSpeech(); + initStatusBar(); + resetRandW(); + g_sludge->_evtMan->init(); + g_sludge->_txtMan->init(); + g_sludge->_cursorMan->init(); + + g_sludge->_soundMan->init(); + if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) { + g_sludge->_soundMan->initSoundStuff(); + } + + // global variables + numGlobals = 0; + speechMode = 0; + launchResult = nullptr; + + lastFramesPerSecond = -1; + thumbWidth = thumbHeight = 0; + allowAnyFilename = true; + captureAllKeys = false; + noStack = nullptr; + numBIFNames = numUserFunc = 0; + allUserFunc = allBIFNames = nullptr; + speechSpeed = 1; + brightnessLevel = 255; + fadeMode = 2; + saveEncoding = false; +} + +void killSludge() { + killAllFunctions(); + killAllPeople(); + killAllRegions(); + setFloorNull(); + killAllSpeech(); + g_sludge->_languageMan->kill(); + g_sludge->_gfxMan->kill(); + g_sludge->_resMan->kill(); + g_sludge->_objMan->kill(); + g_sludge->_soundMan->killSoundStuff(); + g_sludge->_evtMan->kill(); + g_sludge->_txtMan->kill(); + g_sludge->_cursorMan->kill(); + + // global variables + pastePalette.reset(); + numBIFNames = numUserFunc = 0; + delete []allUserFunc; + delete []allBIFNames; +} + bool initSludge(const Common::String &filename) { - int a = 0; + initSludge(); + int a = 0; Common::File *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER, gameVersion); if (!fp) return false; @@ -203,7 +273,7 @@ bool initSludge(const Common::String &filename) { Common::String dataFol = (gameVersion >= VERSION(1, 3)) ? readString(fp) : ""; debugC(2, kSludgeDebugDataLoad, "dataFol : %s", dataFol.c_str()); - g_sludge->_languageMan->init(fp); + g_sludge->_languageMan->createTable(fp); if (gameVersion >= VERSION(1, 6)) { fp->readByte(); @@ -407,27 +477,16 @@ bool continueFunction(LoadedFunction *fun) { return true; } -// if (numBIFNames) newDebug ("*** Function:", allUserFunc[fun->originalNumber]); - - //debugOut ("SLUDGER: continueFunction\n"); - while (keepLooping) { advanceNow = true; debugC(1, kSludgeDebugStackMachine, "Executing command line %i : ", fun->runThisLine); param = fun->compiledLines[fun->runThisLine].param; com = fun->compiledLines[fun->runThisLine].theCommand; -// fprintf (stderr, "com: %d param: %d (%s)\n", com, param, -// (com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE); fflush(stderr); if (numBIFNames) { setFatalInfo((fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function", (com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE); -// newDebug ( -// (com < numSludgeCommands) ? sludgeText[com] : "Unknown SLUDGE machine code", -// param); } - //debugOut ("SLUDGER: continueFunction - in da loop: %s\n", sludgeText[com]); - switch (com) { case SLU_RETURN: if (fun->calledBy) { @@ -913,6 +972,11 @@ bool runSludge() { return true; } +void killAllFunctions() { + while (allRunningFunctions) + finishFunction(allRunningFunctions); +} + bool loadFunctionCode(LoadedFunction *newFunc) { uint numLines, numLinesRead; |