From 84135396a755bf78bb09fdcd715731a18fee6124 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <Joseph.WaltonRivers@falmouth.ac.uk>
Date: Wed, 22 Jun 2022 13:46:26 +0100
Subject: [PATCH] changes to build on windows

---
 .gitignore                             |  1 +
 CMakeLists.txt                         | 12 ++--
 demo/CMakeLists.txt                    |  6 +-
 fggl/CMakeLists.txt                    | 12 +++-
 fggl/audio/openal/CMakeLists.txt       |  4 +-
 fggl/audio/types.cpp                   |  4 +-
 fggl/ecs3/prototype/loader.cpp         | 90 ++++++++++++++++++++++++++
 fggl/gfx/ogl/CMakeLists.txt            | 10 +--
 fggl/gfx/ogl/renderer.cpp              |  2 +-
 fggl/gfx/ogl/shader.cpp                |  4 +-
 fggl/math/CMakeLists.txt               |  4 +-
 fggl/phys/bullet/CMakeLists.txt        | 10 +--
 include/fggl/ecs3/prototype/loader.hpp | 89 +------------------------
 include/fggl/gui/fonts.hpp             |  2 +-
 include/fggl/gui/widget.hpp            |  2 +-
 include/fggl/phys/bullet/phys_draw.hpp |  7 +-
 16 files changed, 135 insertions(+), 124 deletions(-)
 create mode 100644 fggl/ecs3/prototype/loader.cpp

diff --git a/.gitignore b/.gitignore
index a0feae3..6371960 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,5 +12,6 @@ compile_commands.json
 
 # windows visual studio
 .vs/
+out/
 CMakePresets.json
 CMakeSettings.json
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 663220e..1eb567c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,6 +12,11 @@ option(FGGL_DOCS "Should we build documentation?" ON)
 
 set(CONAN_BUILD_TYPE "Debug")
 
+if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+  set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
+      CACHE STRING "")
+endif()
+
 # Define the project
 project(fggl
 	VERSION 0.1
@@ -43,13 +48,6 @@ endif()
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 
 
-##
-# begin windows support
-##
-if(MSVC)
-  target_compile_options(${PROJECT_NAME} PUBLIC "/ZI")
-  target_link_options(${PROJECT_NAME} PUBLIC "/INCREMENTAL")
-endif()
 ##
 # end windows support
 ##
diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt
index faccc6a..c45405f 100644
--- a/demo/CMakeLists.txt
+++ b/demo/CMakeLists.txt
@@ -1,5 +1,5 @@
-cmake_minimum_required(VERSION 3.16)
-project(demo)
+#cmake_minimum_required(VERSION 3.16)
+#project(demo)
 
 # Executable
 add_executable(demo
@@ -32,4 +32,4 @@ install(
 install(
         DIRECTORY data
         DESTINATION ${CMAKE_INSTALL_DATADIR}
-)
\ No newline at end of file
+)
diff --git a/fggl/CMakeLists.txt b/fggl/CMakeLists.txt
index b8d35b1..476c4f6 100644
--- a/fggl/CMakeLists.txt
+++ b/fggl/CMakeLists.txt
@@ -3,7 +3,7 @@ file(GLOB_RECURSE HEADER_LIST CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/include/fgg
 
 # the fggl library itself
 # Should be shared linkage for legal reasons (LGPL)
-add_library(fggl SHARED ${HEADER_LIST})
+add_library(fggl ${HEADER_LIST})
 
 # we need to tell people using the library about our headers
 target_include_directories(fggl
@@ -65,7 +65,7 @@ target_link_libraries(fggl PUBLIC yaml-cpp)
 
 # model loading
 find_package(assimp)
-target_link_libraries(${PROJECT_NAME} PUBLIC assimp)
+target_link_libraries(${PROJECT_NAME} PUBLIC assimp::assimp)
 
 find_package(Freetype)
 target_link_libraries(${PROJECT_NAME} PUBLIC Freetype::Freetype)
@@ -79,3 +79,11 @@ add_subdirectory(phys/bullet)
 
 # Debug backend
 add_subdirectory(debug)
+
+##
+# begin windows support
+##
+if(MSVC)
+  target_compile_options(${PROJECT_NAME} PUBLIC "/ZI")
+  target_link_options(${PROJECT_NAME} PUBLIC "/INCREMENTAL")
+endif()
diff --git a/fggl/audio/openal/CMakeLists.txt b/fggl/audio/openal/CMakeLists.txt
index 00be68a..df765a0 100644
--- a/fggl/audio/openal/CMakeLists.txt
+++ b/fggl/audio/openal/CMakeLists.txt
@@ -1,5 +1,5 @@
-find_package( OpenAL REQUIRED )
-target_link_libraries( fggl PUBLIC openal )
+find_package( OpenAL CONFIG REQUIRED )
+target_link_libraries( fggl PUBLIC OpenAL::OpenAL )
 
 target_sources(fggl
     PRIVATE
diff --git a/fggl/audio/types.cpp b/fggl/audio/types.cpp
index e71ffac..7de8e0a 100644
--- a/fggl/audio/types.cpp
+++ b/fggl/audio/types.cpp
@@ -26,11 +26,11 @@ namespace fggl::data {
 
 	template<>
 	bool fggl_deserialize<audio::AudioClip>(std::filesystem::path &data, audio::AudioClip* out) {
-		out->sampleCount = stb_vorbis_decode_filename(data.c_str(),
+		out->sampleCount = stb_vorbis_decode_filename(data.string().c_str(),
 													 &out->channels,
 													 &out->sampleRate,
 													 &out->data);
 		return out->sampleCount != -1;
 	}
 
-} // namespace fggl::data
\ No newline at end of file
+} // namespace fggl::data
diff --git a/fggl/ecs3/prototype/loader.cpp b/fggl/ecs3/prototype/loader.cpp
new file mode 100644
index 0000000..5c91504
--- /dev/null
+++ b/fggl/ecs3/prototype/loader.cpp
@@ -0,0 +1,90 @@
+#include "fggl/ecs3/prototype/loader.hpp"
+
+namespace fggl::ecs {
+	template<>
+	bool restore_config(math::Transform* comp, const YAML::Node& node) {
+		comp->origin(node["origin"].as<math::vec3>( math::VEC3_ZERO ));
+		comp->euler(node["rotation"].as<math::vec3>(math::VEC3_ZERO));
+		comp->scale(node["scale"].as<math::vec3>(math::VEC3_ONES));
+		return true;
+	}
+
+	template<>
+	bool restore_config(gfx::PhongMaterial* comp, const YAML::Node& node) {
+		comp->diffuse = node["diffuse"].as<math::vec3>( gfx::DEFAULT_DIFFUSE );
+		comp->ambient = node["ambient"].as<math::vec3>( gfx::DEFAULT_AMBIENT );
+		comp->specular = node["specular"].as<math::vec3>( gfx::DEFAULT_SPECULAR );
+		comp->shininess = node["shininess"].as<float>( gfx::DEFAULT_SHININESS );
+		return true;
+	}
+
+	template<>
+	bool restore_config(data::StaticMesh* meshComp, const YAML::Node& node) {
+		if ( !node["pipeline"] ) {
+			return false;
+		}
+
+		meshComp->pipeline = node["pipeline"].as<std::string>();
+
+		if ( node["shape"] ) {
+			data::Mesh mesh;
+			if (node["shape"].IsSequence()) {
+				// is a composite shape
+				for (const auto &shapeNode : node["shape"]) {
+					process_mesh(mesh, shapeNode);
+				}
+			} else {
+				// is a basic shape
+				process_mesh(mesh, node["shape"]);
+			}
+
+			// optimise and load
+			mesh.removeDups();
+			meshComp->mesh = mesh;
+		} else {
+			return false;
+		}
+
+		return true;
+	}
+
+	template<>
+	bool restore_config(phys::RigidBody* body, const YAML::Node& node) {
+		body->type = node["type"].as<fggl::phys::BodyType>(fggl::phys::BodyType::DYNAMIC);
+		if ( body->type == fggl::phys::BodyType::STATIC) {
+			body->mass = phys::MASS_STATIC;
+		} else {
+			body->mass = node["mass"].as<float>( phys::MASS_DEFAULT );
+		}
+
+		// shape detection
+		if ( node["shape"] ) {
+			auto type = node["shape"]["type"].as< std::string >();
+
+			if ( type == SHAPE_BOX_VALUE ) {
+				// assume unit box if extents are missing
+				auto extents = node["shape"]["extents"].as<math::vec3>(phys::UNIT_EXTENTS);
+				body->shape = new phys::Box(extents);
+			} else if ( type == SHAPE_SPHERE_VALUE ) {
+				auto radius = node["shape"]["radius"].as<float>(0.5F);
+				body->shape = new phys::Sphere(radius);
+			} else {
+				return false;
+			}
+		}
+
+		return true;
+	}
+
+	template<>
+	bool restore_config(phys::CollisionCallbacks* callbacks, const YAML::Node& node) {
+		// TODO implement callback scripting
+		return true;
+	}
+
+	template<>
+	bool restore_config(phys::CollisionCache* cache, const YAML::Node& node){
+		// probably nothing needed here. Ideally, this should be automatically added when callbacks are.
+		return true;
+	}
+}
diff --git a/fggl/gfx/ogl/CMakeLists.txt b/fggl/gfx/ogl/CMakeLists.txt
index 9e40c86..da1e4ad 100644
--- a/fggl/gfx/ogl/CMakeLists.txt
+++ b/fggl/gfx/ogl/CMakeLists.txt
@@ -10,14 +10,10 @@ target_sources(fggl
 )
 
 # OpenGL Backend
-if ( WIN32 )
-	message("There is a hack to make opengl detection work on windows, someone should look into this...")
-	find_package( opengl REQUIRED )
-	include_directories( ${OPENGL_INCLUDE_DIR} )
-	target_link_libraries(${PROJECT_NAME} PUBLIC opengl::opengl)
+find_package( OpenGL REQUIRED )
+if ( MSVC )
+	target_link_libraries(${PROJECT_NAME} PUBLIC OpenGL::GL)
 else()
-	find_package( OpenGL REQUIRED )
-	include_directories( ${OPENGL_INCLUDE_DIR} )
 	target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::OpenGL)
 endif()
 
diff --git a/fggl/gfx/ogl/renderer.cpp b/fggl/gfx/ogl/renderer.cpp
index 09782d1..d267708 100644
--- a/fggl/gfx/ogl/renderer.cpp
+++ b/fggl/gfx/ogl/renderer.cpp
@@ -94,7 +94,7 @@ constexpr auto static fggl_ogl_type(GLenum type) -> const char * {
 
 constexpr const char* OGL_LOG_FMT {"[GL] {}, {}: [{}]: {}"};
 
-void static fggl_ogl_to_spdlog(GLenum source, GLenum type, unsigned int msgId, GLenum severity, GLsizei  /*length*/,
+void static GLAPIENTRY fggl_ogl_to_spdlog(GLenum source, GLenum type, unsigned int msgId, GLenum severity, GLsizei  /*length*/,
 							   const char *message, const void * /*userParam*/) {
 
 	const auto *const sourceStr = fggl_ogl_source(source);
diff --git a/fggl/gfx/ogl/shader.cpp b/fggl/gfx/ogl/shader.cpp
index 5f9e251..dcba3cd 100644
--- a/fggl/gfx/ogl/shader.cpp
+++ b/fggl/gfx/ogl/shader.cpp
@@ -76,10 +76,10 @@ void ShaderCache::setupIncludes() {
 
 	for ( auto& path : paths ){
 		std::string source;
-		m_storage->load( fggl::data::Data, path, &source );
+		m_storage->load( fggl::data::Data, path.string(), &source );
 
 		auto relPath = std::filesystem::relative(path, root);
-		const auto relPathStr = "/" + std::string(relPath);
+		const auto relPathStr = "/" + relPath.string();
 		glNamedStringARB(GL_SHADER_INCLUDE_ARB, -1, relPathStr.c_str(), -1, source.c_str() );
 	}
 
diff --git a/fggl/math/CMakeLists.txt b/fggl/math/CMakeLists.txt
index 85eebe0..a3d1d39 100644
--- a/fggl/math/CMakeLists.txt
+++ b/fggl/math/CMakeLists.txt
@@ -1,9 +1,9 @@
 # math
-find_package( glm REQUIRED )
+find_package( glm CONFIG REQUIRED )
 target_link_libraries( fggl PUBLIC glm::glm )
 
 target_sources(fggl
         PRIVATE
             shapes.cpp
             triangulation.cpp
-)
\ No newline at end of file
+)
diff --git a/fggl/phys/bullet/CMakeLists.txt b/fggl/phys/bullet/CMakeLists.txt
index decc694..bb2ac62 100644
--- a/fggl/phys/bullet/CMakeLists.txt
+++ b/fggl/phys/bullet/CMakeLists.txt
@@ -1,10 +1,10 @@
 # bullet integration support
-find_package( Bullet )
+find_package( Bullet CONFIG )
 if ( NOT Bullet_FOUND )
-    message("Bullet not found - disabling bullet physics integration")
+    message(WARNING "Bullet not found - disabling bullet physics integration")
 else()
-    target_link_libraries(fggl PUBLIC ${BULLET_LIBRARIES})
-    target_include_directories(fggl PUBLIC ${BULLET_INCLUDE_DIR})
+    message(STATUS "Bullet found")
+    target_link_libraries(fggl PUBLIC LinearMath Bullet3Common BulletCollision BulletDynamics BulletSoftBody )
 
     # bullet cpp files
     target_sources(fggl
@@ -12,4 +12,4 @@ else()
             simulation.cpp
             phys_draw.cpp
     )
-endif()
\ No newline at end of file
+endif()
diff --git a/include/fggl/ecs3/prototype/loader.hpp b/include/fggl/ecs3/prototype/loader.hpp
index c9e1040..e3c00c8 100644
--- a/include/fggl/ecs3/prototype/loader.hpp
+++ b/include/fggl/ecs3/prototype/loader.hpp
@@ -48,7 +48,7 @@ namespace fggl::ecs3 {
 	void load_prototype_file( ecs3::World& world, data::Storage& storage, const std::string& name ) {
 		auto path = storage.resolvePath( data::Data, name );
 
-		auto root = YAML::LoadFile( path );
+		auto root = YAML::LoadFile( path.string().c_str() );
 		for (const auto& node : root["prefabs"] ) {
 			load_prototype_node(world, node);
 		}
@@ -170,93 +170,6 @@ namespace fggl::ecs {
 		}
 	}
 
-	template<>
-	bool restore_config(math::Transform* comp, const YAML::Node& node) {
-		comp->origin(node["origin"].as<math::vec3>( math::VEC3_ZERO ));
-		comp->euler(node["rotation"].as<math::vec3>(math::VEC3_ZERO));
-		comp->scale(node["scale"].as<math::vec3>(math::VEC3_ONES));
-		return true;
-	}
-
-	template<>
-	bool restore_config(gfx::PhongMaterial* comp, const YAML::Node& node) {
-		comp->diffuse = node["diffuse"].as<math::vec3>( gfx::DEFAULT_DIFFUSE );
-		comp->ambient = node["ambient"].as<math::vec3>( gfx::DEFAULT_AMBIENT );
-		comp->specular = node["specular"].as<math::vec3>( gfx::DEFAULT_SPECULAR );
-		comp->shininess = node["shininess"].as<float>( gfx::DEFAULT_SHININESS );
-		return true;
-	}
-
-	template<>
-	bool restore_config(data::StaticMesh* meshComp, const YAML::Node& node) {
-		if ( !node["pipeline"] ) {
-			return false;
-		}
-
-		meshComp->pipeline = node["pipeline"].as<std::string>();
-
-		if ( node["shape"] ) {
-			data::Mesh mesh;
-			if (node["shape"].IsSequence()) {
-				// is a composite shape
-				for (const auto &shapeNode : node["shape"]) {
-					process_mesh(mesh, shapeNode);
-				}
-			} else {
-				// is a basic shape
-				process_mesh(mesh, node["shape"]);
-			}
-
-			// optimise and load
-			mesh.removeDups();
-			meshComp->mesh = mesh;
-		} else {
-			return false;
-		}
-
-		return true;
-	}
-
-	template<>
-	bool restore_config(phys::RigidBody* body, const YAML::Node& node) {
-		body->type = node["type"].as<fggl::phys::BodyType>(fggl::phys::BodyType::DYNAMIC);
-		if ( body->type == fggl::phys::BodyType::STATIC) {
-			body->mass = phys::MASS_STATIC;
-		} else {
-			body->mass = node["mass"].as<float>( phys::MASS_DEFAULT );
-		}
-
-		// shape detection
-		if ( node["shape"] ) {
-			auto type = node["shape"]["type"].as< std::string >();
-
-			if ( type == SHAPE_BOX_VALUE ) {
-				// assume unit box if extents are missing
-				auto extents = node["shape"]["extents"].as<math::vec3>(phys::UNIT_EXTENTS);
-				body->shape = new phys::Box(extents);
-			} else if ( type == SHAPE_SPHERE_VALUE ) {
-				auto radius = node["shape"]["radius"].as<float>(0.5F);
-				body->shape = new phys::Sphere(radius);
-			} else {
-				return false;
-			}
-		}
-
-		return true;
-	}
-
-	template<>
-	bool restore_config(phys::CollisionCallbacks* callbacks, const YAML::Node& node) {
-		// TODO implement callback scripting
-		return true;
-	}
-
-	template<>
-	bool restore_config(phys::CollisionCache* cache, const YAML::Node& node){
-		// probably nothing needed here. Ideally, this should be automatically added when callbacks are.
-		return true;
-	}
-
 }
 
 #endif //FGGL_ECS3_PROTOTYPE_LOADER_HPP
diff --git a/include/fggl/gui/fonts.hpp b/include/fggl/gui/fonts.hpp
index 51d6018..332467d 100644
--- a/include/fggl/gui/fonts.hpp
+++ b/include/fggl/gui/fonts.hpp
@@ -88,7 +88,7 @@ namespace fggl::gui {
 				auto path = storage->resolvePath(data::StorageType::Data, name);
 
 				FT_Face face;
-				if ( FT_New_Face(m_context, path.c_str(), 0, &face) ) {
+				if ( FT_New_Face(m_context, path.string().c_str(), 0, &face) ) {
 					return nullptr;
 				}
 				FT_Set_Pixel_Sizes(face, 0, 18);
diff --git a/include/fggl/gui/widget.hpp b/include/fggl/gui/widget.hpp
index 2133a84..f40967b 100644
--- a/include/fggl/gui/widget.hpp
+++ b/include/fggl/gui/widget.hpp
@@ -35,7 +35,7 @@ namespace fggl::gui {
 	 * @param value assumed 0 - 1
 	 * @return RGB, in the range 0,1 for each component
 	 */
-	constexpr math::vec3 HSVtoNormal(float hue, float saturation, float value) {
+	inline math::vec3 HSVtoNormal(float hue, float saturation, float value) {
 		assert( 0 < hue && hue <= 360);
 		assert( 0 < saturation && saturation <= 1);
 		assert( 0 < value && value <= 1);
diff --git a/include/fggl/phys/bullet/phys_draw.hpp b/include/fggl/phys/bullet/phys_draw.hpp
index 5ddc0fb..b5901af 100644
--- a/include/fggl/phys/bullet/phys_draw.hpp
+++ b/include/fggl/phys/bullet/phys_draw.hpp
@@ -19,7 +19,12 @@
 #ifndef FGGL_PHYS_BULLET_PHYS_DRAW_HPP
 #define FGGL_PHYS_BULLET_PHYS_DRAW_HPP
 
-#include "LinearMath/btIDebugDraw.h"
+# if WIN32
+	#include "bullet/LinearMath/btIDebugDraw.h"
+# else
+	#include "LinearMath/btIDebugDraw.h"
+# endif
+
 #include "fggl/gfx/ogl/types.hpp"
 
 #include <array>
-- 
GitLab