move ClientSimulation in Client

This commit is contained in:
2025-08-10 12:19:50 +02:00
parent 8bdcffcfa6
commit e0080fa50c
8 changed files with 59 additions and 54 deletions

View File

@@ -3,9 +3,39 @@
namespace td {
namespace client {
GameState::GameState(Client& a_Client, const std::shared_ptr<game::World>& a_World) : ClientState(a_Client), m_World(a_World) {}
void GameState::HandlePacket(const protocol::PacketBase& a_Packet) {}
void GameState::Update(float a_Delta) {}
class ClientHandler : public protocol::PacketHandler {
private:
sim::ClientSimulation& m_Simulation;
using protocol::PacketHandler::Handle;
public:
ClientHandler(sim::ClientSimulation& a_Simulation) : m_Simulation(a_Simulation) {}
void Handle(const protocol::packets::LockStepsPacket& a_LockStep) {
m_Simulation.Handle(a_LockStep);
}
void Handle(const protocol::packets::LockStepResponsePacket& a_LockStep) {
m_Simulation.Handle(a_LockStep);
}
};
GameState::GameState(Client& a_Client, const std::shared_ptr<game::World>& a_World, std::uint64_t a_StepTime) :
ClientState(a_Client), m_World(a_World), m_Simulation(a_World, a_StepTime) {
m_Simulation.OnMissingLockSteps.Connect([this](const std::vector<td::StepTime>& a_MissingSteps) {
SendPacket(protocol::packets::LockStepRequestPacket(a_MissingSteps));
});
}
void GameState::HandlePacket(const protocol::PacketBase& a_Packet) {
ClientHandler handler(m_Simulation);
a_Packet.Dispatch(handler);
}
void GameState::Update(float a_Delta) {
m_CurrentLerp = m_Simulation.Update(a_Delta);
}
} // namespace client
} // namespace td