switching timer count to double instead of int

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13248 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hilnius 2013-07-15 15:00:59 +00:00
parent 83d64e6fc2
commit 1d1728553d
2 changed files with 9 additions and 9 deletions

View File

@ -98,7 +98,7 @@ void SynchronizationProtocol::notifyEvent(Event* event)
void SynchronizationProtocol::setup()
{
Log::info("SynchronizationProtocol", "Ready !");
m_countdown = 5000; // init the countdown to 5k
m_countdown = 5.0; // init the countdown to 5s
}
//-----------------------------------------------------------------------------
@ -107,6 +107,11 @@ void SynchronizationProtocol::asynchronousUpdate()
{
static double timer = Time::getRealTime();
double current_time = Time::getRealTime();
if (m_countdown_activated)
{
m_countdown -= (current_time - m_last_countdown_update);
m_last_countdown_update = current_time;
}
if (current_time > timer+0.1)
{
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
@ -127,11 +132,6 @@ void SynchronizationProtocol::asynchronousUpdate()
m_pings_count[i]++;
}
}
if (m_countdown_activated)
{
m_countdown -= (int)((current_time - m_last_countdown_update)*1000.0);
m_last_countdown_update = current_time;
}
Log::info("SynchronizationProtocol", "Update! Countdown remaining : %d", m_countdown);
}
@ -141,7 +141,7 @@ void SynchronizationProtocol::asynchronousUpdate()
void SynchronizationProtocol::startCountdown(int ms_countdown)
{
m_countdown_activated = true;
m_countdown = ms_countdown;
m_countdown = (double)(ms_countdown)/1000.0;
m_last_countdown_update = Time::getRealTime();
Log::info("SynchronizationProtocol", "Countdown started.");
}

View File

@ -18,7 +18,7 @@ class SynchronizationProtocol : public Protocol
void startCountdown(int ms_countdown);
int getCountdown() { return m_countdown; }
int getCountdown() { return (int)(m_countdown*1000); }
protected:
std::vector<std::map<uint32_t, double> > m_pings;
@ -27,7 +27,7 @@ class SynchronizationProtocol : public Protocol
std::vector<uint32_t> m_successed_pings;
std::vector<double> m_total_diff;
bool m_countdown_activated;
int m_countdown;
double m_countdown;
double m_last_countdown_update;
};