aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/Base/BGame.h
blob: 0d1d0fe15d71772ca7e751b4d686342e3bc51bfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This file is based on WME Lite.
 * http://dead-code.org/redir.php?target=wmelite
 * Copyright (c) 2011 Jan Nedoma
 */

#ifndef WINTERMUTE_BGAME_H
#define WINTERMUTE_BGAME_H

#include "engines/wintermute/Base/BDebugger.h"
#include "engines/wintermute/Base/BRenderer.h"
#include "engines/wintermute/Base/BObject.h"
#include "engines/wintermute/persistent.h"
#include "engines/wintermute/coll_templ.h"
#include "common/events.h"

namespace WinterMute {

typedef void (*ENGINE_LOG_CALLBACK)(char *Text, HRESULT Result, void *Data);

class CBSoundMgr;
class CBFader;
class CBFont;
class CBFileManager;
class CBTransitionMgr;
class CScEngine;
class CBFontStorage;
class CBStringTable;
class CBQuickMsg;
class CUIWindow;
class CBViewport;
class CBRenderer;
class CBRegistry;
class CBSaveThumbHelper;
class CBSurfaceStorage;
class CSXStore;
class CSXMath;
class CBKeyboardState;
class CVidPlayer;
class CVidTheoraPlayer;

#define NUM_MUSIC_CHANNELS 5

class CBGame: public CBObject {
public:
	DECLARE_PERSISTENT(CBGame, CBObject)

	virtual HRESULT onScriptShutdown(CScScript *script);

	virtual HRESULT onActivate(bool activate, bool refreshMouse);
	virtual HRESULT onMouseLeftDown();
	virtual HRESULT onMouseLeftUp();
	virtual HRESULT onMouseLeftDblClick();
	virtual HRESULT onMouseRightDblClick();
	virtual HRESULT onMouseRightDown();
	virtual HRESULT onMouseRightUp();
	virtual HRESULT onMouseMiddleDown();
	virtual HRESULT onMouseMiddleUp();
	virtual HRESULT onPaint();
	virtual HRESULT onWindowClose();

	bool isLeftDoubleClick();
	bool isRightDoubleClick();

	bool _autorunDisabled;

	uint32 _lastMiniUpdate;
	bool _miniUpdateEnabled;

	virtual HRESULT miniUpdate();

	void getMousePos(POINT *Pos);
	RECT _mouseLockRect;

	bool _shuttingDown;

	virtual HRESULT displayDebugInfo();
	bool _dEBUG_ShowFPS;

	bool _suspendedRendering;
	int _soundBufferSizeSec;

	TTextEncoding _textEncoding;
	bool _textRTL;

	CBSprite *_loadingIcon;
	int _loadingIconX;
	int _loadingIconY;
	int _loadingIconPersistent;

	virtual HRESULT resetContent();

	void DEBUG_DumpClassRegistry();
	HRESULT setWaitCursor(const char *filename);
	char *_localSaveDir;
	bool _saveDirChecked;


	bool _indicatorDisplay;
	uint32 _indicatorColor;
	int _indicatorProgress;
	int _indicatorX;
	int _indicatorY;
	int _indicatorWidth;
	int _indicatorHeight;

	bool _richSavedGames;
	char *_savedGameExt;

	char *_loadImageName;
	char *_saveImageName;
	int _saveImageX;
	int _saveImageY;
	int _loadImageX;
	int _loadImageY;
	CBSurface *_saveLoadImage;

	HRESULT displayIndicator();

	int _thumbnailWidth;
	int _thumbnailHeight;

	bool _reportTextureFormat;

	void setEngineLogCallback(ENGINE_LOG_CALLBACK callback = NULL, void *data = NULL);
	ENGINE_LOG_CALLBACK _engineLogCallback;
	void *_engineLogCallbackData;
	bool _editorMode;

	bool _doNotExpandStrings;
	void getOffset(int *offsetX, int *offsetY);
	void setOffset(int offsetX, int offsetY);
	int getSequence();
	int _offsetY;
	int _offsetX;
	float _offsetPercentX;
	float _offsetPercentY;
	CBObject *_mainObject;

	HRESULT initInput();
	HRESULT initLoop();
	uint32 _currentTime;
	uint32 _deltaTime;
	CBFont *_systemFont;
	CBFont *_videoFont;
	HRESULT initialize1();
	HRESULT initialize2();
	HRESULT initialize3();
	CBFileManager *_fileManager;
	CBTransitionMgr *_transMgr;
	CBDebugger *getDebugMgr();

	void LOG(HRESULT res, LPCSTR fmt, ...);

	CBRenderer *_renderer;
	CBSoundMgr *_soundMgr;
	CScEngine *_scEngine;
	CSXMath *_mathClass;
	CSXStore *_store;
	CBSurfaceStorage *_surfaceStorage;
	CBFontStorage *_fontStorage;
	CBGame();

	virtual ~CBGame();
	void DEBUG_DebugDisable();
	void DEBUG_DebugEnable(const char *filename = NULL);
	bool _dEBUG_DebugMode;
	bool _dEBUG_AbsolutePathWarning;

	void *_dEBUG_LogFile;
	int _sequence;
	virtual HRESULT loadFile(const char *filename);
	virtual HRESULT loadBuffer(byte *buffer, bool complete = true);
	CBArray<CBQuickMsg *, CBQuickMsg *> _quickMessages;
	CBArray<CUIWindow *, CUIWindow *> _windows;
	CBArray<CBViewport *, CBViewport *> _viewportStack;

	int _viewportSP;
	bool _mouseLeftDown;
	bool _mouseRightDown;
	bool _mouseMidlleDown;
	CBStringTable *_stringTable;

	int _settingsResWidth;
	int _settingsResHeight;
	bool _settingsRequireAcceleration;
	bool _settingsAllowWindowed;
	bool _settingsAllowAdvanced;
	bool _settingsAllowAccessTab;
	bool _settingsAllowAboutTab;
	bool _settingsRequireSound;
	bool _settingsAllowDesktopRes;
	int _settingsTLMode;
	char *_settingsGameFile;
	CBFader *_fader;
	bool _suppressScriptErrors;

	virtual HRESULT invalidateDeviceObjects();
	virtual HRESULT restoreDeviceObjects();

	virtual HRESULT ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name);
	// scripting interface
	virtual CScValue *scGetProperty(const char *name);
	virtual HRESULT scSetProperty(const char *name, CScValue *value);
	virtual HRESULT scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name);
	virtual const char *scToString();
	// compatibility bits
	bool _compatKillMethodThreads;

private:
	// FPS stuff
	uint32 _lastTime;
	uint32 _fpsTime;
	uint32 _framesRendered;

public:
	uint32 _surfaceGCCycleTime;
	bool _smartCache;
	bool _videoSubtitles;
	bool _subtitles;
	uint32 _musicStartTime[NUM_MUSIC_CHANNELS];
	bool _compressedSavegames;
	int _scheduledLoadSlot;
	bool _loading;
	bool _personalizedSave;
	HRESULT emptySaveSlot(int slot);
	bool isSaveSlotUsed(int slot);
	HRESULT getSaveSlotDescription(int slot, char *buffer);
	HRESULT getSaveSlotFilename(int slot, char *buffer);
	void setWindowTitle();
	virtual bool handleMouseWheel(int delta);
	bool _quitting;
	virtual HRESULT getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor);

	virtual bool handleKeypress(Common::Event *event, bool printable = false);
	virtual void handleKeyRelease(Common::Event *event);
	int _freezeLevel;
	HRESULT unfreeze();
	HRESULT freeze(bool includingMusic = true);
	HRESULT focusWindow(CUIWindow *window);
	CVidPlayer *_videoPlayer;
	CVidTheoraPlayer *_theoraPlayer;
	bool _loadInProgress;
	CUIWindow *_focusedWindow;
	bool _editorForceScripts;
	static void afterLoadRegion(void *region, void *data);
	static void afterLoadSubFrame(void *subframe, void *data);
	static void afterLoadSound(void *sound, void *data);
	static void afterLoadFont(void *font, void *data);
	static void afterLoadScript(void *script, void *data);
	static void invalidateValues(void *value, void *data);

	HRESULT loadSettings(const char *filename);
	HRESULT resumeMusic(int channel);
	HRESULT setMusicStartTime(int channel, uint32 time);
	HRESULT pauseMusic(int channel);
	HRESULT stopMusic(int channel);
	HRESULT playMusic(int channel, const char *filename, bool looping = true, uint32 loopStart = 0);
	CBSound *_music[NUM_MUSIC_CHANNELS];
	bool _musicCrossfadeRunning;
	bool _musicCrossfadeSwap;
	uint32 _musicCrossfadeStartTime;
	uint32 _musicCrossfadeLength;
	int _musicCrossfadeChannel1;
	int _musicCrossfadeChannel2;
	HRESULT displayWindows(bool inGame = false);
	CBRegistry *_registry;
	bool _useD3D;
	virtual HRESULT cleanup();
	virtual HRESULT loadGame(int slot);
	virtual HRESULT loadGame(const char *filename);
	virtual HRESULT SaveGame(int slot, const char *desc, bool quickSave = false);
	virtual HRESULT showCursor();

	CBSprite *_cursorNoninteractive;
	CBObject *_activeObject;
	CBKeyboardState *_keyboardState;
	bool _interactive;
	TGameState _state;
	TGameState _origState;
	bool _origInteractive;
	uint32 _timer;
	uint32 _timerDelta;
	uint32 _timerLast;

	uint32 _liveTimer;
	uint32 _liveTimerDelta;
	uint32 _liveTimerLast;

	CBObject *_capturedObject;
	POINT _mousePos;
	bool validObject(CBObject *object);
	HRESULT unregisterObject(CBObject *object);
	HRESULT registerObject(CBObject *object);
	void quickMessage(const char *text);
	void quickMessageForm(LPSTR fmt, ...);
	HRESULT displayQuickMsg();
	uint32 _fps;
	HRESULT updateMusicCrossfade();

	bool isVideoPlaying();
	HRESULT stopVideo();

	CBArray<CBObject *, CBObject *> _regObjects;
public:
	virtual HRESULT displayContent(bool update = true, bool displayAll = false);
	virtual HRESULT displayContentSimple();
	bool _forceNonStreamedSounds;
	void resetMousePos();
	int _subtitlesSpeed;
	void setInteractive(bool state);
	virtual HRESULT windowLoadHook(CUIWindow *win, char **buf, char **params);
	virtual HRESULT windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name);
	HRESULT getCurrentViewportOffset(int *offsetX = NULL, int *offsetY = NULL);
	HRESULT getCurrentViewportRect(RECT *rect, bool *custom = NULL);
	HRESULT popViewport();
	HRESULT pushViewport(CBViewport *Viewport);
	HRESULT setActiveObject(CBObject *Obj);
	CBSprite *_lastCursor;
	HRESULT drawCursor(CBSprite *Cursor);

	virtual HRESULT initAfterLoad();
	CBSaveThumbHelper *_cachedThumbnail;
	AnsiString getDataDir();
	void addMem(int bytes);

	bool _touchInterface;
	bool _constrainedMemory;
	AnsiString getDeviceType() const;

private:
	CBDebugger *_debugMgr;

	struct LastClickInfo {
		LastClickInfo() {
			PosX = PosY = 0;
			Time = 0;
		}

		int PosX;
		int PosY;
		uint32 Time;
	};

	LastClickInfo _lastClick[2];
	bool isDoubleClick(int buttonIndex);
	uint32 _usedMem;



protected:
	// WME Lite specific
	bool _autoSaveOnExit;
	int _autoSaveSlot;
	bool _cursorHidden;

public:
	void autoSaveOnExit();

};

} // end of namespace WinterMute

#endif