Original Post
Hey, I'm having a little issue with a small calculation in my game and was hoping someone could help me out. To start, I read in the timelimit for the match from a config file and save it in a variable called m_fInGameTime. This is done on server initialization and then reset whenever changing levels. I then convert the value to milliseconds and save it in a seperate variable called m_fTimeLimit which will be compared vs the m_iServerStartTime to decide if the match has gone too long. Each frame move I want to calculate the new real in-game time as follows: The problem with my calculation (as I'm sure you'll see immediately) is the following: // update the game clock m_fInGameTime -= 0.01f; The problem here is that it will take a value like 25.00 and when I subtract 0.01f, the value then becomes 24.99 when it should be 24.59. I'm sure there is a better way of doing this but as of right now I'm a little stuck on it and think maybe a pair of fresh eyes might help ^_^. Thanks, Permafried-
// get the current game time
m_fCurrentGameTime = static_cast<float>( timeGetTime() *
0.001 );
// get the elapsed time since last frame
m_fElapsedFrameTime = ( m_fCurrentGameTime -
m_fOldGameTime );
// update the in-game clock if we need to
if( ( m_fCurrentGameTime - m_fLastClockUpdateTime ) > 1 )
{
// update the game clock
m_fInGameTime -= 0.01f;
// set the last update time
m_fLastClockUpdateTime = m_fCurrentGameTime;
}
// set this game time as the old game time
m_fOldGameTime = m_fCurrentGameTime;