ScummVM API documentation
game.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_GAME_H
29 #define GOB_GAME_H
30 
31 #include "common/stack.h"
32 #include "common/str.h"
33 
34 #include "gob/util.h"
35 #include "gob/video.h"
36 #include "gob/sound/sounddesc.h"
37 
38 namespace Gob {
39 
40 class Script;
41 class Resources;
42 class Variables;
43 class Hotspots;
44 
45 enum FuncCallType {
46  kStartGame,
47  kCallSub,
48  kEvaluateHotspots,
49  kTotSub,
50  kSwitchTotSub,
51  kNamedFunctionSub,
52  kHotspotEnter,
53  kHotspotLeave
54 };
55 
56 struct FuncCall {
57  FuncCallType type = kCallSub;
58  Common::String callingTot;
59  int32 callSiteOffset = -1;
60  Common::String calledTot;
61  int32 calleeOffset = -1;
62  bool tailCall = false;
63 };
64 
65 class Environments {
66 public:
67  static const uint8 kEnvironmentCount = 20;
68 
70  ~Environments();
71 
72  void set(uint8 env);
73  void get(uint8 env) const;
74 
75  const Common::String &getTotFile(uint8 env) const;
76 
77  bool has(Variables *variables, uint8 startEnv = 0, int16 except = -1) const;
78  bool has(Script *script , uint8 startEnv = 0, int16 except = -1) const;
79  bool has(Resources *resources, uint8 startEnv = 0, int16 except = -1) const;
80 
81  void deleted(Variables *variables);
82 
83  void clear();
84 
85  bool setMedia(uint8 env);
86  bool getMedia(uint8 env);
87  bool clearMedia(uint8 env);
88 
89 private:
90  struct Environment {
91  int32 cursorHotspotX;
92  int32 cursorHotspotY;
93  Common::String totFile;
94  Variables *variables;
95  Script *script;
96  Resources *resources;
97  };
98 
99  struct Media {
100  SurfacePtr sprites[10];
101  SoundDesc sounds[10];
102  Font *fonts[17];
103  };
104 
105  GobEngine *_vm;
106 
107  Environment _environments[kEnvironmentCount];
108  Media _media[kEnvironmentCount];
109 };
110 
112 public:
113  TotFunctions(GobEngine *vm);
114  ~TotFunctions();
115 
116  int find(const Common::String &totFile) const;
117 
118  bool load(const Common::String &totFile);
119  bool unload(const Common::String &totFile);
120 
121  bool call(const Common::String &totFile, const Common::String &function) const;
122  bool call(const Common::String &totFile, uint16 offset) const;
123  Common::String getFunctionName(const Common::String &totFile, uint16 offset) const;
124 
125 private:
126  static const uint8 kTotCount = 100;
127 
128  struct Function {
129  Common::String name;
130  byte type;
131  uint16 offset;
132  };
133 
134  struct Tot {
135  Common::String file;
136 
137  Common::List<Function> functions;
138 
139  Script *script;
140  Resources *resources;
141  };
142 
143  GobEngine *_vm;
144 
145  Tot _tots[kTotCount];
146 
147  bool loadTot(Tot &tot, const Common::String &file);
148  void freeTot(Tot &tot);
149 
150  bool loadIDE(Tot &tot);
151 
152  int findFree() const;
153 
154  bool call(const Tot &tot, uint16 offset) const;
155 };
156 
157 class Game {
158 public:
159  Script *_script;
160  Resources *_resources;
161  Hotspots *_hotspots;
162 
163  Common::String _curTotFile;
164  Common::String _totToLoad;
165 
166  int32 _startTimeKey;
167  MouseButtons _mouseButtons;
168 
169  bool _hasForwardedEventsFromVideo;
170  MouseButtons _forwardedMouseButtonsFromVideo;
171  int16 _forwardedKeyFromVideo;
172 
173  bool _noScroll;
174  bool _preventScroll;
175 
176  bool _wantScroll;
177  int16 _wantScrollX;
178  int16 _wantScrollY;
179 
180  byte _handleMouse;
181  char _forceHandleMouse;
182 
183  Game(GobEngine *vm);
184  virtual ~Game();
185 
186  void prepareStart();
187 
188  void playTot(int32 function);
189 
190  void capturePush(int16 left, int16 top, int16 width, int16 height);
191  void capturePop(char doDraw);
192 
193  void freeSoundSlot(int16 slot);
194 
195  void wantScroll(int16 x, int16 y);
196  void evaluateScroll();
197 
198  int16 checkKeys(int16 *pMousex = 0, int16 *pMouseY = 0,
199  MouseButtons *pButtons = 0, char handleMouse = 0);
200  void start();
201 
202  void totSub(int8 flags, const Common::String &totFile);
203  void switchTotSub(int16 index, int16 function);
204 
205  void deletedVars(Variables *variables);
206 
207  bool loadFunctions(const Common::String &tot, uint16 flags);
208  bool callFunction(const Common::String &tot, const Common::String &function, int16 param);
209  Common::String getFunctionName(const Common::String &tot, uint16 offset);
210 
211  Common::String getGobStack();
212  void printGobStack();
213 
214  void pushOnGlobalCallStack(FuncCallType type,
215  const Common::String &callingTot, int32 callSiteOffset,
216  const Common::String &calledTot, int32 calleeOffset);
217  void popGlobalCallStack();
218 
219  Common::Stack<FuncCall> _globalFuncCallStack; // for debugging only
220 
221 protected:
222  GobEngine *_vm;
223 
224  char _tempStr[256];
225 
226  // Capture
227  Common::Rect _captureStack[20];
228  int16 _captureCount;
229 
230  // For totSub()
231  int8 _curEnvironment;
232  int8 _numEnvironments;
233  Environments _environments;
234 
235  TotFunctions _totFunctions;
236 
237  void clearUnusedEnvironment();
238 
239  Common::String formatSubNameInCallStack(const Common::String &totFile, int32 offset);
240 };
241 
242 } // End of namespace Gob
243 
244 #endif // GOB_GAME_H
Definition: gob.h:166
Definition: str.h:59
Definition: game.h:65
Definition: variables.h:33
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: game.h:111
Definition: script.h:41
Definition: rect.h:524
Definition: video.h:40
Definition: anifile.h:40
Definition: game.h:157
Definition: game.h:56
Definition: resources.h:82
Definition: anims.h:26
Definition: sounddesc.h:43
Definition: hotspots.h:40
Definition: stack.h:102