My Project
ParaEngineApp.h
1 #pragma once
2 
3 
4 #ifdef PLATFORM_MAC
5  #include "platform/mac/ParaEngineApp.h"
6 #else
7 
8 
9 #include "ParaEngineAppBase.h"
10 #include "common/d3dapp.h"
11 #include "ITouchInputTranslator.h"
12 
13 #include <map>
14 
15 // forward declare
16 namespace ParaEngine
17 {
18  struct SpriteFontEntity;
19  class CDirectKeyboard;
20  class CGUIRoot;
21  class CSceneObject;
22  class CAISimulator;
23  class CParaWorldAsset;
24  class CAudioEngine;
25  class CWinRawMsgQueue;
26  class CViewportManager;
27  struct CWinRawMsg;
28 }
29 
76 namespace ParaEngine
77 {
97  {
98  public:
103  CParaEngineApp(const char* lpCmdLine);
106  CParaEngineApp();
107  virtual ~CParaEngineApp();
108 
110  virtual int Run(HINSTANCE hInstance);
111 
113  bool IsDebugBuild();
114 
118  virtual HRESULT DoWork();
119 
121  virtual void EnablePassiveRendering( bool bEnable );
123  virtual bool IsPassiveRenderingEnabled( );
124 
129  virtual void Enable3DRendering(bool bEnable);
130 
133  virtual bool Is3DRenderingEnabled();
134 
135 
137  virtual void SetFullScreenMode(bool bFullscreen);
138  virtual bool IsFullScreenMode();
139 
142  virtual void BringWindowToTop();
143 
147  virtual void SetAllowWindowClosing(bool bAllowClosing);
148  virtual bool IsWindowClosingAllowed();
149 
151  virtual void ShowMenu(bool bShow);
152 
154  virtual void GetScreenResolution(Vector2* pOut);
155  virtual void SetScreenResolution(const Vector2& vSize);
156 
157  virtual void GetResolution(float* pX, float* pY);
158  virtual void SetResolution(float x, float y);
159 
161  virtual int GetMultiSampleType();
162  virtual void SetMultiSampleType(int nType);
163 
165  virtual int GetMultiSampleQuality();
166  virtual void SetMultiSampleQuality(int nType);
167 
169  virtual bool UpdateScreenMode();
170 
171  // ParaEngine pipeline routines
173  virtual bool SetWindowedMode(bool bWindowed);
174 
176  virtual bool IsWindowedMode();
179  virtual void SetWindowText(const char* pChar);
181  virtual const char* GetWindowText();
182  virtual void FixWindowSize(bool fixed);
183 
189  virtual void GetStats(string& output, DWORD dwFields=0);
190 
199  bool WriteRegStr(const string& root_key, const string& sSubKey, const string& name, const string& value);
204  const char* ReadRegStr(const string& root_key, const string& sSubKey, const string& name);
205 
209  bool WriteRegDWORD(const string& root_key, const string& sSubKey, const string& name, DWORD value);
210 
214  DWORD ReadRegDWORD(const string& root_key, const string& sSubKey, const string& name);
215 
221  virtual void GetCursorPosition(int* pX,int * pY, bool bInBackbuffer = true);
222 
228  virtual void GameToClient(int& inout_x,int & inout_y, bool bInBackbuffer = true);
229 
235  virtual void ClientToGame(int& inout_x,int & inout_y, bool bInBackbuffer = true);
236 
241  virtual void WriteConfigFile(const char* sFileName);
242 
244  virtual bool HasNewConfig();
245 
247  virtual void SetHasNewConfig(bool bHasNewConfig);
248 
251  virtual void SetIgnoreWindowSizeChange(bool bIgnoreSizeChange);
252 
254  virtual bool GetIgnoreWindowSizeChange();
255 
258  virtual bool ForceRender();
259  public:
262  HRESULT OnCreateWindow();
263 
268  HRESULT ConfirmDevice( LPDIRECT3D9 pD3d, D3DCAPS9*, DWORD, D3DFORMAT, D3DFORMAT );
269 
271  HRESULT Init(HWND* pHWND);
272 
277  HRESULT OneTimeSceneInit();
278 
286  virtual HRESULT InitDeviceObjects();
287 
295  virtual HRESULT RestoreDeviceObjects();
296 
297 
305  virtual HRESULT Render();
306 
308  void GenerateD3DDebugString();
309 
317  virtual HRESULT FrameMove();
318  virtual HRESULT FrameMove(double fTime);
319 
327  virtual HRESULT InvalidateDeviceObjects();
334  virtual HRESULT DeleteDeviceObjects();
335 
339  virtual HRESULT FinalCleanup();
340 
341  public:
343  void HandleUserInput();
344 
345  virtual void SetMainWindow(HWND hWnd, bool bIsExternalWindow=true);
346  virtual HWND GetMainWindow();
347 
352  virtual HRESULT StartApp(const char* sCommandLine = 0);
353 
354  void InitSystemModules();
355 
356  void InitWin3DSettings();
357 
358  void InitLogger();
359 
360  void BootStrapAndLoadConfig();
361 
362  void InitApp(const char* sCommandLine);
363 
364  bool CheckClientLicense();
365 
366  void LoadAndApplySettings();
367 
368  virtual HRESULT StopApp();
369 
370  virtual LRESULT MsgProcWinThread( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool bCallDefProcedure = true);
371 
372  virtual LRESULT MsgProcWinThreadCustom( UINT uMsg, WPARAM wParam, LPARAM lParam);
373 
374  virtual LRESULT SendMessageToApp( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
375 
376  virtual bool PostWinThreadMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
377 
383  virtual bool GetMessageFromApp(CWinRawMsg* pMsg);
384 
389  virtual LRESULT MsgProcApp( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
390 
392  virtual HRESULT Create( HINSTANCE hInstance = 0 );
393 
394  virtual HRESULT CreateFromD3D9Device(IDirect3DDevice9* pD3dDevice, IDirect3DSwapChain9* apSwapChain);
395 
396  virtual HRESULT Render3DEnvironment(bool bForceRender = false);
397  virtual float GetFPS();
398  void UpdateFrameStats(double fTime);
399 
401  //void UpdateRecordingState();
402 
404  virtual HINSTANCE GetModuleHandle();
405 
406  virtual void SetRefreshTimer(float fTimeInterval, int nFrameRateControl = 0);
407 
408  virtual float GetRefreshTimer();
409 
410  virtual void GetWindowCreationSize(int * pWidth, int * pHeight);
411 
412  virtual PEAppState GetAppState();
413 
415  virtual void SetAppState(ParaEngine::PEAppState state);
416 
420  virtual void ActivateApp(bool bActivate);
421 
423  virtual bool IsAppActive();
424 
429  virtual DWORD GetCoreUsage();
430 
435  virtual void SetCoreUsage(DWORD dwUsage);
436 
445  virtual void SetMinUIResolution(int nWidth, int nHeight, bool bAutoUIScaling = true);
446 
451  virtual void Exit(int nReturnCode = 0);
452 
456  virtual bool HasFocus(HWND hWnd = 0);
457 
458  virtual bool IsTouchInputting(){ return m_isTouching; }
459  virtual bool IsSlateMode();
460 
461  // deprecated:
462  virtual int32 GetTouchPointX(){ return m_touchPointX; }
463  virtual int32 GetTouchPointY(){ return m_touchPointY; }
464 
465 
467  virtual bool IsServerMode();;
468  public:
470  void SetAutoLowerFrameRateWhenNotFocused(bool bEnabled);
471  bool GetAutoLowerFrameRateWhenNotFocused();
472 
474  void SetToggleSoundWhenNotFocused(bool bEnabled);
475  bool GetToggleSoundWhenNotFocused();
476 
478  bool AppHasFocus();
479 
482 
483  private:
484  bool UpdateScreenDevice();
485 
487  const char* GetTouchEventSCodeFromMessage(const char * event_type, HWND hWnd, WPARAM wParam, LPARAM lParam);
488 
490  void SetAppWndRect(const RECT& rect);
491  protected:
492  HINSTANCE m_hInstance; // app instance
493 
502 
503  CDirectKeyboard* m_pKeyboard;
504  float m_fAspectRatio; // Aspect ratio used by the FPS camera
505  CAudioEngine* m_pAudioEngine; // audio engine class
506 
507  bool m_bDrawReflection:1; // reflection-drawing option
508  bool m_bDisplayText:1; // whether to display text
509  bool m_bDisplayHelp:1; // whether to display help text
510  bool m_bServerMode:1;
511  // whether we are loaded from config/config.new.txt.
512  bool m_bHasNewConfig:1;
513  bool m_bAllowWindowClosing:1;
514  // default to false. if true, we will lower frame rate when the window is not focused.
515  bool m_bAutoLowerFrameRateWhenNotFocused:1;
516  // if true, sound volume will be set to 0, when not focused.
517  bool m_bToggleSoundWhenNotFocused:1;
518 
521 
522 
525  bool m_bIsKeyEvent;
526  bool m_bUpdateScreenDevice; // whether to toggle screen in the next frame
527 
528  // for keeping command line arguments.
529  std::string m_cmd;
530 
533 
536 
539 
542 
544  std::string m_sTitleString;
545 
548 
549  bool m_isSlateMode;
550  // deprecated:
551  int32 m_touchPointX;
552  int32 m_touchPointY;
553 
554  float m_fFPS;
555 
556  ITouchInputTranslator* m_pTouchInput;
557 
558  ITouchInputTranslator* LoadTouchInputPlug();
559 
560  };
561 
562 }
563 
564 #endif
virtual void ShowMenu(bool bShow)
turn on/off menu
Definition: ParaEngineApp.cpp:1473
virtual bool HasFocus(HWND hWnd=0)
this returns true if the main window or one of its child window has key focus.
Definition: ParaEngineApp.cpp:2209
virtual void Enable3DRendering(bool bEnable)
disable 3D rendering, do not present the scene.
Definition: ParaEngineApp.cpp:2076
virtual float GetRefreshTimer()
get the refresh timer.
Definition: ParaEngineApp.cpp:2111
virtual void GetStats(string &output, DWORD dwFields=0)
get the render engine stats to output.
Definition: ParaEngineApp.cpp:1337
bool AppHasFocus()
return true if app has focus.
Definition: ParaEngineApp.cpp:1079
HRESULT ConfirmDevice(LPDIRECT3D9 pD3d, D3DCAPS9 *, DWORD, D3DFORMAT, D3DFORMAT)
Called during device initialization, this code checks the device for some minimum set of capabilities...
Definition: ParaEngineApp.cpp:493
virtual LRESULT SendMessageToApp(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Send a RAW win32 message the application to be processed in the next main thread update interval...
Definition: ParaEngineApp.cpp:2247
virtual void SetMainWindow(HWND hWnd, bool bIsExternalWindow=true)
set the hWnd on to which we will render and process window messages.
Definition: ParaEngineApp.cpp:424
bool IsDebugBuild()
whether it is debug build.
Definition: ParaEngineApp.cpp:1301
virtual void ActivateApp(bool bActivate)
this function is called whenever the application is disabled or enabled.
Definition: ParaEngineApp.cpp:2134
virtual HINSTANCE GetModuleHandle()
change the cursor to indicate a movie recording state
Definition: ParaEngineApp.cpp:419
virtual DWORD GetCoreUsage()
Get the current ParaEngine app usage.
Definition: ParaEngineApp.cpp:2185
virtual int32 GetTouchPointX()
obsoleted function:
Definition: ParaEngineApp.h:462
virtual void WriteConfigFile(const char *sFileName)
write the current setting to config file.
Definition: ParaEngineApp.cpp:1557
CWinRawMsgQueue * m_pWinRawMsgQueue
The thread safe message queue target for receiving messages from window thread.
Definition: ParaEngineApp.h:532
virtual void EnablePassiveRendering(bool bEnable)
passive rendering, it will not render the scene, but simulation and time remains the same...
Definition: ParaEngineApp.cpp:2067
HRESULT OnCreateWindow()
this function should be called when the application is created.
Definition: ParaEngineApp.cpp:483
Definition: ParaEngineAppBase.h:11
virtual bool GetMessageFromApp(CWinRawMsg *pMsg)
get a message from the application message queue and remove it from the queue.
Definition: ParaEngineApp.cpp:2257
HRESULT Init(HWND *pHWND)
init application
Definition: ParaEngineApp.cpp:558
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual void SetAppState(ParaEngine::PEAppState state)
set application state
Definition: ParaEngineApp.cpp:2129
virtual void SetMinUIResolution(int nWidth, int nHeight, bool bAutoUIScaling=true)
set the minimum UI resolution size.
Definition: ParaEngineApp.cpp:2195
virtual HRESULT Create(HINSTANCE hInstance=0)
create instance
Definition: ParaEngineApp.cpp:465
Class: CAudioEngine.
Definition: AudioEngine.h:49
void GenerateD3DDebugString()
Output text information to console, for debugging only.
Definition: ParaEngineApp.cpp:1156
Definition: ManagedDef.h:18
virtual void GameToClient(int &inout_x, int &inout_y, bool bInBackbuffer=true)
translate a position from game coordination system to client window position.
Definition: ParaEngineApp.cpp:1666
virtual void SetHasNewConfig(bool bHasNewConfig)
set whether ParaEngine is loaded from config/config.new.txt.
Definition: ParaEngineApp.cpp:1639
virtual bool ForceRender()
render the current frame and does not return until everything is presented to screen.
Definition: ParaEngineApp.cpp:3227
HWND m_hwndTopLevelWnd
set foreground window
Definition: ParaEngineApp.h:547
virtual void GetCursorPosition(int *pX, int *pY, bool bInBackbuffer=true)
get the current mouse cursor position.
Definition: ParaEngineApp.cpp:1644
int m_nInitialGameEffectSet
initial game effect setting to be loaded from the config file.
Definition: ParaEngineApp.h:520
virtual LRESULT MsgProcWinThread(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool bCallDefProcedure=true)
the window message processor.
Definition: ParaEngineApp.cpp:2371
virtual const char * GetWindowText()
get the window title when at windowed mode
Definition: ParaEngineApp.cpp:1548
Definition: GUIDirectInput.h:106
virtual void GetResolution(float *pX, float *pY)
change the full screen mode, it does not immediately change the device, call UpdateScreenMode() to up...
Definition: ParaEngineApp.cpp:1401
bool WriteRegDWORD(const string &root_key, const string &sSubKey, const string &name, DWORD value)
Write a DWORD to the registry.
Definition: ParaEngineApp.cpp:1937
virtual bool HasNewConfig()
get whether ParaEngine is loaded from config/config.new.txt.
Definition: ParaEngineApp.cpp:1634
virtual void SetIgnoreWindowSizeChange(bool bIgnoreSizeChange)
switch to ignore windows size change.
Definition: ParaEngineApp.cpp:1511
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
virtual HRESULT FrameMove()
This callback function will be called once at the beginning of every frame.
Definition: ParaEngineApp.cpp:918
virtual HRESULT RestoreDeviceObjects()
This callback function will be called immediately after the Direct3D device has been reset...
Definition: ParaEngineApp.cpp:759
std::string m_sTitleString
for debugging display
Definition: ParaEngineApp.h:544
virtual PEAppState GetAppState()
get application state
Definition: ParaEngineApp.cpp:2124
virtual void GetWindowCreationSize(int *pWidth, int *pHeight)
get the window creation size in default application config.
Definition: ParaEngineApp.cpp:2116
void SetToggleSoundWhenNotFocused(bool bEnabled)
if true, sound volume will be set to 0, when not focused.
Definition: ParaEngineApp.cpp:2237
raw win32 message
Definition: OSWindows.h:27
DWORD m_dwWinThreadID
the thread id of the main window thread.
Definition: ParaEngineApp.h:535
virtual bool Is3DRenderingEnabled()
whether 3D rendering is enabled, do not present the scene.
Definition: ParaEngineApp.cpp:2083
virtual bool IsAppActive()
whether the application is active or not.
Definition: ParaEngineApp.cpp:2178
const char * ReadRegStr(const string &root_key, const string &sSubKey, const string &name)
Read string from the registry.
Definition: ParaEngineApp.cpp:1858
HRESULT OneTimeSceneInit()
This function should be called only once when the application start, one can initialize game objects ...
Definition: ParaEngineApp.cpp:721
The ref_ptr class template stores a pointer to a dynamically allocated (AssetEntity|CRefCounted|BaseA...
Definition: PERefPtr.h:13
bool m_bAppHasFocus
whether app has focus.
Definition: ParaEngineApp.h:541
virtual HRESULT DoWork()
this function is called per frame, in most cases, it will render the 3d scene and frame move...
Definition: ParaEngineApp.cpp:2088
A base class for creating D3D device based application.
Definition: d3dapp.h:13
virtual HRESULT DeleteDeviceObjects()
This callback function will be called immediately after the Direct3D device has been destroyed...
Definition: ParaEngineApp.cpp:844
virtual void SetRefreshTimer(float fTimeInterval, int nFrameRateControl=0)
Set the frame rate timer interval.
Definition: ParaEngineApp.cpp:2098
virtual bool IsServerMode()
server mode has no user interface
Definition: ParaEngineApp.cpp:199
virtual void ClientToGame(int &inout_x, int &inout_y, bool bInBackbuffer=true)
translate a position from client window position to game coordination system.
Definition: ParaEngineApp.cpp:1684
virtual HRESULT InitDeviceObjects()
This callback function will be called immediately after the Direct3D device has been created...
Definition: ParaEngineApp.cpp:732
virtual bool IsWindowedMode()
return true if it is currently under windowed mode.
Definition: ParaEngineApp.cpp:1457
Definition: enum_maker.hpp:46
ref_ptr< CViewportManager > m_pViewportManager
viewport
Definition: ParaEngineApp.h:499
virtual void Exit(int nReturnCode=0)
Send the exit message, so that the game engine will prepare to exit in the next frame.
Definition: ParaEngineApp.cpp:3155
virtual int GetMultiSampleQuality()
anti-aliasing for both windowed and full screen mode.
Definition: ParaEngineApp.cpp:1431
DWORD m_dwCoreUsage
the Core usage.
Definition: ParaEngineApp.h:538
CParaEngineApp()
One needs to manually start the application.
Definition: ParaEngineApp.cpp:153
CViewportManager * GetViewportManager()
managing multiple 3d views
Definition: ParaEngineApp.cpp:175
the message queue.
Definition: OSWindows.h:53
virtual void BringWindowToTop()
The BringWindowToTop current window to the top of the Z order.
Definition: ParaEngineApp.cpp:1728
virtual int GetMultiSampleType()
anti-aliasing for both windowed and full screen mode.
Definition: ParaEngineApp.cpp:1420
void HandleUserInput()
process game input.
Definition: ParaEngineApp.cpp:1360
virtual void SetAllowWindowClosing(bool bAllowClosing)
whether the user can close the window (sending WM_CLOSE message).
Definition: ParaEngineApp.cpp:473
virtual bool IsTouchInputting()
whether the last mouse input is from touch or mouse.
Definition: ParaEngineApp.h:458
ref_ptr< CSceneObject > m_pRootScene
3d scene root object
Definition: ParaEngineApp.h:497
virtual HRESULT Render3DEnvironment(bool bForceRender=false)
Frame move and render a frame during idle time (no messages are waiting).
Definition: ParaEngineApp.cpp:2093
virtual bool GetIgnoreWindowSizeChange()
return true if it is currently under windowed mode.
Definition: ParaEngineApp.cpp:1516
virtual int Run(HINSTANCE hInstance)
only call this function if one does not want to manage game loop externally.
Definition: ParaEngineApp.cpp:1310
void SetAutoLowerFrameRateWhenNotFocused(bool bEnabled)
default to false. if true, we will lower frame rate when the window is not focused.
Definition: ParaEngineApp.cpp:2227
virtual HRESULT StartApp(const char *sCommandLine=0)
call this function to create the ParaEngine main rendering device based on the current window...
Definition: ParaEngineApp.cpp:353
virtual void SetWindowText(const char *pChar)
set the window title when at windowed mode
Definition: ParaEngineApp.cpp:1541
virtual void SetFullScreenMode(bool bFullscreen)
whether to use full screen mode, it does not immediately change the device, call UpdateScreenMode() t...
Definition: ParaEngineApp.cpp:1462
PEAppState
ParaEngine application state.
Definition: IParaEngineApp.h:40
virtual HRESULT Render()
This callback function will be called at the end of every frame to perform all the rendering calls fo...
Definition: ParaEngineApp.cpp:1235
virtual bool PostWinThreadMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
post a raw win32 message from any thread to the thread on which hWnd is created.
Definition: ParaEngineApp.cpp:2274
int m_nWindowedDesired
1 window mode desired, 0 full screen mode desired, -1 if unknown.
Definition: ParaEngineApp.h:524
virtual void SetCoreUsage(DWORD dwUsage)
Set the current ParaEngine app usage.
Definition: ParaEngineApp.cpp:2190
virtual HRESULT InvalidateDeviceObjects()
This callback function will be called immediately after the Direct3D device has entered a lost state ...
Definition: ParaEngineApp.cpp:829
virtual bool SetWindowedMode(bool bWindowed)
switch to either windowed mode or full screen mode.
Definition: ParaEngineApp.cpp:1448
virtual HRESULT StopApp()
This is the last function that should be called.
Definition: ParaEngineApp.cpp:376
manager multiple viewport
Definition: ViewportManager.h:18
Definition: ITouchInputTranslator.h:22
virtual Vector2 GetScreenResolution()
change the full screen mode, it does not immediately change the device, call UpdateScreenMode() to up...
Definition: ParaEngineApp.cpp:429
virtual HRESULT FinalCleanup()
This function should be called only once when the application end, one can destroy game objects here...
Definition: ParaEngineApp.cpp:861
This class demonstrate how to initialize, destroy and drive the game loop of ParaEngine through the C...
Definition: ParaEngineApp.h:96
ref_ptr< CParaWorldAsset > m_pParaWorldAsset
asset manager
Definition: ParaEngineApp.h:501
virtual bool UpdateScreenMode()
call this function to update changes of FullScreen Mode and Screen Resolution.
Definition: ParaEngineApp.cpp:1442
ref_ptr< CGUIRoot > m_pGUIRoot
2d gui root
Definition: ParaEngineApp.h:495
virtual bool IsPassiveRenderingEnabled()
passive rendering, it will not render the scene, but simulation and time remains the same...
Definition: ParaEngineApp.cpp:2071
virtual LRESULT MsgProcApp(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Before handling window messages, application should pass incoming windows messages to the application...
Definition: ParaEngineApp.cpp:2781
void InitWin3DSettings()
Definition: ParaEngineApp.cpp:242
bool WriteRegStr(const string &root_key, const string &sSubKey, const string &name, const string &value)
Write a string to the registry.
Definition: ParaEngineApp.cpp:1833
DWORD ReadRegDWORD(const string &root_key, const string &sSubKey, const string &name)
Read DWORD from the registry.
Definition: ParaEngineApp.cpp:1969