From 1dca4a91d9d869049077ac37128dea702e7845d2 Mon Sep 17 00:00:00 2001 From: Jordon Brooks Date: Tue, 6 May 2025 16:59:40 +0100 Subject: [PATCH] Fixed it --- .gitignore | 5 +- .vscode/launch.json | 22 +++++++++ .vscode/settings.json | 3 +- .vscode/tasks.json | 24 ++++++++++ FluxEngine/meson.build | 51 +++++++++++++++++---- FluxEngine/src/private/Application.cpp | 19 -------- FluxEngine/src/private/Engine/Engine.cpp | 58 ++++++++++++++++++++++++ FluxEngine/src/private/EntryPoint.h | 21 --------- FluxEngine/src/private/Log.cpp | 49 ++++++++++++++++---- FluxEngine/src/public/Application.h | 18 -------- FluxEngine/src/public/Core.h | 26 +++++++---- FluxEngine/src/public/Engine/Engine.h | 56 +++++++++++++++++++++++ FluxEngine/src/public/Flux.h | 6 +-- FluxEngine/src/public/Log.h | 31 ++++++++----- GenerateProjects.bat | 14 +----- Sandbox/meson.build | 28 ++++++++++-- Sandbox/src/private/SandboxApp.cpp | 22 +++------ meson.build | 18 ++------ subprojects/spdlog.wrap | 18 ++++++-- 19 files changed, 333 insertions(+), 156 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json delete mode 100644 FluxEngine/src/private/Application.cpp create mode 100644 FluxEngine/src/private/Engine/Engine.cpp delete mode 100644 FluxEngine/src/private/EntryPoint.h delete mode 100644 FluxEngine/src/public/Application.h create mode 100644 FluxEngine/src/public/Engine/Engine.h diff --git a/.gitignore b/.gitignore index bcb2e7c..939337a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ bin-int/ *.sln *.vcxproj *.vcxproj.filters -!/vendor/** \ No newline at end of file +!/vendor/** + +subprojects/ +!subprojects/*.wrap diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b6298db --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + "configurations": [ + { + "type": "cppvsdbg", + "request": "launch", + "name": "Debug Sandbox Shared", + "program": "${workspaceFolder}/builddir/Sandbox/sandbox_shared.exe", + "args": [], + "cwd": "${workspaceFolder}", + "preLaunchTask": "build" + }, + { + "type": "cppvsdbg", + "request": "launch", + "name": "Debug Sandbox Static", + "program": "${workspaceFolder}/builddir/Sandbox/sandbox_static.exe", + "args": [], + "cwd": "${workspaceFolder}", + "preLaunchTask": "build" + }, + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index c02c8a3..d78211f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "C_Cpp.default.compileCommands": "d:\\FluxEngine\\builddir/compile_commands.json", "C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild", - "cmake.ignoreCMakeListsMissing": true + "cmake.ignoreCMakeListsMissing": true, + "C_Cpp.errorSquiggles": "enabled" } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..e7320b7 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,24 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "setup", + "type": "shell", + "command": "meson setup builddir", + "group": { + "kind": "build", + "isDefault": true + }, + }, + { + "label": "build", + "type": "shell", + "command": "meson compile -C builddir", + "group": { + "kind": "build", + "isDefault": true + }, + "dependsOn": "setup", + } + ] +} \ No newline at end of file diff --git a/FluxEngine/meson.build b/FluxEngine/meson.build index 8a4d40a..4b45802 100644 --- a/FluxEngine/meson.build +++ b/FluxEngine/meson.build @@ -1,23 +1,54 @@ flux_inc = include_directories('src/public') flux_sources = files( - 'src/private/Application.cpp', + 'src/private/Engine/Engine.cpp', 'src/private/Log.cpp', ) -spd = subproject('spdlog') -spdlog_dep = spd.get_variable('spdlog') +# 1) Grab the active C++ compiler +cpp = meson.get_compiler('cpp') +ccid = cpp.get_id() # e.g. 'msvc', 'gcc', 'clang', 'intel', ... -flux_lib = library( - 'fluxengine', +# 2) Decide your D-flag prefix +if ccid == 'msvc' + dflag = '/D' +else + dflag = '-D' +endif + +if meson.get_compiler('cpp').get_id() == 'msvc' + add_project_arguments('/utf-8', language: 'cpp') +endif + +spdlog_dep = dependency( + 'spdlog', + required: true, + fallback: ['spdlog', 'spdlog_dep'], + version: '>=1.15.0', + method: 'cmake', + static: true, +) + +# 2A) Shared library (DLL + import lib) +flux_shared = shared_library( + 'FluxEngine_shared', flux_sources, include_directories: flux_inc, - link_with : spdlog_dep, - version : meson.project_version(), - install : true, + dependencies: [spdlog_dep], + cpp_args: [ + dflag + 'FLUX_BUILD_DLL' + ], + install: true ) -flux_dep = declare_dependency( +# 2B) Static library +flux_static = static_library( + 'FluxEngine_static', + flux_sources, include_directories: flux_inc, - link_with : [ flux_lib, spdlog_dep ], + dependencies: [spdlog_dep], + cpp_args: [ + dflag + 'FLUX_STATIC' + ], + install: true ) diff --git a/FluxEngine/src/private/Application.cpp b/FluxEngine/src/private/Application.cpp deleted file mode 100644 index dc977d1..0000000 --- a/FluxEngine/src/private/Application.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "Application.h" - -#include "Log.h" - -namespace Flux { - - Application::Application() - { - } - - Application::~Application() - { - } - void Application::Run() - { - FLUX_CORE_TRACE("FLUX Engine Running!"); - while (true); - } -} diff --git a/FluxEngine/src/private/Engine/Engine.cpp b/FluxEngine/src/private/Engine/Engine.cpp new file mode 100644 index 0000000..a84bcd6 --- /dev/null +++ b/FluxEngine/src/private/Engine/Engine.cpp @@ -0,0 +1,58 @@ +#include "Engine/Engine.h" + +namespace Flux +{ + bool FluxEngine::GIsRunning = false; + FluxEngine* FluxEngine::GInstance = nullptr; + + FluxEngine::FluxEngine() : _Logger(*new Logger()) + { + if (GIsRunning) + { + GetLogger()->LogTrace("Engine already running!"); + bErrorState = true; + return; + } + + if (GInstance != nullptr) + { + FluxEngine* Engine = GetInstance(); + + if (Engine) + { + Engine->GetLogger()->LogTrace("Engine already running!"); + } + return; + } + + GInstance = this; + } + + FluxEngine::~FluxEngine() + { + GetLogger()->LogTrace("Engine shutting down!"); + } + + void FluxEngine::Start() + { + if (bErrorState) + { + GetLogger()->LogTrace("Engine failed to start!"); + return; + } + + GetLogger()->LogTrace("Engine started!"); + GIsRunning = true; + EngineLoop(); + } + + void Flux::FluxEngine::EngineLoop() + { + while (IsRunning()) + { + GetLogger()->LogTrace("Loop running!"); + // Main engine loop + // Update, render, etc. + } + } +} diff --git a/FluxEngine/src/private/EntryPoint.h b/FluxEngine/src/private/EntryPoint.h deleted file mode 100644 index 425bed1..0000000 --- a/FluxEngine/src/private/EntryPoint.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "Log.h" - -#ifdef FLUX_PLATFORM_WINDOWS - -extern Flux::Application* Flux::CreateApplication(); - -int main(int argc, char** argv) -{ - Flux::Log::Init(); - - FLUX_CORE_WARN("Logging Initialized!"); - int a = 5; - FLUX_INFO("Hello! {0}", a); - - auto app = Flux::CreateApplication(); - app->Run(); - delete app; -} -#endif \ No newline at end of file diff --git a/FluxEngine/src/private/Log.cpp b/FluxEngine/src/private/Log.cpp index 33c9c28..2121ae1 100644 --- a/FluxEngine/src/private/Log.cpp +++ b/FluxEngine/src/private/Log.cpp @@ -1,19 +1,50 @@ #include "Log.h" +#include "spdlog/spdlog.h" #include "spdlog/sinks/stdout_color_sinks.h" namespace Flux { - std::shared_ptr Log::s_CoreLogger; - std::shared_ptr Log::s_ClientLogger; - - void Log::Init() + struct LoggerImpl { - spdlog::set_pattern("%^[%T] %n: %v%$"); - s_CoreLogger = spdlog::stdout_color_mt("FLUX"); - s_CoreLogger->set_level(spdlog::level::trace); + LoggerImpl() = default; + ~LoggerImpl() = default; - s_ClientLogger = spdlog::stdout_color_mt("APP"); - s_ClientLogger->set_level(spdlog::level::trace); + std::shared_ptr _logger; + }; + + Logger::~Logger() = default; + + spdlog::logger *Logger::GetLogger() const + { + return _impl._logger.get(); + } + + Logger::Logger() : _impl(* new LoggerImpl()) + { + // Initialize the logger + if (GetLogger()) { + return; + } + + // Create a new logger instance + spdlog::set_pattern("%^[%T] %n: %v%$"); + + _impl._logger = spdlog::stdout_color_mt("FLUX"); + _impl._logger->set_level(spdlog::level::trace); + + LogTrace("Logger initialized!"); + } + + void Logger::LogTrace(const std::string &message) + { + spdlog::logger* logger = GetLogger(); + + if (!logger) + { + return; + } + + logger->trace(message); } } diff --git a/FluxEngine/src/public/Application.h b/FluxEngine/src/public/Application.h deleted file mode 100644 index 6e81643..0000000 --- a/FluxEngine/src/public/Application.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "Core.h" - -namespace Flux { - class FLUX_API Application - { - public: - Application(); - virtual ~Application(); - - void Run(); - }; - - Application* CreateApplication(); -} - - diff --git a/FluxEngine/src/public/Core.h b/FluxEngine/src/public/Core.h index bec8b5b..8151203 100644 --- a/FluxEngine/src/public/Core.h +++ b/FluxEngine/src/public/Core.h @@ -1,11 +1,21 @@ #pragma once -#ifdef FLUX_PLATFORM_WINDOWS - #ifdef FLUX_BUILD_DLL - #define FLUX_API __declspec(dllexport) - #else - #define FLUX_API __declspec(dllimport) - #endif +#if defined(_WIN32) || defined(_WIN64) + #define FLUX_PLATFORM_WINDOWS +#elif defined(__linux__) + #define FLUX_PLATFORM_LINUX +#elif defined(__APPLE__) || defined(__MACH__) + #define FLUX_PLATFORM_MACOS +#endif + +#if defined(FLUX_PLATFORM_WINDOWS) + #if defined(FLUX_BUILD_DLL) + #define FLUX_API __declspec(dllexport) + #elif defined(FLUX_STATIC) + #define FLUX_API + #else + #define FLUX_API __declspec(dllimport) + #endif #else - #error Flux only supports windows! -#endif \ No newline at end of file + #define FLUX_API +#endif diff --git a/FluxEngine/src/public/Engine/Engine.h b/FluxEngine/src/public/Engine/Engine.h new file mode 100644 index 0000000..b1aa301 --- /dev/null +++ b/FluxEngine/src/public/Engine/Engine.h @@ -0,0 +1,56 @@ +#pragma once + +#include "Core.h" +#include "Log.h" +#include + +namespace Flux +{ + class FLUX_API FluxEngine + { + public: + FluxEngine(); + ~FluxEngine(); + + void Start(); + + static FluxEngine* GetInstance() + { + return GInstance; + } + + static bool IsRunning() + { + return GIsRunning; + } + + static Logger* GetLogger() + { + if (GIsRunning || GInstance != nullptr) + { + FluxEngine* Engine = GetInstance(); + if (Engine) + { + return &Engine->_Logger; + } + } + + return nullptr; + } + + void RequestExit() + { + GIsRunning = false; + } + + void EngineLoop(); + + private: + Flux::Logger& _Logger; + + static bool GIsRunning; + static FluxEngine* GInstance; + + bool bErrorState = false; + }; +} \ No newline at end of file diff --git a/FluxEngine/src/public/Flux.h b/FluxEngine/src/public/Flux.h index 63b57d5..9c5eaea 100644 --- a/FluxEngine/src/public/Flux.h +++ b/FluxEngine/src/public/Flux.h @@ -1,6 +1,4 @@ #pragma once -#include "Flux/Application.h" -#include "Flux/Log.h" - -#include "Flux/EntryPoint.h" \ No newline at end of file +#include "Engine/Engine.h" +#include "Log.h" \ No newline at end of file diff --git a/FluxEngine/src/public/Log.h b/FluxEngine/src/public/Log.h index 70e24b6..e7c690b 100644 --- a/FluxEngine/src/public/Log.h +++ b/FluxEngine/src/public/Log.h @@ -1,28 +1,35 @@ #pragma once #include - +#include #include "Core.h" -#include "spdlog/spdlog.h" + +namespace spdlog +{ + class logger; +} namespace Flux { - class FLUX_API Log + struct LoggerImpl; + + class FLUX_API Logger { public: - static void Init(); - inline static std::shared_ptr& GetCoreLogger() { return s_CoreLogger; } - inline static std::shared_ptr& GetClientLogger() { return s_ClientLogger; } - private: - static std::shared_ptr s_CoreLogger; - static std::shared_ptr s_ClientLogger; - }; + Logger(); + ~Logger(); + void LogTrace(const std::string& message); + private: + spdlog::logger* GetLogger() const; + + Flux::LoggerImpl& _impl; + }; } // Core log macros -#define FLUX_CORE_TRACE(...) ::Flux::Log::GetCoreLogger()->trace(__VA_ARGS__) +/*#define FLUX_CORE_TRACE(...) ::Flux::Log::GetCoreLogger()->trace(__VA_ARGS__) #define FLUX_CORE_INFO(...) ::Flux::Log::GetCoreLogger()->info(__VA_ARGS__) #define FLUX_CORE_WARN(...) ::Flux::Log::GetCoreLogger()->warn(__VA_ARGS__) #define FLUX_CORE_ERROR(...) ::Flux::Log::GetCoreLogger()->error(__VA_ARGS__) @@ -33,4 +40,4 @@ namespace Flux #define FLUX_INFO(...) ::Flux::Log::GetCoreLogger()->info(__VA_ARGS__) #define FLUX_WARN(...) ::Flux::Log::GetCoreLogger()->warn(__VA_ARGS__) #define FLUX_ERROR(...) ::Flux::Log::GetCoreLogger()->error(__VA_ARGS__) -#define FLUX_FATAL(...) ::Flux::Log::GetCoreLogger()->fatal(__VA_ARGS__) +#define FLUX_FATAL(...) ::Flux::Log::GetCoreLogger()->fatal(__VA_ARGS__)*/ diff --git a/GenerateProjects.bat b/GenerateProjects.bat index f8ba26f..6275275 100644 --- a/GenerateProjects.bat +++ b/GenerateProjects.bat @@ -5,7 +5,7 @@ rem ───────────────────────── rem Defaults (override by passing [backend] [build]) rem ────────────────────────────────────────────────── set BUILD_DIR=builddir -set BACKEND=ninja +set BACKEND=vs2022 set BUILD=debug rem ────────────────────────────────────────────────── @@ -22,18 +22,6 @@ rem ───────────────────────── if not "%~1"=="" set BACKEND=%~1 if not "%~2"=="" set BUILD=%~2 -rem ────────────────────────────────────────────────── -rem Bootstrap Visual Studio if requested -rem ────────────────────────────────────────────────── -if /I "%BACKEND:~0,2%"=="vs" ( - echo [INFO] Initializing Visual Studio environment for %BACKEND%... - call "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 >nul 2>&1 - if errorlevel 1 ( - echo [ERROR] Failed to initialize VS environment. Check the vcvarsall.bat path. - exit /b 1 - ) -) - rem ────────────────────────────────────────────────── rem Configure or reconfigure with Meson rem ────────────────────────────────────────────────── diff --git a/Sandbox/meson.build b/Sandbox/meson.build index 0d1e978..fc1fa84 100644 --- a/Sandbox/meson.build +++ b/Sandbox/meson.build @@ -1,12 +1,32 @@ +# 1) Grab the active C++ compiler +cpp = meson.get_compiler('cpp') +ccid = cpp.get_id() # e.g. 'msvc', 'gcc', 'clang', 'intel', ... + +# 2) Decide your D-flag prefix +if ccid == 'msvc' + dflag = '/D' +else + dflag = '-D' +endif + # Point to the public headers of FluxEngine sandbox_inc = include_directories( '../FluxEngine/src/public' ) executable( - 'sandbox', + 'sandbox_Shared', 'src/private/SandboxApp.cpp', - include_directories: sandbox_inc, - dependencies : flux_dep, - install : true, + include_directories: [sandbox_inc, flux_inc], + link_with: [ flux_shared ], +) + +executable( + 'sandbox_Static', + 'src/private/SandboxApp.cpp', + include_directories: [sandbox_inc, flux_inc], + link_with: [ flux_static ], + cpp_args: [ + dflag + 'FLUX_STATIC' + ], ) diff --git a/Sandbox/src/private/SandboxApp.cpp b/Sandbox/src/private/SandboxApp.cpp index c668a04..ced09ed 100644 --- a/Sandbox/src/private/SandboxApp.cpp +++ b/Sandbox/src/private/SandboxApp.cpp @@ -1,19 +1,9 @@ -#include +#include "Flux.h" -class Sandbox : public Flux::Application +int main (int argc, char** argv) { -public: - Sandbox() - { - - } - ~Sandbox() - { - - } -}; - -Flux::Application* Flux::CreateApplication() -{ - return new Sandbox(); + Flux::FluxEngine engine; + engine.Start(); + + return 0; } \ No newline at end of file diff --git a/meson.build b/meson.build index facaa72..d2381a9 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ project( 'FluxEngine', 'cpp', version : '0.1.0', - meson_version : '>=0.60.0', + meson_version : '>=0.63.0', default_options : [ 'cpp_std=c++20', 'warning_level=3', @@ -21,22 +21,10 @@ else dflag = '-D' endif -# 3) Platform macro (all OSes) -sys = host_machine.system() -if sys == 'windows' - plat = 'FLUX_PLATFORM_WINDOWS' -elif sys == 'linux' - plat = 'FLUX_PLATFORM_LINUX' -elif sys == 'darwin' - plat = 'FLUX_PLATFORM_MACOS' -elif sys == 'freebsd' - plat = 'FLUX_PLATFORM_FREEBSD' -else - plat = 'FLUX_PLATFORM_UNKNOWN' +if meson.get_compiler('cpp').get_id() == 'msvc' + add_project_arguments('/utf-8', language: 'cpp') endif -add_global_arguments(dflag + plat, language : 'cpp') - # 4) Build-type macros bt = get_option('buildtype') if bt == 'debug' diff --git a/subprojects/spdlog.wrap b/subprojects/spdlog.wrap index 1e8bb55..f7a4360 100644 --- a/subprojects/spdlog.wrap +++ b/subprojects/spdlog.wrap @@ -1,5 +1,13 @@ -[wrap-git] -url = https://github.com/gabime/spdlog.git -revision = v1.15.2 -depth = 1 -method = cmake \ No newline at end of file +[wrap-file] +directory = spdlog-1.15.2 +source_url = https://github.com/gabime/spdlog/archive/refs/tags/v1.15.2.tar.gz +source_filename = spdlog-1.15.2.tar.gz +source_hash = 7a80896357f3e8e920e85e92633b14ba0f229c506e6f978578bdc35ba09e9a5d +patch_filename = spdlog_1.15.2-3_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.15.2-3/get_patch +patch_hash = d5ab078661f571ef5113a8e4bc5c4121e16c044e7772a24b44b1ca8f3ee7c6cb +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/spdlog_1.15.2-3/spdlog-1.15.2.tar.gz +wrapdb_version = 1.15.2-3 + +[provide] +spdlog = spdlog_dep