ScummVM API documentation
base_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 
22 /*
23  * This file is based on WME Lite.
24  * http://dead-code.org/redir.php?target=wmelite
25  * Copyright (c) 2011 Jan Nedoma
26  */
27 
28 #ifndef WINTERMUTE_BASE_GAME_H
29 #define WINTERMUTE_BASE_GAME_H
30 
31 #include "engines/wintermute/base/base_object.h"
32 #include "engines/wintermute/base/base_game_custom_actions.h"
33 #include "engines/wintermute/base/timer.h"
34 #include "engines/wintermute/persistent.h"
35 #include "engines/wintermute/coll_templ.h"
36 #include "engines/wintermute/math/rect32.h"
37 #include "engines/wintermute/debugger.h"
38 #include "common/events.h"
39 #include "common/random.h"
40 #if EXTENDED_DEBUGGER_ENABLED
41 #include "engines/wintermute/base/scriptables/debuggable/debuggable_script_engine.h"
42 #endif
43 
44 namespace Wintermute {
45 
46 typedef void (*ENGINE_LOG_CALLBACK)(char *text, bool result, void *data);
47 
48 class BaseSoundMgr;
49 class BaseFader;
50 class BaseFont;
51 class BaseFileManager;
52 class BaseTransitionMgr;
53 class BaseFontStorage;
54 class BaseGameMusic;
55 class BaseQuickMsg;
56 class BaseViewport;
57 class BaseRenderer;
58 class BaseRegistry;
59 class BaseSurfaceStorage;
60 class BaseKeyboardState;
61 class BaseGameSettings;
62 class ScEngine;
63 class SXMath;
64 class SXDirectory;
65 class UIWindow;
66 class VideoPlayer;
67 class VideoTheoraPlayer;
68 class SaveThumbHelper;
69 
70 #ifdef ENABLE_WME3D
71 class BaseRenderer3D;
72 struct FogParameters;
73 #endif
74 
75 class BaseGame: public BaseObject {
76 public:
77  DECLARE_PERSISTENT(BaseGame, BaseObject)
78 
79  virtual bool getLayerSize(int *LayerWidth, int *LayerHeight, Rect32 *viewport, bool *customViewport);
80 #ifdef ENABLE_WME3D
81  virtual uint32 getAmbientLightColor();
82  virtual bool getFogParams(bool *fogEnabled, uint32 *fogColor, float *start, float *end);
83 #endif
84 
85  virtual bool onScriptShutdown(ScScript *script);
86 
87  virtual bool onActivate(bool activate, bool refreshMouse);
88  virtual bool onMouseLeftDown();
89  virtual bool onMouseLeftUp();
90  virtual bool onMouseLeftDblClick();
91  virtual bool onMouseRightDblClick();
92  virtual bool onMouseRightDown();
93  virtual bool onMouseRightUp();
94  virtual bool onMouseMiddleDown();
95  virtual bool onMouseMiddleUp();
96  virtual bool onPaint();
97  virtual bool onWindowClose();
98 
99  bool isLeftDoubleClick();
100  bool isRightDoubleClick();
101 
102  bool _autorunDisabled;
103 
104  uint32 _lastMiniUpdate;
105  bool _miniUpdateEnabled;
106 
107  virtual void miniUpdate();
108 
109  void getMousePos(Point32 *Pos);
110  Rect32 _mouseLockRect;
111 
112  bool _shuttingDown;
113 
114  virtual bool displayDebugInfo();
115 
116  void setShowFPS(bool enabled) { _debugShowFPS = enabled; }
117  bool getBilinearFiltering() { return _bilinearFiltering; }
118  bool getSuspendedRendering() const { return _suspendedRendering; }
119  virtual bool renderShadowGeometry();
120 
121  TTextEncoding _textEncoding;
122  bool _textRTL;
123 
124  virtual bool resetContent();
125 
126  void DEBUG_DumpClassRegistry();
127  bool setWaitCursor(const char *filename);
128 
129 #ifdef ENABLE_WME3D
130  bool _supportsRealTimeShadows;
131  TShadowType _maxShadowType;
132 
133  bool setMaxShadowType(TShadowType maxShadowType);
134  virtual TShadowType getMaxShadowType(BaseObject *object = nullptr);
135 
136  int32 _editorResolutionWidth;
137  int32 _editorResolutionHeight;
138 #endif
139 
140  uint32 getSaveThumbWidth() const { return _thumbnailWidth; }
141  uint32 getSaveThumbHeight() const { return _thumbnailHeight; }
142 
143  bool _editorMode;
144  void getOffset(int *offsetX, int *offsetY) const;
145  void setOffset(int32 offsetX, int32 offsetY);
146  int getSequence();
147 
148  int32 _offsetY;
149  int32 _offsetX;
150  float _offsetPercentX;
151  float _offsetPercentY;
152 
153  inline BaseObject *getMainObject() { return _mainObject; }
154  inline BaseFont *getSystemFont() { return _systemFont; }
155  inline BaseFont *getVideoFont() { return _videoFont; }
156 
157  bool initInput();
158  bool initLoop();
159  uint32 _currentTime;
160  uint32 _deltaTime;
161 
162  // Init-functions:
163  bool initConfManSettings();
164  bool initRenderer();
165  bool loadGameSettingsFile();
166  bool initialize1();
167  bool initialize2();
168  bool initialize3();
169  BaseTransitionMgr *_transMgr;
170 
171  // String Table
172  void expandStringByStringTable(char **str) const;
173  void expandStringByStringTable(Common::String &str) const;
174  char *getKeyFromStringTable(const char *str) const;
175 
176  void LOG(bool res, const char *fmt, ...);
177 
178  BaseRenderer *_renderer;
179 #ifdef ENABLE_WME3D
180  BaseRenderer3D *_renderer3D;
181  bool _playing3DGame;
182 #endif
183 
184  BaseSoundMgr *_soundMgr;
185 #if EXTENDED_DEBUGGER_ENABLED
186  DebuggableScEngine *_scEngine;
187 #else
188  ScEngine *_scEngine;
189 #endif
190  BaseScriptable *_mathClass;
191  BaseScriptable *_directoryClass;
192  BaseSurfaceStorage *_surfaceStorage;
193  BaseFontStorage *_fontStorage;
194  BaseGame(const Common::String &targetName);
195  ~BaseGame() override;
196 
197  bool _debugDebugMode;
198 
199  int32 _sequence;
200  virtual bool loadFile(const char *filename);
201  virtual bool loadBuffer(char *buffer, bool complete = true);
202 
203  int32 _viewportSP;
204 
205  bool _suppressScriptErrors;
206  bool _mouseLeftDown; // TODO: Hide
207 
208  virtual bool externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name);
209  // scripting interface
210  ScValue *scGetProperty(const Common::String &name) override;
211  bool scSetProperty(const char *name, ScValue *value) override;
212  bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) override;
213  const char *scToString() override;
214  // compatibility bits
215  bool _compatKillMethodThreads;
216 
217  const char* getGameTargetName() const { return _targetName.c_str(); }
218  void setGameTargetName(const Common::String& targetName) { _targetName = targetName; }
219  uint32 _surfaceGCCycleTime;
220  bool _smartCache; // RO
221  bool _subtitles; // RO
222 
223  int32 _scheduledLoadSlot;
224 
225  bool getIsLoading() const { return _loading; }
226 
227  bool handleMouseWheel(int32 delta) override;
228  bool _quitting;
229  virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) const;
230 
231  bool handleKeypress(Common::Event *event, bool printable = false) override;
232  virtual void handleKeyRelease(Common::Event *event);
233  virtual bool handleCustomActionStart(BaseGameCustomAction action);
234  virtual bool handleCustomActionEnd(BaseGameCustomAction action);
235 
236  bool unfreeze();
237  bool freeze(bool includingMusic = true);
238  bool focusWindow(UIWindow *window);
239  bool _loadInProgress;
240  UIWindow *_focusedWindow;
241  bool _editorForceScripts;
242 
243  static void invalidateValues(void *value, void *data);
244 
245  bool loadSettings(const char *filename);
246 
247  bool displayWindows(bool inGame = false);
248  bool _useD3D;
249  virtual bool cleanup();
250  bool loadGame(uint32 slot);
251  bool loadGame(const char *filename);
252  bool saveGame(int32 slot, const char *desc, bool quickSave = false);
253  bool showCursor() override;
254 
255  BaseObject *_activeObject;
256 
257  bool _interactive;
258  TGameState _state;
259  TGameState _origState;
260  bool _origInteractive;
261 
262  const Timer *getTimer() const { return &_timerNormal; }
263  const Timer *getLiveTimer() const { return &_timerLive; }
264 private:
265  Timer _timerNormal;
266  Timer _timerLive;
267 public:
268  BaseObject *_capturedObject;
269  Point32 _mousePos;
270  bool validObject(BaseObject *object);
271  bool unregisterObject(BaseObject *object);
272  bool registerObject(BaseObject *object);
273  void quickMessage(const char *text);
274  void quickMessageForm(char *fmt, ...);
275  bool displayQuickMsg();
276 
277  virtual bool displayContent(bool update = true, bool displayAll = false);
278  virtual bool displayContentSimple();
279  bool _forceNonStreamedSounds;
280  void resetMousePos();
281  int32 _subtitlesSpeed;
282  void setInteractive(bool state);
283  virtual bool windowLoadHook(UIWindow *win, char **buf, char **params);
284  virtual bool windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name);
285  bool getCurrentViewportOffset(int *offsetX = nullptr, int *offsetY = nullptr) const;
286  bool getCurrentViewportRect(Rect32 *rect, bool *custom = nullptr) const;
287  bool popViewport();
288  bool pushViewport(BaseViewport *Viewport);
289  bool setActiveObject(BaseObject *Obj);
290  BaseSprite *_lastCursor;
291  bool drawCursor(BaseSprite *Cursor);
292  bool storeSaveThumbnail();
293  void deleteSaveThumbnail();
294 
295  SaveThumbHelper *_cachedThumbnail;
296  void addMem(int32 bytes);
297  bool _touchInterface;
298  bool _constrainedMemory;
299 
300  bool stopVideo();
301 protected:
302  BaseFont *_systemFont;
303  BaseFont *_videoFont;
304 
305  BaseSprite *_loadingIcon;
306  int32 _loadingIconX;
307  int32 _loadingIconY;
308  int32 _loadingIconPersistent;
309 
310  BaseFader *_fader;
311 
312  int32 _freezeLevel;
313  VideoPlayer *_videoPlayer;
314  VideoTheoraPlayer *_theoraPlayer;
315 private:
316  bool _debugShowFPS;
317  bool _bilinearFiltering;
318 #ifdef ENABLE_WME3D
319  bool _force2dRenderer;
320 #endif
321  void *_debugLogFile;
322  void DEBUG_DebugDisable();
323  void DEBUG_DebugEnable(const char *filename = nullptr);
324 
325  BaseObject *_mainObject;
326 
327  bool _mouseRightDown;
328  bool _mouseMidlleDown;
329 
330  BaseGameSettings *_settings;
331 
332  int32 _soundBufferSizeSec;
333 
334  bool invalidateDeviceObjects() override;
335  bool restoreDeviceObjects() override;
336 
337  // TODO: This can probably be removed completely:
338  bool _saveDirChecked;
339 
340  Common::String _localSaveDir;
341  bool _loading;
342 
343  bool _reportTextureFormat;
344 
345  // FPS stuff
346  uint32 _lastTime;
347  uint32 _fpsTime;
348  uint32 _framesRendered;
349  Common::String _targetName;
350 
351  void setEngineLogCallback(ENGINE_LOG_CALLBACK callback = nullptr, void *data = nullptr);
352  ENGINE_LOG_CALLBACK _engineLogCallback;
353  void *_engineLogCallbackData;
354 
355  bool _videoSubtitles;
356 
357  bool _personalizedSave;
358 
359  uint32 _thumbnailWidth;
360  uint32 _thumbnailHeight;
361 
362  void setWindowTitle();
363 
364  bool _suspendedRendering;
365 
366  BaseSprite *_cursorNoninteractive;
367  BaseKeyboardState *_keyboardState;
368 
369  uint32 _fps;
370  BaseGameMusic *_musicSystem;
371 
372  bool isVideoPlaying();
373 
374  BaseArray<BaseQuickMsg *> _quickMessages;
375  BaseArray<UIWindow *> _windows;
376  BaseArray<BaseViewport *> _viewportStack;
377  BaseArray<BaseObject *> _regObjects;
378 
379  AnsiString getDeviceType() const;
380 
381  struct LastClickInfo {
382  LastClickInfo() {
383  posX = posY = 0;
384  time = 0;
385  }
386 
387  int32 posX;
388  int32 posY;
389  uint32 time;
390  };
391 
392  LastClickInfo _lastClick[2];
393  bool isDoubleClick(int32 buttonIndex);
394  uint32 _usedMem;
395 
396 // TODO: This should be expanded into a proper class eventually:
397  Common::String readRegistryString(const Common::String &key, const Common::String &initValue) const;
398 
399 
400 protected:
401  // WME Lite specific
402  bool _autoSaveOnExit;
403  uint32 _autoSaveSlot;
404  bool _cursorHidden;
405 
406 public:
407  void autoSaveOnExit();
408 
409 #ifdef ENABLE_HEROCRAFT
410 private:
411  // HeroCraft games specific random source with ability a in-script function to set the seed
412  Common::RandomSource *_rndHc;
413 
414  // HeroCraft games specific checksum function, used in Papa's Daughters 2 selfcheck
415  uint8 getFilePartChecksumHc(const char *filename, uint32 begin, uint32 end);
416 #endif
417 
418 };
419 
420 } // End of namespace Wintermute
421 
422 #endif
Definition: script.h:44
Definition: save_thumb_helper.h:35
Definition: base_game.h:75
Definition: script_value.h:42
Definition: str.h:59
Definition: base_font_storage.h:40
Definition: random.h:44
Definition: rect32.h:31
Definition: base_keyboard_state.h:44
Definition: video_theora_player.h:41
Definition: timer.h:37
Definition: base_scriptable.h:41
Definition: base_transition_manager.h:35
Definition: rect32.h:60
Definition: events.h:198
Definition: script_stack.h:41
Definition: cursor.h:27
Definition: video_player.h:41
Definition: base_renderer3d.h:54
Definition: base_fader.h:36
Definition: debuggable_script_engine.h:93
Definition: coll_templ.h:63
Definition: base_font.h:37
Definition: base_game_music.h:42
Definition: base_renderer.h:53
Definition: base_viewport.h:38
Definition: ui_window.h:39
Definition: base_surface_storage.h:36
Definition: base_sprite.h:40
Definition: base_sound_manager.h:38
Definition: script_engine.h:42
Definition: base_game_settings.h:37
Definition: base_object.h:57
Definition: achievements_tables.h:27