Add network timer in main loop
This commit is contained in:
parent
9e500751a1
commit
1992177205
@ -66,6 +66,8 @@ LRESULT CALLBACK separateProcessProc(_In_ HWND hwnd, _In_ UINT uMsg,
|
||||
MainLoop::MainLoop(unsigned parent_pid)
|
||||
: m_abort(false), m_ticks_adjustment(0), m_parent_pid(parent_pid)
|
||||
{
|
||||
m_network_timer.store(StkTime::getRealTimeMs());
|
||||
m_start_game_ticks.store(0);
|
||||
m_curr_time = 0;
|
||||
m_prev_time = 0;
|
||||
m_throttle_fps = true;
|
||||
@ -493,4 +495,18 @@ void MainLoop::abort()
|
||||
m_abort = true;
|
||||
} // abort
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Set game start ticks told by server somewhere in the future.
|
||||
*/
|
||||
void MainLoop::setStartNetworkGameTimer(uint64_t ticks)
|
||||
{
|
||||
uint64_t ticks_now = getNetworkTimer();
|
||||
if (ticks < ticks_now)
|
||||
{
|
||||
Log::warn("MainLoop", "Network timer is too slow to catch up");
|
||||
ticks = ticks_now;
|
||||
}
|
||||
m_start_game_ticks.store(ticks);
|
||||
} // setStartNetworkGameTimer
|
||||
|
||||
/* EOF */
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define HEADER_MAIN_LOOP_HPP
|
||||
|
||||
#include "utils/synchronised.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/types.hpp"
|
||||
#include <atomic>
|
||||
|
||||
@ -39,6 +40,8 @@ private:
|
||||
|
||||
Synchronised<int> m_ticks_adjustment;
|
||||
|
||||
std::atomic<uint64_t> m_network_timer, m_start_game_ticks;
|
||||
|
||||
uint32_t m_curr_time;
|
||||
uint32_t m_prev_time;
|
||||
unsigned m_parent_pid;
|
||||
@ -62,6 +65,16 @@ public:
|
||||
m_ticks_adjustment.getData() += ticks;
|
||||
m_ticks_adjustment.unlock();
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
uint64_t getNetworkTimer() const
|
||||
{ return StkTime::getRealTimeMs() - m_network_timer.load(); }
|
||||
// ------------------------------------------------------------------------
|
||||
void setNetworkTimer(uint64_t ticks)
|
||||
{ m_network_timer.store(StkTime::getRealTimeMs() - ticks); }
|
||||
// ------------------------------------------------------------------------
|
||||
void resetStartNetworkGameTimer() { m_start_game_ticks.store(0); }
|
||||
// ------------------------------------------------------------------------
|
||||
void setStartNetworkGameTimer(uint64_t ticks);
|
||||
|
||||
}; // MainLoop
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user