diff options
author | Simei Yin | 2018-05-30 19:57:32 +0200 |
---|---|---|
committer | Simei Yin | 2018-05-31 23:15:09 +0200 |
commit | 04444b70f97c40fe3893e80d73042b4f11dbfa46 (patch) | |
tree | 7a9c5b72152b9170cde1df6d50e4b1fdac5d1af1 /engines/sludge | |
parent | 6004cd319d3c865821bc2be29647222c957ed517 (diff) | |
download | scummvm-rg350-04444b70f97c40fe3893e80d73042b4f11dbfa46.tar.gz scummvm-rg350-04444b70f97c40fe3893e80d73042b4f11dbfa46.tar.bz2 scummvm-rg350-04444b70f97c40fe3893e80d73042b4f11dbfa46.zip |
SLUDGE: Move unlinkVar into struct Variable
Diffstat (limited to 'engines/sludge')
-rw-r--r-- | engines/sludge/builtin.cpp | 8 | ||||
-rw-r--r-- | engines/sludge/function.cpp | 8 | ||||
-rw-r--r-- | engines/sludge/loadsave.cpp | 2 | ||||
-rw-r--r-- | engines/sludge/variable.cpp | 54 | ||||
-rw-r--r-- | engines/sludge/variable.h | 3 |
5 files changed, 38 insertions, 37 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 0d1d940259..0ebcea1001 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -205,7 +205,7 @@ builtIn(getMatchingFiles) { UNUSEDALL Common::String newText = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); - unlinkVar(fun->reg); + fun->reg.unlinkVar(); // Return value fun->reg.varType = SVT_STACK; @@ -498,7 +498,7 @@ builtIn(stringLength) { builtIn(newStack) { UNUSEDALL - unlinkVar(fun->reg); + fun->reg.unlinkVar(); // Return value fun->reg.varType = SVT_STACK; @@ -2236,7 +2236,7 @@ builtIn(loadCustomData) { return BR_ERROR; trimStack(fun->stack); - unlinkVar(fun->reg); + fun->reg.unlinkVar(); fun->reg.varType = SVT_STACK; fun->reg.varData.theStack = new StackHandler; if (!checkNew(fun->reg.varData.theStack)) @@ -2311,7 +2311,7 @@ builtIn(getPixelColour) { return BR_ERROR; trimStack(fun->stack); - unlinkVar(fun->reg); + fun->reg.unlinkVar(); fun->reg.varType = SVT_STACK; fun->reg.varData.theStack = new StackHandler; if (!checkNew(fun->reg.varData.theStack)) diff --git a/engines/sludge/function.cpp b/engines/sludge/function.cpp index 0a7a344d84..97c51307ab 100644 --- a/engines/sludge/function.cpp +++ b/engines/sludge/function.cpp @@ -100,9 +100,9 @@ void finishFunction(LoadedFunction *fun) { fatal(ERROR_NON_EMPTY_STACK); delete[] fun->compiledLines; for (a = 0; a < fun->numLocals; a++) - unlinkVar(fun->localVars[a]); + fun->localVars[a].unlinkVar(); delete[] fun->localVars; - unlinkVar(fun->reg); + fun->reg.unlinkVar(); delete fun; fun = NULL; } @@ -115,9 +115,9 @@ void abortFunction(LoadedFunction *fun) { trimStack(fun->stack); delete []fun->compiledLines; for (a = 0; a < fun->numLocals; a++) - unlinkVar(fun->localVars[a]); + fun->localVars[a].unlinkVar(); delete []fun->localVars; - unlinkVar(fun->reg); + fun->reg.unlinkVar(); if (fun->calledBy) abortFunction(fun->calledBy); delete fun; diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 4a78b83d29..22781eaba9 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -257,7 +257,7 @@ bool loadGame(const Common::String &fname) { } for (int a = 0; a < numGlobals; a++) { - unlinkVar(globalVars[a]); + globalVars[a].unlinkVar(); loadVariable(&globalVars[a], fp); } diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index b9e7b123d8..dc5604f31b 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -38,36 +38,36 @@ const char *typeName[] = { "undefined", "number", "user function", "string", "built-in function", "file", "stack", "object type", "animation", "costume" }; -void unlinkVar(Variable &thisVar) { - switch (thisVar.varType) { +void Variable::unlinkVar() { + switch (varType) { case SVT_STRING: - delete []thisVar.varData.theString; - thisVar.varData.theString = NULL; + delete []varData.theString; + varData.theString = NULL; break; case SVT_STACK: - thisVar.varData.theStack->timesUsed--; - if (thisVar.varData.theStack->timesUsed <= 0) { - while (thisVar.varData.theStack->first) - trimStack(thisVar.varData.theStack->first); - delete thisVar.varData.theStack; - thisVar.varData.theStack = NULL; + varData.theStack->timesUsed--; + if (varData.theStack->timesUsed <= 0) { + while (varData.theStack->first) + trimStack(varData.theStack->first); + delete varData.theStack; + varData.theStack = NULL; } break; case SVT_FASTARRAY: - thisVar.varData.fastArray->timesUsed--; - if (thisVar.varData.theStack->timesUsed <= 0) { - delete thisVar.varData.fastArray->fastVariables; - delete[] thisVar.varData.fastArray; - thisVar.varData.fastArray = NULL; + varData.fastArray->timesUsed--; + if (varData.theStack->timesUsed <= 0) { + delete varData.fastArray->fastVariables; + delete[] varData.fastArray; + varData.fastArray = NULL; } break; case SVT_ANIM: - if (thisVar.varData.animHandler) { - delete thisVar.varData.animHandler; - thisVar.varData.animHandler = nullptr; + if (varData.animHandler) { + delete varData.animHandler; + varData.animHandler = nullptr; } break; @@ -77,13 +77,13 @@ void unlinkVar(Variable &thisVar) { } void setVariable(Variable &thisVar, VariableType vT, int value) { - unlinkVar(thisVar); + thisVar.unlinkVar(); thisVar.varType = vT; thisVar.varData.intValue = value; } void newAnimationVariable(Variable &thisVar, PersonaAnimation *i) { - unlinkVar(thisVar); + thisVar.unlinkVar(); thisVar.varType = SVT_ANIM; thisVar.varData.animHandler = i; } @@ -100,7 +100,7 @@ PersonaAnimation *getAnimationFromVar(Variable &thisVar) { } void newCostumeVariable(Variable &thisVar, Persona *i) { - unlinkVar(thisVar); + thisVar.unlinkVar(); thisVar.varType = SVT_COSTUME; thisVar.varData.costumeHandler = i; } @@ -198,7 +198,7 @@ void addVariablesInSecond(Variable &var1, Variable &var2) { Common::String string1 = getTextFromAnyVar(var1); Common::String string2 = getTextFromAnyVar(var2); - unlinkVar(var2); + var2.unlinkVar(); var2.varData.theString = createCString(string1 + string2); var2.varType = SVT_STRING; } @@ -240,7 +240,7 @@ void compareVariablesInSecond(const Variable &var1, Variable &var2) { } void makeTextVar(Variable &thisVar, const Common::String &txt) { - unlinkVar(thisVar); + thisVar.unlinkVar(); thisVar.varType = SVT_STRING; thisVar.varData.theString = createCString(txt); } @@ -376,7 +376,7 @@ bool copyMain(const Variable &from, Variable &to) { } bool copyVariable(const Variable &from, Variable &to) { - unlinkVar(to); + to.unlinkVar(); return copyMain(from, to); } @@ -389,7 +389,7 @@ Variable *fastArrayGetByIndex(FastArrayHandler *vS, uint theIndex) { bool makeFastArraySize(Variable &to, int size) { if (size < 0) return fatal("Can't create a fast array with a negative number of elements!"); - unlinkVar(to); + to.unlinkVar(); to.varType = SVT_FASTARRAY; to.varData.fastArray = new FastArrayHandler; if (!checkNew(to.varData.fastArray)) @@ -476,7 +476,7 @@ int deleteVarFromStack(const Variable &va, VariableStack *&thisStack, bool allOf if (compareVars((*huntVar)->thisVar, va)) { killMe = *huntVar; *huntVar = killMe->next; - unlinkVar(killMe->thisVar); + killMe->thisVar.unlinkVar(); delete killMe; if (!allOfEm) return 1; @@ -522,7 +522,7 @@ void trimStack(VariableStack *&stack) { //debugC(2, kSludgeDebugStackMachine, "Variable %s was removed from stack", getTextFromAnyVar(killMe->thisVar)); // When calling this, we've ALWAYS checked that stack != NULL - unlinkVar(killMe->thisVar); + killMe->thisVar.unlinkVar(); delete killMe; } diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h index a3ae673f66..5a750b5a6a 100644 --- a/engines/sludge/variable.h +++ b/engines/sludge/variable.h @@ -73,6 +73,8 @@ struct Variable { varType = SVT_NULL; varData.intValue = 0; } + + void unlinkVar(); }; struct VariableStack { @@ -93,7 +95,6 @@ void compareVariablesInSecond(const Variable &var1, Variable &var2); // Misc. -void unlinkVar(Variable &thisVar); Common::String getTextFromAnyVar(const Variable &from); struct Persona *getCostumeFromVar(Variable &thisVar); struct PersonaAnimation *getAnimationFromVar(Variable &thisVar); |