aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorSimei Yin2018-05-31 22:55:36 +0200
committerSimei Yin2018-05-31 23:15:09 +0200
commitca583ebfcfc420d0b303256a9a088bb2327ea907 (patch)
treeddf0074373f86a9662386edb7bfbdd7c73ebd152 /engines
parent9fb57f944d1105c084b4cf54e037a66b9eb34740 (diff)
downloadscummvm-rg350-ca583ebfcfc420d0b303256a9a088bb2327ea907.tar.gz
scummvm-rg350-ca583ebfcfc420d0b303256a9a088bb2327ea907.tar.bz2
scummvm-rg350-ca583ebfcfc420d0b303256a9a088bb2327ea907.zip
SLUDGE: Move last stack finding function to struct VariableStack
Diffstat (limited to 'engines')
-rw-r--r--engines/sludge/builtin.cpp6
-rw-r--r--engines/sludge/variable.cpp6
-rw-r--r--engines/sludge/variable.h7
3 files changed, 10 insertions, 9 deletions
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);