begin client-server

This commit is contained in:
2025-08-06 20:10:56 +02:00
parent 89213e9a97
commit c813c49707
26 changed files with 264 additions and 188 deletions

View File

@@ -4,20 +4,24 @@ namespace td {
namespace sim {
ServerSimulation::ServerSimulation(game::World& a_World, std::uint64_t a_StepTime) :
m_World(a_World), m_StepTime(a_StepTime), m_CurrentTime(0) {}
m_World(a_World), m_StepTime(a_StepTime), m_CurrentTime(0), m_History(std::numeric_limits<StepTime>::max()) {}
protocol::packets::LockStepsPacket ServerSimulation::Update() {
std::lock_guard<std::mutex> lock(m_Mutex);
m_World.Tick(m_History[m_CurrentTime], FpFloat(m_StepTime) / FpFloat(1000));
m_CurrentTime++;
return MakePacket();
}
protocol::packets::LockStepsPacket ServerSimulation::MakePacket() {
std::array<protocol::LockStep, LOCKSTEP_BUFFER_SIZE> nextSteps;
std::copy(m_History.begin() + m_CurrentTime, m_History.begin() + m_CurrentTime + nextSteps.size(), nextSteps.begin());
return {m_CurrentTime, std::move(nextSteps)};
}
template<typename T>
template <typename T>
void AddToCommandHistory(protocol::LockStep& a_LockStep, const T& a_Cmd) {
a_LockStep.push_back({std::make_shared<T>(a_Cmd)});
}