From d842f41008095b9d73bb2fc88b6100a8a768698c Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Sat, 20 Aug 2022 12:55:40 +0100
Subject: [PATCH] use method rather than free-function for factory

---
 demo/include/PerlinNoise.hpp    | 39 +++++++++++----------------------
 fggl/gfx/ogl/renderer.cpp       | 10 ++++-----
 include/fggl/audio/audio.hpp    |  6 ++---
 include/fggl/gfx/ogl/shader.hpp | 18 ++++++++-------
 include/fggl/modules/module.hpp |  1 -
 5 files changed, 30 insertions(+), 44 deletions(-)

diff --git a/demo/include/PerlinNoise.hpp b/demo/include/PerlinNoise.hpp
index 453af65..65e53d6 100644
--- a/demo/include/PerlinNoise.hpp
+++ b/demo/include/PerlinNoise.hpp
@@ -1,29 +1,16 @@
-//----------------------------------------------------------------------------------------
-//
-//	siv::PerlinNoise
-//	Perlin noise library for modern C++
-//
-//	Copyright (C) 2013-2021 Ryo Suzuki <reputeless@gmail.com>
-//
-//	Permission is hereby granted, free of charge, to any person obtaining a copy
-//	of this software and associated documentation files(the "Software"), to deal
-//	in the Software without restriction, including without limitation the rights
-//	to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
-//	copies of the Software, and to permit persons to whom the Software is
-//	furnished to do so, subject to the following conditions :
-//
-//	The above copyright notice and this permission notice shall be included in
-//	all copies or substantial portions of the Software.
-//
-//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
-//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-//	THE SOFTWARE.
-//
-//----------------------------------------------------------------------------------------
+/*
+ * This file is part of FGGL.
+ *
+ * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
+ * later version.
+ *
+ * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with FGGL.
+ * If not, see <https://www.gnu.org/licenses/>.
+ */
 
 # pragma once
 # include <cstdint>
diff --git a/fggl/gfx/ogl/renderer.cpp b/fggl/gfx/ogl/renderer.cpp
index 8f38d34..241dfc5 100644
--- a/fggl/gfx/ogl/renderer.cpp
+++ b/fggl/gfx/ogl/renderer.cpp
@@ -161,7 +161,7 @@ namespace fggl::gfx {
 		m_cache = std::make_unique<ShaderCache>(m_storage);
 
 		// setup 2D rendering system
-		ShaderConfig shader2DConfig = ShaderFromName("canvas");
+		ShaderConfig shader2DConfig = ShaderConfig::named("canvas");
 		m_canvasPipeline = m_cache->load(shader2DConfig);
 		if ( m_canvasPipeline == INVALID_SHADER_ID) {
 			debug::error("failed to load shader2D - using fallback");
@@ -169,15 +169,15 @@ namespace fggl::gfx {
 		}
 
 		// FIXME this should not be hard-coded, it should be part of the scene loading process
-		m_cache->load(ShaderFromName("phong"));
-		m_cache->load(ShaderFromName("redbook/lighting"));
-		m_cache->load(ShaderFromName("redbook/debug"));
+		m_cache->load(ShaderConfig::named("phong"));
+		m_cache->load(ShaderConfig::named("redbook/lighting"));
+		m_cache->load(ShaderConfig::named("redbook/debug"));
 
 		// rendering helpers
 		m_canvasRenderer = std::make_unique<ogl4::CanvasRenderer>(fonts);
 		m_modelRenderer = std::make_unique<ogl4::StaticModelRenderer>(m_cache.get());
 
-		m_debugRenderer = std::make_unique<ogl4::DebugRenderer>(m_cache->getOrLoad(ShaderFromName("debug")));
+		m_debugRenderer = std::make_unique<ogl4::DebugRenderer>(m_cache->getOrLoad(ShaderConfig::named("debug")));
 		if ( m_debugRenderer ) {
 			dd::initialize(m_debugRenderer.get());
 		}
diff --git a/include/fggl/audio/audio.hpp b/include/fggl/audio/audio.hpp
index db2cb60..4f733d2 100644
--- a/include/fggl/audio/audio.hpp
+++ b/include/fggl/audio/audio.hpp
@@ -43,12 +43,10 @@ namespace fggl::audio {
 	class AudioService {
 		public:
 			constexpr static const modules::ModuleService service = SERVICE_AUDIO_PLAYBACK;
-
-			AudioService() = default;
-			virtual ~AudioService() = default;
-
 			virtual void play(const std::string& filename, bool looping = false) = 0;
 			virtual void play(AudioClip& clip, bool looping = false) = 0;
+
+			virtual ~AudioService() = default;
 	};
 
 } // namespace fggl::audio
diff --git a/include/fggl/gfx/ogl/shader.hpp b/include/fggl/gfx/ogl/shader.hpp
index ef9d895..f1fef1f 100644
--- a/include/fggl/gfx/ogl/shader.hpp
+++ b/include/fggl/gfx/ogl/shader.hpp
@@ -36,6 +36,16 @@ namespace fggl::gfx {
 		// optional parts
 		std::string geometry;
 		bool hasGeom = false;
+
+		constexpr static ShaderConfig named(const std::string& name, bool hasGeom = false) {
+			return {
+				.name = name,
+				.vertex = name + "_vert.glsl",
+				.fragment = name + "_frag.glsl",
+				.geometry = hasGeom ? name + "_geom.glsl" : "",
+				.hasGeom = hasGeom
+			};
+		}
 	};
 
 	struct ShaderSources {
@@ -45,14 +55,6 @@ namespace fggl::gfx {
 		std::string geometrySource;
 	};
 
-	inline ShaderConfig ShaderFromName(const std::string &name) {
-		return {
-			name,
-			name + "_vert.glsl",
-			name + "_frag.glsl"
-		};
-	}
-
 	struct BinaryCache {
 		void *data = nullptr;
 		GLsizei size = 0;
diff --git a/include/fggl/modules/module.hpp b/include/fggl/modules/module.hpp
index 6fac536..1c8c8ee 100644
--- a/include/fggl/modules/module.hpp
+++ b/include/fggl/modules/module.hpp
@@ -30,7 +30,6 @@
 namespace fggl::modules {
 
 	using ModuleIdentifier = std::string;
-
 	using ModuleService = util::OpaqueName<std::string_view, struct ModuleServiceTag>;
 
 	constexpr ModuleService make_service(const std::string_view name) {
-- 
GitLab