Chris Peterson ba0bc9b77d Multiplayer framework in place (can now connect multiple clients and view them in game)
Fixed some bugs with multiplayer
Changed from refptr<map<U8, Player> > to map<U8, refptr<player> >
2012-09-25 20:36:11 -04:00

60 lines
1.1 KiB
C++

#include "Timer.h"
// The number of time steps per second
const float STEPS_PER_SECOND = 60.0f;
double Timer::totalElapsedTime;
float Timer::stepTime;
sf::Uint32 Timer::curTimeStep;
void Timer::Init(void)
{
// Reset the clock
myClock.restart();
// Set the time keepers to zero
myTotalElapsedTime = 0;
// Reset the game speed
gameSpeed = 1.0f;
}
void Timer::Update(void)
{
// Record the time step
stepTime = ((myClock.getElapsedTime().asSeconds() / 1000.0f) * gameSpeed);
myClock.restart();
// Add the time to the total time
myTotalElapsedTime += stepTime;
totalElapsedTime = myTotalElapsedTime;
// Calculate the game step
curTimeStep = (sf::Uint32)(totalElapsedTime * STEPS_PER_SECOND);
}
sf::Uint32 Timer::GetTime(void)
{
return curTimeStep;
}
float Timer::GetStepTime(void)
{
return stepTime;
}
sf::Uint32 Timer::GetTotalTime(void)
{
return (sf::Uint32)(totalElapsedTime * 1000.0f);
}
double Timer::GetTimeDouble(void)
{
return totalElapsedTime;
}
float Timer::GetElapsedTime(sf::Uint32 baseTime)
{
return (totalElapsedTime - ((double)baseTime / STEPS_PER_SECOND));
}