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