From 834402c1b8c7cde21b2b68645cfe358320733959 Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 6 Jul 2025 16:30:38 +0330 Subject: [PATCH] refactor: logger --- modules/engine/include/engine/base/base.hpp | 59 ++++++-- .../engine/include/engine/base/entrypoint.hpp | 21 ++- .../engine/base/portables/debug_trap.hpp | 8 +- .../include/engine/core/application.hpp | 12 +- .../engine/include/engine/debug/logger.hpp | 132 ++++++++++++------ modules/engine/src/core/application.cpp | 36 ++--- modules/engine/src/debug/exceptions.cpp | 36 ++--- modules/engine/src/debug/instrumentor.cpp | 2 +- modules/engine/src/debug/logger.cpp | 51 ++----- modules/engine/src/graphics/framebuffer.cpp | 15 +- modules/engine/src/graphics/renderer.cpp | 14 +- .../src/graphics/renderer_programs/quad.cpp | 2 +- .../graphics/renderer_programs/texture.cpp | 2 +- .../renderer_programs/tinted_texture.cpp | 2 +- modules/engine/src/graphics/shader.cpp | 14 +- modules/engine/src/layer/layer_stack.cpp | 4 +- .../src/platform/graphics/directx/buffers.cpp | 2 +- .../graphics/directx/framebuffers.cpp | 2 +- .../graphics/directx/graphics_context.cpp | 8 +- .../graphics/directx/render_command.cpp | 4 +- .../graphics/directx/user_interface.cpp | 12 +- .../src/platform/graphics/opengl/buffers.cpp | 9 +- .../platform/graphics/opengl/framebuffers.cpp | 2 +- .../graphics/opengl/graphics_context.cpp | 30 ++-- .../src/platform/graphics/opengl/shader.cpp | 9 +- .../graphics/opengl/user_interface.cpp | 12 +- modules/engine/src/scene/scene.cpp | 8 +- modules/engine/src/utils/file_manager.cpp | 17 ++- modules/engine/src/utils/resource_manager.cpp | 2 +- modules/engine/src/utils/serializer.cpp | 26 ++-- modules/mirror/src/panel/asset_browser.cpp | 2 +- 31 files changed, 295 insertions(+), 260 deletions(-) diff --git a/modules/engine/include/engine/base/base.hpp b/modules/engine/include/engine/base/base.hpp index 063e4a6..3190644 100644 --- a/modules/engine/include/engine/base/base.hpp +++ b/modules/engine/include/engine/base/base.hpp @@ -38,43 +38,74 @@ constexpr std::unique_ptr make_scope(t *rawPointer) } // namespace Light -//========== PLATFORM ==========// #define lt_win(x) // windows #define lt_lin(x) // linux #define lt_mac(x) // mac + +enum class Platform : uint8_t +{ + windows, + + /** Named like so because "linux" is a built-in identifier. */ + gnu, + + mac, +}; + + +namespace constants { + #if defined(LIGHT_PLATFORM_WINDOWS) - #define LT_BUILD_PLATFORM "Windows" - #define lt_win(x) x + #define lt_win(x) x +constexpr auto platform = Platform::windows; +constexpr auto platform_name = "windows"; #elif defined(LIGHT_PLATFORM_LINUX) - #define LT_BUILD_PLATFORM "Linux" - #define lt_lin(x) x + #define lt_lin(x) x +constexpr auto platform = Platform::gnu; +constexpr auto platform_name = "linux"; #elif defined(LIGHT_PLATFORM_MAC) - #error "Unsupported platform: MAC" #define lt_mac(x) x +constexpr auto platform = Platform::mac; +constexpr auto platform_name = "mac"; #else #error "Unsupported platform: Unknown" -#endif -//========== PLATFORM ==========// -//====================================================================== OPERATIONS -//======================================================================// -/* assertions */ -#define lt_assert(x, ...) \ +#endif + + +} // namespace constants + +template +concept is_linux = true; + +auto linux_only(auto value) + requires is_linux +{ + if constexpr (is_linux) + { + return value; + } +} + +#define lt_assert(x, ...) \ { \ if (!(x)) \ { \ - lt_log(critical, __VA_ARGS__); \ + log_crt(__VA_ARGS__); \ lt_debug_trap(); \ throw ::Light::FailedAssertion(__FILE__, __LINE__); \ } \ } /* bit-wise */ -#define bit(x) 1 << x +constexpr auto bit(auto x) +{ + return 1 << x; +} /* token */ #define lt_pair_token_value_to_name(token) { token, #token } diff --git a/modules/engine/include/engine/base/entrypoint.hpp b/modules/engine/include/engine/base/entrypoint.hpp index 70aabd7..b80784a 100644 --- a/modules/engine/include/engine/base/entrypoint.hpp +++ b/modules/engine/include/engine/base/entrypoint.hpp @@ -5,12 +5,12 @@ #include // to be defined in client project -extern Light::Application *Light::create_application(); +extern auto Light::create_application() -> Light::Scope; // #todo: use windows specific stuff int main(int argc, char *argv[]) { - Light::Application *application = nullptr; + auto application = Light::Scope {}; int exitCode = 0; std::vector args; @@ -24,26 +24,26 @@ int main(int argc, char *argv[]) lt_assert(application, "Light::Application is not intialized"); for (int i = 0; i < argc; i++) - lt_log(info, "argv[{}]: {}", i, argv[i]); + log_inf("argv[{}]: {}", i, argv[i]); application->game_loop(); } // failed engine assertion catch (Light::FailedAssertion) { - lt_log(critical, "Terminating due to unhandled 'FailedEngineAssertion'"); + log_crt("Terminating due to unhandled 'FailedEngineAssertion'"); exitCode = -1; } // gl exception catch (Light::glException) { - lt_log(critical, "Terminating due to unhandled 'glException'"); + log_crt("Terminating due to unhandled 'glException'"); exitCode = -3; } // dx exception catch (Light::dxException) { - lt_log(critical, "Terminating due to unhandled 'dxException'"); + log_crt("Terminating due to unhandled 'dxException'"); exitCode = -4; } @@ -56,12 +56,12 @@ int main(int argc, char *argv[]) #include // to be defined in client project -extern Light::Application *Light::create_application(); +extern auto Light::create_application() -> Light::Scope; // #todo: use linux specific stuff int main(int argc, char *argv[]) { - Light::Application *application = nullptr; + auto application = Light::Scope {}; int exitCode = 0; try @@ -74,17 +74,16 @@ int main(int argc, char *argv[]) // failed engine assertion catch (Light::FailedAssertion) { - lt_log(critical, "Exitting due to unhandled 'FailedEngineAssertion'"); + log_crt("Exitting due to unhandled 'FailedEngineAssertion'"); exitCode = -1; } // gl exception catch (Light::glException) { - lt_log(critical, "main: exitting due to unhandled 'glException'"); + log_crt("main: exitting due to unhandled 'glException'"); exitCode = -3; } - delete application; return exitCode; } diff --git a/modules/engine/include/engine/base/portables/debug_trap.hpp b/modules/engine/include/engine/base/portables/debug_trap.hpp index 22112a9..cbd757c 100644 --- a/modules/engine/include/engine/base/portables/debug_trap.hpp +++ b/modules/engine/include/engine/base/portables/debug_trap.hpp @@ -127,7 +127,7 @@ static inline void lt_debug_trap(void) #elif defined(LIGHT_DIST) #ifdef _MSC_VER #define lt_debug_trap() \ - lt_log(critical, \ + log_crt( \ "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \ __FUNCSIG__, \ __FILE__, \ @@ -135,13 +135,13 @@ static inline void lt_debug_trap(void) #else #define lt_debug_trap() \ - lt_log(critical, "DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) + log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) #endif #else /* !defined(LIGHT_DIST) */ #ifdef _MSC_VER #define lt_debug_trap() \ - lt_log(critical, \ + log_crt( \ "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \ __FUNCSIG__, \ __FILE__, \ @@ -149,7 +149,7 @@ static inline void lt_debug_trap(void) #else #define lt_debug_trap() \ - lt_log(critical, "DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) + log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) #endif #endif diff --git a/modules/engine/include/engine/core/application.hpp b/modules/engine/include/engine/core/application.hpp index 1f82318..00917e7 100644 --- a/modules/engine/include/engine/core/application.hpp +++ b/modules/engine/include/engine/core/application.hpp @@ -31,9 +31,11 @@ protected: Scope m_window; private: - static Application *s_context; + void on_event(const Event &event); - Scope m_logger; + void log_debug_data(); + + static Application *s_context; Scope m_instrumentor; @@ -42,12 +44,8 @@ private: Scope m_input; Scope m_resource_manager; - - void on_event(const Event &event); - - void log_debug_data(); }; -extern Application *create_application(); +extern Light::Scope create_application(); } // namespace Light diff --git a/modules/engine/include/engine/debug/logger.hpp b/modules/engine/include/engine/debug/logger.hpp index 3cd6d60..55e5cf4 100644 --- a/modules/engine/include/engine/debug/logger.hpp +++ b/modules/engine/include/engine/debug/logger.hpp @@ -1,57 +1,101 @@ #pragma once -#ifndef LIGHT_LOGGER_H - #define LIGHT_LOGGER_H - #include - #include +#include +#include +#include +#include +#include +#include - #define LT_LOG_FILE_LOCATION "Logs/logger.txt" - - #ifndef LIGHT_DIST - #define lt_log(logLevel, ...) \ - SPDLOG_LOGGER_CALL( \ - ::Light::logger::get_engine_logger(), \ - spdlog::level::logLevel, \ - __VA_ARGS__ \ - ) - #else - #define lt_log(logLevel, ...) \ - SPDLOG_LOGGER_CALL( \ - ::Light::logger::get_file_logger(), \ - spdlog::level::logLevel, \ - __VA_ARGS__ \ - ) - #endif - -namespace Light { - -class logger +/** @brief Severity of a log message. + * + * @note Values reflect spdlog::lvl + */ +enum class LogLvl : uint8_t { -public: - static Scope create(); + /** Lowest and most vebose log level, for tracing execution paths and events */ + trace = 0, - static auto get_engine_logger() -> Ref - { - return s_context->m_engine_logger; - } + /** Vebose log level, for enabling temporarily to debug */ + debug = 1, - static auto get_file_logger() -> Ref - { - return s_context->m_file_logger; - } + /** General information */ + info = 2, - void log_debug_data(); + /** Things we should to be aware of and edge cases */ + warn = 3, -private: - static logger *s_context; + /** Defects, bugs and undesired behaviour */ + error = 4, - Ref m_engine_logger, m_file_logger; + /** Unrecoverable errors */ + critical = 5, - std::string m_log_file_path; - - logger(); + /** No logging */ + off = 6, }; -} // namespace Light +namespace spdlog { +class logger; +} -#endif +/** Responsible for logging */ +class Logger +{ +public: + void static show_imgui_window(); + + template + void static log(LogLvl lvl, std::format_string fmt, Args &&...args) + { + instance().spd_logger->log( + (spdlog::level::level_enum)lvl, + std::format(fmt, std::forward(args)...) + ); + } + +private: + Logger(); + + ~Logger(); + + auto static instance() -> Logger &; + + std::shared_ptr spd_logger; +}; + +template +void log_trc(std::format_string fmt, Args &&...args) +{ + Logger::log(LogLvl::trace, fmt, std::forward(args)...); +} + +template +void log_dbg(std::format_string fmt, Args &&...args) +{ + Logger::log(LogLvl::debug, fmt, std::forward(args)...); +} + +template +void log_inf(std::format_string fmt, Args &&...args) +{ + Logger::log(LogLvl::info, fmt, std::forward(args)...); +} + +template +void log_wrn(std::format_string fmt, Args &&...args) +{ + Logger::log(LogLvl::warn, fmt, std::forward(args)...); +} + +template +void log_err(std::format_string fmt, Args &&...args) +{ + Logger::log(LogLvl::error, fmt, std::forward(args)...); +} + +template +void log_crt(std::format_string fmt, Args &&...args) +{ + Logger::log(LogLvl::critical, fmt, std::forward(args)...); +} diff --git a/modules/engine/src/core/application.cpp b/modules/engine/src/core/application.cpp index a8052bf..78d46c6 100644 --- a/modules/engine/src/core/application.cpp +++ b/modules/engine/src/core/application.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace Light { @@ -22,7 +23,6 @@ Application::Application() lt_assert(!s_context, "Repeated singleton construction"); s_context = this; - m_logger = logger::create(); log_debug_data(); m_instrumentor = Instrumentor::create(); @@ -38,8 +38,8 @@ Application::Application() Application::~Application() { - lt_log(trace, "Application::~Application()"); - m_instrumentor->end_session(); // ProfileResults_Termination // + log_trc("Application::~Application()"); + m_instrumentor->end_session(); } void Application::game_loop() @@ -48,14 +48,13 @@ void Application::game_loop() lt_assert(!m_layer_stack->is_empty(), "layer_stack is empty"); // log debug data - m_logger->log_debug_data(); m_window->get_graphics_context()->log_debug_data(); m_window->get_graphics_context()->get_user_interface()->log_debug_data(); // reveal window m_window->set_visibility(true); - m_instrumentor->end_session(); // ProfileResults_GameLoop // + m_instrumentor->end_session(); m_instrumentor->begin_session("Logs/ProfileResults_GameLoop.json"); /* game loop */ @@ -102,7 +101,7 @@ void Application::game_loop() delta_timer.update(); } - m_instrumentor->end_session(); // ProfileResults_GameLoop // + m_instrumentor->end_session(); m_instrumentor->begin_session("Logs/ProfileResults_Termination.json"); } @@ -129,25 +128,30 @@ void Application::on_event(const Event &event) { m_input->on_event(event); - if (!m_input->is_receiving_game_events()) // return if the event is an input event and - // 'Input' has disabled the game events + if (!m_input->is_receiving_game_events()) + { return; + } } - /* layers */ - for (auto it = m_layer_stack->rbegin(); it != m_layer_stack->rend(); it++) - if ((*it)->on_event(event)) + for (auto &it : std::ranges::reverse_view(*m_layer_stack)) + { + if (it->on_event(event)) + { return; + } + } } void Application::log_debug_data() { // #todo: log more information - lt_log(info, "________________________________________"); - lt_log(info, "Platform::"); - lt_log(info, " OS: {}", LT_BUILD_PLATFORM); - lt_log(info, " DIR: {}", std::filesystem::current_path().generic_string()); - lt_log(info, "________________________________________"); + log_inf("________________________________________"); + log_inf("Platform::"); + log_inf(" Platform name: {}", constants::platform_name); + log_inf(" Platform identifier: {}", std::to_underlying(constants::platform)); + log_inf(" CWD: {}", std::filesystem::current_path().generic_string()); + log_inf("________________________________________"); } } // namespace Light diff --git a/modules/engine/src/debug/exceptions.cpp b/modules/engine/src/debug/exceptions.cpp index fde98ec..138274f 100644 --- a/modules/engine/src/debug/exceptions.cpp +++ b/modules/engine/src/debug/exceptions.cpp @@ -10,25 +10,25 @@ namespace Light { FailedAssertion::FailedAssertion(const char *file, int line) { - lt_log(critical, "Assertion failed in: {} (line {})", file, line); + log_crt("Assertion failed in: {} (line {})", file, line); } glException::glException(unsigned int source, unsigned int type, unsigned int id, const char *msg) { // #todo: improve - lt_log(critical, "________________________________________"); - lt_log(critical, "glException::glException::"); - // lt_log(critical, " Severity: {}", + log_crt("________________________________________"); + log_crt("glException::glException::"); + // log_crt(" Severity: {}", // Stringifier::glDebugMsgSeverity(GL_DEBUG_SEVERITY_HIGH)); - lt_log(critical, " Source : {}", Stringifier::glDebugMsgSource(source)); - lt_log(critical, " Type : {}", Stringifier::glDebugMsgType(type)); - lt_log(critical, " ID : {}", id); - // lt_log(critical, " Vendor : {}", glGetString(GL_VENDOR)); - // lt_log(critical, " renderer: {}", glGetString(GL_RENDERER)); - // lt_log(critical, " Version : {}", glGetString(GL_VERSION)); - // lt_log(critical, " critical, SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION)); - lt_log(critical, " {}", msg); - lt_log(critical, "________________________________________"); + log_crt(" Source : {}", Stringifier::glDebugMsgSource(source)); + log_crt(" Type : {}", Stringifier::glDebugMsgType(type)); + log_crt(" ID : {}", id); + // log_crt(" Vendor : {}", glGetString(GL_VENDOR)); + // log_crt(" renderer: {}", glGetString(GL_RENDERER)); + // log_crt(" Version : {}", glGetString(GL_VERSION)); + // log_crt(" critical, SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION)); + log_crt(" {}", msg); + log_crt("________________________________________"); } #ifdef LIGHT_PLATFORM_WINDOWS @@ -46,11 +46,11 @@ dxException::dxException(long hr, const char *file, int line) ); // #todo: improve - lt_log(critical, "________________________________________"); - lt_log(critical, "dxException::dxException::"); - lt_log(critical, " File: {}, Line: {}", file, line); - lt_log(critical, " {}", message); - lt_log(critical, "________________________________________"); + log_crt("________________________________________"); + log_crt("dxException::dxException::"); + log_crt(" File: {}, Line: {}", file, line); + log_crt(" {}", message); + log_crt("________________________________________"); LocalFree(message); } diff --git a/modules/engine/src/debug/instrumentor.cpp b/modules/engine/src/debug/instrumentor.cpp index eae2baf..10bbeca 100644 --- a/modules/engine/src/debug/instrumentor.cpp +++ b/modules/engine/src/debug/instrumentor.cpp @@ -30,7 +30,7 @@ void Instrumentor::begin_session_impl(const std::string &outputPath) void Instrumentor::end_session_impl() { if (m_current_session_count == 0u) - lt_log(warn, "0 profiling for the ended session"); + log_wrn("0 profiling for the ended session"); m_current_session_count = 0u; diff --git a/modules/engine/src/debug/logger.cpp b/modules/engine/src/debug/logger.cpp index dfb86bd..a37ff5f 100644 --- a/modules/engine/src/debug/logger.cpp +++ b/modules/engine/src/debug/logger.cpp @@ -1,54 +1,21 @@ #include #include #include +#include -namespace Light { - -logger *logger::s_context = nullptr; - -auto logger::create() -> Scope +Logger::Logger(): spd_logger(spdlog::stdout_color_mt("Logger")) { - return make_scope(new logger()); + spd_logger->set_pattern("%^%v%$"); + spd_logger->set_level(spdlog::level::level_enum::trace); } -logger::logger() - : m_engine_logger(nullptr) - , m_file_logger(nullptr) - , m_log_file_path(LT_LOG_FILE_LOCATION) +Logger::~Logger() { - lt_assert(!s_context, "An instance of 'logger' already exists, do not construct this class!"); - s_context = this; - - // set spdlog pattern - // create loggers - spdlog::set_pattern("%^[%H:%M:%S]%g@%! ==> %v%$"); -#ifndef LIGHT_DIST - spdlog::set_pattern("%^[%H:%M:%S]%! ==> %v%$"); - m_engine_logger = spdlog::stdout_color_mt("Engine"); -#endif - - m_file_logger = spdlog::basic_logger_mt("File", m_log_file_path); - m_file_logger->set_pattern("%^[%M:%S:%e] <%l>: %v%$"); - - // set level -#if defined(LIGHT_DEBUG) - m_engine_logger->set_level(spdlog::level::trace); - m_client_logger->set_level(spdlog::level::trace); -#elif defined(LIGHT_RELEASE) - s_EngineLogger->set_level(spdlog::level::info); - s_ClientLogger->set_level(spdlog::level::info); -#endif + spdlog::drop_all(); } -void logger::log_debug_data() +auto Logger::instance() -> Logger & { - // #todo: improve - lt_log(info, "________________________________________"); - lt_log(info, "logger::"); - lt_log(info, " EngineLevel : {}", Stringifier::spdlogLevel(m_engine_logger->level())); - lt_log(info, " FileLevel : {}", Stringifier::spdlogLevel(m_file_logger->level())); - lt_log(info, " DefaultLevel: {}", Stringifier::spdlogLevel(spdlog::get_level())); - lt_log(info, "________________________________________"); + static auto logger = Logger {}; + return logger; } - -} // namespace Light diff --git a/modules/engine/src/graphics/framebuffer.cpp b/modules/engine/src/graphics/framebuffer.cpp index 11b9fee..c7e9a23 100644 --- a/modules/engine/src/graphics/framebuffer.cpp +++ b/modules/engine/src/graphics/framebuffer.cpp @@ -23,14 +23,15 @@ auto Framebuffer::create( lt_win(return create_ref( specification, std::static_pointer_cast(sharedContext) - );) + );); + + default: + lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); - default - : lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); return nullptr; } } diff --git a/modules/engine/src/graphics/renderer.cpp b/modules/engine/src/graphics/renderer.cpp index ddb752c..a27bbb6 100644 --- a/modules/engine/src/graphics/renderer.cpp +++ b/modules/engine/src/graphics/renderer.cpp @@ -120,7 +120,7 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint) // advance if (!m_quad_renderer.advance()) { - lt_log(warn, "Exceeded LT_MAX_QUAD_RENDERER_VERTICES: {}", LT_MAX_QUAD_RENDERER_VERTICES); + log_wrn("Exceeded LT_MAX_QUAD_RENDERER_VERTICES: {}", LT_MAX_QUAD_RENDERER_VERTICES); flush_scene(); } } @@ -155,11 +155,7 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, Ref texture) // advance if (!m_texture_renderer.advance()) { - lt_log( - warn, - "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", - LT_MAX_TEXTURE_RENDERER_VERTICES - ); + log_wrn("Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES); flush_scene(); } } @@ -201,11 +197,7 @@ void Renderer::draw_quad_impl( // advance if (!m_tinted_texture_renderer.advance()) { - lt_log( - warn, - "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", - LT_MAX_TEXTURE_RENDERER_VERTICES - ); + log_wrn("Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES); flush_scene(); } } diff --git a/modules/engine/src/graphics/renderer_programs/quad.cpp b/modules/engine/src/graphics/renderer_programs/quad.cpp index 41c0cb2..b82164a 100644 --- a/modules/engine/src/graphics/renderer_programs/quad.cpp +++ b/modules/engine/src/graphics/renderer_programs/quad.cpp @@ -44,7 +44,7 @@ auto QuadRendererProgram::advance() -> bool if (m_map_current >= m_map_end) { - lt_log(warn, "'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); + log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); return false; } diff --git a/modules/engine/src/graphics/renderer_programs/texture.cpp b/modules/engine/src/graphics/renderer_programs/texture.cpp index f52d28a..32560c2 100644 --- a/modules/engine/src/graphics/renderer_programs/texture.cpp +++ b/modules/engine/src/graphics/renderer_programs/texture.cpp @@ -45,7 +45,7 @@ auto TextureRendererProgram::advance() -> bool { if (m_map_current + 4 >= m_map_end) { - lt_log(warn, "'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); + log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); return false; } diff --git a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp b/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp index b9e20ba..5f55d65 100644 --- a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp +++ b/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp @@ -49,7 +49,7 @@ auto TintedTextureRendererProgram::advance() -> bool if (m_map_current >= m_map_end) { - lt_log(warn, "'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); + log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); return false; } diff --git a/modules/engine/src/graphics/shader.cpp b/modules/engine/src/graphics/shader.cpp index d5e8797..e0c32f3 100644 --- a/modules/engine/src/graphics/shader.cpp +++ b/modules/engine/src/graphics/shader.cpp @@ -26,14 +26,14 @@ auto Shader::create( vertexFile, pixelFile, std::static_pointer_cast(sharedContext) - );) + );); - default - : lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default: + lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } diff --git a/modules/engine/src/layer/layer_stack.cpp b/modules/engine/src/layer/layer_stack.cpp index 9d85b47..a5e32f8 100644 --- a/modules/engine/src/layer/layer_stack.cpp +++ b/modules/engine/src/layer/layer_stack.cpp @@ -36,7 +36,7 @@ void LayerStack::attach_layer_impl(Layer *layer) m_begin = m_layers.begin(); m_end = m_layers.end(); - lt_log(trace, "Attached [{}]", layer->get_name()); + log_trc("Attached [{}]", layer->get_name()); } void LayerStack::detach_layer_impl(Layer *layer) @@ -46,7 +46,7 @@ void LayerStack::detach_layer_impl(Layer *layer) m_begin = m_layers.begin(); m_end = m_layers.end(); - lt_log(trace, "Detached [{}]", layer->get_name()); + log_trc("Detached [{}]", layer->get_name()); } } // namespace Light diff --git a/modules/engine/src/platform/graphics/directx/buffers.cpp b/modules/engine/src/platform/graphics/directx/buffers.cpp index f216b35..745692c 100644 --- a/modules/engine/src/platform/graphics/directx/buffers.cpp +++ b/modules/engine/src/platform/graphics/directx/buffers.cpp @@ -118,7 +118,7 @@ dxIndexBuffer::dxIndexBuffer( // check if (count % 6 != 0) { - lt_log(warn, "'indices' can only be null if count is multiple of 6"); + log_wrn("'indices' can only be null if count is multiple of 6"); lt_log( warn, "Adding {} to 'count' -> {}", diff --git a/modules/engine/src/platform/graphics/directx/framebuffers.cpp b/modules/engine/src/platform/graphics/directx/framebuffers.cpp index 9f48e86..4b1e956 100644 --- a/modules/engine/src/platform/graphics/directx/framebuffers.cpp +++ b/modules/engine/src/platform/graphics/directx/framebuffers.cpp @@ -78,7 +78,7 @@ void dxFramebuffer::bind_as_target(const glm::vec4 &clearColor) void dxFramebuffer::bind_as_resource() { - lt_log(err, "NO_IMPLEMENT"); + log_err("NO_IMPLEMENT"); } void dxFramebuffer::resize(const glm::uvec2 &size) diff --git a/modules/engine/src/platform/graphics/directx/graphics_context.cpp b/modules/engine/src/platform/graphics/directx/graphics_context.cpp index 188419f..763ae90 100644 --- a/modules/engine/src/platform/graphics/directx/graphics_context.cpp +++ b/modules/engine/src/platform/graphics/directx/graphics_context.cpp @@ -156,10 +156,10 @@ void dxGraphicsContext::log_debug_data() DXGIAdapter->release(); // #todo: log more information - lt_log(info, "________________________________________"); - lt_log(info, "dxGraphicsContext:"); - lt_log(info, " renderer: {}", adapterDesc); - lt_log(info, "________________________________________"); + log_inf("________________________________________"); + log_inf("dxGraphicsContext:"); + log_inf(" renderer: {}", adapterDesc); + log_inf("________________________________________"); } } // namespace Light diff --git a/modules/engine/src/platform/graphics/directx/render_command.cpp b/modules/engine/src/platform/graphics/directx/render_command.cpp index 2ffa545..eb89cad 100644 --- a/modules/engine/src/platform/graphics/directx/render_command.cpp +++ b/modules/engine/src/platform/graphics/directx/render_command.cpp @@ -15,8 +15,8 @@ void dxRenderCommand::swap_buffers() { if (hr == DXGI_ERROR_DEVICE_REMOVED) { - lt_log(critical, "dxRenderCommand::swap_buffers: DeviceRemoved:"); - lt_log(critical, " {}", m_context->get_device()->GetDeviceRemovedReason()); + log_crt("dxRenderCommand::swap_buffers: DeviceRemoved:"); + log_crt(" {}", m_context->get_device()->GetDeviceRemovedReason()); throw dxException(hr, __FILE__, __LINE__); } } diff --git a/modules/engine/src/platform/graphics/directx/user_interface.cpp b/modules/engine/src/platform/graphics/directx/user_interface.cpp index bd030e8..7afd057 100644 --- a/modules/engine/src/platform/graphics/directx/user_interface.cpp +++ b/modules/engine/src/platform/graphics/directx/user_interface.cpp @@ -55,12 +55,12 @@ void dxUserInterface::end() void dxUserInterface::log_debug_data() { // #todo: improve - lt_log(info, "________________________________________"); - lt_log(info, "UserInterface::"); - lt_log(info, " API : ImGui"); - lt_log(info, " Version: {}", ImGui::GetVersion()); - lt_log(info, " GraphicsAPI : DirectX"); - lt_log(info, "________________________________________"); + log_inf("________________________________________"); + log_inf("UserInterface::"); + log_inf(" API : ImGui"); + log_inf(" Version: {}", ImGui::GetVersion()); + log_inf(" GraphicsAPI : DirectX"); + log_inf("________________________________________"); } } // namespace Light diff --git a/modules/engine/src/platform/graphics/opengl/buffers.cpp b/modules/engine/src/platform/graphics/opengl/buffers.cpp index 894e739..933a6ef 100644 --- a/modules/engine/src/platform/graphics/opengl/buffers.cpp +++ b/modules/engine/src/platform/graphics/opengl/buffers.cpp @@ -80,13 +80,8 @@ glIndexBuffer::glIndexBuffer(unsigned int *indices, unsigned int count): m_buffe // check if (count % 6 != 0) { - lt_log(warn, "'indices' can only be null if count is multiple of 6"); - lt_log( - warn, - "Adding {} to 'count' -> {}", - (6 - (count % 6)), - count + (6 - (count % 6)) - ); + log_wrn("'indices' can only be null if count is multiple of 6"); + log_wrn("Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6))); count = count + (6 - (count % 6)); } diff --git a/modules/engine/src/platform/graphics/opengl/framebuffers.cpp b/modules/engine/src/platform/graphics/opengl/framebuffers.cpp index 3b62719..4440b38 100644 --- a/modules/engine/src/platform/graphics/opengl/framebuffers.cpp +++ b/modules/engine/src/platform/graphics/opengl/framebuffers.cpp @@ -32,7 +32,7 @@ void glFramebuffer::bind_as_target(const glm::vec4 &clearColor) void glFramebuffer::bind_as_resource() { - lt_log(err, "NO_IMPLEMENT!"); + log_err("NO_IMPLEMENT!"); } void glFramebuffer::resize(const glm::uvec2 &size) diff --git a/modules/engine/src/platform/graphics/opengl/graphics_context.cpp b/modules/engine/src/platform/graphics/opengl/graphics_context.cpp index 6094996..1d90a98 100644 --- a/modules/engine/src/platform/graphics/opengl/graphics_context.cpp +++ b/modules/engine/src/platform/graphics/opengl/graphics_context.cpp @@ -16,13 +16,8 @@ namespace Light { glGraphicsContext::glGraphicsContext(GLFWwindow *windowHandle): m_window_handle(windowHandle) { - // set 'GraphicsAPI' m_graphics_api = GraphicsAPI::OpenGL; - - // make context current glfwMakeContextCurrent(windowHandle); - - // load opengl (glad) lt_assert(gladLoadGL(glfwGetProcAddress), "Failed to initialize opengl (glad)"); set_debug_message_callback(); @@ -30,13 +25,10 @@ glGraphicsContext::glGraphicsContext(GLFWwindow *windowHandle): m_window_handle( void glGraphicsContext::log_debug_data() { - // #todo: log more information - lt_log(info, "________________________________________"); - lt_log(info, "GraphicsContext::"); - lt_log(info, " API : OpenGL"); - // lt_log(info, " Version : {}", glGetString(GL_VERSION)); - // lt_log(info, " renderer: {}", glGetString(GL_RENDERER)); - lt_log(info, "________________________________________"); + log_inf("________________________________________"); + log_inf("GraphicsContext::"); + log_inf(" API : OpenGL"); + log_inf("________________________________________"); } void glGraphicsContext::set_debug_message_callback() @@ -89,23 +81,25 @@ void glGraphicsContext::set_debug_message_callback() case GL_DEBUG_SEVERITY_MEDIUM: case GL_DEBUG_SEVERITY_LOW: - lt_log(warn, + log_wrn( "glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}", Stringifier::glDebugMsgSeverity(severity), Stringifier::glDebugMsgSource(source), Stringifier::glDebugMsgType(type), - id); - lt_log(warn, " {}", message); + id + ); + log_wrn(" {}", message); return; case GL_DEBUG_SEVERITY_NOTIFICATION: - lt_log(trace, + log_wrn( "Severity: {} :: Source: {} :: Type: {} :: ID: {}", Stringifier::glDebugMsgSeverity(severity), Stringifier::glDebugMsgSource(source), Stringifier::glDebugMsgType(type), - id); - lt_log(trace, " {}", message); + id + ); + log_trc(" {}", message); return; } }, diff --git a/modules/engine/src/platform/graphics/opengl/shader.cpp b/modules/engine/src/platform/graphics/opengl/shader.cpp index 7735601..5778c61 100644 --- a/modules/engine/src/platform/graphics/opengl/shader.cpp +++ b/modules/engine/src/platform/graphics/opengl/shader.cpp @@ -61,8 +61,8 @@ void glShader::un_bind() // // log error // if (result.GetCompilationStatus() != shaderc_compilation_status_success) // { -// lt_log(err, "Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ? -// "vertex" : "pixel", file.GetPath()); lt_log(err, " {}", result.GetErrorMessage()); +// log_err("Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ? +// "vertex" : "pixel", file.GetPath()); log_err(" {}", result.GetErrorMessage()); // } // // return result; @@ -94,8 +94,7 @@ auto glShader::compile_shader(std::string source, Shader::Stage stage) -> unsign auto *errorLog = (char *)alloca(logLength); glGetShaderInfoLog(shader, logLength, &logLength, &errorLog[0]); - lt_log( - err, + log_err( "glShader::glShader: failed to compile {} shader:\n {}", stage == Shader::Stage::VERTEX ? "Vertex" : "Pixel", errorLog @@ -114,7 +113,7 @@ auto glShader::compile_shader(std::string source, Shader::Stage stage) -> unsign char *infoLog = (char *)alloca(logLength); glGetShaderInfoLog(shader, logLength, &logLength, &infoLog[0]); - lt_log(warn, infoLog); + log_wrn("Shader info: {}", infoLog); } } #endif diff --git a/modules/engine/src/platform/graphics/opengl/user_interface.cpp b/modules/engine/src/platform/graphics/opengl/user_interface.cpp index 243baaa..4d4ddab 100644 --- a/modules/engine/src/platform/graphics/opengl/user_interface.cpp +++ b/modules/engine/src/platform/graphics/opengl/user_interface.cpp @@ -51,12 +51,12 @@ void glUserInterface::end() void glUserInterface::log_debug_data() { // #todo: improve - lt_log(info, "________________________________________"); - lt_log(info, "UserInterface::"); - lt_log(info, " API : ImGui"); - lt_log(info, " Version: {}", ImGui::GetVersion()); - lt_log(info, " GraphicsAPI : OpenGL"); - lt_log(info, "________________________________________"); + log_inf("________________________________________"); + log_inf("UserInterface::"); + log_inf(" API : ImGui"); + log_inf(" Version: {}", ImGui::GetVersion()); + log_inf(" GraphicsAPI : OpenGL"); + log_inf("________________________________________"); } } // namespace Light diff --git a/modules/engine/src/scene/scene.cpp b/modules/engine/src/scene/scene.cpp index 3a8a596..7e44951 100644 --- a/modules/engine/src/scene/scene.cpp +++ b/modules/engine/src/scene/scene.cpp @@ -93,12 +93,12 @@ auto Scene::get_entity_by_tag(const std::string &tag) -> Entity }); if (entity.is_valid()) - return entity; - else { - lt_assert("Scene::get_entity_by_tag: failed to find entity by tag: {}", tag); - return {}; + return entity; } + + lt_assert(false, "Scene::get_entity_by_tag: failed to find entity by tag: {}", tag); + return {}; } auto Scene::create_entity_with_uuid( diff --git a/modules/engine/src/utils/file_manager.cpp b/modules/engine/src/utils/file_manager.cpp index 5917be9..94612a8 100644 --- a/modules/engine/src/utils/file_manager.cpp +++ b/modules/engine/src/utils/file_manager.cpp @@ -39,9 +39,9 @@ auto FileManager::read_text_file(const std::string &path) -> BasicFileHandle // check if (!file) { - lt_log(warn, "Failed to load text file: {}", path); + log_wrn("Failed to load text file: {}", path); file.close(); - return NULL; + return nullptr; } // fetch file size @@ -50,7 +50,9 @@ auto FileManager::read_text_file(const std::string &path) -> BasicFileHandle file.seekg(0, std::ios::beg); if (!size) - lt_log(warn, "Empty text file: {}", path); + { + log_wrn("Empty text file: {}", path); + } // read file auto *data = new uint8_t[size]; @@ -75,15 +77,18 @@ auto FileManager::read_image_file(const std::string &path, int32_t desiredCompon // check if (!pixels) - lt_log(warn, "Failed to load image file: <{}>", path); + { + log_wrn("Failed to load image file: <{}>", path); + } else if (fetchedComponents != desiredComponents) - lt_log( - warn, + { + log_wrn( "Mismatch of fetched/desired components: <{}> ({}/{})", name + '.' + extension, fetchedComponents, desiredComponents ); + } return ImageFileHandle( pixels, diff --git a/modules/engine/src/utils/resource_manager.cpp b/modules/engine/src/utils/resource_manager.cpp index b9f1ba7..03cd106 100644 --- a/modules/engine/src/utils/resource_manager.cpp +++ b/modules/engine/src/utils/resource_manager.cpp @@ -77,7 +77,7 @@ void ResourceManager::release_texture_impl(const std::string &name) { if (!m_textures[name]) { - lt_log(warn, "Failed to find texture named: {}", name); + log_wrn("Failed to find texture named: {}", name); return; } diff --git a/modules/engine/src/utils/serializer.cpp b/modules/engine/src/utils/serializer.cpp index b921688..f47f2ea 100644 --- a/modules/engine/src/utils/serializer.cpp +++ b/modules/engine/src/utils/serializer.cpp @@ -87,7 +87,9 @@ void SceneSerializer::serialize(const std::string &filePath) { auto entity = Entity { static_cast(entityID), m_scene.get() }; if (!entity.is_valid()) + { return; + } serialize_entity(out, entity); }; @@ -98,30 +100,32 @@ void SceneSerializer::serialize(const std::string &filePath) auto fout = std::ofstream { filePath }; if (!fout.is_open()) - lt_log(trace, "Failed to create fout at: {}", filePath); + { + log_trc("Failed to create fout at: {}", filePath); + } fout << out.c_str(); } -auto SceneSerializer::deserialize(const std::string &filePath) -> bool +auto SceneSerializer::deserialize(const std::string &file_path) -> bool { - auto stream = std::ifstream { filePath }; + auto stream = std::ifstream { file_path }; auto ss = std::stringstream {}; ss << stream.rdbuf(); auto data = YAML::Load(ss.str()); if (!data["Scene"]) + { return false; + } auto sceneName = data["Scene"].as(); - lt_log(trace, "Deserializing scene: '{}'", sceneName); + log_trc("Deserializing scene: '{}'", sceneName); auto entities = data["Entities"]; if (entities) { - /* #TEMPORARY SOLUTION# */ auto texturePaths = std::unordered_set {}; - /* #TEMPORARY SOLUTION# */ for (auto entity : entities) { @@ -130,14 +134,16 @@ auto SceneSerializer::deserialize(const std::string &filePath) -> bool auto name = std::string {}; auto tagComponent = entity["TagComponent"]; if (tagComponent) + { name = tagComponent["Tag"].as(); + } - lt_log(trace, "Deserialized entity '{}' : '{}'", uuid, name); + log_trc("Deserialized entity '{}' : '{}'", uuid, name); auto deserializedEntity = m_scene->create_entity_with_uuid(name, uuid); auto gg = deserializedEntity.get_component(); - lt_log(trace, gg.tag); + log_trc("tag: {}", gg.tag); auto transformComponent = entity["TransformComponent"]; if (transformComponent) { @@ -217,12 +223,12 @@ auto SceneSerializer::deserialize(const std::string &filePath) -> bool void SceneSerializer::serialize_binary(const std::string &filePath) { - lt_log(err, "NO_IMPLEMENT"); + log_err("NO_IMPLEMENT"); } auto SceneSerializer::deserialize_binary(const std::string &filePath) -> bool { - lt_log(err, "NO_IMPLEMENT"); + log_err("NO_IMPLEMENT"); return false; } diff --git a/modules/mirror/src/panel/asset_browser.cpp b/modules/mirror/src/panel/asset_browser.cpp index 4604f8b..c7175d5 100644 --- a/modules/mirror/src/panel/asset_browser.cpp +++ b/modules/mirror/src/panel/asset_browser.cpp @@ -113,7 +113,7 @@ void AssetBrowserPanel::on_user_interface_update() )) { auto serializer = SceneSerializer { m_active_scene }; - lt_log(info, "Attempting to deserialize: {}", path.string()); + log_inf("Attempting to deserialize: {}", path.string()); serializer.deserialize(path.string()); } break;