From 91709b16c3eed7d1113aedbd9c92f71e62a3b01d Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 13 Sep 2022 20:35:30 +0800 Subject: [PATCH 1/5] Changed out and intermediatery directories for all projects to use shared directories --- SHADE_Application/SHADE_Application.vcxproj | 8 ++++---- SHADE_Application/premake5.lua | 4 ++-- SHADE_Engine/SHADE_Engine.vcxproj | 9 +++++---- SHADE_Engine/SHADE_Engine.vcxproj.filters | 1 + SHADE_Engine/premake5.lua | 4 ++-- premake5.lua | 5 +++-- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/SHADE_Application/SHADE_Application.vcxproj b/SHADE_Application/SHADE_Application.vcxproj index 2616224e..59d25053 100644 --- a/SHADE_Application/SHADE_Application.vcxproj +++ b/SHADE_Application/SHADE_Application.vcxproj @@ -42,15 +42,15 @@ true - bin\Debug_x86_64\SHADE_Application\ - bin-int\Debug_x86_64\SHADE_Application\ + ..\bin\Debug\ + ..\bin_int\Debug\SHADE_Application\ SHADE_Application .exe false - bin\Release_x86_64\SHADE_Application\ - bin-int\Release_x86_64\SHADE_Application\ + ..\bin\Release\ + ..\bin_int\Release\SHADE_Application\ SHADE_Application .exe diff --git a/SHADE_Application/premake5.lua b/SHADE_Application/premake5.lua index 8c17bf55..d7f47246 100644 --- a/SHADE_Application/premake5.lua +++ b/SHADE_Application/premake5.lua @@ -2,8 +2,8 @@ project "SHADE_Application" kind "WindowedApp" language "C++" cppdialect "C++latest" - targetdir ("bin/" .. outputdir .. "/%{prj.name}") - objdir ("bin-int/" .. outputdir .. "/%{prj.name}") + targetdir (outputdir) + objdir (interdir) systemversion "latest" pchheader "SBpch.h" pchsource "%{prj.location}/src/SBpch.cpp" diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index 1c50ecc0..57c76f8e 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -41,14 +41,14 @@ - bin\Debug_x86_64\SHADE_Engine\ - bin-int\Debug_x86_64\SHADE_Engine\ + ..\bin\Debug\ + ..\bin_int\Debug\SHADE_Engine\ SHADE_Engine .lib - bin\Release_x86_64\SHADE_Engine\ - bin-int\Release_x86_64\SHADE_Engine\ + ..\bin\Release\ + ..\bin_int\Release\SHADE_Engine\ SHADE_Engine .lib @@ -183,6 +183,7 @@ + diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters index 7486fad4..6af93131 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj.filters +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -360,6 +360,7 @@ Resource + Scene diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index c858d538..ddd9eaaa 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -2,8 +2,8 @@ project "SHADE_Engine" kind "StaticLib" language "C++" cppdialect "C++latest" - targetdir ("bin/" .. outputdir .. "/%{prj.name}") - objdir ("bin-int/" .. outputdir .. "/%{prj.name}") + targetdir (outputdir) + objdir (interdir) systemversion "latest" pchheader "SHpch.h" pchsource "%{prj.location}/src/SHpch.cpp" diff --git a/premake5.lua b/premake5.lua index d54f8e40..afb72a33 100644 --- a/premake5.lua +++ b/premake5.lua @@ -14,8 +14,9 @@ workspace "SHADE" { "MultiProcessorCompile" } - - outputdir = "%{cfg.buildcfg}_%{cfg.architecture}" + + outputdir = "%{wks.location}/bin/%{cfg.buildcfg}" + interdir = "%{wks.location}/bin_int" include "SHADE_Application" include "SHADE_Engine" -- 2.40.1 From cba3aa0663d837c5bdf02e807ef5c71d0b264c5f Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 13 Sep 2022 21:08:13 +0800 Subject: [PATCH 2/5] Converted SHADE_Engine to a DLL project and exported common use classes --- SHADE.sln | 3 ++ SHADE_Application/SHADE_Application.vcxproj | 4 +-- SHADE_Application/premake5.lua | 3 +- SHADE_Engine/SHADE_Engine.vcxproj | 24 ++++++------- SHADE_Engine/premake5.lua | 5 +-- .../src/ECS_Base/Components/SHComponent.h | 3 +- SHADE_Engine/src/ECS_Base/Entity/SHEntity.h | 3 +- .../src/ECS_Base/System/SHComponentManager.h | 3 +- .../src/ECS_Base/System/SHEntityManager.h | 3 +- .../src/Graphics/Windowing/SHWindow.h | 3 +- SHADE_Engine/src/SH_API.h | 36 +++++++++++++++++++ SHADE_Engine/src/Tools/SHExceptionHandler.h | 4 ++- SHADE_Engine/src/Tools/SHLogger.h | 3 +- premake5.lua | 4 +-- 14 files changed, 75 insertions(+), 26 deletions(-) create mode 100644 SHADE_Engine/src/SH_API.h diff --git a/SHADE.sln b/SHADE.sln index ff6afa61..e0cb4ef9 100644 --- a/SHADE.sln +++ b/SHADE.sln @@ -2,6 +2,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SHADE_Application", "SHADE_Application\SHADE_Application.vcxproj", "{BDC70008-29DE-FE9D-7255-8ABFDEAACF25}" + ProjectSection(ProjectDependencies) = postProject + {8EAD431C-7A4F-6EF2-630A-82464F4BF542} = {8EAD431C-7A4F-6EF2-630A-82464F4BF542} + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{53E47842-3FC8-3998-A828-34EB942B241A}" EndProject diff --git a/SHADE_Application/SHADE_Application.vcxproj b/SHADE_Application/SHADE_Application.vcxproj index 59d25053..20e738cc 100644 --- a/SHADE_Application/SHADE_Application.vcxproj +++ b/SHADE_Application/SHADE_Application.vcxproj @@ -60,7 +60,7 @@ SBpch.h Level4 _DEBUG;%(PreprocessorDefinitions) - ..\Dependencies\spdlog\include;..\SHADE_Engine\src;src;%(AdditionalIncludeDirectories) + ..\Dependencies\spdlog\include;..\SHADE_Engine\src;src;include;%(AdditionalIncludeDirectories) EditAndContinue Disabled false @@ -80,7 +80,7 @@ SBpch.h Level4 _RELEASE;%(PreprocessorDefinitions) - ..\Dependencies\spdlog\include;..\SHADE_Engine\src;src;%(AdditionalIncludeDirectories) + ..\Dependencies\spdlog\include;..\SHADE_Engine\src;src;include;%(AdditionalIncludeDirectories) Full true true diff --git a/SHADE_Application/premake5.lua b/SHADE_Application/premake5.lua index d7f47246..9eb3a41c 100644 --- a/SHADE_Application/premake5.lua +++ b/SHADE_Application/premake5.lua @@ -23,7 +23,8 @@ project "SHADE_Application" { "%{IncludeDir.spdlog}/include", "../SHADE_Engine/src", - "src" + "src", + "%{IncludeDir.dotnet}/include", } flags diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index 57c76f8e..9b4d09ae 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -19,13 +19,13 @@ - StaticLibrary + DynamicLibrary true Unicode v142 - StaticLibrary + DynamicLibrary false Unicode v142 @@ -41,23 +41,25 @@ + true ..\bin\Debug\ ..\bin_int\Debug\SHADE_Engine\ SHADE_Engine - .lib + .dll + false ..\bin\Release\ ..\bin_int\Release\SHADE_Engine\ SHADE_Engine - .lib + .dll Use SHpch.h Level4 - _LIB;_GLFW_INCLUDE_NONE;MSDFGEN_USE_CPP11;NOMINMAX;_DEBUG;%(PreprocessorDefinitions) + _LIB;_GLFW_INCLUDE_NONE;MSDFGEN_USE_CPP11;NOMINMAX;SH_API_EXPORT;_DEBUG;%(PreprocessorDefinitions) src;..\Dependencies\assimp\include;..\Dependencies\imgui;..\Dependencies\imguizmo;..\Dependencies\imnodes;..\Dependencies\msdf;..\Dependencies\msdf\msdfgen;..\Dependencies\spdlog\include;..\Dependencies\tracy;..\Dependencies\VMA\include;..\Dependencies\yamlcpp\include;..\Dependencies\ktx\include;..\Dependencies\RTTR\include;..\Dependencies\reactphysics3d\include;$(VULKAN_SDK)\include;$(VULKAN_SDK)\Source\SPIRV-Reflect;%(AdditionalIncludeDirectories) EditAndContinue Disabled @@ -69,18 +71,17 @@ Windows true - - vulkan-1.lib;shaderc_shared.lib;assimp-vc142-mtd.lib;ktxd.lib;librttr_core_d.lib;%(AdditionalDependencies) libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories) - + ..\bin\Debug\SHADE_Engine.lib + Use SHpch.h Level4 - _LIB;_GLFW_INCLUDE_NONE;MSDFGEN_USE_CPP11;NOMINMAX;_RELEASE;%(PreprocessorDefinitions) + _LIB;_GLFW_INCLUDE_NONE;MSDFGEN_USE_CPP11;NOMINMAX;SH_API_EXPORT;_RELEASE;%(PreprocessorDefinitions) src;..\Dependencies\assimp\include;..\Dependencies\imgui;..\Dependencies\imguizmo;..\Dependencies\imnodes;..\Dependencies\msdf;..\Dependencies\msdf\msdfgen;..\Dependencies\spdlog\include;..\Dependencies\tracy;..\Dependencies\VMA\include;..\Dependencies\yamlcpp\include;..\Dependencies\ktx\include;..\Dependencies\RTTR\include;..\Dependencies\reactphysics3d\include;$(VULKAN_SDK)\include;$(VULKAN_SDK)\Source\SPIRV-Reflect;%(AdditionalIncludeDirectories) Full true @@ -95,11 +96,10 @@ Windows true true - - vulkan-1.lib;shaderc_shared.lib;assimp-vc142-mt.lib;ktx.lib;librttr_core.lib;%(AdditionalDependencies) libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories) - + ..\bin\Release\SHADE_Engine.lib + diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index ddd9eaaa..681de634 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -1,5 +1,5 @@ project "SHADE_Engine" - kind "StaticLib" + kind "SharedLib" language "C++" cppdialect "C++latest" targetdir (outputdir) @@ -66,7 +66,8 @@ project "SHADE_Engine" "_LIB", "_GLFW_INCLUDE_NONE", "MSDFGEN_USE_CPP11", - "NOMINMAX" + "NOMINMAX", + "SH_API_EXPORT" } flags diff --git a/SHADE_Engine/src/ECS_Base/Components/SHComponent.h b/SHADE_Engine/src/ECS_Base/Components/SHComponent.h index c9c5e6f1..edd8436c 100644 --- a/SHADE_Engine/src/ECS_Base/Components/SHComponent.h +++ b/SHADE_Engine/src/ECS_Base/Components/SHComponent.h @@ -14,13 +14,14 @@ #include "SHpch.h" #include "../SHECSMacros.h" +#include "SH_API.h" namespace SHADE { class SHComponentManager; - class SHComponent + class SH_API SHComponent { friend SHComponentManager; diff --git a/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h b/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h index d499042c..685ba99a 100644 --- a/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h +++ b/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h @@ -15,6 +15,7 @@ #include "../Components/SHComponent.h" #include "../System/SHComponentManager.h" //#include "../../Scene/SHSceneNode.h" +#include "SH_API.h" @@ -23,7 +24,7 @@ namespace SHADE class SHComponentManager; class SHEntityManager; - class SHEntity + class SH_API SHEntity { public: diff --git a/SHADE_Engine/src/ECS_Base/System/SHComponentManager.h b/SHADE_Engine/src/ECS_Base/System/SHComponentManager.h index 2f6ff504..75db35d5 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHComponentManager.h +++ b/SHADE_Engine/src/ECS_Base/System/SHComponentManager.h @@ -19,13 +19,14 @@ #include "../Components/SHComponent.h" #include "../Components/SHComponentGroup.h" //#include "Scene/SHSceneNode.h" +#include "SH_API.h" #include namespace SHADE { - class SHComponentManager + class SH_API SHComponentManager { private: diff --git a/SHADE_Engine/src/ECS_Base/System/SHEntityManager.h b/SHADE_Engine/src/ECS_Base/System/SHEntityManager.h index 11e896d5..802ef75d 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHEntityManager.h +++ b/SHADE_Engine/src/ECS_Base/System/SHEntityManager.h @@ -22,11 +22,12 @@ #include "../Components/SHComponent.h" #include "../General/SHHandleGenerator.h" #include "../SHECSMacros.h" +#include "SH_API.h" namespace SHADE { - class SHEntityManager + class SH_API SHEntityManager { private: static std::vector> entityVec; diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h index a70058a1..1e08dcb0 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h @@ -5,6 +5,7 @@ #include #include #include "SHWindowMap.h" +#include "SH_API.h" namespace SHADE { @@ -67,7 +68,7 @@ namespace SHADE std::string icoPath = ""; }; - class SHWindow + class SH_API SHWindow { public: using SHVec2 = std::pair; diff --git a/SHADE_Engine/src/SH_API.h b/SHADE_Engine/src/SH_API.h new file mode 100644 index 00000000..64d1eebe --- /dev/null +++ b/SHADE_Engine/src/SH_API.h @@ -0,0 +1,36 @@ +/************************************************************************************//*! +\file SH_API.h +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Sep 13, 2022 +\brief Contains dllexport and dllimport macros for the SHADE Engine. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// Select the correct export system based on the compiler +#if defined SH_LIB +# define SH_API +#else +# if defined _WIN32 || defined __CYGWIN__ || defined _MSC_VER +# define SH_EXPORT __declspec(dllexport) +# define SH_IMPORT __declspec(dllimport) +# elif defined __GNUC__ && __GNUC__ >= 4 +# define SH_EXPORT __attribute__((visibility("default"))) +# define SH_IMPORT __attribute__((visibility("default"))) +# else /* Unsupported compiler */ +# define SH_EXPORT +# define SH_IMPORT +# endif + // Define the correct +# ifndef SH_API +# if defined SH_API_EXPORT +# define SH_API SH_EXPORT +# else +# define SH_API SH_IMPORT +# endif +# endif +#endif \ No newline at end of file diff --git a/SHADE_Engine/src/Tools/SHExceptionHandler.h b/SHADE_Engine/src/Tools/SHExceptionHandler.h index dd1d7596..32cda608 100644 --- a/SHADE_Engine/src/Tools/SHExceptionHandler.h +++ b/SHADE_Engine/src/Tools/SHExceptionHandler.h @@ -12,13 +12,15 @@ #include +#include "SH_API.h" + namespace SHADE { /*-----------------------------------------------------------------------------------*/ /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SHExceptionHandler + class SH_API SHExceptionHandler { public: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Tools/SHLogger.h b/SHADE_Engine/src/Tools/SHLogger.h index ac5f9308..dfb7dffd 100644 --- a/SHADE_Engine/src/Tools/SHLogger.h +++ b/SHADE_Engine/src/Tools/SHLogger.h @@ -15,6 +15,7 @@ #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE #include +#include "SH_API.h" /*-------------------------------------------------------------------------------------*/ /* Macros */ @@ -27,7 +28,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SHLogger + class SH_API SHLogger { public: /*---------------------------------------------------------------------------------*/ diff --git a/premake5.lua b/premake5.lua index afb72a33..e136702a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -12,14 +12,14 @@ workspace "SHADE" flags { - "MultiProcessorCompile" + "MultiProcessorCompile" } outputdir = "%{wks.location}/bin/%{cfg.buildcfg}" interdir = "%{wks.location}/bin_int" - include "SHADE_Application" include "SHADE_Engine" + include "SHADE_Application" group "Dependencies" include "Dependencies/msdf" -- 2.40.1 From a3e4b0a845b36df3b09bc21d2b24f69c7adcb3e5 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Wed, 14 Sep 2022 09:14:18 +0800 Subject: [PATCH 3/5] update premakes for spdlog changes --- SHADE_Application/premake5.lua | 12 ++++++++++-- SHADE_Engine/premake5.lua | 4 +--- premake5.lua | 1 - 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/SHADE_Application/premake5.lua b/SHADE_Application/premake5.lua index 9eb3a41c..8aa03a13 100644 --- a/SHADE_Application/premake5.lua +++ b/SHADE_Application/premake5.lua @@ -14,6 +14,7 @@ project "SHADE_Application" files { "%{prj.location}/src/**.h", + "%{prj.location}/src/**.hpp", "%{prj.location}/src/**.c", "%{prj.location}/src/**.cpp", "%{prj.location}/src/**.glsl", @@ -34,9 +35,14 @@ project "SHADE_Application" links { - "SHADE_Engine" + "SHADE_Engine", } + libdirs + { + "%{IncludeDir.spdlog}/lib", + } + postbuildcommands { } @@ -46,7 +52,9 @@ project "SHADE_Application" filter "configurations:Debug" symbols "On" defines {"_DEBUG"} + links{"spdlogd.lib"} filter "configurations:Release" optimize "On" - defines{"_RELEASE"} \ No newline at end of file + defines{"_RELEASE"} + links{"spdlog.lib"} diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index 681de634..841eaab3 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -35,7 +35,7 @@ project "SHADE_Engine" "%{IncludeDir.RTTR}/include", "%{IncludeDir.reactphysics3d}/include", "%{IncludeDir.VULKAN}/include", - "%{IncludeDir.VULKAN}/Source/SPIRV-Reflect" + "%{IncludeDir.VULKAN}/Source/SPIRV-Reflect" } libdirs @@ -56,7 +56,6 @@ project "SHADE_Engine" "msdf-atlas-gen", "reactphysics3d", "imgui", - "spdlog", "vulkan-1.lib", "shaderc_shared.lib" } @@ -82,7 +81,6 @@ project "SHADE_Engine" "msdf-atlas-gen", "reactphysics3d", "imgui", - "spdlog", } warnings 'Extra' diff --git a/premake5.lua b/premake5.lua index e136702a..45ed41fa 100644 --- a/premake5.lua +++ b/premake5.lua @@ -24,7 +24,6 @@ workspace "SHADE" group "Dependencies" include "Dependencies/msdf" include "Dependencies/imgui" - include "Dependencies/spdlog" --include "Dependencies/tracy" include "Dependencies/yamlcpp" include "Dependencies/reactphysics3d" -- 2.40.1 From 44ef3a500f3404b112e14237542e4f9aecc04498 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 14 Sep 2022 13:29:14 +0800 Subject: [PATCH 4/5] Added post build command to copy spdlog.dll to output --- SHADE.sln | 11 ----------- SHADE_Application/SHADE_Application.vcxproj | 4 ++++ SHADE_Engine/SHADE_Engine.vcxproj | 9 ++++++--- SHADE_Engine/premake5.lua | 5 +++++ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/SHADE.sln b/SHADE.sln index e0cb4ef9..96aa6455 100644 --- a/SHADE.sln +++ b/SHADE.sln @@ -2,9 +2,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SHADE_Application", "SHADE_Application\SHADE_Application.vcxproj", "{BDC70008-29DE-FE9D-7255-8ABFDEAACF25}" - ProjectSection(ProjectDependencies) = postProject - {8EAD431C-7A4F-6EF2-630A-82464F4BF542} = {8EAD431C-7A4F-6EF2-630A-82464F4BF542} - EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{53E47842-3FC8-3998-A828-34EB942B241A}" EndProject @@ -18,8 +15,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msdfgen", "Dependencies\msd EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reactphysics3d", "Dependencies\reactphysics3d\reactphysics3d.vcxproj", "{2ECAB41A-1A98-A820-032C-1947EF988485}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spdlog", "Dependencies\spdlog\spdlog.vcxproj", "{8EAD431C-7A4F-6EF2-630A-82464F4BF542}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yaml-cpp", "Dependencies\yamlcpp\yaml-cpp.vcxproj", "{88F1A057-74BE-FB62-9DD7-E90A890331F1}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SHADE_Engine", "SHADE_Engine\SHADE_Engine.vcxproj", "{3F92E998-2BF5-783D-D47A-B1F3C0BC44C0}" @@ -29,7 +24,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SHADE_Engine", "SHADE_Engin {38BD587B-248B-4C81-0D1F-BDA7F98B28E6} = {38BD587B-248B-4C81-0D1F-BDA7F98B28E6} {2ECAB41A-1A98-A820-032C-1947EF988485} = {2ECAB41A-1A98-A820-032C-1947EF988485} {C0FF640D-2C14-8DBE-F595-301E616989EF} = {C0FF640D-2C14-8DBE-F595-301E616989EF} - {8EAD431C-7A4F-6EF2-630A-82464F4BF542} = {8EAD431C-7A4F-6EF2-630A-82464F4BF542} EndProjectSection EndProject Global @@ -62,10 +56,6 @@ Global {2ECAB41A-1A98-A820-032C-1947EF988485}.Debug|x64.Build.0 = Debug|x64 {2ECAB41A-1A98-A820-032C-1947EF988485}.Release|x64.ActiveCfg = Release|x64 {2ECAB41A-1A98-A820-032C-1947EF988485}.Release|x64.Build.0 = Release|x64 - {8EAD431C-7A4F-6EF2-630A-82464F4BF542}.Debug|x64.ActiveCfg = Debug|x64 - {8EAD431C-7A4F-6EF2-630A-82464F4BF542}.Debug|x64.Build.0 = Debug|x64 - {8EAD431C-7A4F-6EF2-630A-82464F4BF542}.Release|x64.ActiveCfg = Release|x64 - {8EAD431C-7A4F-6EF2-630A-82464F4BF542}.Release|x64.Build.0 = Release|x64 {88F1A057-74BE-FB62-9DD7-E90A890331F1}.Debug|x64.ActiveCfg = Debug|x64 {88F1A057-74BE-FB62-9DD7-E90A890331F1}.Debug|x64.Build.0 = Debug|x64 {88F1A057-74BE-FB62-9DD7-E90A890331F1}.Release|x64.ActiveCfg = Release|x64 @@ -84,7 +74,6 @@ Global {38BD587B-248B-4C81-0D1F-BDA7F98B28E6} = {53E47842-3FC8-3998-A828-34EB942B241A} {8900D8DD-F5DF-5679-FEF7-E14F6A56BDDA} = {53E47842-3FC8-3998-A828-34EB942B241A} {2ECAB41A-1A98-A820-032C-1947EF988485} = {53E47842-3FC8-3998-A828-34EB942B241A} - {8EAD431C-7A4F-6EF2-630A-82464F4BF542} = {53E47842-3FC8-3998-A828-34EB942B241A} {88F1A057-74BE-FB62-9DD7-E90A890331F1} = {53E47842-3FC8-3998-A828-34EB942B241A} EndGlobalSection EndGlobal diff --git a/SHADE_Application/SHADE_Application.vcxproj b/SHADE_Application/SHADE_Application.vcxproj index 20e738cc..65a17de9 100644 --- a/SHADE_Application/SHADE_Application.vcxproj +++ b/SHADE_Application/SHADE_Application.vcxproj @@ -71,6 +71,8 @@ Windows true + spdlogd.lib;%(AdditionalDependencies) + ..\Dependencies\spdlog\lib;%(AdditionalLibraryDirectories) wWinMainCRTStartup @@ -94,6 +96,8 @@ Windows true true + spdlog.lib;%(AdditionalDependencies) + ..\Dependencies\spdlog\lib;%(AdditionalLibraryDirectories) wWinMainCRTStartup diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index 9b4d09ae..327995ca 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -75,6 +75,9 @@ libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories) ..\bin\Debug\SHADE_Engine.lib + + xcopy /s /r /y /q "$(SolutionDir)/Dependencies/spdlog/bin" "$(OutDir)" + @@ -100,6 +103,9 @@ libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories) ..\bin\Release\SHADE_Engine.lib + + xcopy /s /r /y /q "$(SolutionDir)/Dependencies/spdlog/bin" "$(OutDir)" + @@ -280,9 +286,6 @@ {C0FF640D-2C14-8DBE-F595-301E616989EF} - - {8EAD431C-7A4F-6EF2-630A-82464F4BF542} - diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index 841eaab3..41693aa8 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -83,6 +83,11 @@ project "SHADE_Engine" "imgui", } + postbuildcommands + { + "xcopy /s /r /y /q \"%{IncludeDir.spdlog}/bin\" \"$(OutDir)\"" + } + warnings 'Extra' filter "configurations:Debug" -- 2.40.1 From 803b29146ea4394d008daecdbc11f55f91b20612 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Wed, 14 Sep 2022 17:57:36 +0800 Subject: [PATCH 5/5] Fixed memory error with SHLogger & spdlog The logger needs to be registered outside the library. As such, a macro SHLOG_REGISTER has been added, as well as a variable to the actual logger. The logger needs to be passed into the macro anywhere outside the library after it has been initialised to work on the dll. This has already been done right before the application runs. --- SHADE_Application/src/WinMain.cpp | 6 ++++-- SHADE_Engine/src/Tools/SHLogger.cpp | 17 ++++++++++------- SHADE_Engine/src/Tools/SHLogger.h | 13 ++++++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/SHADE_Application/src/WinMain.cpp b/SHADE_Application/src/WinMain.cpp index ea1ac5fe..e993d23f 100644 --- a/SHADE_Application/src/WinMain.cpp +++ b/SHADE_Application/src/WinMain.cpp @@ -26,13 +26,15 @@ INT WINAPI wWinMain ) { const SHADE::SHLogger::Config LOGGER_CONFIG{ .directoryPath = "./logs/" }; - SHADE::SHLogger::Initialise(LOGGER_CONFIG); + auto logger = SHADE::SHLogger::Initialise(LOGGER_CONFIG); try { #ifndef SHEDITOR //ShowWindow(::GetConsoleWindow(), SW_HIDE); - #endif + #endif + + SHLOG_REGISTER(logger) SHLOG_INFO("sup") diff --git a/SHADE_Engine/src/Tools/SHLogger.cpp b/SHADE_Engine/src/Tools/SHLogger.cpp index 7b39e979..9b6e5da2 100644 --- a/SHADE_Engine/src/Tools/SHLogger.cpp +++ b/SHADE_Engine/src/Tools/SHLogger.cpp @@ -30,8 +30,9 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Static Data Member Definitions */ /*-----------------------------------------------------------------------------------*/ - unsigned char SHLogger::configFlags = DEFAULT_CONFIG_FLAG; - SHLogger::DateFormat SHLogger::dateFormat = SHLogger::DateFormat::DD_MM_YY; + unsigned char SHLogger::configFlags = DEFAULT_CONFIG_FLAG; + SHLogger::DateFormat SHLogger::dateFormat = SHLogger::DateFormat::DD_MM_YY; + SHLogger::Logger SHLogger::logger = nullptr; std::string SHLogger::trivialPattern; std::string SHLogger::verbosePattern; @@ -142,7 +143,7 @@ namespace SHADE /* Public Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHLogger::Initialise(const Config& config) + SHLogger::Logger SHLogger::Initialise(const Config& config) { SetConfig(config); @@ -176,10 +177,10 @@ namespace SHADE FILE_SINK->set_pattern(trivialPattern + "%v"); // Create and register logger with spdlog - const auto LOGGER = std::make_shared(SHLOGGER_NAME, sinks.begin(), sinks.end()); - LOGGER->set_level(spdlog::level::trace); - LOGGER->flush_on(spdlog::level::trace); - register_logger(LOGGER); + logger = std::make_shared(SHLOGGER_NAME, sinks.begin(), sinks.end()); + logger->set_level(spdlog::level::trace); + logger->flush_on(spdlog::level::trace); + spdlog::register_logger(logger); // Flush every 3 seconds spdlog::flush_every(std::chrono::seconds(config.flushTime)); @@ -190,6 +191,8 @@ namespace SHADE { std::cout << "Log initialisation failed: " << e.what() << std::endl; } + + return logger; } void SHLogger::Shutdown() noexcept diff --git a/SHADE_Engine/src/Tools/SHLogger.h b/SHADE_Engine/src/Tools/SHLogger.h index dfb7dffd..f6ffda47 100644 --- a/SHADE_Engine/src/Tools/SHLogger.h +++ b/SHADE_Engine/src/Tools/SHLogger.h @@ -35,6 +35,8 @@ namespace SHADE /* Type Definitions */ /*---------------------------------------------------------------------------------*/ + using Logger = std::shared_ptr; + enum class ClockFormat { _12HR, _24HR }; enum class DateFormat @@ -107,7 +109,7 @@ namespace SHADE * @brief Creates a console and a file to log to. * @param[in] config The configuration parameters for the logger. */ - static void Initialise (const Config& config = Config{}); + static Logger Initialise (const Config& config = Config{}); static void Shutdown () noexcept; /** @@ -127,7 +129,9 @@ namespace SHADE static constexpr short DEFAULT_CONSOLE_LEN = 1024; static unsigned char configFlags; // Initialised 0 0 FuncLine# FuncFileName Date TimeFormat Time - static DateFormat dateFormat; + static DateFormat dateFormat; + + static Logger logger; static std::string trivialPattern; static std::string verbosePattern; @@ -172,4 +176,7 @@ namespace SHADE #define SHLOGV_CRITICAL(format, ...) SHADE::SHLogger::UseVerbosePattern(); SPDLOG_LOGGER_CRITICAL(spdlog::get(SHLOGGER_NAME), format, ## __VA_ARGS__); // Misc Logging Macros -#define SHLOG_FLOOR() SHADE::SHLogger::UseTrivialPattern(); SPDLOG_LOGGER_INFO(spdlog::get(SHLOGGER_NAME), "--------------------------------"); \ No newline at end of file +#define SHLOG_FLOOR() SHADE::SHLogger::UseTrivialPattern(); SPDLOG_LOGGER_INFO(spdlog::get(SHLOGGER_NAME), "--------------------------------"); + +// For use outside the library to register the logger +#define SHLOG_REGISTER(logger) spdlog::register_logger(logger); spdlog::set_level(spdlog::level::level_enum::trace); \ No newline at end of file -- 2.40.1