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  Common::String getFunctionName(const Common::String &totFile, uint16 offset) const;
103 
104 private:
105  static const uint8 kTotCount = 100;
106 
107  struct Function {
108  Common::String name;
109  byte type;
110  uint16 offset;
111  };
112 
113  struct Tot {
114  Common::String file;
115 
116  Common::List<Function> functions;
117 
118  Script *script;
119  Resources *resources;
120  };
121 
122  GobEngine *_vm;
123 
124  Tot _tots[kTotCount];
125 
126  bool loadTot(Tot &tot, const Common::String &file);
127  void freeTot(Tot &tot);
128 
129  bool loadIDE(Tot &tot);
130 
131  int findFree() const;
132 
133  bool call(const Tot &tot, uint16 offset) const;
134 };
135 
136 class Game {
137 public:
138  Script *_script;
139  Resources *_resources;
140  Hotspots *_hotspots;
141 
142  Common::String _curTotFile;
143  Common::String _totToLoad;
144 
145  int32 _startTimeKey;
146  MouseButtons _mouseButtons;
147 
148  bool _hasForwardedEventsFromVideo;
149  MouseButtons _forwardedMouseButtonsFromVideo;
150  int16 _forwardedKeyFromVideo;
151 
152  bool _noScroll;
153  bool _preventScroll;
154 
155  bool _wantScroll;
156  int16 _wantScrollX;
157  int16 _wantScrollY;
158 
159  byte _handleMouse;
160  char _forceHandleMouse;
161 
162  Game(GobEngine *vm);
163  virtual ~Game();
164 
165  void prepareStart();
166 
167  void playTot(int32 function);
168 
169  void capturePush(int16 left, int16 top, int16 width, int16 height);
170  void capturePop(char doDraw);
171 
172  void freeSoundSlot(int16 slot);
173 
174  void wantScroll(int16 x, int16 y);
175  void evaluateScroll();
176 
177  int16 checkKeys(int16 *pMousex = 0, int16 *pMouseY = 0,
178  MouseButtons *pButtons = 0, char handleMouse = 0);
179  void start();
180 
181  void totSub(int8 flags, const Common::String &totFile);
182  void switchTotSub(int16 index, int16 function);
183 
184  void deletedVars(Variables *variables);
185 
186  bool loadFunctions(const Common::String &tot, uint16 flags);
187  bool callFunction(const Common::String &tot, const Common::String &function, int16 param);
188  Common::String getFunctionName(const Common::String &tot, uint16 offset);
189 
190 protected:
191  GobEngine *_vm;
192 
193  char _tempStr[256];
194 
195  // Capture
196  Common::Rect _captureStack[20];
197  int16 _captureCount;
198 
199  // For totSub()
200  int8 _curEnvironment;
201  int8 _numEnvironments;
202  Environments _environments;
203 
204  TotFunctions _totFunctions;
205 
206  void clearUnusedEnvironment();
207 };
208 
209 } // End of namespace Gob
210 
211 #endif // GOB_GAME_H
Definition: gob.h:166
Definition: str.h:59
Definition: game.h:44
Definition: variables.h:33
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: game.h:90
Definition: script.h:41
Definition: rect.h:524
Definition: video.h:40
Definition: anifile.h:40
Definition: game.h:136
Definition: resources.h:82
Definition: sounddesc.h:43
Definition: hotspots.h:40