diff options
author | Simei Yin | 2018-05-31 22:38:26 +0200 |
---|---|---|
committer | Simei Yin | 2018-05-31 23:15:09 +0200 |
commit | 399ff4788cd5a03d37ac1945ed76bc47bc8d4218 (patch) | |
tree | 73161e19bb316847fa35b9c4a96271358ae6e64f | |
parent | 746fb3819faa7239b41c06492583bbe4296b5e02 (diff) | |
download | scummvm-rg350-399ff4788cd5a03d37ac1945ed76bc47bc8d4218.tar.gz scummvm-rg350-399ff4788cd5a03d37ac1945ed76bc47bc8d4218.tar.bz2 scummvm-rg350-399ff4788cd5a03d37ac1945ed76bc47bc8d4218.zip |
SLUDGE: Move fastarray functions to struct Variable
-rw-r--r-- | engines/sludge/builtin.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/variable.cpp | 24 | ||||
-rw-r--r-- | engines/sludge/variable.h | 6 |
3 files changed, 18 insertions, 16 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 6c98ca0e3d..61f1726ec0 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -2329,7 +2329,7 @@ builtIn(makeFastArray) { UNUSEDALL switch (fun->stack->thisVar.varType) { case SVT_STACK: { - bool success = makeFastArrayFromStack(fun->reg, fun->stack->thisVar.varData.theStack); + bool success = fun->reg.makeFastArrayFromStack(fun->stack->thisVar.varData.theStack); trimStack(fun->stack); return success ? BR_CONTINUE : BR_ERROR; } @@ -2338,7 +2338,7 @@ builtIn(makeFastArray) { case SVT_INT: { int i = fun->stack->thisVar.varData.intValue; trimStack(fun->stack); - return makeFastArraySize(fun->reg, i) ? BR_CONTINUE : BR_ERROR; + return fun->reg.makeFastArraySize(i) ? BR_CONTINUE : BR_ERROR; } break; diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index af6d388f7a..50bd52e93c 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -386,25 +386,25 @@ Variable *fastArrayGetByIndex(FastArrayHandler *vS, uint theIndex) { return &vS->fastVariables[theIndex]; } -bool makeFastArraySize(Variable &to, int size) { +bool Variable::makeFastArraySize(int size) { if (size < 0) return fatal("Can't create a fast array with a negative number of elements!"); - to.unlinkVar(); - to.varType = SVT_FASTARRAY; - to.varData.fastArray = new FastArrayHandler; - if (!checkNew(to.varData.fastArray)) + unlinkVar(); + varType = SVT_FASTARRAY; + varData.fastArray = new FastArrayHandler; + if (!checkNew(varData.fastArray)) return false; - to.varData.fastArray->fastVariables = new Variable[size]; - if (!checkNew(to.varData.fastArray->fastVariables)) + varData.fastArray->fastVariables = new Variable[size]; + if (!checkNew(varData.fastArray->fastVariables)) return false; - to.varData.fastArray->size = size; - to.varData.fastArray->timesUsed = 1; + varData.fastArray->size = size; + varData.fastArray->timesUsed = 1; return true; } -bool makeFastArrayFromStack(Variable &to, const StackHandler *stacky) { +bool Variable::makeFastArrayFromStack(const StackHandler *stacky) { int size = stackSize(stacky); - if (!makeFastArraySize(to, size)) + if (!makeFastArraySize(size)) return false; // Now let's fill up the new array @@ -412,7 +412,7 @@ bool makeFastArrayFromStack(Variable &to, const StackHandler *stacky) { VariableStack *allV = stacky->first; size = 0; while (allV) { - to.varData.fastArray->fastVariables[size].copyMain(allV->thisVar); + varData.fastArray->fastVariables[size].copyMain(allV->thisVar); size++; allV = allV->next; } diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h index febd94207b..de7d2efc34 100644 --- a/engines/sludge/variable.h +++ b/engines/sludge/variable.h @@ -97,6 +97,10 @@ struct Variable { void makeCostumeVariable(Persona *i); struct Persona *getCostumeFromVar(); + // Fast array variable + bool makeFastArrayFromStack(const StackHandler *stacky); + bool makeFastArraySize(int size); + // Add variables void addVariablesInSecond(const Variable &other); void compareVariablesInSecond(const Variable &other); @@ -127,8 +131,6 @@ bool stackSetByIndex(VariableStack *, uint, const Variable &); Variable *stackGetByIndex(VariableStack *, uint); bool getSavedGamesStack(StackHandler *sH, const Common::String &ext); -bool makeFastArrayFromStack(Variable &to, const StackHandler *stacky); -bool makeFastArraySize(Variable &to, int size); Variable *fastArrayGetByIndex(FastArrayHandler *vS, uint theIndex); // load & save |