Compare commits

..

2 commits

Author SHA1 Message Date
1dca4a91d9
Fixed it 2025-05-06 16:59:40 +01:00
0460ae1a50
Changed build files to meson 2025-05-05 14:14:36 +01:00
26 changed files with 473 additions and 253 deletions

3
.gitignore vendored
View file

@ -4,3 +4,6 @@ bin-int/
*.vcxproj
*.vcxproj.filters
!/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"
},
]
}

6
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,6 @@
{
"C_Cpp.default.compileCommands": "d:\\FluxEngine\\builddir/compile_commands.json",
"C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild",
"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",
}
]
}

54
FluxEngine/meson.build Normal file
View file

@ -0,0 +1,54 @@
flux_inc = include_directories('src/public')
flux_sources = files(
'src/private/Engine/Engine.cpp',
'src/private/Log.cpp',
)
# 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
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,
dependencies: [spdlog_dep],
cpp_args: [
dflag + 'FLUX_BUILD_DLL'
],
install: true
)
# 2B) Static library
flux_static = static_library(
'FluxEngine_static',
flux_sources,
include_directories: flux_inc,
dependencies: [spdlog_dep],
cpp_args: [
dflag + 'FLUX_STATIC'
],
install: true
)

View file

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

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

@ -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 +0,0 @@
#pragma once
#ifdef FLUX_PLATFORM_WINDOWS
#ifdef FLUX_BUILD_DLL
#define FLUX_API __declspec(dllexport)
#else
#define FLUX_API __declspec(dllimport)
#endif
#else
#error Flux only supports windows!
#endif

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

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

@ -0,0 +1,50 @@
#include "Log.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
namespace Flux
{
struct LoggerImpl
{
LoggerImpl() = default;
~LoggerImpl() = default;
std::shared_ptr<spdlog::logger> _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);
}
}

View file

@ -0,0 +1,21 @@
#pragma once
#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
#define FLUX_API
#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

@ -0,0 +1,4 @@
#pragma once
#include "Engine/Engine.h"
#include "Log.h"

View file

@ -1,28 +1,35 @@
#pragma once
#include <memory>
#include <string>
#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<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; }
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;
};
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__)*/

View file

@ -1,2 +1,59 @@
call .\vendor\bin\premake\premake5.exe vs2022
PAUSE
@echo off
setlocal enabledelayedexpansion
rem ──────────────────────────────────────────────────
rem Defaults (override by passing [backend] [build])
rem ──────────────────────────────────────────────────
set BUILD_DIR=builddir
set BACKEND=vs2022
set BUILD=debug
rem ──────────────────────────────────────────────────
rem Recognize help flags
rem ──────────────────────────────────────────────────
if /I "%~1"=="-?" goto usage
if /I "%~1"=="/?" goto usage
if /I "%~1"=="-h" goto usage
if /I "%~1"=="--help" goto usage
rem ──────────────────────────────────────────────────
rem Parse positional arguments
rem ──────────────────────────────────────────────────
if not "%~1"=="" set BACKEND=%~1
if not "%~2"=="" set BUILD=%~2
rem ──────────────────────────────────────────────────
rem Configure or reconfigure with Meson
rem ──────────────────────────────────────────────────
if not exist "%BUILD_DIR%" (
echo [INFO] Creating build directory "%BUILD_DIR%" with backend "%BACKEND%" and build "%BUILD%"...
meson setup "%BUILD_DIR%" --backend=%BACKEND% --buildtype=%BUILD%
) else (
echo [INFO] Reconfiguring "%BUILD_DIR%" with backend "%BACKEND%" and build "%BUILD%"...
meson setup --reconfigure "%BUILD_DIR%" --backend=%BACKEND% --buildtype=%BUILD%
)
if errorlevel 1 (
echo [ERROR] Meson configuration failed.
exit /b 1
)
rem ──────────────────────────────────────────────────
rem Compile
rem ──────────────────────────────────────────────────
echo [INFO] Configuration succeeded—starting build...
meson compile -C "%BUILD_DIR%"
if errorlevel 1 (
echo [ERROR] Build failed.
exit /b 1
)
echo [SUCCESS] Build completed successfully.
exit /b 0
:usage
echo Usage: %~nx0 [backend] [build]
echo.
echo backend ninja (default) ^| vs2022 ^| vs2019 ^| vs2017
echo build debug (default) ^| debugoptimized ^| release ^| relwithdebinfo
exit /b 0

32
Sandbox/meson.build Normal file
View file

@ -0,0 +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_Shared',
'src/private/SandboxApp.cpp',
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'
],
)

View file

@ -1,19 +0,0 @@
#include <Flux.h>
class Sandbox : public Flux::Application
{
public:
Sandbox()
{
}
~Sandbox()
{
}
};
Flux::Application* Flux::CreateApplication()
{
return new Sandbox();
}

View file

@ -0,0 +1,9 @@
#include "Flux.h"
int main (int argc, char** argv)
{
Flux::FluxEngine engine;
engine.Start();
return 0;
}

42
meson.build Normal file
View file

@ -0,0 +1,42 @@
project(
'FluxEngine',
'cpp',
version : '0.1.0',
meson_version : '>=0.63.0',
default_options : [
'cpp_std=c++20',
'warning_level=3',
'buildtype=debugoptimized',
]
)
# 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
if meson.get_compiler('cpp').get_id() == 'msvc'
add_project_arguments('/utf-8', language: 'cpp')
endif
# 4) Build-type macros
bt = get_option('buildtype')
if bt == 'debug'
add_project_arguments(dflag + 'FLUX_DEBUG', language : 'cpp')
elif bt == 'release'
add_project_arguments(dflag + 'FLUX_RELEASE', language : 'cpp')
elif bt == 'debugoptimized'
add_project_arguments(dflag + 'FLUX_DIST', language : 'cpp')
else
warning('Unrecognized buildtype: ' + bt)
endif
# Tell Meson to descend into these directories
subdir('FluxEngine')
subdir('Sandbox')

View file

@ -1,98 +0,0 @@
workspace "FluxEngine"
architecture "x64"
startproject "Sandbox"
configurations { "Debug", "Release", "Dist" }
outputdir = "%{cfg.buildcfg}-%{cfg.system}"
project "FluxEngine"
location "FluxEngine"
kind "SharedLib"
language "C++"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp",
}
includedirs
{
"%{prj.name}/vendor/spdlog/include",
}
filter "system:windows"
cppdialect "C++20"
staticruntime "on"
systemversion "latest"
defines
{
"FLUX_PLATFORM_WINDOWS",
"FLUX_BUILD_DLL"
}
postbuildcommands
{
("{COPY} %{cfg.buildtarget.relpath} ../bin/".. outputdir .. "/Sandbox")
}
filter "configurations:Debug"
defines "FLUX_DEBUG"
symbols "On"
filter "configurations:Release"
defines "FLUX_RELEASE"
optimize "On"
filter "configurations:Dist"
defines "FLUX_DIST"
optimize "On"
project "Sandbox"
location "Sandbox"
kind "ConsoleApp"
language "C++"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp",
}
includedirs
{
"FluxEngine/vendor/spdlog/include",
"FluxEngine/src"
}
links
{
"FluxEngine"
}
filter "system:windows"
cppdialect "C++20"
staticruntime "on"
systemversion "latest"
defines
{
"FLUX_PLATFORM_WINDOWS"
}
filter "configurations:Debug"
defines "FLUX_DEBUG"
symbols "On"
filter "configurations:Release"
defines "FLUX_RELEASE"
optimize "On"
filter "configurations:Dist"
defines "FLUX_DIST"
optimize "On"

13
subprojects/spdlog.wrap Normal file
View file

@ -0,0 +1,13 @@
[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

View file

@ -1,27 +0,0 @@
Copyright (c) 2003-2022 Jason Perkins and individual contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of Premake nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Binary file not shown.