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/base_string_table.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/debugger.h"
38 #if EXTENDED_DEBUGGER_ENABLED
39 #include "engines/wintermute/base/scriptables/debuggable/debuggable_script_engine.h"
40 #endif
41 
42 #include "common/events.h"
43 #include "common/random.h"
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 BaseAccessMgr;
64 class ScEngine;
65 class SXMath;
66 class SXDirectory;
67 class UIWindow;
68 class VideoPlayer;
69 class VideoTheoraPlayer;
70 class SaveThumbHelper;
71 
72 #ifdef ENABLE_WME3D
73 class BaseRenderer3D;
74 struct FogParameters;
75 #endif
76 
77 #define NUM_MUSIC_CHANNELS 5
78 
79 class BaseGame : public BaseObject {
80 public:
81 
82 
83  DECLARE_PERSISTENT(BaseGame, BaseObject)
84 
85  virtual bool onScriptShutdown(ScScript *script);
86 
87  virtual bool getLayerSize(int *LayerWidth, int *LayerHeight, Common::Rect32 *viewport, bool *customViewport);
88 #ifdef ENABLE_WME3D
89  virtual uint32 getAmbientLightColor();
90  virtual bool getFogParams(bool *fogEnabled, uint32 *fogColor, float *start, float *end);
91 #endif
92  virtual BaseObject *getNextAccessObject(BaseObject *currObject);
93  virtual BaseObject *getPrevAccessObject(BaseObject *currObject);
94 
95  virtual bool onActivate(bool activate, bool refreshMouse);
96  virtual bool onMouseLeftDown();
97  virtual bool onMouseLeftUp();
98  virtual bool onMouseLeftDblClick();
99  virtual bool onMouseRightDblClick();
100  virtual bool onMouseRightDown();
101  virtual bool onMouseRightUp();
102  virtual bool onMouseMiddleDown();
103  virtual bool onMouseMiddleUp();
104  virtual bool onPaint();
105  virtual bool onWindowClose();
106 
107  bool isLeftDoubleClick();
108  bool isRightDoubleClick();
109 
110  bool _autorunDisabled;
111  uint32 _lastMiniUpdate;
112  bool _miniUpdateEnabled;
113  virtual bool miniUpdate();
114 
115  void getMousePos(Common::Point32 *pos);
116  Common::Rect32 _mouseLockRect;
117 
118  bool _shuttingDown;
119 
120  virtual bool displayDebugInfo();
121  bool _debugShowFPS;
122 
123  bool _suspendedRendering;
124  int32 _soundBufferSizeSec;
125  virtual bool renderShadowGeometry();
126 
127  TTextEncoding _textEncoding;
128  bool _textRTL;
129 
130  BaseSprite *_loadingIcon;
131  int32 _loadingIconX;
132  int32 _loadingIconY;
133  int32 _loadingIconPersistent;
134 
135  virtual bool resetContent();
136 
137  void DEBUG_DumpClassRegistry();
138  bool setWaitCursor(const char *filename);
139 
140  char *_localSaveDir;
141  bool _saveDirChecked;
142 
143 #ifdef ENABLE_WME3D
144  bool _supportsRealTimeShadows;
145  TShadowType _maxShadowType;
146  bool setMaxShadowType(TShadowType maxShadowType);
147  virtual TShadowType getMaxShadowType(BaseObject *object = nullptr);
148 #endif
149 
150  bool _indicatorDisplay;
151  uint32 _indicatorColor;
152  int32 _indicatorProgress;
153  int32 _indicatorX;
154  int32 _indicatorY;
155  int32 _indicatorWidth;
156  int32 _indicatorHeight;
157 
158  bool _richSavedGames;
159  char *_savedGameExt;
160 
161 #ifdef ENABLE_WME3D
162  int32 _editorResolutionWidth;
163  int32 _editorResolutionHeight;
164 #endif
165 
166  char *_loadImageName;
167  char *_saveImageName;
168  int32 _saveImageX;
169  int32 _saveImageY;
170  int32 _loadImageX;
171  int32 _loadImageY;
172  BaseSurface *_saveLoadImage;
173  bool _hasDrawnSaveLoadImage;
174 
175  bool displayIndicator();
176 #ifdef ENABLE_FOXTAIL
177  bool displayIndicatorFoxTail();
178 #endif
179  uint32 _thumbnailWidth;
180  uint32 _thumbnailHeight;
181 
182  bool _reportTextureFormat;
183 
184  void setEngineLogCallback(ENGINE_LOG_CALLBACK callback = nullptr, void *data = nullptr);
185  ENGINE_LOG_CALLBACK _engineLogCallback;
186  void *_engineLogCallbackData;
187 
188  bool _editorMode;
189  void getOffset(int *offsetX, int *offsetY) const;
190  void setOffset(int32 offsetX, int32 offsetY);
191  int getSequence();
192  int32 _offsetY;
193  int32 _offsetX;
194  float _offsetPercentX;
195  float _offsetPercentY;
196  BaseObject *_mainObject;
197  bool initInput();
198  bool initLoop();
199  uint32 _currentTime{};
200  uint32 _deltaTime;
201  BaseFont *_systemFont;
202  BaseFont *_videoFont;
203  bool initConfManSettings();
204  bool initRenderer();
205  bool initialize1();
206  bool initialize2();
207  bool initialize3();
208  BaseAccessMgr *_accessMgr;
209  BaseFileManager *_fileManager;
210  BaseTransitionMgr *_transMgr;
211 
212  void LOG(bool res, const char *fmt, ...);
213  BaseRenderer *_renderer;
214 #ifdef ENABLE_WME3D
215  BaseRenderer3D *_renderer3D;
216  bool _playing3DGame;
217 #endif
218  BaseSoundMgr *_soundMgr;
219 #if EXTENDED_DEBUGGER_ENABLED
220  DebuggableScEngine *_scEngine;
221 #else
222  ScEngine *_scEngine;
223 #endif
224  BaseScriptable *_mathClass;
225  BaseScriptable *_directoryClass;
226  BaseSurfaceStorage *_surfaceStorage;
227  BaseFontStorage *_fontStorage;
228  BaseGame(const Common::String &targetName);
229  ~BaseGame() override;
230  void debugDisable();
231  void debugEnable(const char *filename = nullptr);
232  bool _debugMode;
233  void *_debugLogFile;
234  int32 _sequence;
235  virtual bool loadFile(const char *filename);
236  virtual bool loadBuffer(char *buffer, bool complete = true);
237  BaseArray<BaseQuickMsg *> _quickMessages;
238  BaseArray<UIWindow *> _windows;
239  BaseArray<BaseViewport *> _viewportStack;
240  int32 _viewportSP;
241  bool _mouseLeftDown;
242  bool _mouseRightDown;
243  bool _mouseMidlleDown;
244  BaseStringTable *_stringTable;
245 
246  int _settingsResWidth;
247  int _settingsResHeight;
248  bool _settingsRequireAcceleration;
249  bool _settingsAllowWindowed;
250  bool _settingsAllowAdvanced;
251  bool _settingsAllowAccessTab;
252  bool _settingsAllowAboutTab;
253  bool _settingsRequireSound;
254  bool _settingsAllowDesktopRes;
255  int32 _settingsTLMode;
256  char *_settingsGameFile;
257  BaseFader *_fader;
258  bool _suppressScriptErrors;
259 
260  bool invalidateDeviceObjects() override;
261  bool restoreDeviceObjects() override;
262 
263  virtual bool externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name);
264 
265  // scripting interface
266  ScValue *scGetProperty(const char *name) override;
267  bool scSetProperty(const char *name, ScValue *value) override;
268  bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) override;
269  const char *scToString() override;
270 
271  // compatibility bits
272  bool _compatKillMethodThreads;
273 
274 private:
275  // FPS stuff
276  uint32 _lastTime;
277  uint32 _fpsTime;
278  uint32 _framesRendered;
279 
280 public:
281  uint32 _surfaceGCCycleTime;
282  bool _smartCache; // RO
283  bool _videoSubtitles;
284  bool _subtitles; // RO
285  uint32 _musicStartTime[NUM_MUSIC_CHANNELS];
286  bool _compressedSavegames;
287  int32 _scheduledLoadSlot;
288  bool _loading;
289  bool _personalizedSave;
290  static bool emptySaveSlot(int slot);
291  static bool isSaveSlotUsed(int slot);
292  static bool getSaveSlotDescription(int slot, Common::String &desc);
293  static void getSaveSlotTimestamp(int slot, TimeDate *time);
294  static bool getSaveSlotFilename(int slot, Common::String &desc);
295  void setWindowTitle();
296  bool handleMouseWheel(int32 delta) override;
297  bool _quitting;
298  virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor);
299  bool handleKeypress(Common::Event *event, bool printable = false) override;
300  virtual void handleKeyRelease(Common::Event *event);
301  bool handleAccessKey(Common::Event *event, bool printable);
302  virtual bool handleCustomActionStart(BaseGameCustomAction action);
303  virtual bool handleCustomActionEnd(BaseGameCustomAction action);
304  int32 _freezeLevel;
305  bool unfreeze();
306  bool freeze(bool includingMusic = true);
307  bool focusWindow(UIWindow *window);
308  VideoPlayer *_videoPlayer;
309  VideoTheoraPlayer *_theoraPlayer;
310  bool _loadInProgress;
311  UIWindow *_focusedWindow;
312  bool _editorForceScripts;
313  static void afterLoadRegion(void *region, void *data);
314  static void afterLoadSubFrame(void *subframe, void *data);
315  static void afterLoadSound(void *sound, void *data);
316  static void afterLoadFont(void *font, void *data);
317 #ifdef ENABLE_WME3D
318  static void afterLoadXModel(void *model, void *data);
319 #endif
320  static void afterLoadScript(void *script, void *data);
321  static void afterLoadScene(void *scene, void *data);
322  static void invalidateValues(void *value, void *data);
323  bool loadSettings(const char *filename);
324  bool resumeMusic(int channel);
325  bool setMusicStartTime(int channel, uint32 time);
326  bool pauseMusic(int channel);
327  bool stopMusic(int channel);
328  bool playMusic(int channel, const char *filename, bool looping = true, uint32 loopStart = 0, uint32 privVolume = 100);
329  BaseSound *_music[NUM_MUSIC_CHANNELS];
330  bool _musicCrossfadeRunning;
331  bool _musicCrossfadeSwap;
332  uint32 _musicCrossfadeStartTime;
333  uint32 _musicCrossfadeLength;
334  int32 _musicCrossfadeChannel1;
335  int32 _musicCrossfadeChannel2;
336  int32 _musicCrossfadeVolume1;
337  int32 _musicCrossfadeVolume2;
338  bool displayWindows(bool inGame = false);
339  Common::String readRegistryString(const Common::String &key, const Common::String &initValue) const;
340  bool _useD3D;
341  virtual bool cleanup();
342  bool loadGame(uint32 slot);
343  bool loadGame(const char *filename);
344  bool saveGame(int32 slot, const char *desc, bool quickSave = false);
345  bool showCursor() override;
346  BaseSprite *_cursorNoninteractive;
347  BaseObject *_activeObject;
348  BaseKeyboardState *_keyboardState;
349  bool _interactive;
350  TGameState _state;
351  TGameState _origState;
352  bool _origInteractive;
353  uint32 _timer;
354  uint32 _timerDelta;
355  uint32 _timerLast;
356 
357  uint32 _liveTimer;
358  uint32 _liveTimerDelta;
359  uint32 _liveTimerLast;
360 
361  BaseObject *_capturedObject;
362  Common::Point32 _mousePos;
363  bool validObject(BaseObject *object);
364  bool unregisterObject(BaseObject *object);
365  bool registerObject(BaseObject *object);
366  void quickMessage(const char *text);
367  void quickMessageForm(char *fmt, ...);
368  bool displayQuickMsg();
369  uint32 _fps;
370  bool updateMusicCrossfade();
371 
372  bool isVideoPlaying();
373  bool stopVideo();
374 
375  BaseArray<BaseObject *> _regObjects;
376 
377  // accessibility flags
378  bool _accessTTSEnabled;
379  bool _accessTTSTalk;
380  bool _accessTTSCaptions;
381  bool _accessTTSKeypress;
382  bool _accessKeyboardEnabled;
383  bool _accessKeyboardCursorSkip;
384  bool _accessKeyboardPause;
385 
386  bool _accessGlobalPaused;
387 
388  UIWindow *_accessShieldWin;
389  bool accessPause();
390  bool accessUnpause();
391 
392 public:
393  virtual bool displayContent(bool update = true, bool displayAll = false);
394  virtual bool displayContentSimple();
395  bool _forceNonStreamedSounds;
396  void resetMousePos();
397  int32 _subtitlesSpeed;
398  void setInteractive(bool state);
399  virtual bool windowLoadHook(UIWindow *win, char **buf, char **params);
400  virtual bool windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name);
401  bool getCurrentViewportOffset(int *offsetX = nullptr, int *offsetY = nullptr);
402  bool getCurrentViewportRect(Common::Rect32 *rect, bool *custom = nullptr);
403  bool popViewport();
404  bool pushViewport(BaseViewport *viewport);
405  bool setActiveObject(BaseObject *obj);
406 
407  BaseSprite *_lastCursor;
408  bool drawCursor(BaseSprite *cursor);
409 
410  virtual bool initAfterLoad();
411 
412  SaveThumbHelper *_cachedThumbnail;
413 
414 private:
415  bool getSaveDir(char *Buffer);
416 
417 
418 
419 public:
420  BaseGameMusic *_musicSystem;
421  Common::String _targetName;
422 
423  void setIndicatorVal(int value);
424  bool getBilinearFiltering() { return _bilinearFiltering; }
425  void addMem(int32 bytes);
426 
427  bool _touchInterface;
428  bool _bilinearFiltering{};
429 #ifdef ENABLE_WME3D
430  bool _force2dRenderer{};
431 #endif
432 
433  AnsiString getDeviceType() const;
434 
435  struct LastClickInfo {
436  LastClickInfo() {
437  posX = posY = 0;
438  time = 0;
439  }
440 
441  int32 posX;
442  int32 posY;
443  uint32 time;
444  };
445 
446  LastClickInfo _lastClick[2];
447  bool isDoubleClick(int32 buttonIndex);
448  uint32 _usedMem;
449 
450 protected:
451  // WME Lite specific
452  bool _autoSaveOnExit;
453  uint32 _autoSaveSlot;
454  bool _cursorHidden;
455 
456 public:
457  void autoSaveOnExit();
458  PluginEvent &pluginEvents() { return _pluginEvents; }
459 
460 private:
461 
462 #ifdef ENABLE_HEROCRAFT
463  // HeroCraft games specific random source with ability a in-script function to set the seed
464  Common::RandomSource *_rndHc;
465 
466  // HeroCraft games specific checksum function, used in Papa's Daughters 2 selfcheck
467  uint8 getFilePartChecksumHc(const char *filename, uint32 begin, uint32 end);
468 #endif
469 
470  PluginEvent _pluginEvents;
471 };
472 
473 } // End of namespace Wintermute
474 
475 #endif
Definition: script.h:44
Definition: save_thumb_helper.h:35
Definition: base_game.h:79
Definition: rect.h:526
Definition: script_value.h:42
Definition: system.h:108
Definition: str.h:59
Definition: base_font_storage.h:40
Definition: random.h:44
Definition: base_keyboard_state.h:44
Definition: base_game.h:435
Definition: base_file_manager.h:39
Definition: video_theora_player.h:41
Definition: base_scriptable.h:41
Definition: base_transition_manager.h:35
Definition: events.h:210
Definition: script_stack.h:41
Definition: base_surface.h:37
Definition: base_access_mgr.h:41
Definition: rect.h:146
Definition: video_player.h:45
Definition: plugin_event.h:48
Definition: base_renderer3d.h:60
Definition: base_fader.h:36
Definition: debuggable_script_engine.h:93
Definition: coll_templ.h:347
Definition: base_font.h:37
Definition: base_sound.h:39
Definition: display_client.h:113
Definition: base_renderer.h:53
Definition: base_viewport.h:37
Definition: ui_window.h:39
Definition: base_surface_storage.h:36
Definition: base_sprite.h:40
Definition: base_string_table.h:39
Definition: base_sound_manager.h:38
Definition: script_engine.h:43
Definition: base_object.h:49
Definition: achievements_tables.h:27