diff options
| -rw-r--r-- | engines/sludge/builtin.cpp | 8 | ||||
| -rw-r--r-- | engines/sludge/function.cpp | 21 | ||||
| -rw-r--r-- | engines/sludge/variable.cpp | 36 | ||||
| -rw-r--r-- | engines/sludge/variable.h | 6 | 
4 files changed, 34 insertions, 37 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index e8990144ab..2ee7de3d07 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -443,7 +443,7 @@ builtIn(pickOne) {  	// Return value  	while (numParams--) {  		if (i == numParams) -			copyVariable(fun->stack->thisVar, fun->reg); +			fun->reg.copyFrom(fun->stack->thisVar);  		trimStack(fun->stack);  	}  	return BR_CONTINUE; @@ -646,7 +646,7 @@ builtIn(popFromStack) {  	}  	// Return value -	copyVariable(fun->stack->thisVar.varData.theStack->first->thisVar, fun->reg); +	fun->reg.copyFrom(fun->stack->thisVar.varData.theStack->first->thisVar);  	trimStack(fun->stack->thisVar.varData.theStack->first);  	trimStack(fun->stack);  	return BR_CONTINUE; @@ -664,7 +664,7 @@ builtIn(peekStart) {  	}  	// Return value -	copyVariable(fun->stack->thisVar.varData.theStack->first->thisVar, fun->reg); +	fun->reg.copyFrom(fun->stack->thisVar.varData.theStack->first->thisVar);  	trimStack(fun->stack);  	return BR_CONTINUE;  } @@ -681,7 +681,7 @@ builtIn(peekEnd) {  	}  	// Return value -	copyVariable(fun->stack->thisVar.varData.theStack->last->thisVar, fun->reg); +	fun->reg.copyFrom(fun->stack->thisVar.varData.theStack->last->thisVar);  	trimStack(fun->stack);  	return BR_CONTINUE;  } diff --git a/engines/sludge/function.cpp b/engines/sludge/function.cpp index 232a040417..f876746700 100644 --- a/engines/sludge/function.cpp +++ b/engines/sludge/function.cpp @@ -190,7 +190,7 @@ bool continueFunction(LoadedFunction *fun) {  			if (fun->calledBy) {  				LoadedFunction *returnTo = fun->calledBy;  				if (fun->returnSomething) -					copyVariable(fun->reg, returnTo->reg); +					returnTo->reg.copyFrom(fun->reg);  				finishFunction(fun);  				fun = returnTo;  				restartFunction(fun); @@ -290,7 +290,7 @@ bool continueFunction(LoadedFunction *fun) {  			break;  		case SLU_LOAD_LOCAL: -			if (!copyVariable(fun->localVars[param], fun->reg)) +			if (!fun->reg.copyFrom(fun->localVars[param]))  				return false;  			break; @@ -379,7 +379,7 @@ bool continueFunction(LoadedFunction *fun) {  							break;  						default: -							if (!copyVariable(*grab, fun->reg)) +							if (!fun->reg.copyFrom(*grab))  								return false;  						}  					} @@ -418,7 +418,7 @@ bool continueFunction(LoadedFunction *fun) {  						fun->stack->thisVar.varData.fastArray, ii);  				if (v == NULL)  					return fatal("Not within bounds of fast array."); -				if (!copyVariable(fun->stack->next->thisVar, *v)) +				if (!v->copyFrom(fun->stack->next->thisVar))  					return false;  				trimStack(fun->stack);  				trimStack(fun->stack); @@ -470,22 +470,17 @@ bool continueFunction(LoadedFunction *fun) {  			break;  		case SLU_SET_LOCAL: -			if (!copyVariable(fun->reg, fun->localVars[param])) +			if (!fun->localVars[param].copyFrom(fun->reg))  				return false;  			break;  		case SLU_SET_GLOBAL: -//			newDebug ("  Copying TO global variable", param); -//			newDebug ("  Global type at the moment", globalVars[param].varType); -			if (!copyVariable(fun->reg, globalVars[param])) +			if (!globalVars[param].copyFrom(fun->reg))  				return false; -//			newDebug ("  New type", globalVars[param].varType);  			break;  		case SLU_LOAD_GLOBAL: -//			newDebug ("  Copying FROM global variable", param); -//			newDebug ("  Global type at the moment", globalVars[param].varType); -			if (!copyVariable(globalVars[param], fun->reg)) +			if (!fun->reg.copyFrom(globalVars[param]))  				return false;  			break; @@ -685,7 +680,7 @@ int startNewFunctionNum(uint funcNum, uint numParamsExpected,  		if (vStack == NULL)  			return fatal(  					"Corrupted file!The stack's empty and there were still parameters expected"); -		copyVariable(vStack->thisVar, newFunc->localVars[numParamsExpected]); +		newFunc->localVars[numParamsExpected].copyFrom(vStack->thisVar);  		trimStack(vStack);  	} diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index d52e5ef764..90a2f14e72 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -332,37 +332,37 @@ bool getBoolean(const Variable &from) {  	return true;  } -bool copyMain(const Variable &from, Variable &to) { -	to.varType = from.varType; -	switch (to.varType) { +bool Variable::copyMain(const Variable &from) { +	varType = from.varType; +	switch (varType) {  		case SVT_INT:  		case SVT_FUNC:  		case SVT_BUILT:  		case SVT_FILE:  		case SVT_OBJTYPE: -			to.varData.intValue = from.varData.intValue; +			varData.intValue = from.varData.intValue;  			return true;  		case SVT_FASTARRAY: -			to.varData.fastArray = from.varData.fastArray; -			to.varData.fastArray->timesUsed++; +			varData.fastArray = from.varData.fastArray; +			varData.fastArray->timesUsed++;  			return true;  		case SVT_STRING: -			to.varData.theString = createCString(from.varData.theString); -			return to.varData.theString ? true : false; +			varData.theString = createCString(from.varData.theString); +			return varData.theString ? true : false;  		case SVT_STACK: -			to.varData.theStack = from.varData.theStack; -			to.varData.theStack->timesUsed++; +			varData.theStack = from.varData.theStack; +			varData.theStack->timesUsed++;  			return true;  		case SVT_COSTUME: -			to.varData.costumeHandler = from.varData.costumeHandler; +			varData.costumeHandler = from.varData.costumeHandler;  			return true;  		case SVT_ANIM: -			to.varData.animHandler = new PersonaAnimation(from.varData.animHandler); +			varData.animHandler = new PersonaAnimation(from.varData.animHandler);  			return true;  		case SVT_NULL: @@ -375,9 +375,9 @@ bool copyMain(const Variable &from, Variable &to) {  	return false;  } -bool copyVariable(const Variable &from, Variable &to) { -	to.unlinkVar(); -	return copyMain(from, to); +bool Variable::copyFrom(const Variable &from) { +	unlinkVar(); +	return copyMain(from);  }  Variable *fastArrayGetByIndex(FastArrayHandler *vS, uint theIndex) { @@ -412,7 +412,7 @@ bool makeFastArrayFromStack(Variable &to, const StackHandler *stacky) {  	VariableStack *allV = stacky->first;  	size = 0;  	while (allV) { -		copyMain(allV->thisVar, to.varData.fastArray->fastVariables[size]); +		to.varData.fastArray->fastVariables[size].copyMain(allV->thisVar);  		size++;  		allV = allV->next;  	} @@ -424,7 +424,7 @@ bool addVarToStack(const Variable &va, VariableStack *&thisStack) {  	if (!checkNew(newStack))  		return false; -	if (!copyMain(va, newStack->thisVar)) +	if (!newStack->thisVar.copyMain(va))  		return false;  	newStack->next = thisStack;  	thisStack = newStack; @@ -454,7 +454,7 @@ bool stackSetByIndex(VariableStack *vS, uint theIndex, const Variable &va) {  		if (!vS)  			return fatal("Index past end of stack.");  	} -	return copyVariable(va, vS->thisVar); +	return vS->thisVar.copyFrom(va);  }  Variable *stackGetByIndex(VariableStack *vS, uint theIndex) { diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h index c78976afa6..22ed395142 100644 --- a/engines/sludge/variable.h +++ b/engines/sludge/variable.h @@ -77,6 +77,10 @@ struct Variable {  	void unlinkVar();  	void setVariable(VariableType vT, int value); +	// Copy from another variable +	bool copyFrom(const Variable &from); +	bool copyMain(const Variable &from); // without variable unlink +  	// Load & save  	bool save(Common::WriteStream *stream);  	bool load(Common::SeekableReadStream *stream); @@ -88,8 +92,6 @@ struct VariableStack {  };  // Setting variables - -bool copyVariable(const Variable &from, Variable &to);  bool loadStringToVar(Variable &thisVar, int value);  void newAnimationVariable(Variable &thisVar, struct PersonaAnimation  *i);  void newCostumeVariable(Variable &thisVar, struct Persona *i);  | 
