My Project
InterprocessAppClient.h
1 #pragma once
2 #include <boost/thread.hpp>
3 #include <boost/shared_ptr.hpp>
4 #include <boost/asio.hpp>
5 #include "util/Mutex.hpp"
6 #include "ipc_message_queue.hpp"
7 #include "InterprocessQueue.hpp"
8 #include "IParaEngineApp.h"
9 #include "InterprocessMsg.h"
10 #include "AutoUpdaterApp.h"
11 #include <boost/asio/steady_timer.hpp>
12 
13 namespace ParaEngine
14 {
15  class CMyProcessAppThread;
16  class CCommandLineParser;
17 
20  {
21  public:
23 
24  CInterprocessAppClient(const char* appName = NULL);
26 
27  public:
29  void SetAppName(const char* appName);
30 
32  virtual int SetCommandLine(const char* sCmdLine);
33 
35  int Run(HINSTANCE hInst, const char* sCmdLine);
36  public:
38  void SetParentWindow(HWND hWndParent);
39 
40  int Start(int nMinResolutionWidth = 0, int nMinResolutionHeight = 0);
41 
42  int Stop();
43 
44  HWND GetMainHWnd(){return m_hWnd;}
45 
47  virtual bool SendHostMsg(int nMsg, DWORD param1 = 0, DWORD param2 = 0, const char* filename = NULL, const char* sCode = NULL, int nPriority = 0);
48 
49  protected:
50  static LRESULT CALLBACK DefaultWinThreadWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
51 
54 
56  bool CheckLoad();
57 
59  void handle_mainloop_timer(const boost::system::error_code& err);
60 
61  double GetElapsedAppTime();
62 
66  HRESULT StartWindowThread();
67  void DefaultWinThreadProc();
68 
70  void PrintGetLastError();
71 
73  void EnableAutoUpdateWhenComplete(bool bEnable);
74 
75  protected:
77  std::string m_app_name;
79  std::string m_app_host;
80  std::string m_sUsage;
83  int m_nMinWidth;
84  int m_nMinHeight;
85 
86  HWND m_hWndParent;
87  bool m_bStarted;
88  ParaEngine::CPluginLoader m_ParaEngine_plugin;
89  ParaEngine::IParaEngineCore* m_pParaEngine;
90  ParaEngine::IParaEngineApp * m_pParaEngineApp;
91 
92 
93  CInterprocessQueue* m_ipAppQueueIn;
94  CInterprocessQueue* m_ipHostQueueOut;
95 
96  bool m_bQuit;
97  bool m_bMainLoopExited;
98 
99  ParaEngine::Mutex m_mutex;
100 
102  boost::asio::io_service m_main_io_service;
104  boost::asio::steady_timer m_main_timer;
105  // main render window hWnd.
106  HWND m_hWnd;
107 
108  std::string m_sRedistDir;
109 
110  Domain_Map_t m_trusted_domains;
111 
112  // the default window thread ptr.
113  Boost_Thread_ptr_type m_win_thread;
114  ParaEngine::Mutex m_win_thread_mutex;
115  DWORD m_dwWinThreadID;
116 
117  HINSTANCE m_hInst;
118  friend class CMyProcessAppThread;
119  };
120 
121 }
void handle_mainloop_timer(const boost::system::error_code &err)
the main loop in the main thread.
Definition: InterprocessAppClient.cpp:314
bool CheckLoad()
load ParaEngineClient.dll if not loaded before.
Definition: InterprocessAppClient.cpp:279
int Run(HINSTANCE hInst, const char *sCmdLine)
run the application using a given command line.
Definition: InterprocessAppClient.cpp:185
HRESULT StartWindowThread()
create the default win32 windows for rendering.
Definition: InterprocessAppClient.cpp:523
virtual int SetCommandLine(const char *sCmdLine)
init command line so that we can use IPC calls before calling Run() method.
Definition: InterprocessAppClient.cpp:173
void SetParentWindow(HWND hWndParent)
set the parent window
Definition: InterprocessAppClient.cpp:224
different physics engine has different winding order.
Definition: EventBinding.h:32
This is used to create an application using interprocess communication.
Definition: InterprocessAppClient.h:19
virtual bool SendHostMsg(int nMsg, DWORD param1=0, DWORD param2=0, const char *filename=NULL, const char *sCode=NULL, int nPriority=0)
sent interprocess message to the host process.
Definition: InterprocessAppClient.cpp:650
int HandleAppMsg(InterProcessMessage &msg)
return 0 if succeed, otherwise we will terminate the application.
Definition: InterprocessAppClient.cpp:53
void SetAppName(const char *appName)
set the application name
Definition: InterprocessAppClient.cpp:161
boost::asio::steady_timer m_main_timer
the main timer that ticks 30 times a second
Definition: InterprocessAppClient.h:104
a DLL/so plug-in loaded explicitly at runtime.
Definition: PluginLoader.hpp:51
This is used to create an application using interprocess communication.
Definition: AutoUpdaterApp.h:12
a table of virtual functions which are used by plug-ins to access the game engine ...
Definition: IParaEngineCore.h:17
cross platform mutex
Definition: Mutex.hpp:88
void DefaultWinThreadProc()
Definition: InterprocessAppClient.cpp:538
it represents an interprocess message
Definition: InterprocessQueue.hpp:27
void PrintGetLastError()
print the GetLastError
bool m_bAutoUpdateWhenStart
whether we will automatically update the client when receiving PEAPP_Start.
Definition: InterprocessAppClient.h:82
boost::asio::io_service m_main_io_service
the main game loop
Definition: InterprocessAppClient.h:102
void EnableAutoUpdateWhenComplete(bool bEnable)
enable auto update when complete.
Definition: InterprocessAppClient.cpp:673
a table of virtual functions which are used by plug-ins to access the game engine ...
Definition: IParaEngineApp.h:98
std::string m_app_host
the interprocess queue name for the host app.
Definition: InterprocessAppClient.h:79
std::string m_app_name
the application name is also the interprocess message queue name.
Definition: InterprocessAppClient.h:77