diff --git a/examples/dev_testing/src/main.cpp b/examples/dev_testing/src/main.cpp index ac8a39c..fcef86b 100644 --- a/examples/dev_testing/src/main.cpp +++ b/examples/dev_testing/src/main.cpp @@ -64,9 +64,7 @@ public: // Check if the last print was 1 second ago. if (current_time - last_frame_time_tps >= 1.0) { - double ms_per_frame = 1000 / (double)frame_count_tps; - - printf("Fixed update: %d tps, %f ms/frame\n", frame_count_tps, ms_per_frame); + SE_DEBUG("performance", "Fixed update: {}tps", frame_count_tps); frame_count_tps = 0; last_frame_time_tps += 1.0; } @@ -78,11 +76,10 @@ public: // Check if the last print was 1 second ago. if (current_time - last_frame_time_input >= 1.0) { - double ms_per_frame = 1000 / (double)frame_count_input; - - printf("Input: %d tps, %f ms/frame\n", frame_count_input, ms_per_frame); + SE_DEBUG("performance", "Input: {}tps", frame_count_input); frame_count_input = 0; last_frame_time_input += 1.0; + } } @@ -94,7 +91,8 @@ public: if (current_time - last_frame_time_render >= 1.0) { double ms_per_frame = 1000 / (double)frame_count_render; - printf("Render: %d fps, %f ms/frame\n\n", frame_count_render, ms_per_frame); + SE_DEBUG("performance", "Render: {}fps, {}ms/frame", frame_count_render, ms_per_frame); + SE_DEBUG("performance", "-------------------------------"); frame_count_render = 0; last_frame_time_render += 1.0; } @@ -145,6 +143,7 @@ int main(int argc, char *argv[]) { auto light = std::make_shared(core_shader, glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f)); game.add_event(light); + // TODO: Fix, for some reason it crashes auto fps_counter = std::make_shared(); game.add_renderable(fps_counter); diff --git a/include/simpleengine/log/logger.h b/include/simpleengine/log/logger.h index bad1bf7..ff55f00 100644 --- a/include/simpleengine/log/logger.h +++ b/include/simpleengine/log/logger.h @@ -17,7 +17,7 @@ namespace simpleengine::log { /** * @brief Construct a new Logger object from a name * - * This will first check if the logger exists, if it does not it will create a new `color_mt` logger + * This will first check if the spdlog logger exists, if it does not it will create a new `color_mt` logger * * @param name The name of the logger. */ @@ -63,7 +63,7 @@ namespace simpleengine::log { * @param msg The message to log */ void log(spdlog::level::level_enum lvl, spdlog::string_view_t msg) { - inner->log(spdlog::source_loc{}, lvl, msg); + inner->log(lvl, msg); } /** @@ -77,7 +77,7 @@ namespace simpleengine::log { template void log(spdlog::level::level_enum lvl, fmt::format_string fmt, Args &&...args) { - inner->log(spdlog::source_loc{}, lvl, fmt, std::forward(args)...); + inner->log(lvl, fmt, std::forward(args)...); } /** @@ -219,11 +219,9 @@ namespace simpleengine::log { } }; - using LoggerPtr = std::shared_ptr; - class LoggerManager { private: - static std::shared_ptr core_logger; + static Logger core_logger; public: /** * @brief Initialize the logger. @@ -241,9 +239,9 @@ namespace simpleengine::log { /** * @brief Get the core logger. * - * @return std::shared_ptr + * @return Logger& */ - static std::shared_ptr get_core_logger(); + static Logger& get_core_logger(); /** * @brief Create a new logger. @@ -282,7 +280,7 @@ namespace simpleengine::log { * @param message The (to be) formatted message to log. * @param ... The variables that will be formatted in the text. */ -#define SE_CLOG(level, message, ...) simpleengine::log::LoggerManager::get_core_logger()->log(level, fmt::format(message, ##__VA_ARGS__)); +#define SE_CLOG(level, message, ...) simpleengine::log::LoggerManager::get_core_logger().log(level, fmt::format(message, ##__VA_ARGS__)); /** * @brief Log a critical message to a logger. diff --git a/src/log/logger.cpp b/src/log/logger.cpp index fd61f0f..80d5253 100644 --- a/src/log/logger.cpp +++ b/src/log/logger.cpp @@ -3,14 +3,12 @@ #include namespace simpleengine::log { - std::shared_ptr LoggerManager::core_logger; + Logger LoggerManager::core_logger = Logger("engine"); void LoggerManager::init() { spdlog::set_pattern("[%T %D] [thread %t] [%n] [%l] %v"); - core_logger = std::make_shared("engine"); - - spdlog::set_default_logger(core_logger->get_inner()); + spdlog::set_default_logger(core_logger.get_inner()); set_level(spdlog::level::info); } @@ -18,7 +16,7 @@ namespace simpleengine::log { spdlog::set_level(lvl); } - std::shared_ptr LoggerManager::get_core_logger() { + Logger& LoggerManager::get_core_logger() { return core_logger; } @@ -27,6 +25,6 @@ namespace simpleengine::log { } Logger LoggerManager::get_logger(std::string name) { - return Logger(spdlog::get(name)); + return Logger(name); } } \ No newline at end of file diff --git a/src/scene.cpp b/src/scene.cpp index 732e185..e53d8ae 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -8,6 +8,7 @@ #include "log/logger.h" #include +#include #include namespace simpleengine {