From d6362a62dfec2d45c8499e597fa20b49a24fca7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20H=C3=B6hne?= <77296181+THoehne@users.noreply.github.com> Date: Tue, 18 Feb 2025 00:50:10 +0100 Subject: [PATCH] Fixing Logging. DevPlayground compiles and runs on Linux now. --- .gitignore | 56 ++++++++++-- .vscode/settings.json | 89 ++++++++++++++++++- DevPlayground/CMakeLists.txt | 3 - Engine/Source/Runtime/Core/CMakeLists.txt | 3 + Engine/Source/Runtime/Core/Logging/Logging.h | 36 ++++---- .../Runtime/Core/Logging/private/Logging.cpp | 9 +- .../Runtime/Core/StartingPoint/EntryPoint.h | 5 +- .../StartingPoint/private/StartingPoint.cpp | 17 ++-- 8 files changed, 179 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 5fa1cb2..27d2c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,16 +6,60 @@ external/ # Frequently edited tests Tests/TestProject/ +# CMake Build Files +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles/ +CMakeScripts/ +Testing/ +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps/ +CMakeUserPresets.json +build/ + + # Exclude files +# C++ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + # Temporary excludes -Core/private/Math/ - -Matrix4.h -IntVector4.h -Vector4.h - ############################################################################################ ## Ignore Visual Studio temporary files, build results, and diff --git a/.vscode/settings.json b/.vscode/settings.json index 2935f1f..d79b09c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,8 +3,8 @@ "C_Cpp.loggingLevel": "Error", "C_Cpp.default.cppStandard": "c++20", "C_Cpp.default.includePath": [ - "${workspaceFolder}/Engine/Source/Runtime", - "${workspaceFolder}/Engine/Source/ThirdParty" + "${workspaceFolder}/Engine/Source/Runtime/", + "${workspaceFolder}/Engine/Source/ThirdParty/" ], "C_Cpp.default.browse.path": [ @@ -13,10 +13,93 @@ ], "C_Cpp.default.browse.databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db", "files.associations": { - "cstdint": "cpp" + "cstdint": "cpp", + "chrono": "cpp", + "string": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "charconv": "cpp", + "cinttypes": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "expected": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "source_location": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "hash_map": "cpp", + "hash_set": "cpp", + "format": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "shared_mutex": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stdfloat": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "text_encoding": "cpp", + "thread": "cpp", + "cfenv": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "variant": "cpp" }, "C_Cpp.default.defines": [ "P_LINUX_BUILD", "__SSE__", ], + "cmake.sourceDirectory": "/home/morthaine/Development/PhanesEngine/DevPlayground", } \ No newline at end of file diff --git a/DevPlayground/CMakeLists.txt b/DevPlayground/CMakeLists.txt index 9340c9f..8887b04 100644 --- a/DevPlayground/CMakeLists.txt +++ b/DevPlayground/CMakeLists.txt @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.15...3.30) project(DevPlayground) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../Engine/Source/Runtime ${CMAKE_BINARY_DIR}/Engine) diff --git a/Engine/Source/Runtime/Core/CMakeLists.txt b/Engine/Source/Runtime/Core/CMakeLists.txt index c76489b..e6f5ca0 100644 --- a/Engine/Source/Runtime/Core/CMakeLists.txt +++ b/Engine/Source/Runtime/Core/CMakeLists.txt @@ -22,5 +22,8 @@ ${StartingPointPCH} add_compile_definitions(P_LINUX_BUILD) add_compile_definitions(P_DEBUG) +# fmt for spdlog. It uses the external module which needs to be linked manually +find_package(fmt) +target_link_libraries(PhanesCore fmt::fmt) target_include_directories(PhanesCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../) \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Logging/Logging.h b/Engine/Source/Runtime/Core/Logging/Logging.h index 5ff70bf..e45e8f1 100644 --- a/Engine/Source/Runtime/Core/Logging/Logging.h +++ b/Engine/Source/Runtime/Core/Logging/Logging.h @@ -6,13 +6,19 @@ namespace Phanes::Core::Logging { - static Phanes::Ref _PEngineLogger; - static Phanes::Ref _PAppLogger; + class Logger { - void Init(); + public: - inline std::shared_ptr& PEngineLogger() { return _PEngineLogger; }; - inline std::shared_ptr& PAppLogger() { return _PAppLogger; }; + static void Init(); + + static std::shared_ptr& PEngineLogger() { return _PEngineLogger; } + static std::shared_ptr& PAppLogger() { return _PAppLogger; } + + private: + static std::shared_ptr _PEngineLogger; + static std::shared_ptr _PAppLogger; + }; } @@ -22,18 +28,18 @@ namespace PLog = Phanes::Core::Logging; // User Macros // Default logger -#define PENGINE_LOG_TRACE(...) ::Phanes::Core::Logging::PEngineLogger()->trace(__VA_ARGS__) -#define PENGINE_LOG_INFO(...) ::Phanes::Core::Logging::PEngineLogger()->info(__VA_ARGS__) -#define PENGINE_LOG_WARN(...) ::Phanes::Core::Logging::PEngineLogger()->warn(__VA_ARGS__) -#define PENGINE_LOG_ERROR(...) ::Phanes::Core::Logging::PEngineLogger()->error(__VA_ARGS__) -#define PENGINE_LOG_FATAL(...) ::Phanes::Core::Logging::PEngineLogger()->critical(__VA_ARGS__) +#define PENGINE_LOG_TRACE(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->trace(__VA_ARGS__) +#define PENGINE_LOG_INFO(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->info(__VA_ARGS__) +#define PENGINE_LOG_WARN(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->warn(__VA_ARGS__) +#define PENGINE_LOG_ERROR(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->error(__VA_ARGS__) +#define PENGINE_LOG_FATAL(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->critical(__VA_ARGS__) -#define PAPP_LOG_TRACE(...) ::Phanes::Core::Logging::PAppLogger()->trace(__VA_ARGS__) -#define PAPP_LOG_INFO(...) ::Phanes::Core::Logging::PAppLogger()->info(__VA_ARGS__) -#define PAPP_LOG_WARN(...) ::Phanes::Core::Logging::PAppLogger()->warn(__VA_ARGS__) -#define PAPP_LOG_ERROR(...) ::Phanes::Core::Logging::PAppLogger()->error(__VA_ARGS__) -#define PAPP_LOG_FATAL(...) ::Phanes::Core::Logging::PAppLogger()->critical(__VA_ARGS__) +#define PAPP_LOG_TRACE(...) ::Phanes::Core::Logging::Logger::PAppLogger()->trace(__VA_ARGS__) +#define PAPP_LOG_INFO(...) ::Phanes::Core::Logging::Logger::PAppLogger()->info(__VA_ARGS__) +#define PAPP_LOG_WARN(...) ::Phanes::Core::Logging::Logger::PAppLogger()->warn(__VA_ARGS__) +#define PAPP_LOG_ERROR(...) ::Phanes::Core::Logging::Logger::PAppLogger()->error(__VA_ARGS__) +#define PAPP_LOG_FATAL(...) ::Phanes::Core::Logging::Logger::PAppLogger()->critical(__VA_ARGS__) #else diff --git a/Engine/Source/Runtime/Core/Logging/private/Logging.cpp b/Engine/Source/Runtime/Core/Logging/private/Logging.cpp index 21542d2..d5502b3 100644 --- a/Engine/Source/Runtime/Core/Logging/private/Logging.cpp +++ b/Engine/Source/Runtime/Core/Logging/private/Logging.cpp @@ -1,6 +1,13 @@ #include "Core/Logging/Logging.h" -void Phanes::Core::Logging::Init() +namespace Phanes::Core::Logging +{ + std::shared_ptr Logger::_PEngineLogger; + std::shared_ptr Logger::_PAppLogger; +} // namespace Phanes::Core::Logging + + +void Phanes::Core::Logging::Logger::Init() { spdlog::set_pattern("%^[%n][%T][%l]:%$ %v"); diff --git a/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h b/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h index edc7fdd..1ba4209 100644 --- a/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h +++ b/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h @@ -7,14 +7,11 @@ extern Phanes::Core::Application::PhanesProject* Phanes::Core::Application::Crea int main(int argc, char** argv) { - Phanes::Core::Logging::Init(); + Phanes::Core::Logging::Logger::Init(); PENGINE_LOG_INFO("Logger initialized!"); PENGINE_LOG_INFO("Welcome to PhanesEngine!"); - auto phanes_game = Phanes::Core::Application::CreatePhanesGame(); - - PENGINE_LOG_INFO("Loading project {0}...", phanes_game->GetName()); phanes_game->Run(); diff --git a/Engine/Source/Runtime/Core/StartingPoint/private/StartingPoint.cpp b/Engine/Source/Runtime/Core/StartingPoint/private/StartingPoint.cpp index 3afd49b..0fb3ad1 100644 --- a/Engine/Source/Runtime/Core/StartingPoint/private/StartingPoint.cpp +++ b/Engine/Source/Runtime/Core/StartingPoint/private/StartingPoint.cpp @@ -1,24 +1,25 @@ #include "Core/StartingPoint/StartingPoint.h" +#include "Core/Logging/Logging.h" static void IdleMsg() { - std::cout << "\n\nWelcome to PhanesEngine!" << std::endl << std::endl; + std::cout << "\nWelcome to PhanesEngine!\n"; std::this_thread::sleep_for(std::chrono::seconds(5)); - std::cout << "It's silent..." << std::endl << std::endl; + std::cout << "It's silent...\n"; std::this_thread::sleep_for(std::chrono::seconds(3)); - std::cout << "To silent." << std::endl; + std::cout << "To silent.\n"; std::this_thread::sleep_for(std::chrono::seconds(5)); - std::cout << "\nI will go now" << std::endl; + std::cout << "I will go now\n"; std::this_thread::sleep_for(std::chrono::seconds(4)); - std::cout << "\nGood by!" << std::endl; + std::cout << "Good by!\n\n"; std::this_thread::sleep_for(std::chrono::seconds(3)); } @@ -27,11 +28,13 @@ static void IdleMsg() Phanes::Core::Application::PhanesProject::PhanesProject(std::string _ProjectName) : projectName(_ProjectName) -{}; +{ + PAPP_LOG_INFO("Loading project: {0}", this->GetName()); +}; Phanes::Core::Application::PhanesProject::~PhanesProject() { - this->projectName = "Unnamed Project"; + PAPP_LOG_INFO("Unloading project: {0}", this->GetName()); }; std::string Phanes::Core::Application::PhanesProject::GetName()