00001 /******************************************************************************* 00002 This file is Part of the ZEngine Library for SDL Game Development. 00003 Copyright (C) 2002 ConceptOfZero.net 00004 00005 Licensed under the BSD License, see licensing.txt. 00006 00007 The maintainer of this library is James Turk (jturk@conceptofzero.net) 00008 and the home of this Library is http://www.conceptofzero.net/ 00009 *******************************************************************************/ 00010 00024 #ifndef __ze_zengine_h__ 00025 #define __ze_zengine_h__ 00026 00027 #include "ZE_Error.h" 00028 #include "ZE_Defines.h" 00029 #include "ZE_Macros.h" 00030 #include "ZE_Includes.h" 00031 00037 namespace ZE 00038 { 00039 00046 class ZEngine 00047 { 00049 //Singleton + Memory Management// 00051 00052 private: 00054 static ZEngine *sInstance; 00055 00061 ZEngine(); 00062 00063 public: 00064 00071 static ZEngine* GetInstance(); 00072 00078 static void ReleaseInstance(); 00079 00086 static string GetVersion(); 00087 00089 //Initialization// 00091 00092 private: 00094 int mWidth; 00096 int mHeight; 00098 int mBPP; 00100 bool mFullscreen; 00101 00102 #ifdef USE_SDL_MIXER 00103 00104 int mRate; 00106 bool mStereo; 00107 #endif 00108 00109 00110 public: 00111 //add initialization 00112 00123 void SetupDisplay(int width, int height, int bpp, bool fullscreen); 00124 00125 #ifdef USE_SDL_MIXER 00126 00134 void SetupSound(int rate, bool stereo); 00135 #endif 00136 00146 void CreateDisplay(string title, string icon=""); 00147 00153 void CloseDisplay(); 00154 00156 //Screen Access// 00158 00159 private: 00161 SDL_Surface *mScreen; 00162 00163 public: 00170 SDL_Surface *Display(); 00171 00177 void UpdateScreen(); 00178 00188 void Clear(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=1.0f); 00189 00191 //OpenGL Specific Functions// 00193 public: 00194 00201 void SetGL2D(); 00202 00204 //Timer and Framerate Independent Movement// 00206 00207 private: 00209 bool mPaused; 00211 bool mUnpauseOnActive; 00213 Uint32 mLastPause; 00215 Uint32 mPausedTime; 00217 Uint32 mLastTime; 00219 double mSecPerFrame; 00220 00221 public: 00228 void Delay(Uint32 milliseconds); 00229 00236 Uint32 GetTime(); 00237 00243 void PauseTimer(); 00244 00250 void UnpauseTimer(); 00251 00258 double GetFrameTime(); 00259 00266 bool IsPaused(); 00267 00269 //Event and Input Handling// 00271 00272 private: 00274 bool mActive; 00276 bool mQuit; 00278 Uint8 *mKeyIsPressed; 00280 bool mKeyPress[SDLK_LAST]; 00282 int mMouseX; 00284 int mMouseY; 00286 Uint8 mMouseB; 00287 00288 public: 00295 bool IsActive(); 00296 00303 void RequestQuit(); 00304 00312 bool QuitRequested(); 00313 00323 void SetKeyRepeatRate(int rate); 00324 00332 bool KeyIsPressed(SDLKey key); 00333 00341 bool KeyPress(SDLKey key); 00342 00348 void HideCursor(); 00349 00355 void ShowCursor(); 00356 00363 int MouseX(); 00364 00371 int MouseY(); 00372 00379 bool LButtonPressed(); 00380 00387 bool RButtonPressed(); 00388 00396 bool MouseInRect(SDL_Rect *rect); 00397 00403 void CheckEvents(); 00404 00405 #ifdef USE_PHYSFS 00406 00407 //Physfs Utilities// 00409 public: 00416 void InitPhysFS(string argv); 00417 00424 void AddPhysFSDir(string dir); 00425 00426 #endif //USE_PHYSFS 00427 00428 00430 //Data Loading + Unloading// 00432 public: 00440 SDL_Surface* LoadImage(string filename); 00441 00442 #ifdef USE_SDL_MIXER 00443 00450 Mix_Chunk* LoadSound(string filename); 00451 00459 Mix_Music* LoadMusic(string filename); 00460 #endif 00461 00462 #ifdef USE_SDL_TTF 00463 00471 TTF_Font* LoadFont(string filename, int size); 00472 #endif 00473 00475 //Accessors// 00477 00478 public: 00485 int Width(); 00486 00493 int Height(); 00494 00501 int BPP(); 00502 00509 bool IsFullscreen(); 00510 }; 00511 00512 } 00513 00514 #endif //__ze_zengine_h__