From ca583ebfcfc420d0b303256a9a088bb2327ea907 Mon Sep 17 00:00:00 2001 From: Simei Yin Date: Thu, 31 May 2018 22:55:36 +0200 Subject: SLUDGE: Move last stack finding function to struct VariableStack --- engines/sludge/builtin.cpp | 6 ++++-- engines/sludge/variable.cpp | 6 ++---- engines/sludge/variable.h | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'engines/sludge') diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 61f1726ec0..bf7c4228d3 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -609,7 +609,8 @@ builtIn(deleteFromStack) { fun->reg.setVariable(SVT_INT, deleteVarFromStack(fun->stack->thisVar, fun->stack->next->thisVar.varData.theStack->first, false)); // Horrible hacking because 'last' value might now be wrong! - fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first); + VariableStack *nextFirstStack = fun->stack->next->thisVar.varData.theStack->first; + fun->stack->next->thisVar.varData.theStack->last = (nextFirstStack == NULL) ? NULL : nextFirstStack->stackFindLast(); trimStack(fun->stack); trimStack(fun->stack); @@ -627,7 +628,8 @@ builtIn(deleteAllFromStack) { fun->reg.setVariable(SVT_INT, deleteVarFromStack(fun->stack->thisVar, fun->stack->next->thisVar.varData.theStack->first, true)); // Horrible hacking because 'last' value might now be wrong! - fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first); + VariableStack *nextFirstStack = fun->stack->next->thisVar.varData.theStack->first; + fun->stack->next->thisVar.varData.theStack->last = (nextFirstStack == NULL) ? NULL : nextFirstStack->stackFindLast(); trimStack(fun->stack); trimStack(fun->stack); diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index 9b72185cb8..5da52483e6 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -492,10 +492,8 @@ int deleteVarFromStack(const Variable &va, VariableStack *&thisStack, bool allOf } // Would be a LOT better just to keep this up to date in the above function... ah well -VariableStack *stackFindLast(VariableStack *hunt) { - if (hunt == NULL) - return NULL; - +VariableStack *VariableStack::stackFindLast() { + VariableStack *hunt = this; while (hunt->next) hunt = hunt->next; diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h index dafc761019..51fba77e85 100644 --- a/engines/sludge/variable.h +++ b/engines/sludge/variable.h @@ -121,6 +121,9 @@ struct VariableStack { // Variable getter & setter bool stackSetByIndex(uint, const Variable &); Variable *stackGetByIndex(uint); + + // Find last + VariableStack *stackFindLast(); }; // Stacky stuff @@ -128,9 +131,7 @@ struct VariableStack { bool addVarToStack(const Variable &va, VariableStack *&thisStack); bool addVarToStackQuick(Variable &va, VariableStack *&thisStack); void trimStack(VariableStack *&stack); -int deleteVarFromStack(const Variable &va, VariableStack *&thisStack, - bool allOfEm = false); -VariableStack *stackFindLast(VariableStack *hunt); +int deleteVarFromStack(const Variable &va, VariableStack *&thisStack, bool allOfEm = false); bool copyStack(const Variable &from, Variable &to); int stackSize(const StackHandler *me); bool getSavedGamesStack(StackHandler *sH, const Common::String &ext); -- cgit v1.2.3