ScummVM API documentation
grim.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 
22 #ifndef GRIM_ENGINE_H
23 #define GRIM_ENGINE_H
24 
25 #include "engines/engine.h"
26 #include "engines/advancedDetector.h"
27 
28 #include "common/str-array.h"
29 #include "common/hashmap.h"
30 #include "common/events.h"
31 
32 #include "graphics/renderer.h"
33 
34 #include "engines/grim/textobject.h"
35 #include "engines/grim/iris.h"
36 #include "engines/grim/detection.h"
37 
38 namespace Grim {
39 
40 class Actor;
41 class SaveGame;
42 class Bitmap;
43 class Font;
44 class Color;
45 class ObjectState;
46 class Set;
47 class TextObject;
48 class PrimitiveObject;
49 class LuaBase;
50 class Commentary;
51 class GfxBase;
52 
54  const char *name;
55  int key;
56 };
57 
58 class GrimEngine : public Engine {
59 
60 protected:
61  // Engine APIs
62  Common::Error run() override;
63 
64 public:
65  enum EngineMode {
66  PauseMode = 1,
67  NormalMode = 2,
68  SmushMode = 3,
69  DrawMode = 4,
70  OverworldMode = 5
71  };
72  enum SpeechMode {
73  TextOnly = 1,
74  VoiceOnly = 2,
75  TextAndVoice = 3
76  };
77 
78  GrimEngine(OSystem *syst, uint32 gameFlags, GrimGameType gameType, Common::Platform platform, Common::Language language);
79  virtual ~GrimEngine();
80 
81  void clearPools();
82 
83  uint32 getGameFlags() { return _gameFlags; }
84  GrimGameType getGameType() { return _gameType; }
85  Common::Language getGameLanguage() { return _gameLanguage; }
86  Common::Platform getGamePlatform() { return _gamePlatform; }
87  virtual const char *getUpdateFilename();
88  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
89  Common::Error loadGameState(int slot) override;
90  bool isRemastered() const { return !!(_gameFlags & ADGF_REMASTERED); }
91 
92  void setMode(EngineMode mode);
93  EngineMode getMode() { return _mode; }
94  void setPreviousMode(EngineMode mode) { _previousMode = mode; }
95  EngineMode getPreviousMode() { return _previousMode; }
96  void setSpeechMode(SpeechMode mode) { _speechMode = mode; }
97  SpeechMode getSpeechMode() { return _speechMode; }
98  SaveGame *savedState() { return _savedState; }
99  bool getJustSaveLoaded() { return _justSaveLoaded; }
100  void setJustSaveLoaded(bool state) { _justSaveLoaded = state; }
101 
102  void handleDebugLoadResource();
103  void luaUpdate();
104  void updateDisplayScene();
105  void doFlip();
106  void setFlipEnable(bool state) { _flipEnable = state; }
107  bool getFlipEnable() { return _flipEnable; }
108  virtual void drawTextObjects();
109  void playIrisAnimation(Iris::Direction dir, int x, int y, int time);
110 
111  void mainLoop();
112  unsigned getFrameStart() const { return _frameStart; }
113  unsigned getFrameTime() const { return _frameTime; }
114 
115  // perSecond should allow rates of zero, some actors will accelerate
116  // up to their normal speed (such as the bone wagon) so handling
117  // a walking rate of zero should happen in the default actor creation
118  float getPerSecond(float rate) const;
119 
120  int getTextSpeed() { return _textSpeed; }
121  void setTextSpeed(int speed);
122 
123  void enableControl(int num) { _controlsEnabled[num] = true; }
124  void disableControl(int num) { _controlsEnabled[num] = false; }
125  float getControlAxis(int num);
126  bool getControlState(int num);
127  void clearEventQueue();
128 
129  Set *findSet(const Common::String &name);
130  void setSetLock(const char *name, bool lockStatus);
131  Set *loadSet(const Common::String &name);
132  void setSet(const char *name);
133  void setSet(Set *scene);
134  Set *getCurrSet() { return _currSet; }
135  void makeCurrentSetup(int num);
136 
137  void flagRefreshShadowMask(bool flag) { _refreshShadowMask = flag; }
138  bool getFlagRefreshShadowMask() { return _refreshShadowMask; }
139 
140  void setSelectedActor(Actor *a) { _selectedActor = a; }
141  Actor *getSelectedActor() { return _selectedActor; }
142 
147  virtual void invalidateActiveActorsList();
148  virtual void invalidateTextObjectsSortOrder() {};
152  const Common::List<Actor *> &getActiveActors() const { return _activeActors; }
153 
157  void addTalkingActor(Actor *actor);
158  inline const Common::List<Actor *> &getTalkingActors() const { return _talkingActors; }
159  bool areActorsTalking() const;
160  void immediatelyRemoveActor(Actor *actor);
161 
162  void drawMovieSubtitle();
163  void setMovieSubtitle(TextObject *to);
164  void setMovieSetup();
165 
166  int getLanguage() const { return _language; }
167  void setLanguage(int langId) { _language = langId; }
168  Common::String getLanguagePrefix() const;
169 
170  bool isConceptEnabled(uint32 number) const;
171  void enableConcept(uint32 number);
172 
173  bool isCutsceneEnabled(uint32 number) const;
174  void enableCutscene(uint32 number);
175 
176  Commentary *getCommentary() { return _commentary; }
177 
178  Graphics::RendererType getRendererType();
179 
180  // TODO: Refactor.
181  void setSaveMetaData(const char*, int, const char*);
182 
183  void saveGame(const Common::String &file);
184  void loadGame(const Common::String &file);
185 
186  void changeHardwareState();
187 
188  // Engine APIs
189  bool hasFeature(EngineFeature f) const override;
190 
191  static Common::Array<Common::Keymap *> initKeymapsGrim(const char *target);
192  static Common::Array<Common::Keymap *> initKeymapsEMI(const char *target);
193 
194  Common::StringArray _listFiles;
196 
197  TextObjectDefaults _sayLineDefaults, _printLineDefaults, _blastTextDefaults;
198 
199  void debugLua(const Common::String &str);
200 
201 protected:
202  void pauseEngineIntern(bool pause) override;
203 
204  void handleControls(Common::EventType type, const Common::KeyState &key);
205  void handleChars(Common::EventType type, const Common::KeyState &key);
206  void handleJoyAxis(byte axis, int16 position);
207  void handleMouseAxis(byte axis, int16 position);
208  void handleJoyButton(Common::EventType type, byte button);
209  void handleExit();
210  void handlePause();
211  void handleUserPaint();
212  void cameraChangeHandle(int prev, int next);
213  void cameraPostChangeHandle(int num);
214  void buildActiveActorsList();
215  void savegameCallback();
216  GfxBase *createRenderer(int screenW, int screenH);
217  void playAspyrLogo();
218  virtual LuaBase *createLua();
219  virtual void updateNormalMode();
220  virtual void updateDrawMode();
221  virtual void drawNormalMode();
222 
223  void savegameSave();
224  void saveGRIM();
225 
226  void savegameRestore();
227  void restoreGRIM();
228 
229  virtual void storeSaveGameMetadata(SaveGame *state);
230  virtual void storeSaveGameImage(SaveGame *savedState);
231 
232  bool _savegameLoadRequest = false;
233  bool _savegameSaveRequest = false;
234  Common::String _savegameFileName;
235  SaveGame *_savedState;
236  bool _justSaveLoaded;
237 
238  Set *_currSet;
239  EngineMode _mode, _previousMode;
240  SpeechMode _speechMode;
241  int _textSpeed;
242  bool _flipEnable;
243  char _fps[8];
244  bool _doFlip;
245  bool _refreshShadowMask = false;
246  bool _shortFrame = false;
247  bool _setupChanged = true;
248  // This holds the name of the setup in which the movie must be drawed
249  Common::String _movieSetup;
250 
251  unsigned _frameStart = 0, _frameTime = 0, _movieTime = 0;
252  int _prevSmushFrame = 0;
253  unsigned int _frameCounter = 0;
254  unsigned int _lastFrameTime = 0;
255  unsigned _speedLimitMs;
256  bool _showFps;
257  bool _softRenderer;
258 
259  bool *_controlsEnabled;
260  bool *_controlsState;
261  float *_joyAxisPosition;
262 
263  bool _changeHardwareState = false;
264 
265  Actor *_selectedActor;
266  Iris *_iris;
267  TextObject::Ptr _movieSubtitle;
268 
269  bool _buildActiveActorsList;
270  Common::List<Actor *> _activeActors;
271  Common::List<Actor *> _talkingActors;
272 
273  uint32 _gameFlags;
274  GrimGameType _gameType;
275  Common::Platform _gamePlatform;
276  Common::Language _gameLanguage;
277  uint32 _pauseStartTime;
278 
279  // Remastered;
280  uint32 _language;
281  static const uint32 kNumConcepts = 98;
282  static const uint32 kNumCutscenes = 40;
283  bool _cutsceneEnabled[kNumCutscenes]; // TODO, could probably use a different data structure
284  bool _conceptEnabled[kNumConcepts];
285 
286  Common::String _saveMeta1;
287  int _saveMeta2 = 0;
288  Common::String _saveMeta3;
289 
290  Commentary *_commentary;
291 
292 public:
293  int _cursorX = 0;
294  int _cursorY = 0;
295  bool _isUtf8 = false;
296  Font *_overrideFont = nullptr;
297 };
298 
299 extern GrimEngine *g_grim;
300 
301 extern int g_imuseState;
302 
303 // Fake KEYCODE_* values for joystick and mouse events
304 
305 enum {
306  KEYCODE_JOY1_A = 512,
307  KEYCODE_JOY1_B,
308  KEYCODE_JOY1_X,
309  KEYCODE_JOY1_Y,
310  KEYCODE_JOY1_BACK,
311  KEYCODE_JOY1_GUIDE,
312  KEYCODE_JOY1_START,
313  KEYCODE_JOY1_LEFTSTICK,
314  KEYCODE_JOY1_RIGHTSTICK,
315  KEYCODE_JOY1_L1,
316  KEYCODE_JOY1_R1,
317  KEYCODE_JOY1_HUP,
318  KEYCODE_JOY1_HDOWN,
319  KEYCODE_JOY1_HLEFT,
320  KEYCODE_JOY1_HRIGHT,
321  KEYCODE_JOY1_L2,
322  KEYCODE_JOY1_R2,
323  KEYCODE_JOY1_B14,
324  KEYCODE_JOY1_B15,
325  KEYCODE_JOY1_B16,
326  KEYCODE_JOY1_B17,
327  KEYCODE_JOY1_B18,
328  KEYCODE_JOY1_B19,
329  KEYCODE_JOY1_B20,
330  KEYCODE_JOY2_A,
331  KEYCODE_JOY2_B,
332  KEYCODE_JOY2_X,
333  KEYCODE_JOY2_Y,
334  KEYCODE_JOY2_BACK,
335  KEYCODE_JOY2_GUIDE,
336  KEYCODE_JOY2_START,
337  KEYCODE_JOY2_LEFTSTICK,
338  KEYCODE_JOY2_RIGHTSTICK,
339  KEYCODE_JOY2_L1,
340  KEYCODE_JOY2_R1,
341  KEYCODE_JOY2_HUP,
342  KEYCODE_JOY2_HDOWN,
343  KEYCODE_JOY2_HLEFT,
344  KEYCODE_JOY2_HRIGHT,
345  KEYCODE_JOY2_L2,
346  KEYCODE_JOY2_R2,
347  KEYCODE_MOUSE_B1,
348  KEYCODE_MOUSE_B2,
349  KEYCODE_MOUSE_B3,
350  KEYCODE_MOUSE_B4,
351  KEYCODE_AXIS_JOY1_X,
352  KEYCODE_AXIS_JOY1_Y,
353  KEYCODE_AXIS_JOY1_Z,
354  KEYCODE_AXIS_JOY1_R,
355  KEYCODE_AXIS_JOY1_U,
356  KEYCODE_AXIS_JOY1_V,
357  KEYCODE_AXIS_JOY2_X,
358  KEYCODE_AXIS_JOY2_Y,
359  KEYCODE_AXIS_JOY2_Z,
360  KEYCODE_AXIS_JOY2_R,
361  KEYCODE_AXIS_JOY2_U,
362  KEYCODE_AXIS_JOY2_V,
363  KEYCODE_AXIS_MOUSE_X,
364  KEYCODE_AXIS_MOUSE_Y,
365  KEYCODE_AXIS_MOUSE_Z,
366  KEYCODE_EXTRA_LAST
367 };
368 
369 #define NUM_JOY_AXES (KEYCODE_AXIS_JOY1_V - KEYCODE_AXIS_JOY1_X + 1)
370 #define NUM_JOY_BUTTONS (KEYCODE_JOY1_R2 - KEYCODE_JOY1_A + 1)
371 
372 extern const ControlDescriptor controls[];
373 
374 } // end of namespace Grim
375 
376 #endif
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: grim.h:88
Definition: grim.h:58
Definition: str.h:59
RendererType
Definition: renderer.h:45
EngineFeature
Definition: engine.h:250
Definition: error.h:84
Definition: array.h:52
EventType
Definition: events.h:48
Definition: list.h:44
Definition: savegame.h:33
Definition: actor.h:33
const Common::List< Actor * > & getActiveActors() const
Definition: grim.h:152
Definition: ustr.h:57
Definition: textobject.h:84
Definition: gfx_base.h:71
Definition: commentary.h:32
Definition: font.h:38
Actor represents a 3D character on screen.
Definition: actor.h:72
Definition: keyboard.h:294
Definition: grim.h:53
Definition: lua.h:102
Definition: textobject.h:80
Definition: system.h:175
Definition: engine.h:143
Platform
Definition: platform.h:46
Add "-remastered&#39; to gameid.
Definition: advancedDetector.h:114
Definition: iris.h:29
Definition: set.h:44
Language
Definition: language.h:45