#pragma once
#include
#include
namespace td {
namespace sim {
using GameHistory = std::vector;
using GameBuffer = std::vector>;
class RealTimeSimulation {
private:
std::uint64_t m_StepTime;
game::World& m_World;
GameBuffer m_History;
std::uint64_t m_CurrentTime;
std::uint64_t m_LastTime;
std::size_t m_CurrentStep;
std::shared_ptr m_LastSnapshot;
std::uint64_t m_LastValidStep;
static const protocol::LockStep EMPTY_LOCKSTEP;
public:
/**
* \brief Replay constructor
* \param a_StepTime in ms
*/
RealTimeSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime);
/**
* \brief Live update constructor (continuous game updates)
* \param a_StepTime in ms
*/
RealTimeSimulation(game::World& a_World, std::uint64_t a_StepTime);
/**
* \return the progress [0-1] between two steps
*/
float Update();
void HandlePacket(const protocol::packets::LockStepsPacket& a_LockSteps);
void HandlePacket(const protocol::packets::PredictCommandPacket& a_Predict);
private:
void Step();
/**
* \brief Ticks a_Count times
*/
void FastForward(std::size_t a_Count);
/**
* \brief Tries to recompute simulation if needed (for example in late command receival)
*/
void FastReplay();
};
} // namespace sim
} // namespace td
|