ScummVM API documentation
variable.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 #ifndef SLUDGE_VARIABLE_H
22 #define SLUDGE_VARIABLE_H
23 
24 namespace Common {
25 class SeekableReadStream;
26 class WriteStream;
27 }
28 
29 namespace Sludge {
30 
31 struct Persona;
32 struct PersonaAnimation;
33 struct Variable;
34 struct VariableStack;
35 
36 enum VariableType {
37  SVT_NULL,
38  SVT_INT,
39  SVT_FUNC,
40  SVT_STRING,
41  SVT_BUILT,
42  SVT_FILE,
43  SVT_STACK,
44  SVT_OBJTYPE,
45  SVT_ANIM,
46  SVT_COSTUME,
47  SVT_FASTARRAY,
48  SVT_NUM_TYPES
49 };
50 
52  struct Variable *fastVariables;
53  int size;
54  int timesUsed;
55 
56  Variable *fastArrayGetByIndex(uint theIndex);
57  void debugPrint();
58 };
59 
60 struct StackHandler {
61  struct VariableStack *first;
62  struct VariableStack *last;
63  int timesUsed;
64 
65  int getStackSize() const;
66  bool getSavedGamesStack(const Common::String &ext);
67 
68  void debugPrint();
69 };
70 
71 union VariableData {
72  signed int intValue;
73  const char *theString;
74  StackHandler *theStack;
75  PersonaAnimation *animHandler;
76  Persona *costumeHandler;
77  FastArrayHandler *fastArray;
78 };
79 
80 struct Variable {
81  VariableType varType;
82  VariableData varData;
83 
84  Variable() {
85  varType = SVT_NULL;
86  varData.intValue = 0;
87  }
88 
89  void unlinkVar();
90  void setVariable(VariableType vT, int value);
91 
92  // Copy from another variable
93  bool copyFrom(const Variable &from);
94  bool copyMain(const Variable &from); // without variable unlink
95 
96  // Load & save
97  bool save(Common::WriteStream *stream);
98  bool load(Common::SeekableReadStream *stream);
99 
100  // Text variable
101  void makeTextVar(const Common::String &txt);
102  bool loadStringToVar(int value);
103 
104  // Animation variable
105  void makeAnimationVariable(PersonaAnimation *i);
106  struct PersonaAnimation *getAnimationFromVar();
107 
108  // Custome variable
109  void makeCostumeVariable(Persona *i);
110  struct Persona *getCostumeFromVar();
111 
112  // Fast array variable
113  bool makeFastArrayFromStack(const StackHandler *stacky);
114  bool makeFastArraySize(int size);
115 
116  // Stack variable
117  bool copyStack(const Variable &from);
118 
119  // Add variables
120  void addVariablesInSecond(const Variable &other);
121  void compareVariablesInSecond(const Variable &other);
122  int compareVars(const Variable &other) const;
123 
124  // General getters
125  Common::String getTextFromAnyVar(bool skipLoad = false) const;
126  bool getBoolean() const;
127  bool getValueType(int &toHere, VariableType vT) const;
128 
129  void debugPrint();
130 };
131 
133  Variable thisVar;
134  VariableStack *next;
135 
136  // Variable getter & setter
137  bool stackSetByIndex(uint, const Variable &);
138  Variable *stackGetByIndex(uint);
139 
140  // Find last
141  VariableStack *stackFindLast();
142 };
143 
144 // Stacky stuff
145 
146 bool addVarToStack(const Variable &va, VariableStack *&thisStack);
147 bool addVarToStackQuick(Variable &va, VariableStack *&thisStack);
148 void trimStack(VariableStack *&stack);
149 int deleteVarFromStack(const Variable &va, VariableStack *&thisStack, bool allOfEm = false);
150 
151 // load & save
152 void saveStack(VariableStack *vs, Common::WriteStream *stream);
153 VariableStack *loadStack(Common::SeekableReadStream *stream, VariableStack **last);
154 bool saveStackRef(StackHandler *vs, Common::WriteStream *stream);
155 StackHandler *loadStackRef(Common::SeekableReadStream *stream);
156 void clearStackLib();
157 
158 } // End of namespace Sludge
159 
160 #endif
Definition: str.h:59
Definition: variable.h:132
Definition: people.h:49
Definition: stream.h:77
Definition: variable.h:80
Definition: variable.h:60
Definition: stream.h:745
Definition: people.h:67
Definition: variable.h:71
Definition: builtin.h:27
Definition: algorithm.h:29
Definition: variable.h:51