Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

GXGraphicsEngine.h

Go to the documentation of this file.
00001 #ifndef __GXENGINE
00002 #define __GXENGINE
00003 
00004 
00005 
00006 #include "GXStandardDefines.h"
00007 #include "GXVector.h"
00008 
00009 
00010 #include "GXLandRenderer.h"
00011 #include "GXSky.h"
00012 #include "GXLandGenerator.h"
00013 #include "GXMutex.h"
00014 #include "GXWindow.h"
00015 #include "GXDeviceContainer.h"
00016 #include "GXFirstPersonMovement.h"
00017 #include "GXModelManager.h"
00018 #include "GXEntityList.h"
00019 #include "GXEntityWaypoint.h"
00020 #include "GXSpriteManager.h"
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 class CGXGraphicsEngine
00031 {
00032 public:
00033         CGXGraphicsEngine();
00034         ~CGXGraphicsEngine();
00035 
00036         //todo, get rid of often-called virtuals        
00038         //Initialization
00040         bool Cleanup();
00041 
00042         bool Init(UINT uWindowWidth, UINT uWindowHeight,
00043                          UINT uBBWidth, UINT uBBHeight,
00044                                 bool bFullScreen,
00045                                 HWND hWnd, HINSTANCE hInstance);
00046 
00047 
00048 
00050         //Display Params
00052         bool SetCameraPos(CGXVector<3>* pPos);
00053         bool GetCameraPos(CGXVector<3>* pPos);
00054         bool MoveCamera(GXMOVEDIR Direction, float fAmt);
00055 
00056         inline void SetCameraVelocity(const float fAmt)
00057         {
00058                 m_fCameraVelocity=fAmt;
00059         }
00060 
00061         inline float GetCameraVelocity() const
00062         {
00063                 return m_fCameraVelocity;
00064         }
00065 
00066         inline void RotateCamera(const float fX, const float fY)
00067         {
00068                 m_Mover.Look(fX, fY);
00069         }
00070 
00071         inline void GetCameraDirection(CGXVector<3>* pOut) 
00072         {
00073                 m_Mover.GetCameraDirection((D3DXVECTOR3*)pOut);
00074         }
00075 
00076 
00077         bool ToggleWindowConfig(bool bFullScreen, UINT uWidth, UINT uHeight);
00078 
00079 
00080         //todo, inline some of these
00082         //Timing
00084         inline UINT GetTime()
00085         {
00086                 return m_uCurrentTime;
00087         }
00088 
00089         bool SetTime(UINT uNewTime);
00090 
00091         bool IncrementTime();
00092 
00094         //Land
00096         bool LoadLand(char* szFileName);
00097         bool SaveLand(char* szFileName);
00098         bool GenerateLand(const UINT uRandSeed, char* szColorSpline);
00099 
00100         bool ToggleWireFrame();
00101 
00102 
00103 
00105         //Entity Management
00107         int             PrecacheModel(char* szFileName);//-1 on error, else model id
00108         int             CreateEntity(UINT uModel);//-1 on error
00109         bool    DeleteEntity(UINT uEntityID);
00110 
00111         bool    GetEntityWaypoint(UINT uID, SGXEntityWaypoints* pOut);
00112         bool    SetEntityWaypoint(UINT uID, SGXEntityWaypoints* pIn);
00113 
00114         bool    GetEntityPosition(UINT uID, CGXVector<3>* pOut);
00115 
00116 
00117 
00119         //Sprites
00121         inline int      PrecacheSprite(char* szFileName)
00122         {
00123                 if(!m_RenderMutex.Lock(-1))
00124                 {
00125                     return -1;
00126                 }
00127                 
00128 
00129                 int nRet=m_SpriteManager.PrecacheSprite(szFileName);
00130 
00131                 m_RenderMutex.Unlock();
00132 
00133                 return nRet;
00134         }
00135 
00136         inline int      AddSpriteInstance(SGXSpriteInfo* pInfo)
00137         {
00138                 if(!m_RenderMutex.Lock(-1))
00139                 {
00140                     return -1;
00141                 }
00142                 
00143 
00144                 int nRet=m_SpriteManager.AddSpriteInstance(pInfo);
00145 
00146                 m_RenderMutex.Unlock();
00147 
00148                 return nRet;
00149         }
00150 
00151         inline bool DeleteSpriteInstance(UINT uIndex)
00152         {
00153                 if(!m_RenderMutex.Lock(-1))
00154                 {
00155                     return false;
00156                 }
00157                 
00158 
00159                 bool bRet=m_SpriteManager.DeleteSpriteInstance(uIndex);
00160 
00161                 m_RenderMutex.Unlock();
00162 
00163                 return bRet;
00164         }
00165 
00166         inline bool     GetSpriteInfo(UINT uIndex, SGXSpriteInfo* pOut)
00167         {
00168                 if(!m_RenderMutex.Lock(-1))
00169                 {
00170                     return false;
00171                 }
00172                 
00173 
00174                 bool bRet=m_SpriteManager.GetSpriteInfo(uIndex, pOut);
00175 
00176                 m_RenderMutex.Unlock();
00177                 
00178                 return bRet;
00179         }
00180 
00181 
00182         inline bool     SetSpriteInfo(UINT uIndex, SGXSpriteInfo* pIn)
00183         {
00184                 if(!m_RenderMutex.Lock(-1))
00185                 {
00186                     return false;
00187                 }
00188                 
00189 
00190                 bool bRet=m_SpriteManager.SetSpriteInfo(uIndex, pIn);
00191 
00192                 m_RenderMutex.Unlock();
00193 
00194                 return bRet;
00195         }
00196 
00197 
00198 
00199 
00200 
00202         //to be called by worker thread
00204         bool    RenderStuff();
00205         bool    ShouldThreadExit();
00206         HANDLE  GetThreadDeathEvent();
00207         bool    WakeUpThread();
00208 
00209         inline  HANDLE GetWorkerThreadHandle()
00210         {
00211                 return m_hWorkerThread;
00212         }
00213 
00214 
00215 
00216 
00217         inline  HWND GetHWND()
00218         {
00219                 return m_hWnd;
00220         }
00221 
00222         bool    ValidateWindow();
00223 
00224         void    DisplayStats(bool bStats);
00225 
00226 
00227 protected:
00228         bool    OnDeviceLost();
00229 
00230         bool    KillWorkerThread();
00231         bool    CreateWorkerThread();
00232 
00233         bool    SetupMatrices();//todo, cache stuff here
00234         bool    CheckForLostDevice();//todo, profile this guy, returns true if we are good to go
00235 
00236 
00237         bool    SetRenderStates();
00238 
00239 
00240 
00241 protected:
00242         CGXDeviceContainer              m_Device;
00243         //CGXWindow                             m_Window;
00244         CGXLandRenderer                 m_LandRenderer;
00245         CGXSky                                  m_Sky;
00246         CGXMutex                                m_RenderMutex;//Locked for RenderStuff, and anything that could affect it
00247         CGXFirstPersonMovement  m_Mover;
00248         CGXModelManager                 m_ModelManager;
00249         CGXEntityList                   m_EntityList;
00250         CGXSpriteManager                m_SpriteManager;
00251 
00252 
00253         HANDLE                                  m_hWorkerThread;//calls RenderStuff
00254         HANDLE                                  m_hThreadHasDiedEvent;          
00255 
00256         bool                                    m_bShouldThreadExit;
00257 
00258         UINT                                    m_uCurrentTime;
00259 
00260         D3DXMATRIX                              m_mViewMatrix;
00261         D3DXMATRIX                              m_mProjectionMatrix;
00262 
00263         bool                                    m_bReadyToRender;//land etc
00264 
00265         HWND                                    m_hWnd;
00266 
00267         float                                   m_fCameraVelocity;
00268 
00269         RECT                                    m_WindowRect;//for going between full screen and windowed mode
00270 };
00271 
00272 
00273 
00274 
00275 
00276 
00277 DWORD WINAPI GXEngineRenderThread(
00278   LPVOID lpParameter   // thread data
00279 );
00280 
00281 
00282 
00283 void GXDeviceErrorCallBack(char*);
00284 
00285 
00286 
00287 #endif

Generated on Thu May 23 17:51:00 2002 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001