diff --git a/src/network/protocols/synchronization_protocol.cpp b/src/network/protocols/synchronization_protocol.cpp index d6f8d5f99..d3a89cd15 100644 --- a/src/network/protocols/synchronization_protocol.cpp +++ b/src/network/protocols/synchronization_protocol.cpp @@ -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 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."); } diff --git a/src/network/protocols/synchronization_protocol.hpp b/src/network/protocols/synchronization_protocol.hpp index 54ccb3b2b..cd4b42614 100644 --- a/src/network/protocols/synchronization_protocol.hpp +++ b/src/network/protocols/synchronization_protocol.hpp @@ -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 > m_pings; @@ -27,7 +27,7 @@ class SynchronizationProtocol : public Protocol std::vector m_successed_pings; std::vector m_total_diff; bool m_countdown_activated; - int m_countdown; + double m_countdown; double m_last_countdown_update; };