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