migrate main

This commit is contained in:
2025-08-10 11:49:07 +02:00
parent 6b987cf78d
commit 8bdcffcfa6
13 changed files with 276 additions and 192 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <memory>
#include <cassert>
namespace td {
@@ -19,16 +20,17 @@ class StateMachine {
};
StateMachine() {}
StateMachine(StateMachine&&) = default;
virtual ~StateMachine() {}
TReturn Update(TArgs... args) {
assert(m_State);
virtual TReturn Update(TArgs... args) {
assert(m_State && "You must change state at least once before updating !");
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...);
m_State = std::make_unique<T>(static_cast<TDerived&>(*this), std::forward<Args>(args)...);
}
private:

View File

@@ -2,39 +2,14 @@
#include <string>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_keycode.h>
#include <SDL3/SDL_video.h>
#include <td/common/StateMachine.h>
#include <td/misc/Signal.h>
namespace td {
class Display {
public:
utils::Signal<float> OnAspectRatioChange;
utils::Signal<SDL_Keycode> OnKeyDown;
Display(int a_Width, int a_Height, const std::string& a_Title);
~Display();
void PollEvents();
void Update();
bool IsCloseRequested() {
return m_ShouldClose;
}
float GetAspectRatio() {
return m_AspectRatio;
}
int GetWindowWidth() {
return m_LastWidth;
}
int GetWindowHeight() {
return m_LastHeight;
}
class Display : public StateMachine<Display, void, float> {
private:
SDL_Window* m_Window;
SDL_GLContext m_GLContext;
@@ -43,6 +18,33 @@ class Display {
float m_AspectRatio;
bool m_ShouldClose;
public:
utils::Signal<float> OnAspectRatioChange;
utils::Signal<SDL_Keycode> OnKeyDown;
Display(int a_Width, int a_Height, const std::string& a_Title);
~Display();
void PollEvents();
void Update(float a_Delta) override;
void Close();
bool IsCloseRequested() {
return m_ShouldClose;
}
float GetAspectRatio() {
return m_AspectRatio;
}
int GetWindowWidth() {
return m_LastWidth;
}
int GetWindowHeight() {
return m_LastHeight;
}
};
} // namespace td

View File

@@ -0,0 +1,16 @@
#pragma once
#include <td/display/Display.h>
#include <td/misc/SlotGuard.h>
namespace td {
class DisplayState : public Display::State, private utils::SlotGuard {
public:
DisplayState(Display& a_Display);
virtual ~DisplayState() {}
protected:
virtual void OnAspectRatioChange(float a_Ratio) {}
virtual void OnKeyDown(SDL_Keycode a_Key) {}
};
} // namespace td

View File

@@ -0,0 +1,33 @@
#pragma once
#include <client/Client.h>
#include <server/Server.h>
#include <td/display/DisplayState.h>
#include <td/render/Renderer.h>
#include <td/simulation/ClientSimulation.h>
namespace td {
class ClientHandler;
class DebugWorldState : public DisplayState {
private:
render::RenderPipeline m_Renderer;
std::unique_ptr<client::Client> m_Client;
std::unique_ptr<server::Server> m_Server;
std::unique_ptr<sim::ClientSimulation> m_Simulation;
render::Camera m_Camera;
std::unique_ptr<ClientHandler> m_ClientHandler;
public:
DebugWorldState(Display& a_Display);
~DebugWorldState();
virtual void Update(float a_Delta) override;
protected:
virtual void OnAspectRatioChange(float a_Ratio) override;
virtual void OnKeyDown(SDL_Keycode a_Key) override;
};
} // namespace td