send world to client

This commit is contained in:
2025-08-22 11:41:58 +02:00
parent 20acbc0499
commit 7d58b881b2
22 changed files with 217 additions and 107 deletions

View File

@@ -1,7 +1,7 @@
#pragma once
#include <cassert>
#include <memory>
#include <td/misc/Signal.h>
namespace td {
@@ -16,7 +16,7 @@ class StateMachine {
virtual TReturn Update(TArgs... args) = 0;
template <typename T, typename... Args>
T* ChangeState(Args&&... args) {
T* ChangeState(Args... args) {
return m_StateMachine.template ChangeState<T>(std::forward<Args>(args)...);
}
@@ -24,18 +24,25 @@ class StateMachine {
TDerived& m_StateMachine;
};
utils::Signal<State&> OnStateChange;
StateMachine() {}
StateMachine(StateMachine&&) = default;
virtual ~StateMachine() {}
virtual TReturn Update(TArgs... args) {
assert(m_State && "You must change state at least once before updating !");
return m_State->Update(args...);
return m_State->Update(std::forward<TArgs>(args)...);
}
template <typename T, typename... Args>
T* ChangeState(Args&&... args) {
m_State = std::make_unique<T>(static_cast<TDerived&>(*this), std::forward<Args>(args)...);
T* ChangeState(Args... args) {
auto* currentState = m_State.get();
auto newState = std::make_unique<T>(static_cast<TDerived&>(*this), std::forward<Args>(args)...);
// This allows chaining
if (m_State.get() == currentState)
m_State = std::move(newState);
OnStateChange(*m_State);
return static_cast<T*>(m_State.get());
}

View File

@@ -2,8 +2,10 @@
#include <td/display/Display.h>
#include <td/misc/SlotGuard.h>
#include <client/ClientState.h>
namespace td {
class DisplayState : public Display::State, private utils::SlotGuard {
public:
DisplayState(Display& a_Display);
@@ -13,4 +15,5 @@ class DisplayState : public Display::State, private utils::SlotGuard {
virtual void OnAspectRatioChange(float a_Ratio) {}
virtual void OnKeyDown(SDL_Keycode a_Key) {}
};
} // namespace td

View File

@@ -33,6 +33,9 @@ class World {
bool LoadMap(const protocol::pdata::WorldHeader& worldHeader);
bool LoadMap(const protocol::pdata::WorldData& worldData);
protocol::packets::WorldHeaderPacket GetPacketHeader() const;
protocol::packets::WorldDataPacket GetPacketData() const;
bool LoadMapFromFile(const std::string& fileName);
bool SaveMap(const std::string& fileName) const;