diff options
author | Simei Yin | 2018-05-31 19:33:57 +0200 |
---|---|---|
committer | Simei Yin | 2018-05-31 23:15:09 +0200 |
commit | 56f0821876b20da1c20afde9799bb22829cc537d (patch) | |
tree | 0cf0adb042647ed22d59aa7895b182c40b284477 | |
parent | 2ab7665e56b303e7d5311b4d88945cd2007bee3e (diff) | |
download | scummvm-rg350-56f0821876b20da1c20afde9799bb22829cc537d.tar.gz scummvm-rg350-56f0821876b20da1c20afde9799bb22829cc537d.tar.bz2 scummvm-rg350-56f0821876b20da1c20afde9799bb22829cc537d.zip |
SLUDGE: Move save/loadVariable() to struct Variable
-rw-r--r-- | engines/sludge/function.cpp | 8 | ||||
-rw-r--r-- | engines/sludge/loadsave.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/variable.cpp | 46 | ||||
-rw-r--r-- | engines/sludge/variable.h | 7 |
4 files changed, 33 insertions, 32 deletions
diff --git a/engines/sludge/function.cpp b/engines/sludge/function.cpp index 7ed6207526..232a040417 100644 --- a/engines/sludge/function.cpp +++ b/engines/sludge/function.cpp @@ -749,14 +749,14 @@ void saveFunction(LoadedFunction *fun, Common::WriteStream *stream) { stream->writeByte(fun->cancelMe); stream->writeByte(fun->returnSomething); stream->writeByte(fun->isSpeech); - saveVariable(&(fun->reg), stream); + fun->reg.save(stream); if (fun->freezerLevel) { fatal(ERROR_GAME_SAVE_FROZEN); } saveStack(fun->stack, stream); for (a = 0; a < fun->numLocals; a++) { - saveVariable(&(fun->localVars[a]), stream); + fun->localVars[a].save(stream); } } @@ -785,13 +785,13 @@ LoadedFunction *loadFunction(Common::SeekableReadStream *stream) { buildFunc->cancelMe = stream->readByte(); buildFunc->returnSomething = stream->readByte(); buildFunc->isSpeech = stream->readByte(); - loadVariable(&(buildFunc->reg), stream); + buildFunc->reg.load(stream); loadFunctionCode(buildFunc); buildFunc->stack = loadStack(stream, NULL); for (a = 0; a < buildFunc->numLocals; a++) { - loadVariable(&(buildFunc->localVars[a]), stream); + buildFunc->localVars[a].load(stream); } return buildFunc; diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index bb41d0a36e..453e78f3e5 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -132,7 +132,7 @@ bool saveGame(const Common::String &fname) { } for (int a = 0; a < numGlobals; a++) { - saveVariable(&globalVars[a], fp); + globalVars[a].save(fp); } g_sludge->_peopleMan->savePeople(fp); @@ -258,7 +258,7 @@ bool loadGame(const Common::String &fname) { for (int a = 0; a < numGlobals; a++) { globalVars[a].unlinkVar(); - loadVariable(&globalVars[a], fp); + globalVars[a].load(fp); } g_sludge->_peopleMan->loadPeople(fp); diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index faaf9bd363..d52e5ef764 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -554,7 +554,7 @@ void saveStack(VariableStack *vs, Common::WriteStream *stream) { stream->writeUint16BE(elements); search = vs; for (a = 0; a < elements; a++) { - saveVariable(&search->thisVar, stream); + search->thisVar.save(stream); search = search->next; } } @@ -569,7 +569,7 @@ VariableStack *loadStack(Common::SeekableReadStream *stream, VariableStack **las VariableStack *nS = new VariableStack; if (!checkNew(nS)) return NULL; - loadVariable(&(nS->thisVar), stream); + nS->thisVar.load(stream); if (last && a == elements - 1) { *last = nS; } @@ -656,72 +656,72 @@ StackHandler *loadStackRef(Common::SeekableReadStream *stream) { //---------------------------------------------------------------------- // For saving and loading variables... //---------------------------------------------------------------------- -bool saveVariable(Variable *from, Common::WriteStream *stream) { - stream->writeByte(from->varType); - switch (from->varType) { +bool Variable::save(Common::WriteStream *stream) { + stream->writeByte(varType); + switch (varType) { case SVT_INT: case SVT_FUNC: case SVT_BUILT: case SVT_FILE: case SVT_OBJTYPE: - stream->writeUint32LE(from->varData.intValue); + stream->writeUint32LE(varData.intValue); return true; case SVT_STRING: - writeString(from->varData.theString, stream); + writeString(varData.theString, stream); return true; case SVT_STACK: - return saveStackRef(from->varData.theStack, stream); + return saveStackRef(varData.theStack, stream); case SVT_COSTUME: - from->varData.costumeHandler->save(stream); + varData.costumeHandler->save(stream); return false; case SVT_ANIM: - from->varData.animHandler->save(stream); + varData.animHandler->save(stream); return false; case SVT_NULL: return false; default: - fatal("Can't save variables of this type:", (from->varType < SVT_NUM_TYPES) ? typeName[from->varType] : "bad ID"); + fatal("Can't save variables of this type:", (varType < SVT_NUM_TYPES) ? typeName[varType] : "bad ID"); } return true; } -bool loadVariable(Variable *to, Common::SeekableReadStream *stream) { - to->varType = (VariableType)stream->readByte(); - switch (to->varType) { +bool Variable::load(Common::SeekableReadStream *stream) { + varType = (VariableType)stream->readByte(); + switch (varType) { case SVT_INT: case SVT_FUNC: case SVT_BUILT: case SVT_FILE: case SVT_OBJTYPE: - to->varData.intValue = stream->readUint32LE(); + varData.intValue = stream->readUint32LE(); return true; case SVT_STRING: - to->varData.theString = createCString(readString(stream)); + varData.theString = createCString(readString(stream)); return true; case SVT_STACK: - to->varData.theStack = loadStackRef(stream); + varData.theStack = loadStackRef(stream); return true; case SVT_COSTUME: - to->varData.costumeHandler = new Persona; - if (!checkNew(to->varData.costumeHandler)) + varData.costumeHandler = new Persona; + if (!checkNew(varData.costumeHandler)) return false; - to->varData.costumeHandler->load(stream); + varData.costumeHandler->load(stream); return true; case SVT_ANIM: - to->varData.animHandler = new PersonaAnimation; - if (!checkNew(to->varData.animHandler)) + varData.animHandler = new PersonaAnimation; + if (!checkNew(varData.animHandler)) return false; - to->varData.animHandler->load(stream); + varData.animHandler->load(stream); return true; default: diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h index 33810514d6..c78976afa6 100644 --- a/engines/sludge/variable.h +++ b/engines/sludge/variable.h @@ -76,6 +76,10 @@ struct Variable { void unlinkVar(); void setVariable(VariableType vT, int value); + + // Load & save + bool save(Common::WriteStream *stream); + bool load(Common::SeekableReadStream *stream); }; struct VariableStack { @@ -120,9 +124,6 @@ bool makeFastArraySize(Variable &to, int size); Variable *fastArrayGetByIndex(FastArrayHandler *vS, uint theIndex); // load & save -bool saveVariable(Variable *from, Common::WriteStream *stream); -bool loadVariable(Variable *to, Common::SeekableReadStream *stream); - void saveStack(VariableStack *vs, Common::WriteStream *stream); VariableStack *loadStack(Common::SeekableReadStream *stream, VariableStack **last); bool saveStackRef(StackHandler *vs, Common::WriteStream *stream); |