begin client-server
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
@@ -30,13 +32,13 @@ ClientSimulation::ClientSimulation(game::World& a_World, GameHistory&& a_History
|
||||
ClientSimulation::ClientSimulation(game::World& a_World, std::uint64_t a_StepTime) :
|
||||
m_StepTime(a_StepTime),
|
||||
m_World(a_World),
|
||||
m_History(std::numeric_limits<std::uint16_t>::max()),
|
||||
m_History(std::numeric_limits<StepTime>::max()),
|
||||
m_CurrentTime(0),
|
||||
m_LastTime(GetTime()),
|
||||
m_CurrentStep(0),
|
||||
m_LastSnapshot(std::make_shared<WorldSnapshot>()),
|
||||
m_LastValidStep(0) {
|
||||
Step();
|
||||
// Step();
|
||||
}
|
||||
|
||||
float ClientSimulation::Update() {
|
||||
@@ -45,7 +47,7 @@ float ClientSimulation::Update() {
|
||||
m_LastTime = GetTime();
|
||||
if (m_CurrentTime > m_StepTime) {
|
||||
Step();
|
||||
m_CurrentTime -= m_StepTime;
|
||||
m_CurrentTime %= m_StepTime;
|
||||
}
|
||||
return (float)m_CurrentTime / (float)m_StepTime;
|
||||
}
|
||||
@@ -69,25 +71,25 @@ void ClientSimulation::Handle(const protocol::packets::LockStepsPacket& a_LockSt
|
||||
FastReplay();
|
||||
}
|
||||
|
||||
void ClientSimulation::Handle(const protocol::packets::PredictCommandPacket& a_Predict) {
|
||||
|
||||
}
|
||||
void ClientSimulation::Handle(const protocol::packets::PredictCommandPacket& a_Predict) {}
|
||||
|
||||
void ClientSimulation::FastForward(std::size_t a_Count) {
|
||||
for (std::size_t i = 0; i < a_Count; i++) {
|
||||
Step();
|
||||
}
|
||||
std::cout << "Was behind " << a_Count << " ticks !\n";
|
||||
}
|
||||
|
||||
void ClientSimulation::FastReplay() {
|
||||
if (m_LastValidStep >= m_CurrentStep)
|
||||
if (m_LastValidStep + 1 >= m_CurrentStep)
|
||||
return;
|
||||
|
||||
m_World.ResetSnapshots(m_LastSnapshot, m_LastSnapshot);
|
||||
|
||||
// TODO: cover holes
|
||||
const std::size_t stepCount = m_CurrentStep - m_LastValidStep;
|
||||
m_CurrentStep = m_LastValidStep;
|
||||
|
||||
|
||||
FastForward(stepCount);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user