begin serversimulation
This commit is contained in:
63
include/td/simulation/ClientSimulation.h
Normal file
63
include/td/simulation/ClientSimulation.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/game/World.h>
|
||||
#include <optional>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
using GameHistory = std::vector<td::protocol::LockStep>;
|
||||
using GameBuffer = std::vector<std::optional<td::protocol::LockStep>>;
|
||||
|
||||
// TODO: OnEnd signal
|
||||
class ClientSimulation : public protocol::PacketHandler {
|
||||
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<WorldSnapshot> m_LastSnapshot;
|
||||
std::uint64_t m_LastValidStep;
|
||||
|
||||
static const protocol::LockStep EMPTY_LOCKSTEP;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Replay constructor
|
||||
* \param a_StepTime in ms
|
||||
*/
|
||||
ClientSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime);
|
||||
|
||||
/**
|
||||
* \brief Live update constructor (continuous game updates)
|
||||
* \param a_StepTime in ms
|
||||
*/
|
||||
ClientSimulation(game::World& a_World, std::uint64_t a_StepTime);
|
||||
|
||||
/**
|
||||
* \return the progress [0-1] between two steps
|
||||
*/
|
||||
float Update();
|
||||
|
||||
void Handle(const protocol::packets::LockStepsPacket& a_LockSteps) override;
|
||||
void Handle(const protocol::packets::PredictCommandPacket& a_Predict) override;
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user