src/tools/tSysTime.cpp File Reference

#include "aa_config.h"
#include "tSysTime.h"
#include "tRecorder.h"
#include "tError.h"
#include "tConsole.h"
#include "tConfiguration.h"
#include "tLocale.h"
#include <sys/time.h>

Include dependency graph for tSysTime.cpp:

Go to the source code of this file.

Classes

struct  tTime
 time structure More...
class  TimeArchiver< Archiver >

Defines

#define NORMALIZER   1000000
 seconds

Functions

void GetTime (tTime &time)
bool tTimerIsAccurate ()
 returns true if a timer with more than millisecond accuracy is available
void tAdvanceFrameSys (tTime &start, tTime &relative)
void tDelay (int usecdelay)
 andvances one frame: updates the system time
void tDelayForce (int usecdelay)
 delays for the specified number of microseconds
void tAdvanceFrame (int usecdelay)
 returns the current frame's time ( from the real system )
double tSysTimeFloat ()
 returns true if a timer with more than millisecond accuracy is available
double tRealSysTimeFloat ()
 returns the current frame's time ( from the playback )

Variables

static char const * recordingSection = "T"
static struct tTime timeStart
static struct tTime timeRelative
static bool s_delayedInPlayback = false
static float st_timeFactor = 1.0
static tSettingItem< float > st_timeFactorConf ("TIME_FACTOR", st_timeFactor)
static struct tTime timeRealStart
static struct tTime timeRealRelative


Define Documentation

#define NORMALIZER   1000000

seconds

Definition at line 49 of file tSysTime.cpp.

Referenced by tTime::Normalize().


Function Documentation

void GetTime ( tTime time  ) 

Definition at line 207 of file tSysTime.cpp.

References tTime::microseconds, tTime::Normalize(), and tTime::seconds.

Referenced by tAdvanceFrameSys().

00209 {
00210     struct timeval tp;
00211     struct timezone tzp;
00212 
00213     gettimeofday(&tp, &tzp);
00214 
00215     time.microseconds = tp.tv_usec;
00216     time.seconds = tp.tv_sec;
00217 
00218     time.Normalize();

Here is the call graph for this function:

Here is the caller graph for this function:

void tAdvanceFrame ( int  usecdelay  ) 

returns the current frame's time ( from the real system )

Definition at line 320 of file tSysTime.cpp.

References TimeArchiver< Archiver >::Archive(), tRecorderBase::IsPlayingBack(), tTime::microseconds, tTime::seconds, st_Breakpoint(), tAdvanceFrameSys(), tASSERT, tDelay(), timeRelative, and timeStart.

Referenced by ConnectToServerCore(), nServerInfo::GetFromLAN(), nServerInfo::GetFromMaster(), main(), uMenu::Message(), gGame::NetSync(), next_free(), nNetObject::Object(), uMenu::OnEnter(), sg_HostGame(), gGame::StateUpdate(), nServerInfo::TellMasterAboutMe(), and welcome().

00322 {
00323     // delay a bit if we're not playing back
00324     if ( usecdelay > 0 )
00325         tDelay( usecdelay );
00326 
00327     static tTime timeNewRelative;
00328     tAdvanceFrameSys( timeStart, timeNewRelative );
00329 
00330     // try to fetch time from playback
00331     // tTime timeAdvance;
00332     if ( TimeArchiver< tPlaybackBlock >::Archive( timeRelative ) )
00333     {
00334         // timeRelative = timeRelative + timeAdvance;
00335 
00336         // correct start time so transition to normal time after the recording ended is smooth
00337         timeStart = timeStart + timeNewRelative - timeRelative;
00338     }
00339     else
00340     {
00341         // must never be called when a recording is running
00342         tASSERT( !tRecorder::IsPlayingBack() );
00343 
00344 #ifdef FIXED_FRAMERATE
00345         tTime fixed, catchup, timeFixedRelative;
00346     fixed.seconds = 0;
00347     fixed.microseconds = (int)(1000000. / FIXED_FRAMERATE);
00348         timeFixedRelative = timeRelative + fixed;
00349 
00350     catchup = timeFixedRelative/*game-time*/ - timeNewRelative/*real-time*/;
00351     if (catchup.seconds >= 0) {
00352 #ifdef DEBUG
00353             printf("catching up %d.%d seconds\n", catchup.seconds, catchup.microseconds);
00354 #endif
00355             for (int i = catchup.seconds; i; --i)
00356                 tDelay(1000000);
00357             tDelay(catchup.microseconds);
00358             timeNewRelative = timeFixedRelative;
00359         } else {
00360             printf("WARNING: Real time ahead of game time!\nreal: %d.%06d\ngame: %d.%06d\ncatchup: %d.%06d\n", timeNewRelative.seconds, timeNewRelative.microseconds, timeFixedRelative.seconds, timeFixedRelative.microseconds, 1 - catchup.seconds, 1000000 - catchup.microseconds);
00361 #ifdef FIXED_FRAMERATE_PRIORITY
00362             timeNewRelative = timeFixedRelative;
00363 #endif
00364         }
00365 #endif
00366 
00367         // timeAdvance = timeRealRelative - timeRelative;
00368         timeRelative = timeNewRelative;
00369     }
00370 
00371     // try to archive it
00372     TimeArchiver< tRecordingBlock >::Archive( timeRelative );
00373 #ifdef DEBUG
00374     {
00375         if ( timeRelative.microseconds == 337949 && timeRelative.seconds == 25 )
00376         {
00377             st_Breakpoint();
00378         }
00379     }
00380 #endif

Here is the call graph for this function:

Here is the caller graph for this function:

void tAdvanceFrameSys ( tTime start,
tTime relative 
)

Definition at line 250 of file tSysTime.cpp.

References con, GetTime(), tRecorderBase::IsPlayingBack(), tTime::microseconds, and tTime::seconds.

Referenced by tAdvanceFrame(), and tRealSysTimeFloat().

00252 {
00253     struct tTime time;
00254 
00255     // get time from OS
00256     GetTime( time );
00257 
00258     // test hickupery
00259     // time.seconds -= time.seconds/10;
00260 
00261     // record starting point
00262     if ( start.microseconds == 0 && start.seconds == 0 )
00263     {
00264         start = time;
00265     }
00266 
00267     // detect and counter timer hickups
00268     tTime newRelative = time - start;
00269     tTime timeStep = newRelative - relative;
00270     if ( !tRecorder::IsPlayingBack() && ( timeStep.seconds < 0 || timeStep.seconds > 10 ) )
00271     {
00272         static bool warn = true;
00273         if ( warn )
00274         {
00275             warn = false;
00276             con << tOutput( "$timer_hickup", float( timeStep.seconds + timeStep.microseconds * 1E-6  ) );
00277         }
00278 
00279         start = start + timeStep;
00280     }
00281     else
00282     {
00283         relative = newRelative;
00284     }
00285 
00286 
00287     if ( relative.seconds > 20 )
00288     {
00289         int x;
00290         x = 0;
00291     }

Here is the call graph for this function:

Here is the caller graph for this function:

void tDelay ( int  usecdelay  ) 

andvances one frame: updates the system time

Definition at line 294 of file tSysTime.cpp.

References tRecorderBase::IsPlayingBack().

Referenced by gGame::GameLoop(), uMenu::GenericBackground(), nServerInfo::GetFromLAN(), nServerInfo::GetFromLANContinuously(), uMenu::OnEnter(), Render(), nBasicNetworkSystem::Select(), and tAdvanceFrame().

00296 {
00297     // delay a bit if we're not playing back
00298     if ( ! tRecorder::IsPlayingBack() )
00299         usleep( usecdelay );
00300     else
00301         s_delayedInPlayback = true;

Here is the call graph for this function:

Here is the caller graph for this function:

void tDelayForce ( int  usecdelay  ) 

delays for the specified number of microseconds

Definition at line 303 of file tSysTime.cpp.

References tTime::microseconds, and timeStart.

Referenced by rSysDep::SwapGL().

00305 {
00306     // delay a bit
00307     if ( !s_delayedInPlayback )
00308         usleep( usecdelay );
00309     else
00310     {
00311         // when recording, the machine was idling around. No need to play that back.
00312         // Only pretend to delay.
00313         tTime timeDelay;
00314         timeDelay.microseconds = usecdelay;
00315         timeStart = timeStart - timeDelay;
00316     }
00317 
00318     s_delayedInPlayback = false;

Here is the caller graph for this function:

double tRealSysTimeFloat (  ) 

returns the current frame's time ( from the playback )

Definition at line 408 of file tSysTime.cpp.

References tTime::microseconds, tTime::seconds, tAdvanceFrameSys(), timeRealRelative, and timeRealStart.

Referenced by PerformanceCounter::PerformanceCounter(), and rSysDep::SwapGL().

00410 {
00411     // get real time from real OS
00412     tAdvanceFrameSys( timeRealStart, timeRealRelative );
00413     return ( timeRealRelative.seconds + timeRealRelative.microseconds*1E-6 ) * st_timeFactor;

Here is the call graph for this function:

Here is the caller graph for this function:

double tSysTimeFloat (  ) 

returns true if a timer with more than millisecond accuracy is available

Definition at line 385 of file tSysTime.cpp.

References tTime::microseconds, tTime::seconds, and timeRelative.

Referenced by gJoystick::Act(), eTeam::AddPlayer(), eTeam::AddPlayerDirty(), eVoter::Age(), eVoter::AllowNameChange(), gGame::Analysis(), nQueryMessageStats::Block(), nSpamProtection::BlockTime(), cCockpit::cb_Framerate(), cCockpit::cb_RunningTime(), CenterDisplay(), eChatSpamTester::Check(), nSpamProtection::CheckSpam(), ConnectToServerCore(), gLogo::Display(), eVoteItemKick::DoCheckValid(), eVoteItemHarm::DoCheckValid(), rConsole::DoPrint(), nServerInfo::DoQueryAll(), gCycleMovement::DoTurn(), gCycle::DoTurn(), ePlayerNetID::ePlayerNetID(), eTimer::eTimer(), eVoteItem::Evaluate(), gServerMenuItem::Event(), gBrowserMenuItem::Event(), eVoter::eVoter(), nQueryMessageStats::FloodProtection(), free_server(), GameLoop(), nServerInfo::GetFromLAN(), nServerInfo::GetFromMaster(), nServerInfo::GetMasters(), nServerInfo::GetSmallServerInfo(), uMenu::HandleEvent(), uMenu::IdleInput(), uBind::IsDoubleBind(), ePlayerNetID::LastActivity(), login_callback(), main(), MenuBackground(), uMenu::Message(), gCycleMovement::MyInitAfterCreation(), gCycle::MyInitAfterCreation(), ePlayerNetID::MyInitAfterCreation(), net_destroy_handler(), nServerInfo::NetReadThis(), next_free(), nNetObject::Object(), nNetObject::ObjectDangerous(), uMenu::OnEnter(), gCycle::OnNotifyNewDestination(), gServerMenu::OnRender(), eVoter::PlayerChanged(), nQueryMessageStats::PrintWarning(), nServerInfo::QueryServer(), ePlayerNetID::RemoveChatbots(), gCycle::Render(), rConsole::Render(), gCycle::RenderName(), nServerLag::Report(), nClientLag::ReportLag(), gCycle::RequestSyncAll(), gCycle::RequestSyncOwner(), eTimer::Reset(), nServerLag::Reset(), gCycle::RightBeforeDeath(), nServerInfo::RunMaster(), nConfItemBase::s_GetConfigMessage(), rConsole::Scroll(), nDeletedInfo::Set(), uMenuItem::SetColor(), rConsole::SetHeight(), sg_FullscreenMessage(), sg_HostGame(), sg_Timestamp(), sn_DoDestroy(), sn_SendPlanned1(), sn_Statistics(), sn_Sync(), gGame::StateUpdate(), su_InputSync(), rSysDep::SwapGL(), nNetObject::SyncAll(), gGame::SyncState(), eTimer::SyncTime(), nServerLag::TakeCredit(), nServerInfo::TellMasterAboutMe(), eTimer::TimeNoSync(), gCycle::Timestep(), nClientLag::Timestep(), gCycleMovement::TimestepCore(), gCycle::TimestepCore(), gJoystick::Turn(), gServerMenu::Update(), update_settings(), ePlayerNetID::WaitToLeaveChat(), welcome(), and nNetObject::~nNetObject().

00387 {
00388 #ifdef DEBUG
00389     // if ( ! tRecorder::IsPlayingBack() )
00390     // {
00391     // static tTime time;
00392     // tAdvanceFrameSys( timeStart, time );
00393     // tTime timeStep = time - timeRelative;
00394     //        if ( timeStep.seconds > 5 )
00395     //        {
00396     //            std::cout << "tAdvanceFrame not called often enough!\n";
00397     //            st_Breakpoint();
00398     //            tAdvanceFrameSys( timeRealRelative );
00399     //        }
00400     // }
00401 #endif
00402 
00403     return ( timeRelative.seconds + timeRelative.microseconds*1E-6 ) * st_timeFactor;

bool tTimerIsAccurate (  ) 

returns true if a timer with more than millisecond accuracy is available

Definition at line 221 of file tSysTime.cpp.

Referenced by se_SmoothTime(), and eTimer::SyncTime().

00223 {
00224     return true; // always on unix

Here is the caller graph for this function:


Variable Documentation

char const* recordingSection = "T" [static]

Definition at line 228 of file tSysTime.cpp.

bool s_delayedInPlayback = false [static]

Definition at line 293 of file tSysTime.cpp.

float st_timeFactor = 1.0 [static]

Definition at line 382 of file tSysTime.cpp.

tSettingItem< float > st_timeFactorConf("TIME_FACTOR", st_timeFactor) [static]

struct tTime timeRealRelative [static]

Definition at line 406 of file tSysTime.cpp.

Referenced by tRealSysTimeFloat().

struct tTime timeRealStart [static]

Definition at line 405 of file tSysTime.cpp.

Referenced by tRealSysTimeFloat().

struct tTime timeRelative [static]

Definition at line 248 of file tSysTime.cpp.

Referenced by tAdvanceFrame(), and tSysTimeFloat().

struct tTime timeStart [static]

Definition at line 247 of file tSysTime.cpp.

Referenced by tAdvanceFrame(), and tDelayForce().


Generated on Sat Mar 15 23:13:01 2008 for Armagetron Advanced by  doxygen 1.5.4