Gel2D - The free/open source game creation suite

gelTimer.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2010-2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELTIMER_H__
00017 #define __GELTIMER_H__
00018 
00019 #include "gelNamespace.h"
00020 
00021 #ifdef _GEL_WIN32
00022     #include <windows.h>
00023 #endif // _GEL_WIN32
00024 
00025 #ifdef _GEL_LINUX
00026     #include <sys/time.h>
00027     #include <unistd.h>
00028 #endif // _GEL_LINUX
00029 
00030 namespace gel
00031 {
00032         #ifdef _GEL_WIN32
00033 
00035 
00036     class GelTimer
00037     {
00038         public:
00040 
00041             GelTimer();
00042 
00044 
00049             double getTime();
00050 
00052 
00055             void setTime( double time );
00056 
00058 
00061             int getFPS();
00062 
00064 
00067             void setFPS( int fps );
00068 
00070 
00074             double getDelta();
00075 
00077 
00078             void sleep( double time );
00079 
00080         private:
00082             // Win32
00084             bool perfTimer; // Whether or not performance timer will be used
00085 
00086             __int64 freq; // Timer frequency
00087 
00088             __int64 perfTimer_start;
00089             __int64 perfTimer_elapsed;
00090 
00091             GELuint tickTimer_start;
00092             GELuint tickTimer_elapsed;
00093 
00095             // Global
00097             // Timer resolution
00098             double res;
00099 
00100             // fps
00101             GELuint fps;
00102             GELuint rfps;
00103             double rtime;
00104 
00105             // delta
00106             int dframe;
00107             double ddelta;
00108             double dtime;
00109     };
00111         #endif // _GEL_WIN32
00112 
00113     #ifdef _GEL_LINUX
00114 
00116 
00117     class GelTimer
00118     {
00119         public:
00121 
00122             GelTimer();
00123 
00125 
00130             double getTime();
00131 
00133 
00136             void setTime( double time );
00137 
00139 
00142             int getFPS();
00143 
00145 
00148             void setFPS( int fps );
00149 
00151 
00155             double getDelta();
00156 
00158 
00159             void sleep( double time );
00160 
00161         private:
00163             // Linux
00165                         long long t0;
00166 
00168             // Global
00170             // Timer resolution
00171             double res;
00172 
00173             // fps
00174             GELuint fps;
00175             GELuint rfps;
00176             double rtime;
00177 
00178             // delta
00179             int dframe;
00180             double ddelta;
00181             double dtime;
00182     };
00184     #endif // _GEL_LINUX
00185 }
00186 
00187 #endif // __GELTIMER_H__