too many things
This commit is contained in:
32
src/td/simulation/RealTimeSimulation.cpp
Normal file
32
src/td/simulation/RealTimeSimulation.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <td/simulation/RealTimeSimulation.h>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
std::uint64_t GetTime() {
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock().now().time_since_epoch()).count());
|
||||
}
|
||||
|
||||
RealTimeSimulation::RealTimeSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime) :
|
||||
m_StepTime(a_StepTime),
|
||||
m_World(a_World),
|
||||
m_History(std::move(a_History)),
|
||||
m_CurrentTime(0),
|
||||
m_LastTime(GetTime()),
|
||||
m_CurrentStep(0) {}
|
||||
|
||||
void RealTimeSimulation::Update() {
|
||||
m_CurrentTime += GetTime() - m_LastTime;
|
||||
m_LastTime = GetTime();
|
||||
if (m_CurrentTime > m_StepTime) {
|
||||
m_World.Tick(m_History[m_CurrentStep], FpFloat(m_StepTime) / FpFloat(1000));
|
||||
m_CurrentStep++;
|
||||
m_CurrentTime -= m_StepTime;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sim
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user