aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/BGame.h
blob: 5de2beacc3322e98dd34c96367c9b64abf0e18a2 (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
/* 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/BDebugger.h"
//#include "BSaveThumbHelper.h"
//#include "BFader.h"
#include "engines/wintermute/BRenderer.h"
//#include "BSurfaceStorage.h"
#include "engines/wintermute/BObject.h"
#include "engines/wintermute/persistent.h"
#include "coll_templ.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;

#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 m_AutorunDisabled;

	uint32 m_LastMiniUpdate;
	bool m_MiniUpdateEnabled;
	
	virtual HRESULT MiniUpdate();

	void GetMousePos(POINT *Pos);
	RECT m_MouseLockRect;

	bool m_ShuttingDown;

	virtual HRESULT DisplayDebugInfo();
	bool m_DEBUG_ShowFPS;

	bool m_SuspendedRendering;
	int m_SoundBufferSizeSec;

	TTextEncoding m_TextEncoding;
	bool m_TextRTL;

	CBSprite *m_LoadingIcon;
	int m_LoadingIconX;
	int m_LoadingIconY;
	int m_LoadingIconPersistent;

	virtual HRESULT ResetContent();

	void DEBUG_DumpClassRegistry();
	HRESULT SetWaitCursor(char *Filename);
	char *m_LocalSaveDir;
	bool m_SaveDirChecked;


	bool m_IndicatorDisplay;
	uint32 m_IndicatorColor;
	int m_IndicatorProgress;
	int m_IndicatorX;
	int m_IndicatorY;
	int m_IndicatorWidth;
	int m_IndicatorHeight;

	bool m_RichSavedGames;
	char *m_SavedGameExt;

	char *m_LoadImageName;
	char *m_SaveImageName;
	int m_SaveImageX;
	int m_SaveImageY;
	int m_LoadImageX;
	int m_LoadImageY;
	CBSurface *m_SaveLoadImage;

	HRESULT DisplayIndicator();

	int m_ThumbnailWidth;
	int m_ThumbnailHeight;

	bool m_ReportTextureFormat;
	HMODULE m_ResourceModule;
	void SetResourceModule(HMODULE ResModule);

	void SetEngineLogCallback(ENGINE_LOG_CALLBACK Callback = NULL, void *Data = NULL);
	ENGINE_LOG_CALLBACK m_EngineLogCallback;
	void *m_EngineLogCallbackData;
	bool m_EditorMode;

	bool m_DoNotExpandStrings;
	void GetOffset(int *OffsetX, int *OffsetY);
	void SetOffset(int OffsetX, int OffsetY);
	int GetSequence();
	int m_OffsetY;
	int m_OffsetX;
	float m_OffsetPercentX;
	float m_OffsetPercentY;
	CBObject *m_MainObject;

	HRESULT InitInput(HINSTANCE hInst, HWND hWnd);
	HRESULT InitLoop();
	uint32 m_CurrentTime;
	uint32 m_DeltaTime;
	CBFont *m_SystemFont;
	CBFont *m_VideoFont;
	HRESULT Initialize1();
	HRESULT Initialize2();
	HRESULT Initialize3();
	CBFileManager *m_FileManager;
	CBTransitionMgr *m_TransMgr;
	CBDebugger *GetDebugMgr();

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

	CBRenderer *m_Renderer;
	CBSoundMgr *m_SoundMgr;
	CScEngine *m_ScEngine;
	CSXMath *m_MathClass;
	CSXStore *m_Store;
	CBSurfaceStorage *m_SurfaceStorage;
	CBFontStorage *m_FontStorage;
	CBGame();

	virtual ~CBGame();
	void DEBUG_DebugDisable();
	void DEBUG_DebugEnable(const char *Filename = NULL);
	bool m_DEBUG_DebugMode;
	bool m_DEBUG_AbsolutePathWarning;

	void *m_DEBUG_LogFile;
	int m_Sequence;
	virtual HRESULT LoadFile(const char *Filename);
	virtual HRESULT LoadBuffer(byte  *Buffer, bool Complete = true);
	CBArray<CBQuickMsg *, CBQuickMsg *> m_QuickMessages;
	CBArray<CUIWindow *, CUIWindow *> m_Windows;
	CBArray<CBViewport *, CBViewport *> m_ViewportStack;

	int m_ViewportSP;
	bool m_MouseLeftDown;
	bool m_MouseRightDown;
	bool m_MouseMidlleDown;
	CBStringTable *m_StringTable;

	int m_SettingsResWidth;
	int m_SettingsResHeight;
	bool m_SettingsRequireAcceleration;
	bool m_SettingsAllowWindowed;
	bool m_SettingsAllowAdvanced;
	bool m_SettingsAllowAccessTab;
	bool m_SettingsAllowAboutTab;
	bool m_SettingsRequireSound;
	bool m_SettingsAllowDesktopRes;
	int m_SettingsTLMode;
	char *m_SettingsGameFile;
	CBFader *m_Fader;
	bool m_SuppressScriptErrors;

	virtual HRESULT InvalidateDeviceObjects();
	virtual HRESULT RestoreDeviceObjects();

	virtual void PublishNatives();
	virtual HRESULT ExternalCall(CScScript *Script, CScStack *Stack, CScStack *ThisStack, char *Name);
	// scripting interface
	virtual CScValue *ScGetProperty(char *Name);
	virtual HRESULT ScSetProperty(char *Name, CScValue *Value);
	virtual HRESULT ScCallMethod(CScScript *Script, CScStack *Stack, CScStack *ThisStack, char *Name);
	virtual char *ScToString();
	// compatibility bits
	bool m_CompatKillMethodThreads;

private:
	// FPS stuff
	uint32 m_LastTime;
	uint32 m_FpsTime;
	uint32 m_FramesRendered;

public:
	uint32 m_SurfaceGCCycleTime;
	bool m_SmartCache;
	bool m_VideoSubtitles;
	bool m_Subtitles;
	uint32 m_MusicStartTime[NUM_MUSIC_CHANNELS];
	bool m_CompressedSavegames;
	int m_ScheduledLoadSlot;
	bool m_Loading;
	bool m_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 m_Quitting;
	virtual HRESULT GetVersion(byte  *VerMajor, byte *VerMinor, byte *ExtMajor, byte *ExtMinor);

	virtual bool HandleKeypress(SDL_Event *event);
	int m_FreezeLevel;
	HRESULT Unfreeze();
	HRESULT Freeze(bool IncludingMusic = true);
	HRESULT FocusWindow(CUIWindow *Window);

	bool m_LoadInProgress;
	CUIWindow *m_FocusedWindow;
	bool m_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(char *Filename);
	HRESULT ResumeMusic(int Channel);
	HRESULT SetMusicStartTime(int Channel, uint32 Time);
	HRESULT PauseMusic(int Channel);
	HRESULT StopMusic(int Channel);
	HRESULT PlayMusic(int Channel, char *Filename, bool Looping = true, uint32 LoopStart = 0);
	CBSound *m_Music[NUM_MUSIC_CHANNELS];
	bool m_MusicCrossfadeRunning;
	bool m_MusicCrossfadeSwap;
	uint32 m_MusicCrossfadeStartTime;
	uint32 m_MusicCrossfadeLength;
	int m_MusicCrossfadeChannel1;
	int m_MusicCrossfadeChannel2;
	HRESULT DisplayWindows(bool InGame = false);
	CBRegistry *m_Registry;
	bool m_UseD3D;
	virtual HRESULT Cleanup();
	virtual HRESULT LoadGame(int Slot);
	virtual HRESULT LoadGame(char *Filename);
	virtual HRESULT SaveGame(int slot, char *desc, bool quickSave = false);
	virtual HRESULT ShowCursor();

	CBSprite *m_CursorNoninteractive;
	CBObject *m_ActiveObject;
	CBKeyboardState *m_KeyboardState;
	bool m_Interactive;
	TGameState m_State;
	TGameState m_OrigState;
	bool m_OrigInteractive;
	uint32 m_Timer;
	uint32 m_TimerDelta;
	uint32 m_TimerLast;

	uint32 m_LiveTimer;
	uint32 m_LiveTimerDelta;
	uint32 m_LiveTimerLast;

	CBObject *m_CapturedObject;
	POINT m_MousePos;
	bool ValidObject(CBObject *Object);
	HRESULT UnregisterObject(CBObject *Object);
	HRESULT RegisterObject(CBObject *Object);
	void QuickMessage(char *Text);
	void QuickMessageForm(LPSTR fmt, ...);
	HRESULT DisplayQuickMsg();
	uint32 m_Fps;
	HRESULT UpdateMusicCrossfade();

	CBArray<CBObject *, CBObject *> m_RegObjects;
public:
	virtual HRESULT DisplayContent(bool Update = true, bool DisplayAll = false);
	virtual HRESULT DisplayContentSimple();
	bool m_ForceNonStreamedSounds;
	void ResetMousePos();
	int m_SubtitlesSpeed;
	void SetInteractive(bool State);
	virtual HRESULT WindowLoadHook(CUIWindow *Win, char **Buf, char **Params);
	virtual HRESULT WindowScriptMethodHook(CUIWindow *Win, CScScript *Script, CScStack *Stack, 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 *m_LastCursor;
	HRESULT DrawCursor(CBSprite *Cursor);

	virtual HRESULT InitAfterLoad();
	CBSaveThumbHelper *m_CachedThumbnail;
	AnsiString GetDataDir();
	void AddMem(int bytes);

	bool m_TouchInterface;
	bool m_ConstrainedMemory;
	AnsiString GetDeviceType() const;

private:
	CBDebugger *m_DebugMgr;

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

		int PosX;
		int PosY;
		uint32 Time;
	};

	LastClickInfo m_LastClick[2];
	bool IsDoubleClick(int buttonIndex);
	uint32 m_UsedMem;



protected:
	// WME Lite specific
	bool m_AutoSaveOnExit;
	int m_AutoSaveSlot;
	bool m_CursorHidden;

public:
	void AutoSaveOnExit();

};

} // end of namespace WinterMute

#endif