begin serversimulation
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
#include <td/simulation/RealTimeSimulation.h>
|
||||
#include <td/simulation/ClientSimulation.h>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
const protocol::LockStep RealTimeSimulation::EMPTY_LOCKSTEP;
|
||||
const protocol::LockStep ClientSimulation::EMPTY_LOCKSTEP;
|
||||
|
||||
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) :
|
||||
ClientSimulation::ClientSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime) :
|
||||
m_StepTime(a_StepTime),
|
||||
m_World(a_World),
|
||||
m_CurrentTime(0),
|
||||
@@ -27,7 +27,7 @@ RealTimeSimulation::RealTimeSimulation(game::World& a_World, GameHistory&& a_His
|
||||
Step();
|
||||
}
|
||||
|
||||
RealTimeSimulation::RealTimeSimulation(game::World& a_World, std::uint64_t a_StepTime) :
|
||||
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()),
|
||||
@@ -39,7 +39,7 @@ RealTimeSimulation::RealTimeSimulation(game::World& a_World, std::uint64_t a_Ste
|
||||
Step();
|
||||
}
|
||||
|
||||
float RealTimeSimulation::Update() {
|
||||
float ClientSimulation::Update() {
|
||||
// TODO: handle freezes (m_CurrentTime > 2 * m_StepTime)
|
||||
m_CurrentTime += GetTime() - m_LastTime;
|
||||
m_LastTime = GetTime();
|
||||
@@ -50,7 +50,7 @@ float RealTimeSimulation::Update() {
|
||||
return (float)m_CurrentTime / (float)m_StepTime;
|
||||
}
|
||||
|
||||
void RealTimeSimulation::Step() {
|
||||
void ClientSimulation::Step() {
|
||||
const auto& step = m_History[m_CurrentStep];
|
||||
if (step.has_value()) {
|
||||
m_LastSnapshot = m_World.Tick(step.value(), FpFloat(m_StepTime) / FpFloat(1000));
|
||||
@@ -61,7 +61,7 @@ void RealTimeSimulation::Step() {
|
||||
m_CurrentStep++;
|
||||
}
|
||||
|
||||
void RealTimeSimulation::HandlePacket(const protocol::packets::LockStepsPacket& a_LockSteps) {
|
||||
void ClientSimulation::Handle(const protocol::packets::LockStepsPacket& a_LockSteps) {
|
||||
const auto& steps = a_LockSteps->m_LockSteps;
|
||||
for (std::size_t i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) {
|
||||
m_History[a_LockSteps->m_FirstFrameNumber + i] = steps[i];
|
||||
@@ -69,15 +69,17 @@ void RealTimeSimulation::HandlePacket(const protocol::packets::LockStepsPacket&
|
||||
FastReplay();
|
||||
}
|
||||
|
||||
void RealTimeSimulation::HandlePacket(const protocol::packets::PredictCommandPacket& a_Predict) {}
|
||||
void ClientSimulation::Handle(const protocol::packets::PredictCommandPacket& a_Predict) {
|
||||
|
||||
}
|
||||
|
||||
void RealTimeSimulation::FastForward(std::size_t a_Count) {
|
||||
void ClientSimulation::FastForward(std::size_t a_Count) {
|
||||
for (std::size_t i = 0; i < a_Count; i++) {
|
||||
Step();
|
||||
}
|
||||
}
|
||||
|
||||
void RealTimeSimulation::FastReplay() {
|
||||
void ClientSimulation::FastReplay() {
|
||||
if (m_LastValidStep >= m_CurrentStep)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user