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

@@ -10,7 +10,6 @@
#include <td/render/renderer/EntityRenderer.h>
#include <td/render/renderer/TowerRenderer.h>
#include <td/render/renderer/WorldRenderer.h>
#include <td/simulation/ClientSimulation.h>
#include <sp/common/DataBuffer.h>
#include <sp/extensions/Compress.h>
@@ -30,24 +29,6 @@
namespace td {
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);
}
};
class WorldApply : public protocol::PacketHandler {
private:
game::World& m_World;
@@ -122,26 +103,15 @@ DebugWorldState::DebugWorldState(Display& a_Display) : DisplayState(a_Display) {
m_Camera.SetCamPos({77, 7, 13});
m_Camera.UpdatePerspective(m_StateMachine.GetAspectRatio());
m_Simulation = std::make_unique<sim::ClientSimulation>(*clientWorld, STEP_TIME);
m_ClientHandler = std::make_unique<ClientHandler>(*m_Simulation);
// packets from the server to the client
clientFakeSocket->OnReceive.Connect([this](const protocol::PacketBase& a_Packet) { a_Packet.Dispatch(*m_ClientHandler); });
m_Simulation->OnMissingLockSteps.Connect([clientFakeSocket](const std::vector<td::StepTime>& a_MissingSteps) {
clientFakeSocket->Send(protocol::packets::LockStepRequestPacket(a_MissingSteps));
});
m_ClientState = m_Client->ChangeState<client::GameState>(clientWorld, STEP_TIME);
m_Server->ChangeState<server::GameState>(serverWorld);
m_Client->ChangeState<client::GameState>(clientWorld);
}
void DebugWorldState::Update(float a_Delta) {
m_Server->Update(a_Delta);
m_Client->Update(a_Delta);
float lerp = m_Simulation->Update(a_Delta);
m_Renderer.Render(lerp);
// TODO: m_ClientState might be invalid !
m_Renderer.Render(m_ClientState->GetCurrentLerp());
}
void DebugWorldState::OnAspectRatioChange(float a_Ratio) {