add StateMachine

This commit is contained in:
2025-08-09 11:23:17 +02:00
parent ac3e949323
commit cba790f804
23 changed files with 174 additions and 244 deletions

View File

@@ -0,0 +1,39 @@
#pragma once
#include <memory>
namespace td {
template <typename TDerived, typename TReturn, typename... TArgs>
class StateMachine {
public:
class State {
public:
State(TDerived& a_StateMachine) : m_StateMachine(a_StateMachine) {}
virtual ~State() {}
virtual TReturn Update(TArgs... args) = 0;
protected:
TDerived& m_StateMachine;
};
StateMachine() {}
virtual ~StateMachine() {}
TReturn Update(TArgs... args) {
assert(m_State);
return m_State->Update(args...);
}
template <typename T, typename... Args>
void ChangeState(Args&&... args) {
m_State = std::make_unique<T>(static_cast<TDerived&>(*this), args...);
}
private:
std::unique_ptr<State> m_State;
};
} // namespace td

View File

@@ -16,8 +16,7 @@ class ClientSimulation : public protocol::PacketHandler {
std::uint64_t m_StepTime;
game::World& m_World;
GameBuffer m_History;
std::uint64_t m_CurrentTime;
std::uint64_t m_LastTime;
float m_CurrentTime;
StepTime m_CurrentStep;
std::shared_ptr<WorldSnapshot> m_LastSnapshot;
@@ -45,7 +44,7 @@ class ClientSimulation : public protocol::PacketHandler {
/**
* \return the progress [0-1] between two steps
*/
float Update();
float Update(float a_Delta);
virtual void Handle(const protocol::packets::LockStepsPacket& a_LockSteps) override;
virtual void Handle(const protocol::packets::LockStepResponsePacket& a_LockSteps) override;