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