From 260803896231329081dbebbfac98e747319b2d85 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Sat, 3 Sep 2022 21:05:09 +0100
Subject: [PATCH] don't bother loading 3D stuff for 2D scenes

---
 demo/demo/grid.cpp           | 13 ++++++++-----
 demo/include/grid.hpp        |  6 +++++-
 fggl/scenes/game.cpp         | 14 ++++++++++++++
 include/fggl/scenes/game.hpp | 19 +++++++++++++++++++
 4 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/demo/demo/grid.cpp b/demo/demo/grid.cpp
index 2349a8e..670bbb7 100644
--- a/demo/demo/grid.cpp
+++ b/demo/demo/grid.cpp
@@ -90,14 +90,15 @@ namespace demo {
 			auto player = manager.create();
 			auto& cellPos = manager.add<CellPos>(player);
 			cellPos.pos = {5,5};
+			cellPos.direction = 1;
 		}
 	}
 
-	GridScene::GridScene(fggl::App &app) : Game(app), m_tiles(), m_grid(nullptr) {
+	GridScene::GridScene(fggl::App &app) : GameBase(app), m_tiles(), m_grid(nullptr) {
 	}
 
 	void GridScene::activate() {
-		Game::activate();
+		GameBase::activate();
 		fggl::debug::log(fggl::debug::Level::info, "GridScene::activate()");
 
 
@@ -164,16 +165,18 @@ namespace demo {
 			// convert grid pos to world pos
 			fggl::math::vec2f drawPos = cellPos.pos;
 			drawPos *= DRAW_SIZE;
+			drawPos += cellPos.drawOffset;
 
-			auto shape = fggl::gfx::make_shape(drawPos, DRAW_HALF, 3);
+			fggl::gfx::ShapeOpts opts;
+			opts.angleOffset = (float)cellPos.direction * fggl::math::HALF_PI + cellPos.rotationOffset;
+
+			auto shape = fggl::gfx::make_shape(drawPos, DRAW_HALF, 3, NAVAJO_WHITE, opts);
 			paint.fill(shape);
 		}
 	}
 
 	//float progress = 0.0f;
 	void GridScene::render(fggl::gfx::Graphics &gfx) {
-		Game::render(gfx);
-
 		fggl::gfx::Paint paint;
 		render_grid(paint, *m_grid);
 		render_objects(paint, *m_grid);
diff --git a/demo/include/grid.hpp b/demo/include/grid.hpp
index 4695431..c0fd98d 100644
--- a/demo/include/grid.hpp
+++ b/demo/include/grid.hpp
@@ -35,9 +35,13 @@ namespace demo {
 
 	struct CellPos {
 		fggl::math::vec2i pos;
+		uint8_t direction;
+
+		fggl::math::vec2f drawOffset{0.0F, 0.0F};
+		float rotationOffset{0.0F};
 	};
 
-	class GridScene : public fggl::scenes::Game {
+	class GridScene : public fggl::scenes::GameBase {
 		public:
 			explicit GridScene(fggl::App& app);
 			void activate() override;
diff --git a/fggl/scenes/game.cpp b/fggl/scenes/game.cpp
index c554243..db795a3 100644
--- a/fggl/scenes/game.cpp
+++ b/fggl/scenes/game.cpp
@@ -24,6 +24,20 @@
 
 namespace fggl::scenes {
 
+	GameBase::GameBase(fggl::App& app) : AppState(app) {
+		m_input = app.service<input::Input>();
+	}
+
+	void GameBase::update() {
+		// detect the user quitting
+		if (m_input != nullptr) {
+			bool escapePressed = m_input->keyboard.pressed(glfwGetKeyScancode(GLFW_KEY_ESCAPE));
+			if (escapePressed) {
+				m_owner.change_state(m_previous);
+			}
+		}
+	}
+
 	Game::Game(fggl::App &app) : AppState(app) {
 		m_input = app.service<input::Input>();
 	}
diff --git a/include/fggl/scenes/game.hpp b/include/fggl/scenes/game.hpp
index c5a074d..d9f7155 100644
--- a/include/fggl/scenes/game.hpp
+++ b/include/fggl/scenes/game.hpp
@@ -25,6 +25,25 @@
 
 namespace fggl::scenes {
 
+	class GameBase : public fggl::AppState {
+
+		public:
+			explicit GameBase(fggl::App &app);
+
+			void update() override;
+			void render(fggl::gfx::Graphics &gfx) override = 0;
+
+		protected:
+
+			inline auto input() -> input::Input & {
+				return *m_input;
+			}
+
+		private:
+			input::Input *m_input;
+			std::string m_previous = "menu";
+	};
+
 	class Game : public fggl::AppState {
 
 		public:
-- 
GitLab