aboutsummaryrefslogtreecommitdiff
path: root/engines/sludge
diff options
context:
space:
mode:
authorSimei Yin2018-05-31 20:09:36 +0200
committerSimei Yin2018-05-31 23:15:09 +0200
commit805a47b74ab9b2ffa299d5c8401f178db022d4d8 (patch)
tree80769765d7f111c7638710a64bc314c595f5566f /engines/sludge
parent98f764050a67f67c6bfaa4fb4ba685dd6ee6a0fb (diff)
downloadscummvm-rg350-805a47b74ab9b2ffa299d5c8401f178db022d4d8.tar.gz
scummvm-rg350-805a47b74ab9b2ffa299d5c8401f178db022d4d8.tar.bz2
scummvm-rg350-805a47b74ab9b2ffa299d5c8401f178db022d4d8.zip
SLUDGE: Move text related functions to struct Variable
Diffstat (limited to 'engines/sludge')
-rw-r--r--engines/sludge/builtin.cpp50
-rw-r--r--engines/sludge/event.cpp2
-rw-r--r--engines/sludge/function.cpp2
-rw-r--r--engines/sludge/savedata.cpp6
-rw-r--r--engines/sludge/variable.cpp42
-rw-r--r--engines/sludge/variable.h11
6 files changed, 59 insertions, 54 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 2ee7de3d07..20b4ba8328 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -113,7 +113,7 @@ static BuiltReturn sayCore(int numParams, LoadedFunction *fun, bool sayIt) {
// fall through
case 2:
- newText = getTextFromAnyVar(fun->stack->thisVar);
+ newText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar))
return BR_ERROR;
@@ -197,13 +197,13 @@ builtIn(getMouseScreenY) {
builtIn(getStatusText) {
UNUSEDALL
- makeTextVar(fun->reg, statusBarText());
+ fun->reg.makeTextVar(statusBarText());
return BR_CONTINUE;
}
builtIn(getMatchingFiles) {
UNUSEDALL
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
fun->reg.unlinkVar();
@@ -227,7 +227,7 @@ builtIn(saveGame) {
fatal("Can't save game state while the engine is frozen");
}
- g_sludge->loadNow = getTextFromAnyVar(fun->stack->thisVar);
+ g_sludge->loadNow = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
Common::String aaaaa = encodeFilename(g_sludge->loadNow);
@@ -244,7 +244,7 @@ builtIn(saveGame) {
builtIn(fileExists) {
UNUSEDALL
- g_sludge->loadNow = getTextFromAnyVar(fun->stack->thisVar);
+ g_sludge->loadNow = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
Common::String aaaaa = encodeFilename(g_sludge->loadNow);
g_sludge->loadNow.clear();
@@ -273,7 +273,7 @@ builtIn(fileExists) {
builtIn(loadGame) {
UNUSEDALL
- Common::String aaaaa = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String aaaaa = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
g_sludge->loadNow.clear();
g_sludge->loadNow = encodeFilename(aaaaa);
@@ -462,7 +462,7 @@ builtIn(substring) {
if (!getValueType(start, SVT_INT, fun->stack->thisVar))
return BR_ERROR;
trimStack(fun->stack);
- wholeString = getTextFromAnyVar(fun->stack->thisVar);
+ wholeString = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
UTF8Converter convert;
@@ -484,13 +484,13 @@ builtIn(substring) {
Common::String newString(wholeString.begin() + startoffset, wholeString.begin() + endoffset);
- makeTextVar(fun->reg, newString);
+ fun->reg.makeTextVar(newString);
return BR_CONTINUE;
}
builtIn(stringLength) {
UNUSEDALL
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
fun->reg.setVariable(SVT_INT, g_sludge->_txtMan->stringLength(newText));
return BR_CONTINUE;
@@ -777,7 +777,7 @@ builtIn(setFont) {
return BR_ERROR;
// newDebug (" Height:", newHeight);
trimStack(fun->stack);
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
// newDebug (" Character supported:", newText);
trimStack(fun->stack);
if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar))
@@ -792,7 +792,7 @@ builtIn(setFont) {
builtIn(inFont) {
UNUSEDALL
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
// Return value
@@ -802,7 +802,7 @@ builtIn(inFont) {
builtIn(pasteString) {
UNUSEDALL
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
int y, x;
if (!getValueType(y, SVT_INT, fun->stack->thisVar))
@@ -871,7 +871,7 @@ builtIn(costume) {
builtIn(launch) {
UNUSEDALL
- Common::String newTextA = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newTextA = fun->stack->thisVar.getTextFromAnyVar();
Common::String newText = encodeFilename(newTextA);
@@ -1293,7 +1293,7 @@ builtIn(getOverObject) {
builtIn(rename) {
UNUSEDALL
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
int objT;
trimStack(fun->stack);
if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar))
@@ -1735,7 +1735,7 @@ builtIn(addStatus) {
builtIn(statusText) {
UNUSEDALL
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
setStatusBar(newText);
return BR_CONTINUE;
@@ -1891,7 +1891,7 @@ builtIn(cancelSub) {
builtIn(stringWidth) {
UNUSEDALL
- Common::String theText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String theText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
// Return value
@@ -2067,7 +2067,7 @@ builtIn(fetchEvent) {
builtIn(deleteFile) {
UNUSEDALL
- Common::String namNormal = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String namNormal = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
Common::String nam = encodeFilename(namNormal);
namNormal.clear();
@@ -2083,14 +2083,14 @@ builtIn(renameFile) {
Common::String temp;
temp.clear();
- temp = getTextFromAnyVar(fun->stack->thisVar);
+ temp = fun->stack->thisVar.getTextFromAnyVar();
Common::String newnam = encodeFilename(temp);
trimStack(fun->stack);
if (failSecurityCheck(newnam))
return BR_ERROR;
temp.clear();
- temp = getTextFromAnyVar(fun->stack->thisVar);
+ temp = fun->stack->thisVar.getTextFromAnyVar();
Common::String nam = encodeFilename(temp);
trimStack(fun->stack);
if (failSecurityCheck(nam))
@@ -2114,7 +2114,7 @@ builtIn(cacheSound) {
builtIn(burnString) {
UNUSEDALL
- Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newText = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
int y, x;
if (!getValueType(y, SVT_INT, fun->stack->thisVar))
@@ -2207,7 +2207,7 @@ builtIn(getSoundCache) {
builtIn(saveCustomData) {
UNUSEDALL
// saveCustomData (thisStack, fileName);
- Common::String fileNameB = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String fileNameB = fun->stack->thisVar.getTextFromAnyVar();
Common::String fileName = encodeFilename(fileNameB);
@@ -2228,7 +2228,7 @@ builtIn(saveCustomData) {
builtIn(loadCustomData) {
UNUSEDALL
- Common::String newTextA = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String newTextA = fun->stack->thisVar.getTextFromAnyVar();
Common::String newText = encodeFilename(newTextA);
@@ -2378,7 +2378,7 @@ builtIn(_rem_launchWith) {
trimStack(fun->stack);
// To support some windows only games
- Common::String filename = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String filename = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
if (filename.hasSuffix(".exe")) {
@@ -2418,7 +2418,7 @@ builtIn(showThumbnail) {
trimStack(fun->stack);
// Encode the name!Encode the name!
- Common::String aaaaa = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String aaaaa = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
Common::String file = encodeFilename(aaaaa);
g_sludge->_gfxMan->showThumbnail(file, x, y);
@@ -2490,7 +2490,7 @@ builtIn(_rem_registryGetString) {
builtIn(quitWithFatalError) {
UNUSEDALL
- Common::String mess = getTextFromAnyVar(fun->stack->thisVar);
+ Common::String mess = fun->stack->thisVar.getTextFromAnyVar();
trimStack(fun->stack);
fatal(mess);
return BR_ERROR;
diff --git a/engines/sludge/event.cpp b/engines/sludge/event.cpp
index 16e02e54b7..098720b4c6 100644
--- a/engines/sludge/event.cpp
+++ b/engines/sludge/event.cpp
@@ -320,7 +320,7 @@ bool EventManager::handleInput() {
VariableStack *tempStack = new VariableStack;
if (!checkNew(tempStack))
return false;
- makeTextVar(tempStack->thisVar, tempString);
+ tempStack->thisVar.makeTextVar(tempString);
tempStack->next = nullptr;
if (!startNewFunctionNum(_currentEvents->func[kSpace], 1, nullptr, tempStack))
return false;
diff --git a/engines/sludge/function.cpp b/engines/sludge/function.cpp
index f876746700..ed7280fa2c 100644
--- a/engines/sludge/function.cpp
+++ b/engines/sludge/function.cpp
@@ -322,7 +322,7 @@ bool continueFunction(LoadedFunction *fun) {
break;
case SLU_LOAD_STRING:
- if (!loadStringToVar(fun->reg, param)) {
+ if (!fun->reg.loadStringToVar(param)) {
return false;
}
break;
diff --git a/engines/sludge/savedata.cpp b/engines/sludge/savedata.cpp
index f8b07a5362..b103523f8c 100644
--- a/engines/sludge/savedata.cpp
+++ b/engines/sludge/savedata.cpp
@@ -133,7 +133,7 @@ bool CustomSaveHelper::fileToStack(const Common::String &filename, StackHandler
switch (i) {
case 0: {
Common::String g = readStringEncoded(fp);
- makeTextVar(stringVar, g);
+ stringVar.makeTextVar(g);
}
break;
@@ -154,7 +154,7 @@ bool CustomSaveHelper::fileToStack(const Common::String &filename, StackHandler
char *line = readTextPlain(fp);
if (!line)
break;
- makeTextVar(stringVar, line);
+ stringVar.makeTextVar(line);
}
if (sH->first == NULL) {
@@ -218,7 +218,7 @@ bool CustomSaveHelper::stackToFile(const Common::String &filename, const Variabl
return false;
}
} else {
- Common::String makeSureItsText = getTextFromAnyVar(hereWeAre -> thisVar);
+ Common::String makeSureItsText = hereWeAre->thisVar.getTextFromAnyVar();
if (makeSureItsText.empty())
break;
fp->writeString((makeSureItsText + "\n").c_str());
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index 90a2f14e72..8385476c0a 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -160,7 +160,7 @@ bool getSavedGamesStack(StackHandler *sH, const Common::String &ext) {
Common::StringArray::iterator it;
for (it = sa.begin(); it != sa.end(); ++it) {
(*it).erase((*it).size() - len, len);
- makeTextVar(newName, (*it));
+ newName.makeTextVar((*it));
if (!addVarToStack(newName, sH->first))
return false;
if (sH->last == NULL)
@@ -195,8 +195,8 @@ void addVariablesInSecond(Variable &var1, Variable &var2) {
if (var1.varType == SVT_INT && var2.varType == SVT_INT) {
var2.varData.intValue += var1.varData.intValue;
} else {
- Common::String string1 = getTextFromAnyVar(var1);
- Common::String string2 = getTextFromAnyVar(var2);
+ Common::String string1 = var1.getTextFromAnyVar();
+ Common::String string2 = var2.getTextFromAnyVar();
var2.unlinkVar();
var2.varData.theString = createCString(string1 + string2);
@@ -239,30 +239,30 @@ void compareVariablesInSecond(const Variable &var1, Variable &var2) {
var2.setVariable(SVT_INT, compareVars(var1, var2));
}
-void makeTextVar(Variable &thisVar, const Common::String &txt) {
- thisVar.unlinkVar();
- thisVar.varType = SVT_STRING;
- thisVar.varData.theString = createCString(txt);
+void Variable::makeTextVar(const Common::String &txt) {
+ unlinkVar();
+ varType = SVT_STRING;
+ varData.theString = createCString(txt);
}
-bool loadStringToVar(Variable &thisVar, int value) {
- makeTextVar(thisVar, g_sludge->_resMan->getNumberedString(value));
- return (bool)(thisVar.varData.theString != NULL);
+bool Variable::loadStringToVar(int value) {
+ makeTextVar(g_sludge->_resMan->getNumberedString(value));
+ return (bool)(varData.theString != NULL);
}
-Common::String getTextFromAnyVar(const Variable &from) {
- switch (from.varType) {
+Common::String Variable::getTextFromAnyVar() {
+ switch (varType) {
case SVT_STRING:
- return from.varData.theString;
+ return varData.theString;
case SVT_FASTARRAY: {
Common::String builder = "FAST:";
Common::String builder2 = "";
Common::String grabText = "";
- for (int i = 0; i < from.varData.fastArray->size; i++) {
+ for (int i = 0; i < varData.fastArray->size; i++) {
builder2 = builder + " ";
- grabText = getTextFromAnyVar(from.varData.fastArray->fastVariables[i]);
+ grabText = varData.fastArray->fastVariables[i].getTextFromAnyVar();
builder.clear();
builder = builder2 + grabText;
}
@@ -274,11 +274,11 @@ Common::String getTextFromAnyVar(const Variable &from) {
Common::String builder2 = "";
Common::String grabText = "";
- VariableStack *stacky = from.varData.theStack->first;
+ VariableStack *stacky = varData.theStack->first;
while (stacky) {
builder2 = builder + " ";
- grabText = getTextFromAnyVar(stacky->thisVar);
+ grabText = stacky->thisVar.getTextFromAnyVar();
builder.clear();
builder = builder2 + grabText;
stacky = stacky->next;
@@ -287,16 +287,16 @@ Common::String getTextFromAnyVar(const Variable &from) {
}
case SVT_INT: {
- Common::String buff = Common::String::format("%i", from.varData.intValue);
+ Common::String buff = Common::String::format("%i", varData.intValue);
return buff;
}
case SVT_FILE: {
- return g_sludge->_resMan->resourceNameFromNum(from.varData.intValue);
+ return g_sludge->_resMan->resourceNameFromNum(varData.intValue);
}
case SVT_OBJTYPE: {
- ObjectType *thisType = g_sludge->_objMan->findObjectType(from.varData.intValue);
+ ObjectType *thisType = g_sludge->_objMan->findObjectType(varData.intValue);
if (thisType)
return thisType->screenName;
break;
@@ -306,7 +306,7 @@ Common::String getTextFromAnyVar(const Variable &from) {
break;
}
- return typeName[from.varType];
+ return typeName[varType];
}
bool getBoolean(const Variable &from) {
diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h
index 22ed395142..aa1e2aa802 100644
--- a/engines/sludge/variable.h
+++ b/engines/sludge/variable.h
@@ -84,6 +84,14 @@ struct Variable {
// Load & save
bool save(Common::WriteStream *stream);
bool load(Common::SeekableReadStream *stream);
+
+ // Text variable
+ void makeTextVar(const Common::String &txt);
+ bool loadStringToVar(int value);
+ Common::String getTextFromAnyVar();
+
+ // Get Text
+
};
struct VariableStack {
@@ -92,16 +100,13 @@ struct VariableStack {
};
// Setting variables
-bool loadStringToVar(Variable &thisVar, int value);
void newAnimationVariable(Variable &thisVar, struct PersonaAnimation *i);
void newCostumeVariable(Variable &thisVar, struct Persona *i);
-void makeTextVar(Variable &thisVar, const Common::String &txt);
void addVariablesInSecond(Variable &var1, Variable &var2);
void compareVariablesInSecond(const Variable &var1, Variable &var2);
// Misc.
-Common::String getTextFromAnyVar(const Variable &from);
struct Persona *getCostumeFromVar(Variable &thisVar);
struct PersonaAnimation *getAnimationFromVar(Variable &thisVar);
bool getBoolean(const Variable &from);