move ClientSimulation in Client
This commit is contained in:
@@ -16,7 +16,7 @@ std::uint64_t GetTime() {
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock().now().time_since_epoch()).count());
|
||||
}
|
||||
|
||||
ClientSimulation::ClientSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime) :
|
||||
ClientSimulation::ClientSimulation(std::shared_ptr<game::World> a_World, GameHistory&& a_History, std::uint64_t a_StepTime) :
|
||||
m_StepTime(a_StepTime),
|
||||
m_World(a_World),
|
||||
m_CurrentTime(0),
|
||||
@@ -30,7 +30,7 @@ ClientSimulation::ClientSimulation(game::World& a_World, GameHistory&& a_History
|
||||
Step();
|
||||
}
|
||||
|
||||
ClientSimulation::ClientSimulation(game::World& a_World, std::uint64_t a_StepTime) :
|
||||
ClientSimulation::ClientSimulation(std::shared_ptr<game::World> a_World, std::uint64_t a_StepTime) :
|
||||
m_StepTime(a_StepTime),
|
||||
m_World(a_World),
|
||||
m_History(std::numeric_limits<StepTime>::max()),
|
||||
@@ -41,7 +41,7 @@ ClientSimulation::ClientSimulation(game::World& a_World, std::uint64_t a_StepTim
|
||||
|
||||
float ClientSimulation::Update(float a_Delta) {
|
||||
// TODO: handle freezes (m_CurrentTime > 2 * m_StepTime)
|
||||
static const float stepTimeSecond = static_cast<float>(STEP_TIME) / 1000.0f;
|
||||
static const float stepTimeSecond = static_cast<float>(m_StepTime) / 1000.0f;
|
||||
m_CurrentTime += a_Delta;
|
||||
if (m_CurrentTime > stepTimeSecond) {
|
||||
m_CurrentTime = std::fmod(m_CurrentTime, stepTimeSecond);
|
||||
@@ -53,13 +53,13 @@ float ClientSimulation::Update(float a_Delta) {
|
||||
bool ClientSimulation::Step() {
|
||||
const auto& step = m_History[m_CurrentStep];
|
||||
if (step.has_value()) {
|
||||
auto snapshot = m_World.Tick(step.value(), FpFloat(m_StepTime) / FpFloat(1000));
|
||||
auto snapshot = m_World->Tick(step.value(), FpFloat(m_StepTime) / FpFloat(1000));
|
||||
if (m_LastValidStep + 1 == m_CurrentStep) {
|
||||
m_LastValidStep = m_CurrentStep;
|
||||
m_LastSnapshot = snapshot;
|
||||
}
|
||||
} else {
|
||||
m_World.Tick(EMPTY_LOCKSTEP, FpFloat(m_StepTime) / FpFloat(1000));
|
||||
m_World->Tick(EMPTY_LOCKSTEP, FpFloat(m_StepTime) / FpFloat(1000));
|
||||
std::cout << "Empty tick (" << m_CurrentStep << ") !\n";
|
||||
}
|
||||
m_CurrentStep++;
|
||||
@@ -103,7 +103,7 @@ void ClientSimulation::FastReplay() {
|
||||
if (m_LastValidStep + 1 >= m_CurrentStep)
|
||||
return;
|
||||
|
||||
m_World.ResetSnapshots(m_LastSnapshot, m_LastSnapshot);
|
||||
m_World->ResetSnapshots(m_LastSnapshot, m_LastSnapshot);
|
||||
|
||||
const std::size_t stepCount = m_CurrentStep - m_LastValidStep;
|
||||
m_CurrentStep = m_LastValidStep;
|
||||
|
||||
Reference in New Issue
Block a user