diff options
author | Simei Yin | 2018-05-31 22:05:39 +0200 |
---|---|---|
committer | Simei Yin | 2018-05-31 23:15:09 +0200 |
commit | 9d85b807fbb15c850c2e5d2eb598badf565a4497 (patch) | |
tree | ad55eb777674b4b639e945680079550d0e3f2370 | |
parent | 719f5842fa2199b6003610aa5f4981626e9b52e1 (diff) | |
download | scummvm-rg350-9d85b807fbb15c850c2e5d2eb598badf565a4497.tar.gz scummvm-rg350-9d85b807fbb15c850c2e5d2eb598badf565a4497.tar.bz2 scummvm-rg350-9d85b807fbb15c850c2e5d2eb598badf565a4497.zip |
SLUDGE: Move add/comparison functions to struct Variable
-rw-r--r-- | engines/sludge/function.cpp | 6 | ||||
-rw-r--r-- | engines/sludge/variable.cpp | 40 | ||||
-rw-r--r-- | engines/sludge/variable.h | 10 |
3 files changed, 28 insertions, 28 deletions
diff --git a/engines/sludge/function.cpp b/engines/sludge/function.cpp index ed7280fa2c..179dc1f848 100644 --- a/engines/sludge/function.cpp +++ b/engines/sludge/function.cpp @@ -536,17 +536,17 @@ bool continueFunction(LoadedFunction *fun) { switch (com) { case SLU_PLUS: - addVariablesInSecond(fun->stack->thisVar, fun->reg); + fun->reg.addVariablesInSecond(fun->stack->thisVar); trimStack(fun->stack); break; case SLU_EQUALS: - compareVariablesInSecond(fun->stack->thisVar, fun->reg); + fun->reg.compareVariablesInSecond(fun->stack->thisVar); trimStack(fun->stack); break; case SLU_NOT_EQ: - compareVariablesInSecond(fun->stack->thisVar, fun->reg); + fun->reg.compareVariablesInSecond(fun->stack->thisVar); trimStack(fun->stack); fun->reg.varData.intValue = !fun->reg.varData.intValue; break; diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index d431077235..88b27d0366 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -191,52 +191,52 @@ bool copyStack(const Variable &from, Variable &to) { return true; } -void addVariablesInSecond(Variable &var1, Variable &var2) { - if (var1.varType == SVT_INT && var2.varType == SVT_INT) { - var2.varData.intValue += var1.varData.intValue; +void Variable::addVariablesInSecond(const Variable &other) { + if (other.varType == SVT_INT && varType == SVT_INT) { + varData.intValue += other.varData.intValue; } else { - Common::String string1 = var1.getTextFromAnyVar(); - Common::String string2 = var2.getTextFromAnyVar(); + Common::String string1 = other.getTextFromAnyVar(); + Common::String string2 = getTextFromAnyVar(); - var2.unlinkVar(); - var2.varData.theString = createCString(string1 + string2); - var2.varType = SVT_STRING; + unlinkVar(); + varData.theString = createCString(string1 + string2); + varType = SVT_STRING; } } -int compareVars(const Variable &var1, const Variable &var2) { +int Variable::compareVars(const Variable &other) const { int re = 0; - if (var1.varType == var2.varType) { - switch (var1.varType) { + if (other.varType == varType) { + switch (other.varType) { case SVT_NULL: re = 1; break; case SVT_COSTUME: - re = (var1.varData.costumeHandler == var2.varData.costumeHandler); + re = (other.varData.costumeHandler == varData.costumeHandler); break; case SVT_ANIM: - re = (var1.varData.animHandler == var2.varData.animHandler); + re = (other.varData.animHandler == varData.animHandler); break; case SVT_STRING: - re = (strcmp(var1.varData.theString, var2.varData.theString) == 0); + re = (strcmp(other.varData.theString, varData.theString) == 0); break; case SVT_STACK: - re = (var1.varData.theStack == var2.varData.theStack); + re = (other.varData.theStack == varData.theStack); break; default: - re = (var1.varData.intValue == var2.varData.intValue); + re = (other.varData.intValue == varData.intValue); } } return re; } -void compareVariablesInSecond(const Variable &var1, Variable &var2) { - var2.setVariable(SVT_INT, compareVars(var1, var2)); +void Variable::compareVariablesInSecond(const Variable &other) { + setVariable(SVT_INT, compareVars(other)); } void Variable::makeTextVar(const Common::String &txt) { @@ -250,7 +250,7 @@ bool Variable::loadStringToVar(int value) { return (bool)(varData.theString != NULL); } -Common::String Variable::getTextFromAnyVar() { +Common::String Variable::getTextFromAnyVar() const { switch (varType) { case SVT_STRING: return varData.theString; @@ -473,7 +473,7 @@ int deleteVarFromStack(const Variable &va, VariableStack *&thisStack, bool allOf int reply = 0; while (*huntVar) { - if (compareVars((*huntVar)->thisVar, va)) { + if (va.compareVars((*huntVar)->thisVar)) { killMe = *huntVar; *huntVar = killMe->next; killMe->thisVar.unlinkVar(); diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h index 2537c6e318..c33223253d 100644 --- a/engines/sludge/variable.h +++ b/engines/sludge/variable.h @@ -88,7 +88,7 @@ struct Variable { // Text variable void makeTextVar(const Common::String &txt); bool loadStringToVar(int value); - Common::String getTextFromAnyVar(); + Common::String getTextFromAnyVar() const; // Animation variable void makeAnimationVariable(PersonaAnimation *i); @@ -98,6 +98,10 @@ struct Variable { void makeCostumeVariable(Persona *i); struct Persona *getCostumeFromVar(); + // Add variables + void addVariablesInSecond(const Variable &other); + void compareVariablesInSecond(const Variable &other); + int compareVars(const Variable &other) const; }; struct VariableStack { @@ -105,10 +109,6 @@ struct VariableStack { VariableStack *next; }; -// Setting variables -void addVariablesInSecond(Variable &var1, Variable &var2); -void compareVariablesInSecond(const Variable &var1, Variable &var2); - // Misc. bool getBoolean(const Variable &from); |