Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

clocker.cpp

00001 //FILE:         clocker.cpp
00002 //AUTHOR:       Nathan Cournia <nathan@courina.com>
00003 
00004 #include "clocker.h"
00005 
00007 clocker::clocker( void ): m_elapsed( 0.0 )
00008 {
00009 #ifdef HAVE_SDL
00010         last = SDL_GetTicks( );
00011 #else
00012         clock = new struct timeval;
00013         now = new struct timeval;
00014         gettimeofday( clock, 0 );
00015 #endif
00016 }
00017 
00019 clocker::~clocker( void )
00020 {
00021 #ifndef HAVE_SDL
00022         delete clock;
00023         delete now;
00024 #endif
00025 }
00026 
00028 void
00029 clocker::reset( void )
00030 {
00031         m_elapsed = 0.0;
00032 #ifndef HAVE_SDL
00033         gettimeofday( clock, 0 );
00034 #else
00035         last = SDL_GetTicks( );
00036 #endif
00037 }
00038 
00040 void
00041 clocker::update( void )
00042 {
00043 #ifdef HAVE_SDL
00044         Uint32 now = SDL_GetTicks( );
00045         m_elapsed = (now - last) / 1000.0;
00046         if( m_elapsed < 0.0 ) {
00047                 m_elapsed = 0.0;
00048         }
00049         last = now;
00050 #else
00051         gettimeofday( now, 0 );
00052         m_elapsed = ((double)(now->tv_usec - clock->tv_usec)) / 1000000.0;
00053         if( m_elapsed < 0.0 ) {
00054                 m_elapsed = 0.0;
00055         }
00056 
00057         //swap
00058         struct timeval *tmp;
00059         tmp = now;
00060         now = clock;
00061         clock = tmp;
00062 #endif
00063 }

Generated on Tue Feb 11 18:49:40 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002