From 23b6a1225ee192cb2dd15463b83ee50153830adf Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Tue, 19 Apr 2022 22:29:44 +0100
Subject: [PATCH] clean up includes

---
 demo/main.cpp                   | 56 +++----------------
 include/fggl/ecs3/ecs.hpp       |  1 -
 include/fggl/gfx/compat.hpp     |  8 +--
 include/fggl/gfx/ogl/compat.hpp | 96 ++-------------------------------
 4 files changed, 18 insertions(+), 143 deletions(-)

diff --git a/demo/main.cpp b/demo/main.cpp
index 2a06613..73ff92b 100644
--- a/demo/main.cpp
+++ b/demo/main.cpp
@@ -1,4 +1,3 @@
-#include <fggl/ecs3/types.hpp>
 #include <filesystem>
 #include <iostream>
 #include <memory>
@@ -11,19 +10,22 @@
 #include <fggl/gfx/window.hpp>
 #include <fggl/gfx/camera.hpp>
 
-#include <fggl/gfx/compat.hpp>
-#include <fggl/gfx/ogl/compat.hpp>
+#include "fggl/gfx/ogl/renderer.hpp"
+#include "fggl/gfx/ogl/compat.hpp"
+#include "fggl/gfx/compat.hpp"
 
+#include <fggl/data/heightmap.h>
 #include <fggl/data/procedural.hpp>
 #include <fggl/data/storage.hpp>
 #include <fggl/util/chrono.hpp>
 #include <fggl/util/service.h>
+
+#include <fggl/ecs3/types.hpp>
 #include <fggl/ecs3/ecs.hpp>
 
 #include <fggl/input/camera_input.h>
 
 #include <fggl/debug/debug.h>
-#include <fggl/scenes/Scene.h>
 
 // FIXME: imgui and perlinNoise shouldn't form part of our public API >.<
 #include <imgui.h>
@@ -31,8 +33,6 @@
 
 constexpr bool showNormals = false;
 
-std::shared_ptr<fggl::gfx::ecsOpenGLModule> glModule;
-
 // prototype of resource discovery
 void discover(const std::filesystem::path& base) {
 
@@ -102,46 +102,6 @@ void placeObject(fggl::ecs3::World& world, fggl::ecs::entity_t parent, fggl::ecs
     result->origin( targetPos );
 }
 
-class MenuScene : public fggl::scenes::Scene, public fggl::AppState {
-
-public:
-    explicit MenuScene(fggl::App& app) : fggl::AppState(app), m_inputs(nullptr) {}
-    ~MenuScene() override = default;
-
-    void activate() override {
-        auto& locator = fggl::util::ServiceLocator::instance();
-        m_inputs = locator.providePtr<fggl::input::Input>();
-
-        setup();
-    }
-
-    void setup() override {
-    }
-
-    void cleanup() override {
-
-    }
-
-    void update() override {
-        if ( !m_inputs ) {
-            return;
-        }
-
-        bool leftMouse = m_inputs->mouse.down(fggl::input::MouseButton::LEFT);
-        if (leftMouse) {
-            auto scenes = fggl::util::ServiceLocator::instance().providePtr<fggl::scenes::SceneManager>();
-            scenes->activate("game");
-        }
-    }
-
-    void render() override {
-
-    }
-
-private:
-    InputManager m_inputs;
-
-};
 
 class GameScene : public fggl::AppState {
 public:
@@ -389,8 +349,8 @@ int main(int argc, const char* argv[]) {
     app.setWindow( std::move(window) );
 
 	// load a bunch of modules to provide game functionality
-	app.use<fggl::ecs3::ecsTypes>();
-	app.use<fggl::gfx::ecsOpenGLModule>(storage);
+	//app.use<fggl::ecs3::ecsTypes>();
+	app.use<fggl::gfx::SceneUtils>();
 
 	// atlas testing
 	std::vector< fggl::gfx::ImageAtlas<char>::SubImage > images;
diff --git a/include/fggl/ecs3/ecs.hpp b/include/fggl/ecs3/ecs.hpp
index 0619eda..20e1165 100644
--- a/include/fggl/ecs3/ecs.hpp
+++ b/include/fggl/ecs3/ecs.hpp
@@ -17,7 +17,6 @@ namespace fggl::ecs3 {
 			}
 
 			inline void onLoad(ModuleManager& manager, TypeRegistry& types) override {
-				types.make<math::Transform>();
 			}
 	};
 
diff --git a/include/fggl/gfx/compat.hpp b/include/fggl/gfx/compat.hpp
index 0dfdb9d..6d5f2e6 100644
--- a/include/fggl/gfx/compat.hpp
+++ b/include/fggl/gfx/compat.hpp
@@ -1,5 +1,5 @@
-#ifndef FGGL_GFX_GLFW_COMPAT_H
-#define FGGL_GFX_GLFW_COMPAT_H
+#ifndef FGGL_GFX_COMPAT_HPP
+#define FGGL_GFX_COMPAT_HPP
 /**
  * Window management Calls.
  *
@@ -22,7 +22,6 @@ namespace fggl::gfx {
 	// fake module support - allows us to still RAII
 	//
 	struct ecsGlfwModule : ecs3::Module {
-		std::shared_ptr<GlfwContext> context;
 
 		inline explicit
 		ecsGlfwModule(std::shared_ptr<fggl::input::Input> inputs) : context( std::make_shared<GlfwContext>(std::move(inputs))) {
@@ -44,6 +43,9 @@ namespace fggl::gfx {
 			return "gfx::glfw";
 		}
 
+		private:
+			std::shared_ptr<GlfwContext> context;
+
 	};
 
 }
diff --git a/include/fggl/gfx/ogl/compat.hpp b/include/fggl/gfx/ogl/compat.hpp
index c68c7f2..2b51ecd 100644
--- a/include/fggl/gfx/ogl/compat.hpp
+++ b/include/fggl/gfx/ogl/compat.hpp
@@ -24,117 +24,31 @@
 
 namespace fggl::gfx {
 
-	void generateHeightMesh(data::HeightMap *heightMap, data::Mesh);
-
 	//
 	// fake module support - allows us to still RAII
 	//
-	struct ecsOpenGLModule : ecs3::Module {
-		fggl::gfx::MeshRenderer renderer;
-		fggl::gfx::ShaderCache cache;
+	struct SceneUtils : ecs3::Module {
 
-		explicit ecsOpenGLModule(std::shared_ptr<fggl::data::Storage> storage) :
-			renderer(),
-			cache(std::move(storage)) {}
+		SceneUtils() = default;
 
+		[[nodiscard]]
 		std::string name() const override {
-			return "gfx::opengl";
-		}
-
-		void uploadMesh(ecs3::World *world, ecs::entity_t entity) {
-			auto *meshData = world->get<data::StaticMesh>(entity);
-
-			auto pipeline = cache.get(meshData->pipeline);
-			auto glMesh = renderer.upload(meshData->mesh);
-
-			glMesh.pipeline = pipeline;
-			world->set<fggl::gfx::GlRenderToken>(entity, &glMesh);
-		}
-
-		void uploadHeightmap(ecs3::World *world, ecs::entity_t entity) {
-			auto *const heightmap = world->get<data::HeightMap>(entity);
-
-			data::Mesh tmpMesh{};
-			data::generateHeightMesh(heightmap, tmpMesh);
-			auto glMesh = renderer.upload(tmpMesh);
-
-			auto pipeline = cache.get("phong");
-			glMesh.pipeline = pipeline;
-			glMesh.renderType = GlRenderType::triangle_strip;
-			world->set<fggl::gfx::GlRenderToken>(entity, &glMesh);
+			return "gfx::scene";
 		}
 
 		void onLoad(ecs3::ModuleManager &manager, ecs3::TypeRegistry &types) override {
 			// mesh dependencies
+			types.make<math::Transform>();
 			types.make<data::StaticMesh>();
 			types.make<data::HeightMap>();
 
 			// camera dependencies
 			types.make<fggl::gfx::Camera>();
 			types.make<fggl::input::FreeCamKeys>();
-
-			/*
-			 * old API stuff - not used
-				// opengl
-				types.make<fggl::gfx::GlRenderToken>();
-
-				// callbacks
-				auto upload_cb = [this](auto a, auto b) { this->uploadMesh(a, b); };
-				manager.onAdd<fggl::gfx::StaticMesh>(upload_cb);
-				manager.onAdd<fggl::data::HeightMap>([this](auto a, auto b) { this->uploadHeightmap(a, b); });
-			 */
 		}
 
 	};
 
-	using OglModule = std::shared_ptr<ecsOpenGLModule>;
-
-	//
-	// Loading related functions - should be handled in modules/data-driven
-	//
-	inline void loadPipeline(OglModule &mod, const std::string &name, bool hasGeom) {
-		fggl::gfx::ShaderConfig config;
-		config.name = name;
-		config.vertex = name + "_vert.glsl";
-		config.fragment = name + "_frag.glsl";
-		if (hasGeom) {
-			config.geometry = name + "_geom.glsl";
-		}
-		mod->cache.load(config);
-	}
-
-	inline void loadBasicPipeline(OglModule &mod, const std::string &name) {
-		loadPipeline(mod, name, false);
-	}
-
-	//
-	// fake module/callbacks - our ECS doesn't have module/callback support yet.
-	// 
-	void onStaticMeshAdded(ecs3::World &ecs, ecs::entity_t entity, OglModule &mod) {
-		//spdlog::info("[CALLBACK] static mesh added, renderable?");
-		/*
-		auto meshData = ecs.get<gfx::StaticMesh>(entity);
-		auto pipeline = mod->cache.get(meshData->pipeline);
-
-		auto glMesh = mod->renderer.upload(meshData->mesh);
-		glMesh.pipeline = pipeline;
-
-		ecs.set<fggl::gfx::GlRenderToken>(entity, &glMesh);
-		 */
-	}
-
-	inline void renderMeshes(OglModule &mod, ecs3::World &ecs, float dt) {
-		// get the camera
-		auto cameras = ecs.findMatching<fggl::gfx::Camera>();
-		if (cameras.empty()) {
-			return;
-		}
-		auto camera = cameras[0];
-
-		// get the models
-		mod->renderer.render(ecs, camera, dt);
-	}
-
 }
 
 #endif
-- 
GitLab