00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00024 #ifndef __ze_zengine_h__
00025 #define __ze_zengine_h__
00026
00027 #include "ZE_Defines.h"
00028 #include "ZE_Utility.h"
00029 #include "ZE_Includes.h"
00030 #include "ZE_ZError.h"
00031
00037 namespace ZE
00038 {
00039
00046 class ZEngine
00047 {
00048
00049 private:
00051 static ZEngine *sInstance;
00053 int mWidth;
00055 int mHeight;
00057 int mBPP;
00059 bool mFullscreen;
00061 bool mInitialized;
00063 SDL_Surface *mScreen;
00065 bool mPaused;
00067 bool mUnpauseOnActive;
00069 Uint8 mDesiredFramerate;
00071 Uint32 mNextUpdate;
00073 Uint32 mLastPause;
00075 Uint32 mPausedTime;
00077 Uint32 mLastTime;
00079 double mSecPerFrame;
00081 bool mNeedReload;
00083 bool mActive;
00085 bool mQuit;
00087 Uint8 *mKeyIsPressed;
00089 bool mKeyPress[SDLK_LAST];
00091 int mMouseX;
00093 int mMouseY;
00095 Uint8 mMouseB;
00097 queue<ZError> mErrorQueue;
00099 ZError mCurError;
00101 bool mLogAllErrors;
00103 FILE *mErrlog;
00104
00105 #ifdef USE_SDL_MIXER
00106
00107 int mRate;
00109 bool mStereo;
00110 #endif
00111
00113
00115
00116 private:
00122 ZEngine();
00123
00124 public:
00125
00132 static ZEngine* GetInstance();
00133
00139 static void ReleaseInstance();
00140
00147 static string GetVersion();
00148
00150
00152
00163 void SetupDisplay(int width, int height, int bpp, bool fullscreen);
00164
00165 #ifdef USE_SDL_MIXER
00166
00174 void SetupSound(int rate, bool stereo);
00175 #endif
00176
00188 bool CreateDisplay(string title, string icon="");
00189
00195 void CloseDisplay();
00196
00204 void ToggleFullscreen();
00205
00213 bool Initialized();
00214
00216
00218
00225 SDL_Surface *Display();
00226
00233 void Update();
00234
00244 void Clear(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=1.0f);
00245
00247
00249
00256 void SetGL2D();
00257
00259
00261
00268 void Delay(Uint32 milliseconds);
00269
00276 Uint32 GetTime();
00277
00283 void PauseTimer();
00284
00290 void UnpauseTimer();
00291
00298 double GetFrameTime();
00299
00307 double GetFramerate();
00308
00318 void SetDesiredFramerate(Uint8 rate);
00319
00327 Uint8 GetDesiredFramerate();
00328
00335 bool IsPaused();
00336
00338
00340
00347 bool IsActive();
00348
00355 void RequestQuit();
00356
00364 bool QuitRequested();
00365
00370 void SetReloadNeed(bool state);
00371
00379 bool ImagesNeedReload();
00380
00389 void SetKeyRepeatRate(int rate);
00390
00398 bool KeyIsPressed(SDLKey key);
00399
00407 bool KeyPress(SDLKey key);
00408
00414 void HideCursor();
00415
00421 void ShowCursor();
00422
00429 int MouseX();
00430
00437 int MouseY();
00438
00445 bool LButtonPressed();
00446
00453 bool RButtonPressed();
00454
00462 bool MouseInRect(SDL_Rect *rect);
00463
00469 void CheckEvents();
00470
00481 void SetEventFilter(SDL_EventFilter filter);
00482
00483 #ifdef USE_PHYSFS
00484
00485
00487
00493 void InitPhysFS(string argv);
00494
00501 void AddPhysFSDir(string dir);
00502
00503 #endif //USE_PHYSFS
00504
00506
00508
00516 void LogError(ZError error);
00517
00518 public:
00529 void SetErrorLog(bool logAll, string logFile="");
00530
00541 void ReportError(ZErrorCode code, string desc="", string file="", unsigned int line=0);
00542
00550 ZErrorCode GetLastError();
00551
00559 void WriteLog(string str);
00560
00567 void FlushErrors();
00568
00570
00572
00580 void SeedRandom(unsigned long seed);
00581
00590 unsigned long RandLong(unsigned long max);
00591
00601 long RandLong(long min, long max);
00602
00610 double RandDouble();
00611
00621 double RandDouble(double min, double max);
00622
00624
00626
00633 SDL_Surface* LoadImage(string filename);
00634
00635 #ifdef USE_SDL_MIXER
00636
00643 Mix_Chunk* LoadSound(string filename);
00644
00652 Mix_Music* LoadMusic(string filename);
00653 #endif
00654
00655 #ifdef USE_SDL_TTF
00656
00664 TTF_Font* LoadFont(string filename, int size);
00665 #endif
00666
00668
00670
00677 int Width();
00678
00685 int Height();
00686
00693 int BPP();
00694
00701 bool IsFullscreen();
00702 };
00703
00704 }
00705
00706 #endif //__ze_zengine_h__