From 4bf6b8dad9923d6f3687e8ced72a4eda6a56220d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 2 Jan 2022 20:28:24 +0000 Subject: No need to pass GameState around, it has a global pointer --- ui/gameMainWindow.cpp | 14 +++++--------- ui/gameMainWindow.h | 6 ++---- ui/window.cpp | 6 +++--- ui/window.h | 6 ++---- 4 files changed, 12 insertions(+), 20 deletions(-) (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 41d55da..b904388 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -33,10 +33,7 @@ public: class GameMainSelector : public UIComponent { public: - GameMainSelector(const Camera * c, glm::vec2 size, const GameState * gs) : - UIComponent {{{}, size}}, camera {c}, gameState {gs} - { - } + GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { } void render(const UIShader &, const Position &) const override @@ -63,13 +60,12 @@ public: private: const Camera * camera; - const GameState * gameState; }; -GameMainWindow::GameMainWindow(size_t w, size_t h, const GameState * gameState) : +GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains"}, camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, rdiv(w, h), 0.1F, 10000.0F} { - uiComponents.create(&camera, glm::vec2 {w, h}, gameState); + uiComponents.create(&camera, glm::vec2 {w, h}); uiComponents.create(); uiComponents.create(glm::vec2 {-1150, -1150}); @@ -86,9 +82,9 @@ GameMainWindow::tick(TickDuration) } void -GameMainWindow::render(const GameState * gameState) const +GameMainWindow::render() const { glEnable(GL_DEPTH_TEST); gameState->world.apply(&Renderable::render, shader); - Window::render(gameState); + Window::render(); } diff --git a/ui/gameMainWindow.h b/ui/gameMainWindow.h index e26ad2d..68ad7ad 100644 --- a/ui/gameMainWindow.h +++ b/ui/gameMainWindow.h @@ -6,15 +6,13 @@ #include "window.h" #include -class GameState; - class GameMainWindow : public Window { public: - GameMainWindow(size_t w, size_t h, const GameState *); + GameMainWindow(size_t w, size_t h); void tick(TickDuration) override; - void render(const GameState * gameState) const override; + void render() const override; private: Shader shader; diff --git a/ui/window.cpp b/ui/window.cpp index 6a263aa..74a3a2f 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -77,18 +77,18 @@ Window::glContext() const } void -Window::refresh(const GameState * gameState) const +Window::refresh() const { SDL_GL_MakeCurrent(m_window, glContext()); clear(0.0F, 0.0F, 0.0F, 1.0F); - render(gameState); + render(); swapBuffers(); } void -Window::render(const GameState *) const +Window::render() const { glDisable(GL_DEPTH_TEST); uiComponents.apply(&UIComponent::render, uiShader, UIComponent::Position {}); diff --git a/ui/window.h b/ui/window.h index 49cdf45..b6ade60 100644 --- a/ui/window.h +++ b/ui/window.h @@ -10,8 +10,6 @@ #include #include -class GameState; - class Window { public: Window(size_t width, size_t height, const std::string & title); @@ -21,7 +19,7 @@ public: NO_MOVE(Window); virtual void tick(TickDuration elapsed) = 0; - void refresh(const GameState *) const; + void refresh() const; bool handleInput(const SDL_Event & e); void clear(float r, float g, float b, float a) const; @@ -29,7 +27,7 @@ public: protected: [[nodiscard]] SDL_GLContext glContext() const; - virtual void render(const GameState *) const; + virtual void render() const; using SDL_WindowPtr = wrapped_ptrt; SDL_WindowPtr m_window; -- cgit v1.2.3