Main Page   Namespace List   Compound List   File List   Namespace Members   Compound Members   File Members  

/include/ZE_ZEngine.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002         This file is Part of the ZEngine Library for 2D game development.
00003                    Copyright (C) 2002, 2003 James Turk
00004 
00005                      Licensed under a BSD-style license.
00006 
00007     The maintainer of this library is James Turk (james@conceptofzero.net) 
00008      and the home of this Library is http://www.zengine.sourceforge.net
00009 *******************************************************************************/
00010 
00020 //revision on this is so high.. can this be lowered?
00021 
00022 #ifndef __ze_zengine_h__
00023 #define __ze_zengine_h__
00024 
00025 #include "ZE_Defines.h"
00026 #include "ZE_Utility.h"
00027 #include "ZE_Includes.h"
00028 #include "ZE_ZError.h"
00029 #include "ZE_ZRandGen.h"
00030 #include "VersionInfo.h"
00031 
00037 namespace ZE
00038 {
00039 
00046 class ZEngine
00047 {
00048     public:
00050         static VersionInfo Version;
00051 
00052     private:        
00054         static ZEngine *sInstance;
00056         int mWidth;
00058         int mHeight;
00060         int mBPP;
00062         bool mFullscreen;
00064         bool mInitialized;
00066         SDL_Surface *mScreen;
00068         bool mPaused;
00070         bool mUnpauseOnActive;
00072         Uint8 mDesiredFramerate;
00074         Uint32 mNextUpdate;
00076         Uint32 mLastPause;
00078         Uint32 mPausedTime;
00080         Uint32 mLastTime;
00082         double mSecPerFrame;
00084         bool mNeedReload;
00086         bool mActive;
00088         bool mQuit;
00090         Uint8 *mKeyIsPressed;
00092         bool mKeyPress[SDLK_LAST];
00094         int mMouseX;
00096         int mMouseY;
00098         Uint8 mMouseB;
00100         std::queue<ZError> mErrorQueue;
00102         ZError mCurError;
00104         bool mLogAllErrors;
00106         std::FILE *mErrlog;
00108         SDL_EventFilter mEventFilter;
00110         ZRandGen mRandGen;
00111 
00112 #ifdef USE_SDL_MIXER 
00113 
00114         int mRate;
00116         bool mStereo;
00117 #endif 
00118 
00120     //Singleton + Memory Management//
00122 
00123     private:
00129         ZEngine();
00130 
00131     public:
00132 
00139         static ZEngine* GetInstance();
00140 
00146         static void ReleaseInstance();
00147 
00149     //Initialization//
00151 
00162         void SetupDisplay(int width, int height, int bpp, bool fullscreen);
00163 
00164 #ifdef USE_SDL_MIXER
00165 
00173         void SetupSound(int rate, bool stereo);
00174 #endif 
00175 
00187         bool CreateDisplay(std::string title, std::string icon="");
00188 
00194         void CloseDisplay();
00195 
00203         void ToggleFullscreen();
00204 
00212         bool Initialized();
00213 
00215     //Screen Access//
00217 
00224         SDL_Surface *Display();
00225 
00232         void Update();
00233 
00243         void Clear(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=1.0f);
00244 
00246     //OpenGL Specific Functions//
00248 
00255         void SetGL2D();
00256 
00258     //Timer and Framerate Independent Movement//
00260 
00267         void Delay(Uint32 milliseconds);
00268 
00275         Uint32 GetTime();
00276 
00282         void PauseTimer();
00283 
00289         void UnpauseTimer();
00290 
00297         double GetFrameTime();
00298 
00306         double GetFramerate();
00307 
00317         void SetDesiredFramerate(Uint8 rate);
00318 
00326         Uint8 GetDesiredFramerate();
00327 
00334         bool IsPaused();
00335 
00337     //Event and Input Handling//
00339 
00346         bool IsActive();
00347 
00354         void RequestQuit();
00355 
00363         bool QuitRequested();
00364 
00369         void SetReloadNeed(bool state);
00370 
00378         bool ImagesNeedReload();
00379         
00388         void SetKeyRepeatRate(int rate);
00389 
00397         bool KeyIsPressed(SDLKey key);
00398 
00406         bool KeyPress(SDLKey key);
00407 
00413         void HideCursor();
00414 
00420         void ShowCursor();
00421 
00428         int MouseX();
00429 
00436         int MouseY();
00437 
00444         bool LButtonPressed();
00445 
00452         bool RButtonPressed();
00453 
00461         bool MouseInRect(SDL_Rect *rect);
00462 
00468         void CheckEvents();
00469 
00482         void SetEventFilter(SDL_EventFilter filter);
00483 
00484 #ifdef USE_PHYSFS
00485 
00486     //Physfs Utilities//
00488 
00494         void InitPhysFS(std::string argv);
00495 
00502         void AddPhysFSDir(std::string dir);
00503 
00504 #endif    //USE_PHYSFS
00505 
00507     //Error Logging//
00509     private:
00517         void LogError(ZError error);
00518 
00519     public:
00530         void SetErrorLog(bool logAll, std::string logFile="");
00531 
00542         void ReportError(ZErrorCode code, std::string desc="", std::string file="", unsigned int line=0);
00543 
00551         ZErrorCode GetLastError();
00552 
00560         void WriteLog(std::string str);
00561 
00568         void FlushErrors();
00569 
00571     //Random Number Generation//
00573 
00579         void SeedRandGen(unsigned long seed);
00580 
00588         unsigned int Rand(unsigned int max);
00589 
00597         unsigned long Rand(unsigned long max);
00598 
00607         int Rand(int min, int max);
00608 
00617         long Rand(long min, long max);
00618 
00627         float Rand(float min, float max);
00628 
00637         double Rand(double min, double max);
00638 
00645         double RandDouble();
00646 
00648     //Data Loading + Unloading//
00650 
00657         SDL_Surface* LoadImage(std::string filename);
00658 
00659 #ifdef USE_SDL_MIXER
00660 
00667         Mix_Chunk* LoadSound(std::string filename);
00668 
00676         Mix_Music* LoadMusic(std::string filename);
00677 #endif
00678 
00679 #ifdef USE_SDL_TTF
00680 
00688         TTF_Font* LoadFont(std::string filename, int size);
00689 #endif 
00690 
00692     //Accessors//
00694 
00701         int Width();
00702 
00709         int Height();
00710 
00717         int BPP();
00718 
00725         bool IsFullscreen();
00726 };
00727 
00728 }
00729 
00730 #endif //__ze_zengine_h__

Generated on Sun Jun 29 14:13:51 2003 for ZEngine by doxygen1.3