Fix returning null loggers
This commit is contained in:
parent
dd55b40e60
commit
118fce50fa
|
@ -64,9 +64,7 @@ public:
|
||||||
|
|
||||||
// Check if the last print was 1 second ago.
|
// Check if the last print was 1 second ago.
|
||||||
if (current_time - last_frame_time_tps >= 1.0) {
|
if (current_time - last_frame_time_tps >= 1.0) {
|
||||||
double ms_per_frame = 1000 / (double)frame_count_tps;
|
SE_DEBUG("performance", "Fixed update: {}tps", frame_count_tps);
|
||||||
|
|
||||||
printf("Fixed update: %d tps, %f ms/frame\n", frame_count_tps, ms_per_frame);
|
|
||||||
frame_count_tps = 0;
|
frame_count_tps = 0;
|
||||||
last_frame_time_tps += 1.0;
|
last_frame_time_tps += 1.0;
|
||||||
}
|
}
|
||||||
|
@ -78,11 +76,10 @@ public:
|
||||||
|
|
||||||
// Check if the last print was 1 second ago.
|
// Check if the last print was 1 second ago.
|
||||||
if (current_time - last_frame_time_input >= 1.0) {
|
if (current_time - last_frame_time_input >= 1.0) {
|
||||||
double ms_per_frame = 1000 / (double)frame_count_input;
|
SE_DEBUG("performance", "Input: {}tps", frame_count_input);
|
||||||
|
|
||||||
printf("Input: %d tps, %f ms/frame\n", frame_count_input, ms_per_frame);
|
|
||||||
frame_count_input = 0;
|
frame_count_input = 0;
|
||||||
last_frame_time_input += 1.0;
|
last_frame_time_input += 1.0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +91,8 @@ public:
|
||||||
if (current_time - last_frame_time_render >= 1.0) {
|
if (current_time - last_frame_time_render >= 1.0) {
|
||||||
double ms_per_frame = 1000 / (double)frame_count_render;
|
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;
|
frame_count_render = 0;
|
||||||
last_frame_time_render += 1.0;
|
last_frame_time_render += 1.0;
|
||||||
}
|
}
|
||||||
|
@ -145,6 +143,7 @@ int main(int argc, char *argv[]) {
|
||||||
auto light = std::make_shared<se::gfx::Light>(core_shader, glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f));
|
auto light = std::make_shared<se::gfx::Light>(core_shader, glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f));
|
||||||
game.add_event(light);
|
game.add_event(light);
|
||||||
|
|
||||||
|
// TODO: Fix, for some reason it crashes
|
||||||
auto fps_counter = std::make_shared<FPSCounterEvent>();
|
auto fps_counter = std::make_shared<FPSCounterEvent>();
|
||||||
game.add_renderable(fps_counter);
|
game.add_renderable(fps_counter);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace simpleengine::log {
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Logger object from a name
|
* @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.
|
* @param name The name of the logger.
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +63,7 @@ namespace simpleengine::log {
|
||||||
* @param msg The message to log
|
* @param msg The message to log
|
||||||
*/
|
*/
|
||||||
void log(spdlog::level::level_enum lvl, spdlog::string_view_t msg) {
|
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<typename... Args>
|
template<typename... Args>
|
||||||
void log(spdlog::level::level_enum lvl, fmt::format_string<Args...> fmt, Args &&...args)
|
void log(spdlog::level::level_enum lvl, fmt::format_string<Args...> fmt, Args &&...args)
|
||||||
{
|
{
|
||||||
inner->log(spdlog::source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
inner->log(lvl, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -219,11 +219,9 @@ namespace simpleengine::log {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using LoggerPtr = std::shared_ptr<Logger>;
|
|
||||||
|
|
||||||
class LoggerManager {
|
class LoggerManager {
|
||||||
private:
|
private:
|
||||||
static std::shared_ptr<Logger> core_logger;
|
static Logger core_logger;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the logger.
|
* @brief Initialize the logger.
|
||||||
|
@ -241,9 +239,9 @@ namespace simpleengine::log {
|
||||||
/**
|
/**
|
||||||
* @brief Get the core logger.
|
* @brief Get the core logger.
|
||||||
*
|
*
|
||||||
* @return std::shared_ptr<Logger>
|
* @return Logger&
|
||||||
*/
|
*/
|
||||||
static std::shared_ptr<Logger> get_core_logger();
|
static Logger& get_core_logger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new logger.
|
* @brief Create a new logger.
|
||||||
|
@ -282,7 +280,7 @@ namespace simpleengine::log {
|
||||||
* @param message The (to be) formatted message to log.
|
* @param message The (to be) formatted message to log.
|
||||||
* @param ... The variables that will be formatted in the text.
|
* @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.
|
* @brief Log a critical message to a logger.
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace simpleengine::log {
|
namespace simpleengine::log {
|
||||||
std::shared_ptr<Logger> LoggerManager::core_logger;
|
Logger LoggerManager::core_logger = Logger("engine");
|
||||||
|
|
||||||
void LoggerManager::init() {
|
void LoggerManager::init() {
|
||||||
spdlog::set_pattern("[%T %D] [thread %t] [%n] [%l] %v");
|
spdlog::set_pattern("[%T %D] [thread %t] [%n] [%l] %v");
|
||||||
|
|
||||||
core_logger = std::make_shared<Logger>("engine");
|
spdlog::set_default_logger(core_logger.get_inner());
|
||||||
|
|
||||||
spdlog::set_default_logger(core_logger->get_inner());
|
|
||||||
set_level(spdlog::level::info);
|
set_level(spdlog::level::info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +16,7 @@ namespace simpleengine::log {
|
||||||
spdlog::set_level(lvl);
|
spdlog::set_level(lvl);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Logger> LoggerManager::get_core_logger() {
|
Logger& LoggerManager::get_core_logger() {
|
||||||
return core_logger;
|
return core_logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +25,6 @@ namespace simpleengine::log {
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger LoggerManager::get_logger(std::string name) {
|
Logger LoggerManager::get_logger(std::string name) {
|
||||||
return Logger(spdlog::get(name));
|
return Logger(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
#include "log/logger.h"
|
#include "log/logger.h"
|
||||||
|
|
||||||
#include <glm/gtx/string_cast.hpp>
|
#include <glm/gtx/string_cast.hpp>
|
||||||
|
#include <spdlog/common.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace simpleengine {
|
namespace simpleengine {
|
||||||
|
|
Loading…
Reference in New Issue