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/str.h"
32 
33 #include "gob/util.h"
34 #include "gob/video.h"
35 #include "gob/sound/sounddesc.h"
36 
37 namespace Gob {
38 
39 class Script;
40 class Resources;
41 class Variables;
42 class Hotspots;
43 
44 class Environments {
45 public:
46  static const uint8 kEnvironmentCount = 20;
47 
49  ~Environments();
50 
51  void set(uint8 env);
52  void get(uint8 env) const;
53 
54  const Common::String &getTotFile(uint8 env) const;
55 
56  bool has(Variables *variables, uint8 startEnv = 0, int16 except = -1) const;
57  bool has(Script *script , uint8 startEnv = 0, int16 except = -1) const;
58  bool has(Resources *resources, uint8 startEnv = 0, int16 except = -1) const;
59 
60  void deleted(Variables *variables);
61 
62  void clear();
63 
64  bool setMedia(uint8 env);
65  bool getMedia(uint8 env);
66  bool clearMedia(uint8 env);
67 
68 private:
69  struct Environment {
70  int32 cursorHotspotX;
71  int32 cursorHotspotY;
72  Common::String totFile;
73  Variables *variables;
74  Script *script;
75  Resources *resources;
76  };
77 
78  struct Media {
79  SurfacePtr sprites[10];
80  SoundDesc sounds[10];
81  Font *fonts[17];
82  };
83 
84  GobEngine *_vm;
85 
86  Environment _environments[kEnvironmentCount];
87  Media _media[kEnvironmentCount];
88 };
89 
90 class TotFunctions {
91 public:
93  ~TotFunctions();
94 
95  int find(const Common::String &totFile) const;
96 
97  bool load(const Common::String &totFile);
98  bool unload(const Common::String &totFile);
99 
100  bool call(const Common::String &totFile, const Common::String &function) const;
101  bool call(const Common::String &totFile, uint16 offset) const;
102 
103 private:
104  static const uint8 kTotCount = 100;
105 
106  struct Function {
107  Common::String name;
108  byte type;
109  uint16 offset;
110  };
111 
112  struct Tot {
113  Common::String file;
114 
115  Common::List<Function> functions;
116 
117  Script *script;
118  Resources *resources;
119  };
120 
121  GobEngine *_vm;
122 
123  Tot _tots[kTotCount];
124 
125  bool loadTot(Tot &tot, const Common::String &file);
126  void freeTot(Tot &tot);
127 
128  bool loadIDE(Tot &tot);
129 
130  int findFree() const;
131 
132  bool call(const Tot &tot, uint16 offset) const;
133 };
134 
135 class Game {
136 public:
137  Script *_script;
138  Resources *_resources;
139  Hotspots *_hotspots;
140 
141  Common::String _curTotFile;
142  Common::String _totToLoad;
143 
144  int32 _startTimeKey;
145  MouseButtons _mouseButtons;
146 
147  bool _noScroll;
148  bool _preventScroll;
149 
150  bool _wantScroll;
151  int16 _wantScrollX;
152  int16 _wantScrollY;
153 
154  byte _handleMouse;
155  char _forceHandleMouse;
156 
157  Game(GobEngine *vm);
158  virtual ~Game();
159 
160  void prepareStart();
161 
162  void playTot(int16 function);
163 
164  void capturePush(int16 left, int16 top, int16 width, int16 height);
165  void capturePop(char doDraw);
166 
167  void freeSoundSlot(int16 slot);
168 
169  void wantScroll(int16 x, int16 y);
170  void evaluateScroll();
171 
172  int16 checkKeys(int16 *pMousex = 0, int16 *pMouseY = 0,
173  MouseButtons *pButtons = 0, char handleMouse = 0);
174  void start();
175 
176  void totSub(int8 flags, const Common::String &totFile);
177  void switchTotSub(int16 index, int16 function);
178 
179  void deletedVars(Variables *variables);
180 
181  bool loadFunctions(const Common::String &tot, uint16 flags);
182  bool callFunction(const Common::String &tot, const Common::String &function, int16 param);
183 
184 protected:
185  GobEngine *_vm;
186 
187  char _tempStr[256];
188 
189  // Capture
190  Common::Rect _captureStack[20];
191  int16 _captureCount;
192 
193  // For totSub()
194  int8 _curEnvironment;
195  int8 _numEnvironments;
196  Environments _environments;
197 
198  TotFunctions _totFunctions;
199 
200  void clearUnusedEnvironment();
201 };
202 
203 } // End of namespace Gob
204 
205 #endif // GOB_GAME_H
Definition: gob.h:156
Definition: str.h:59
Definition: game.h:44
Definition: variables.h:33
In find(In first, In last, const T &v)
Definition: algorithm.h:168
Definition: game.h:90
Definition: script.h:41
Definition: rect.h:144
Definition: video.h:40
Definition: anifile.h:40
Definition: game.h:135
Definition: resources.h:82
Definition: sounddesc.h:43
Definition: hotspots.h:40