Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ticktimer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                   ticktimer.h  -  Simple ms-based timing class
00003                              -------------------
00004     begin                : Thu Mar 6 2003
00005     copyright            : (C) 2003 by Tyler Montbriand
00006     email                : tsm@accesscomm.ca
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef TICKTIMER_H
00019 #define TICKTIMER_H
00020 
00021 #include <SDL/SDL_timer.h>
00022 
00023 
00030 
00041 class TickTimer
00042 {
00043 public:
00045   inline TickTimer()
00046   { Reset(); }
00047 
00049   inline void Reset()
00050   {  lasttick=GetCurTime();  }
00051 
00058   inline Sint32 Left(Sint32 time)
00059   {
00060     int t=Ticks();
00061     /* Can't wait backwards */
00062     if(time<0)      return(0);
00063     else if(t>time) return(0);
00064     else            return(t-time);
00065   }
00066 
00068   inline Sint32 Ticks()
00069   { return(GetCurTime()-lasttick);  }
00070 
00072   inline operator Sint32()
00073   { return(Ticks());  }
00074   
00076   inline TickTimer &operator -=(Sint32 offset)
00077   {
00078     lasttick+=offset;
00079     return(*this);
00080   }
00081   
00082 protected:
00084   virtual Sint32 GetCurTime()
00085   { return(SDL_GetTicks());  }
00086   
00088   Sint32 lasttick;
00089 };
00090 
00092 class ManualTimer:public TickTimer
00093 {
00094 public:
00095   ManualTimer():TickTimer()
00096   {
00097     lasttick=0;
00098     curtime=0;        
00099   }
00100 
00102   inline void Advance(Sint32 tick)
00103   { if(tick>0)  curtime+=tick;  }
00104   
00105 protected:
00107   virtual Sint32 GetCurTime()
00108   { return curtime; }
00110   Sint32 curtime;  
00111 };
00112 
00114 
00115 #endif

Generated on Sat Oct 11 13:19:26 2003 for Spritelib by doxygen 1.3.4