My Project
ParaEngineAppBase.h
1 #pragma once
2 #include "IParaEngineApp.h"
3 #include "CommandLineParams.h"
4 
5 namespace ParaEngine
6 {
7  class CParaEngineApp;
8  class CObjectAutoReleasePool;
9 
10  /* base implementation of ParaEngine APP, shared by both mobile and pc version. */
12  {
13  public:
15  CParaEngineAppBase(const char* sCmd);
17  static CParaEngineApp* GetInstance();
18  static void SetCurrentInstance(CParaEngineApp* pInstance);
19  virtual LifetimeType LifetimeControl();
20  virtual BaseInterface* AcquireInterface();
21  virtual void ReleaseInterface();
22  virtual void DeleteInterface();
23  virtual ~CParaEngineAppBase();
24 
25 
27  virtual void OnFrameEnded();
28 
29  void DoTestCode();
30  public:
31  virtual void WriteToLog(const char* sFormat, ...);
32  virtual void AppLog(const char* sFormat);
34  virtual bool FindParaEngineDirectory(const char* sHint = NULL);
35 
36  void AutoSetLocale();
37 
42  virtual void Enable3DRendering(bool bEnable);
43 
46  virtual bool Is3DRenderingEnabled();
47 
49  virtual bool IsTouchInputting();
50  virtual void SetTouchInputting(bool bTouchInputting);
51  virtual bool IsSlateMode();
53  virtual int32 GetTouchPointX() { return 0; };
54  virtual int32 GetTouchPointY() { return 0; };
55 
61  virtual void GetCursorPosition(int* pX, int * pY, bool bInBackbuffer = true);
62 
68  virtual void GameToClient(int& inout_x, int & inout_y, bool bInBackbuffer = true) { };
69 
75  virtual void ClientToGame(int& inout_x, int & inout_y, bool bInBackbuffer = true){ };
76 
79  virtual void SetIgnoreWindowSizeChange(bool bIgnoreSizeChange){};
80 
82  virtual bool GetIgnoreWindowSizeChange(){ return false; };
83 
85  virtual HINSTANCE GetModuleHandle() { return 0; };
86 
93  virtual void SetRefreshTimer(float fTimeInterval, int nFrameRateControl = 0) { };
94 
97  virtual float GetRefreshTimer() { return 0; };
98 
102  virtual void ActivateApp(bool bActivate) { };
103 
105  virtual bool IsAppActive();
106 
111  virtual DWORD GetCoreUsage();
112 
117  virtual void SetCoreUsage(DWORD dwUsage) { };
118 
119 
123  virtual void SetReturnCode(int nReturnCode);
124  virtual int GetReturnCode();
125 
127  virtual void SystemMessageBox(const std::string& msg);
128 
133  virtual void SetAppCommandLine(const char* pCommandLine);
134 
136  virtual const char* GetAppCommandLine();
137 
143  virtual const char* GetAppCommandLineByParam(const char* pParam, const char* defaultValue);
144  public:
149  virtual HRESULT StartApp(const char* sCommandLine = 0) { return S_OK; };
150 
153  virtual HRESULT StopApp() { return S_OK; };
154 
156  virtual HRESULT Init(HWND* pHWND) { return S_OK; };
157 
162  virtual void Exit(int nReturnCode = 0);
163 
165  virtual void SetAppState(ParaEngine::PEAppState state);
166 
167  virtual HRESULT FrameMove(double fTime){ return S_OK; };
171  virtual HRESULT FinalCleanup();
172 
173  // following contains null implementation
180  virtual void SetMainWindow(HWND hWnd, bool bIsExternalWindow = true) { };
181  virtual HWND GetMainWindow() { return 0; };
182 
184  virtual int Run(HINSTANCE hInstance){ return 0; };
185 
189  virtual HRESULT DoWork() { return 0; };
190 
194  virtual HRESULT CreateFromD3D9Device(IDirect3DDevice9* pD3dDevice, IDirect3DSwapChain9* apSwapChain) { return 0; };
195 
203  virtual HRESULT InitDeviceObjects() { return S_OK;}
204 
212  virtual HRESULT RestoreDeviceObjects() { return S_OK; }
213 
221  virtual HRESULT InvalidateDeviceObjects() { return S_OK; }
228  virtual HRESULT DeleteDeviceObjects() { return S_OK; }
229 
233  virtual HRESULT Create(HINSTANCE hInstance = 0) { return 0; };
234 
240  virtual HRESULT Render3DEnvironment(bool bForceRender = false) { return S_OK; }
241 
247  virtual LRESULT MsgProcWinThread(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool bCallDefProcedure = true) { return 0; };
248 
249  /*** process win thread messages without a hWnd. Such messages are usually invoked by PostWinThreadMessage() from other threads. */
250  virtual LRESULT MsgProcWinThreadCustom(UINT uMsg, WPARAM wParam, LPARAM lParam) { return 0; };
251 
255  virtual LRESULT SendMessageToApp(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return 0; };
256 
258  virtual bool PostWinThreadMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { return false; };
259 
265  virtual bool GetMessageFromApp(CWinRawMsg* pMsg) { return false; };
266 
270  virtual LRESULT MsgProcApp(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return 0; };
271 
273  virtual void EnablePassiveRendering(bool bEnable) { };
274 
276  virtual bool IsPassiveRenderingEnabled() { return false; };
277 
280  virtual void BringWindowToTop() { };
281 
285  virtual void SetAllowWindowClosing(bool bAllowClosing) { };
286  virtual bool IsWindowClosingAllowed() { return false; };
287 
289  virtual void SetFullScreenMode(bool bFullscreen){};
290  virtual bool IsFullScreenMode(){ return false; };
291 
293  virtual void ShowMenu(bool bShow){};
294 
296  virtual void GetScreenResolution(Vector2* pOut) { *pOut = Vector2::ZERO; };
297  virtual void SetScreenResolution(const Vector2& vSize){};
298 
300  virtual int GetMultiSampleType(){ return 0; };
301  virtual void SetMultiSampleType(int nType){};
302 
304  virtual int GetMultiSampleQuality(){ return 0; };
305  virtual void SetMultiSampleQuality(int nType){};
306 
308  virtual bool UpdateScreenMode(){ return false; };
309 
310  // ParaEngine pipeline routines
312  virtual bool SetWindowedMode(bool bWindowed){ return false; };
314  virtual bool IsWindowedMode(){ return true; };
316  virtual void SetWindowText(const char* pChar) {};
318  virtual const char* GetWindowText() { return ""; };
319  /* */
320  virtual void FixWindowSize(bool fixed) {};
321 
322 
327  virtual void WriteConfigFile(const char* sFileName) {};
328 
330  virtual bool HasNewConfig() { return false; };
331 
333  virtual void SetHasNewConfig(bool bHasNewConfig) {};
334 
335 
337  virtual void GetWindowCreationSize(int * pWidth, int * pHeight) {};
338 
347  virtual void SetMinUIResolution(int nWidth, int nHeight, bool bAutoUIScaling = true) { };
348 
350  virtual void GetResolution(float* pX, float* pY) {};
351  virtual void SetResolution(float x, float y) {};
352 
354  virtual NPL::INPLRuntime* GetNPLRuntime();
355 
360 
364  virtual bool HasClosingRequest();
365  virtual void SetHasClosingRequest(bool val);
366 
373  virtual bool LoadNPLPackage(const char* sFilePath, std::string * pOutMainFile = NULL);
374 
377  virtual bool FindBootStrapper();
378 
380  virtual bool InitCommandLineParams();
381 
382 
385  virtual bool ForceRender();
386 
388  virtual const char* GetModuleDir();;
389  public:
392 
393  virtual void VerifyCommandLine(const char* sCommandLine, std::string &strCmd);
394 
395  protected:
397  void InitCommon();
398  void DestroySingletons();
399 
404  void LoadPackages();
405  void LoadPackagesInFolder(const std::string& sPkgFolder);
406 
408  void RegisterObjectClass(IAttributeFields* pObject);
409 
411  void RegisterObjectClasses();
412  protected:
413  static CParaEngineApp* g_pCurrentApp;
414  bool m_bEnable3DRendering;
415  bool m_isTouching;
416  bool m_hasClosingRequest;
422  std::string m_sPackagesDir;
424  std::string m_sModuleDir;
426  std::string m_sInitialWorkingDir;
429  };
430 }
431 
virtual void SetAppState(ParaEngine::PEAppState state)
set application state
Definition: ParaEngineAppBase.cpp:301
void InitCommon()
shared init called in constructor.
Definition: ParaEngineAppBase.cpp:170
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: ParaEngineAppBase.h:255
PEAppState m_nAppState
application state
Definition: ParaEngineAppBase.h:428
virtual int GetMultiSampleType()
anti-aliasing for both windowed and full screen mode.
Definition: ParaEngineAppBase.h:300
virtual LRESULT MsgProcApp(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
handle a message in the main application thread.
Definition: ParaEngineAppBase.h:270
virtual HRESULT DeleteDeviceObjects()
This callback function will be called immediately after the Direct3D device has been destroyed...
Definition: ParaEngineAppBase.h:228
virtual bool HasNewConfig()
get whether ParaEngine is loaded from config/config.new.txt.
Definition: ParaEngineAppBase.h:330
virtual void SetFullScreenMode(bool bFullscreen)
whether to use full screen mode, it does not immediately change the device, call UpdateScreenMode() t...
Definition: ParaEngineAppBase.h:289
virtual int GetMultiSampleQuality()
anti-aliasing for both windowed and full screen mode.
Definition: ParaEngineAppBase.h:304
void RegisterObjectClasses()
register any custom classes
Definition: ParaEngineAppBase.cpp:194
The base class for interfaces in ParaEngine.
Definition: baseinterface.h:29
virtual bool IsTouchInputting()
whether the last mouse input is from touch or mouse.
Definition: ParaEngineAppBase.cpp:222
virtual HRESULT Render3DEnvironment(bool bForceRender=false)
Frame move and render a frame during idle time (no messages are waiting).
Definition: ParaEngineAppBase.h:240
static CParaEngineApp * GetInstance()
the singleton application.
Definition: ParaEngineAppBase.cpp:90
Definition: ParaEngineAppBase.h:11
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual void GameToClient(int &inout_x, int &inout_y, bool bInBackbuffer=true)
translate a position from game coordination system to client window position.
Definition: ParaEngineAppBase.h:68
virtual HRESULT CreateFromD3D9Device(IDirect3DDevice9 *pD3dDevice, IDirect3DSwapChain9 *apSwapChain)
create from an existing d3d device.
Definition: ParaEngineAppBase.h:194
virtual const char * GetWindowText()
get the window title when at windowed mode
Definition: ParaEngineAppBase.h:318
virtual void SetCoreUsage(DWORD dwUsage)
Set the current ParaEngine app usage.
Definition: ParaEngineAppBase.h:117
virtual void SystemMessageBox(const std::string &msg)
show a system message box to the user.
Definition: ParaEngineAppBase.cpp:252
virtual HRESULT DoWork()
this function is called per frame, in most cases, it will render the 3d scene and frame move...
Definition: ParaEngineAppBase.h:189
virtual void BringWindowToTop()
The BringWindowToTop current window to the top of the Z order.
Definition: ParaEngineAppBase.h:280
virtual HRESULT Init(HWND *pHWND)
init application
Definition: ParaEngineAppBase.h:156
virtual const char * GetAppCommandLineByParam(const char *pParam, const char *defaultValue)
return a specified parameter value in the command line of the application.
Definition: ParaEngineAppBase.cpp:284
CObjectAutoReleasePool * m_pSingletonReleasePool
a pool of registered singleton object.
Definition: ParaEngineAppBase.h:420
virtual int Run(HINSTANCE hInstance)
only call this function if one does not want to manage game loop externally.
Definition: ParaEngineAppBase.h:184
virtual bool FindBootStrapper()
check if there is bootstrapper file specified at command line, if not it will use NPL code wiki admin...
Definition: ParaEngineAppBase.cpp:641
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
virtual HRESULT Create(HINSTANCE hInstance=0)
create d3d render device based on the current main window.
Definition: ParaEngineAppBase.h:233
void LoadPackagesInFolder(const std::string &sPkgFolder)
Definition: ParaEngineAppBase.cpp:571
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
Definition: PERef.h:11
std::string m_sModuleDir
bin/ module path
Definition: ParaEngineAppBase.h:424
virtual DWORD GetCoreUsage()
Get the current ParaEngine app usage.
Definition: ParaEngineAppBase.cpp:247
virtual bool ForceRender()
render the current frame and does not return until everything is presented to screen.
Definition: ParaEngineAppBase.cpp:160
raw win32 message
Definition: OSWindows.h:27
void LoadPackages()
we will load all packages that matches the following pattern in the order given by their name...
Definition: ParaEngineAppBase.cpp:670
virtual HRESULT FinalCleanup()
This function should be called only once when the application end, one can destroy game objects here...
Definition: ParaEngineAppBase.cpp:306
CViewportManager * GetViewportManager()
managing multiple 3d views
Definition: ParaEngineAppBase.h:391
virtual bool SetWindowedMode(bool bWindowed)
switch to either windowed mode or full screen mode.
Definition: ParaEngineAppBase.h:312
virtual void GetScreenResolution(Vector2 *pOut)
change the full screen mode, it does not immediately change the device, call UpdateScreenMode() to up...
Definition: ParaEngineAppBase.h:296
virtual HINSTANCE GetModuleHandle()
get the module handle, it may be exe or the dll handle, depending on how the main host app is built...
Definition: ParaEngineAppBase.h:85
virtual const char * GetModuleDir()
get the NPL bin directory (main executable directory).
Definition: ParaEngineAppBase.cpp:165
virtual void AppLog(const char *sFormat)
write app log to file with time and code location.
Definition: ParaEngineAppBase.cpp:555
virtual void ActivateApp(bool bActivate)
this function is called whenever the application is disabled or enabled.
Definition: ParaEngineAppBase.h:102
virtual bool Is3DRenderingEnabled()
whether 3D rendering is enabled, do not present the scene.
Definition: ParaEngineAppBase.cpp:212
virtual void SetHasNewConfig(bool bHasNewConfig)
set whether ParaEngine is loaded from config/config.new.txt.
Definition: ParaEngineAppBase.h:333
virtual bool FindParaEngineDirectory(const char *sHint=NULL)
set the current working directory.
Definition: ParaEngineAppBase.cpp:710
virtual bool GetIgnoreWindowSizeChange()
return true if it is currently under windowed mode.
Definition: ParaEngineAppBase.h:82
A common interface for all classes implementing IAttributeFields By implementing this class's virtual...
Definition: IAttributeFields.h:59
void RegisterObjectClass(IAttributeFields *pObject)
register a given class.
Definition: ParaEngineAppBase.cpp:185
virtual bool IsAppActive()
whether the application is active or not.
Definition: ParaEngineAppBase.cpp:242
virtual void Enable3DRendering(bool bEnable)
disable 3D rendering, do not present the scene.
Definition: ParaEngineAppBase.cpp:217
virtual ParaEngine::PEAppState GetAppState()
get application state
Definition: ParaEngineAppBase.cpp:296
virtual const char * GetAppCommandLine()
get string specifying the command line for the application, excluding the program name...
Definition: ParaEngineAppBase.cpp:279
virtual void GetWindowCreationSize(int *pWidth, int *pHeight)
get the window creation size in default application config.
Definition: ParaEngineAppBase.h:337
virtual bool LoadNPLPackage(const char *sFilePath, std::string *pOutMainFile=NULL)
load NPL package from a disk folder.
Definition: ParaEngineAppBase.cpp:391
when base object is created it has zero reference, and is usually added to auto release pool to be re...
Definition: ObjectAutoReleasePool.h:10
virtual void ShowMenu(bool bShow)
turn on/off menu
Definition: ParaEngineAppBase.h:293
virtual void SetMinUIResolution(int nWidth, int nHeight, bool bAutoUIScaling=true)
set the minimum UI resolution size.
Definition: ParaEngineAppBase.h:347
virtual LRESULT MsgProcWinThread(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool bCallDefProcedure=true)
the window message processor.
Definition: ParaEngineAppBase.h:247
virtual int32 GetTouchPointX()
obsoleted function:
Definition: ParaEngineAppBase.h:53
virtual void GetResolution(float *pX, float *pY)
change the full screen mode, it does not immediately change the device, call UpdateScreenMode() to up...
Definition: ParaEngineAppBase.h:350
std::string m_sPackagesDir
packages/ directory path
Definition: ParaEngineAppBase.h:422
PEAppState
ParaEngine application state.
Definition: IParaEngineApp.h:40
virtual void SetReturnCode(int nReturnCode)
Get the exit code that will be used when the standalone executable exit.
Definition: ParaEngineAppBase.cpp:560
virtual void SetAllowWindowClosing(bool bAllowClosing)
whether the user can close the window (sending WM_CLOSE message).
Definition: ParaEngineAppBase.h:285
virtual void WriteToLog(const char *sFormat,...)
append text to log file.
Definition: ParaEngineAppBase.cpp:547
virtual bool IsWindowedMode()
return true if it is currently under windowed mode.
Definition: ParaEngineAppBase.h:314
virtual HRESULT StopApp()
This is the last function that should be called.
Definition: ParaEngineAppBase.h:153
virtual void SetRefreshTimer(float fTimeInterval, int nFrameRateControl=0)
Set the frame rate timer interval.
Definition: ParaEngineAppBase.h:93
virtual HRESULT InitDeviceObjects()
This callback function will be called immediately after the Direct3D device has been created...
Definition: ParaEngineAppBase.h:203
virtual void SetMainWindow(HWND hWnd, bool bIsExternalWindow=true)
set the hWnd on to which we will render and process window messages.
Definition: ParaEngineAppBase.h:180
virtual void SetIgnoreWindowSizeChange(bool bIgnoreSizeChange)
switch to ignore windows size change.
Definition: ParaEngineAppBase.h:79
virtual void SetTouchInputting(bool bTouchInputting)
whether the last mouse input is from touch or mouse.
Definition: ParaEngineAppBase.cpp:232
virtual void OnFrameEnded()
call this function at the end of the frame.
Definition: ParaEngineAppBase.cpp:112
virtual HRESULT StartApp(const char *sCommandLine=0)
This is the first function that should be called when acquiring the IParaEngineApp interface...
Definition: ParaEngineAppBase.h:149
int m_nReturnCode
the application exit code or return code.
Definition: ParaEngineAppBase.h:418
a table of virtual functions which are used by plug-ins to access the game engine ...
Definition: IParaEngineApp.h:98
virtual HRESULT RestoreDeviceObjects()
This callback function will be called immediately after the Direct3D device has been reset...
Definition: ParaEngineAppBase.h:212
std::string m_sInitialWorkingDir
initial working directory
Definition: ParaEngineAppBase.h:426
manager multiple viewport
Definition: ViewportManager.h:18
virtual void WriteConfigFile(const char *sFileName)
write the current setting to config file.
Definition: ParaEngineAppBase.h:327
virtual bool UpdateScreenMode()
call this function to update changes of FullScreen Mode and Screen Resolution.
Definition: ParaEngineAppBase.h:308
virtual void ClientToGame(int &inout_x, int &inout_y, bool bInBackbuffer=true)
translate a position from client window position to game coordination system.
Definition: ParaEngineAppBase.h:75
virtual void SetWindowText(const char *pChar)
set the window title when at windowed mode
Definition: ParaEngineAppBase.h:316
virtual bool HasClosingRequest()
whether there is closing request in the message queue.
Definition: ParaEngineAppBase.cpp:380
virtual bool GetMessageFromApp(CWinRawMsg *pMsg)
get a message from the application message queue and remove it from the queue.
Definition: ParaEngineAppBase.h:265
NPL Runtime Environment interface.
Definition: INPLRuntime.h:30
command line parameters.
Definition: CommandLineParams.h:8
virtual void Exit(int nReturnCode=0)
Send the exit message, so that the game engine will prepare to exit in the next frame.
Definition: ParaEngineAppBase.cpp:289
virtual void GetCursorPosition(int *pX, int *pY, bool bInBackbuffer=true)
get the current mouse cursor position.
Definition: ParaEngineAppBase.cpp:237
This class demonstrate how to initialize, destroy and drive the game loop of ParaEngine through the C...
Definition: ParaEngineApp.h:96
virtual HRESULT InvalidateDeviceObjects()
This callback function will be called immediately after the Direct3D device has entered a lost state ...
Definition: ParaEngineAppBase.h:221
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: ParaEngineAppBase.h:258
virtual bool InitCommandLineParams()
parse common command line parameters
Definition: ParaEngineAppBase.cpp:117
virtual CRefCounted * AddToSingletonReleasePool(CRefCounted *pObject)
we will automatically release singleton object when app stops, in the verse order when object is adde...
Definition: ParaEngineAppBase.cpp:330
virtual NPL::INPLRuntime * GetNPLRuntime()
get the NPL runtime system associate with the application.
Definition: ParaEngineAppBase.cpp:325
virtual float GetRefreshTimer()
get the refresh timer.
Definition: ParaEngineAppBase.h:97
virtual void SetAppCommandLine(const char *pCommandLine)
set string specifying the command line for the application, excluding the program name...
Definition: ParaEngineAppBase.cpp:260
virtual void EnablePassiveRendering(bool bEnable)
passive rendering, it will not render the scene, but simulation and time remains the same...
Definition: ParaEngineAppBase.h:273
virtual bool IsPassiveRenderingEnabled()
passive rendering, it will not render the scene, but simulation and time remains the same...
Definition: ParaEngineAppBase.h:276