This commit is contained in:
Jordon Brooks 2025-05-06 16:59:40 +01:00
parent 0460ae1a50
commit 1dca4a91d9
Signed by: jordon
GPG key ID: DBD9758CD53E786A
19 changed files with 333 additions and 156 deletions

3
.gitignore vendored
View file

@ -4,3 +4,6 @@ bin-int/
*.vcxproj *.vcxproj
*.vcxproj.filters *.vcxproj.filters
!/vendor/** !/vendor/**
subprojects/
!subprojects/*.wrap

22
.vscode/launch.json vendored Normal file
View file

@ -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"
},
]
}

View file

@ -1,5 +1,6 @@
{ {
"C_Cpp.default.compileCommands": "d:\\FluxEngine\\builddir/compile_commands.json", "C_Cpp.default.compileCommands": "d:\\FluxEngine\\builddir/compile_commands.json",
"C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild", "C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild",
"cmake.ignoreCMakeListsMissing": true "cmake.ignoreCMakeListsMissing": true,
"C_Cpp.errorSquiggles": "enabled"
} }

24
.vscode/tasks.json vendored Normal file
View file

@ -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",
}
]
}

View file

@ -1,23 +1,54 @@
flux_inc = include_directories('src/public') flux_inc = include_directories('src/public')
flux_sources = files( flux_sources = files(
'src/private/Application.cpp', 'src/private/Engine/Engine.cpp',
'src/private/Log.cpp', 'src/private/Log.cpp',
) )
spd = subproject('spdlog') # 1) Grab the active C++ compiler
spdlog_dep = spd.get_variable('spdlog') cpp = meson.get_compiler('cpp')
ccid = cpp.get_id() # e.g. 'msvc', 'gcc', 'clang', 'intel', ...
flux_lib = library( # 2) Decide your D-flag prefix
'fluxengine', 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, flux_sources,
include_directories: flux_inc, include_directories: flux_inc,
link_with : spdlog_dep, dependencies: [spdlog_dep],
version : meson.project_version(), cpp_args: [
install : true, 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, include_directories: flux_inc,
link_with : [ flux_lib, spdlog_dep ], dependencies: [spdlog_dep],
cpp_args: [
dflag + 'FLUX_STATIC'
],
install: true
) )

View file

@ -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);
}
}

View file

@ -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.
}
}
}

View file

@ -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

View file

@ -1,19 +1,50 @@
#include "Log.h" #include "Log.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_color_sinks.h"
namespace Flux namespace Flux
{ {
std::shared_ptr<spdlog::logger> Log::s_CoreLogger; struct LoggerImpl
std::shared_ptr<spdlog::logger> Log::s_ClientLogger;
void Log::Init()
{ {
spdlog::set_pattern("%^[%T] %n: %v%$"); LoggerImpl() = default;
s_CoreLogger = spdlog::stdout_color_mt("FLUX"); ~LoggerImpl() = default;
s_CoreLogger->set_level(spdlog::level::trace);
s_ClientLogger = spdlog::stdout_color_mt("APP"); std::shared_ptr<spdlog::logger> _logger;
s_ClientLogger->set_level(spdlog::level::trace); };
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);
} }
} }

View file

@ -1,18 +0,0 @@
#pragma once
#include "Core.h"
namespace Flux {
class FLUX_API Application
{
public:
Application();
virtual ~Application();
void Run();
};
Application* CreateApplication();
}

View file

@ -1,11 +1,21 @@
#pragma once #pragma once
#ifdef FLUX_PLATFORM_WINDOWS #if defined(_WIN32) || defined(_WIN64)
#ifdef FLUX_BUILD_DLL #define FLUX_PLATFORM_WINDOWS
#define FLUX_API __declspec(dllexport) #elif defined(__linux__)
#else #define FLUX_PLATFORM_LINUX
#define FLUX_API __declspec(dllimport) #elif defined(__APPLE__) || defined(__MACH__)
#endif #define FLUX_PLATFORM_MACOS
#else #endif
#error Flux only supports windows!
#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
#define FLUX_API
#endif #endif

View file

@ -0,0 +1,56 @@
#pragma once
#include "Core.h"
#include "Log.h"
#include <memory>
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;
};
}

View file

@ -1,6 +1,4 @@
#pragma once #pragma once
#include "Flux/Application.h" #include "Engine/Engine.h"
#include "Flux/Log.h" #include "Log.h"
#include "Flux/EntryPoint.h"

View file

@ -1,28 +1,35 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <string>
#include "Core.h" #include "Core.h"
#include "spdlog/spdlog.h"
namespace spdlog
{
class logger;
}
namespace Flux namespace Flux
{ {
class FLUX_API Log struct LoggerImpl;
class FLUX_API Logger
{ {
public: public:
static void Init(); Logger();
inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; } ~Logger();
inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return s_ClientLogger; }
private:
static std::shared_ptr<spdlog::logger> s_CoreLogger;
static std::shared_ptr<spdlog::logger> s_ClientLogger;
};
void LogTrace(const std::string& message);
private:
spdlog::logger* GetLogger() const;
Flux::LoggerImpl& _impl;
};
} }
// Core log macros // 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_INFO(...) ::Flux::Log::GetCoreLogger()->info(__VA_ARGS__)
#define FLUX_CORE_WARN(...) ::Flux::Log::GetCoreLogger()->warn(__VA_ARGS__) #define FLUX_CORE_WARN(...) ::Flux::Log::GetCoreLogger()->warn(__VA_ARGS__)
#define FLUX_CORE_ERROR(...) ::Flux::Log::GetCoreLogger()->error(__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_INFO(...) ::Flux::Log::GetCoreLogger()->info(__VA_ARGS__)
#define FLUX_WARN(...) ::Flux::Log::GetCoreLogger()->warn(__VA_ARGS__) #define FLUX_WARN(...) ::Flux::Log::GetCoreLogger()->warn(__VA_ARGS__)
#define FLUX_ERROR(...) ::Flux::Log::GetCoreLogger()->error(__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__)*/

View file

@ -5,7 +5,7 @@ rem ─────────────────────────
rem Defaults (override by passing [backend] [build]) rem Defaults (override by passing [backend] [build])
rem ────────────────────────────────────────────────── rem ──────────────────────────────────────────────────
set BUILD_DIR=builddir set BUILD_DIR=builddir
set BACKEND=ninja set BACKEND=vs2022
set BUILD=debug set BUILD=debug
rem ────────────────────────────────────────────────── rem ──────────────────────────────────────────────────
@ -22,18 +22,6 @@ rem ─────────────────────────
if not "%~1"=="" set BACKEND=%~1 if not "%~1"=="" set BACKEND=%~1
if not "%~2"=="" set BUILD=%~2 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 ──────────────────────────────────────────────────
rem Configure or reconfigure with Meson rem Configure or reconfigure with Meson
rem ────────────────────────────────────────────────── rem ──────────────────────────────────────────────────

View file

@ -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 # Point to the public headers of FluxEngine
sandbox_inc = include_directories( sandbox_inc = include_directories(
'../FluxEngine/src/public' '../FluxEngine/src/public'
) )
executable( executable(
'sandbox', 'sandbox_Shared',
'src/private/SandboxApp.cpp', 'src/private/SandboxApp.cpp',
include_directories: sandbox_inc, include_directories: [sandbox_inc, flux_inc],
dependencies : flux_dep, link_with: [ flux_shared ],
install : true, )
executable(
'sandbox_Static',
'src/private/SandboxApp.cpp',
include_directories: [sandbox_inc, flux_inc],
link_with: [ flux_static ],
cpp_args: [
dflag + 'FLUX_STATIC'
],
) )

View file

@ -1,19 +1,9 @@
#include <Flux.h> #include "Flux.h"
class Sandbox : public Flux::Application int main (int argc, char** argv)
{ {
public: Flux::FluxEngine engine;
Sandbox() engine.Start();
{
} return 0;
~Sandbox()
{
}
};
Flux::Application* Flux::CreateApplication()
{
return new Sandbox();
} }

View file

@ -2,7 +2,7 @@ project(
'FluxEngine', 'FluxEngine',
'cpp', 'cpp',
version : '0.1.0', version : '0.1.0',
meson_version : '>=0.60.0', meson_version : '>=0.63.0',
default_options : [ default_options : [
'cpp_std=c++20', 'cpp_std=c++20',
'warning_level=3', 'warning_level=3',
@ -21,22 +21,10 @@ else
dflag = '-D' dflag = '-D'
endif endif
# 3) Platform macro (all OSes) if meson.get_compiler('cpp').get_id() == 'msvc'
sys = host_machine.system() add_project_arguments('/utf-8', language: 'cpp')
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'
endif endif
add_global_arguments(dflag + plat, language : 'cpp')
# 4) Build-type macros # 4) Build-type macros
bt = get_option('buildtype') bt = get_option('buildtype')
if bt == 'debug' if bt == 'debug'

View file

@ -1,5 +1,13 @@
[wrap-git] [wrap-file]
url = https://github.com/gabime/spdlog.git directory = spdlog-1.15.2
revision = v1.15.2 source_url = https://github.com/gabime/spdlog/archive/refs/tags/v1.15.2.tar.gz
depth = 1 source_filename = spdlog-1.15.2.tar.gz
method = cmake 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