Merge feature/logging
This commit is contained in:
commit
4d0ac5448b
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type,
|
Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type,
|
||||||
-*-non-private-member-variables-in-classes,-*-magic-numbers"
|
-*-non-private-member-variables-in-classes,-*-magic-numbers,-*-macro-usage"
|
||||||
WarningsAsErrors: true
|
WarningsAsErrors: true
|
||||||
HeaderFilterRegex: ""
|
HeaderFilterRegex: ""
|
||||||
AnalyzeTemporaryDtors: false
|
AnalyzeTemporaryDtors: false
|
||||||
|
|
|
@ -21,8 +21,8 @@ find_package(GLEW REQUIRED)
|
||||||
find_package(glfw3 CONFIG REQUIRED)
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
find_package(glm CONFIG REQUIRED)
|
find_package(glm CONFIG REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
find_package(fmt REQUIRED)
|
find_package(fmt CONFIG REQUIRED)
|
||||||
find_package(spdlog REQUIRED)
|
find_package(spdlog CONFIG REQUIRED)
|
||||||
find_package(assimp CONFIG REQUIRED)
|
find_package(assimp CONFIG REQUIRED)
|
||||||
find_package(Bullet REQUIRED)
|
find_package(Bullet REQUIRED)
|
||||||
|
|
||||||
|
@ -48,15 +48,17 @@ cmrc_add_resource_library(
|
||||||
# Link dependencies
|
# Link dependencies
|
||||||
target_link_libraries(simpleengine PUBLIC GLEW::GLEW)
|
target_link_libraries(simpleengine PUBLIC GLEW::GLEW)
|
||||||
target_link_libraries(simpleengine PUBLIC glfw)
|
target_link_libraries(simpleengine PUBLIC glfw)
|
||||||
target_link_libraries(simpleengine PUBLIC fmt)
|
|
||||||
target_link_libraries(simpleengine PUBLIC spdlog)
|
|
||||||
target_link_libraries(simpleengine PUBLIC ${GLM_LIBRARIES})
|
target_link_libraries(simpleengine PUBLIC ${GLM_LIBRARIES})
|
||||||
target_link_libraries(simpleengine PUBLIC ${OPENGL_LIBRARIES})
|
target_link_libraries(simpleengine PUBLIC ${OPENGL_LIBRARIES})
|
||||||
target_link_libraries(simpleengine PUBLIC ${BULLET_LIBRARIES})
|
target_link_libraries(simpleengine PUBLIC ${BULLET_LIBRARIES})
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(simpleengine PUBLIC assimp::assimp)
|
target_link_libraries(simpleengine PUBLIC assimp::assimp)
|
||||||
|
target_link_libraries(simpleengine PUBLIC fmt::fmt)
|
||||||
|
target_link_libraries(simpleengine PUBLIC spdlog::spdlog)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(simpleengine PUBLIC assimp)
|
target_link_libraries(simpleengine PUBLIC assimp)
|
||||||
|
target_link_libraries(simpleengine PUBLIC fmt)
|
||||||
|
target_link_libraries(simpleengine PUBLIC spdlog)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Link resources
|
# Link resources
|
||||||
|
|
|
@ -74,9 +74,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;
|
||||||
}
|
}
|
||||||
|
@ -88,11 +86,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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +101,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, {:.2f}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;
|
||||||
}
|
}
|
||||||
|
@ -116,8 +114,6 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
se::log::LoggerManager::set_level(spdlog::level::trace);
|
se::log::LoggerManager::set_level(spdlog::level::trace);
|
||||||
|
|
||||||
se::log::LoggerPtr logger = se::log::LoggerManager::get_core_logger();
|
|
||||||
|
|
||||||
// Load core shaders from SimpleEngine resources
|
// Load core shaders from SimpleEngine resources
|
||||||
se::gfx::shaders::Core3dShader core_shader;
|
se::gfx::shaders::Core3dShader core_shader;
|
||||||
|
|
||||||
|
@ -169,6 +165,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);
|
||||||
|
|
||||||
|
@ -176,7 +173,7 @@ int main(int argc, char *argv[]) {
|
||||||
game.set_fps_limit(100); */
|
game.set_fps_limit(100); */
|
||||||
int res = game.run();
|
int res = game.run();
|
||||||
|
|
||||||
std::cout << "Engine result: " << res << std::endl;
|
SE_CINFO("Engine result: {}", res);
|
||||||
|
|
||||||
renderer->destroy();
|
renderer->destroy();
|
||||||
scene->destroy();
|
scene->destroy();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../camera.h"
|
#include "../camera.h"
|
||||||
|
#include "../log/logger.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "../renderable.h"
|
#include "../renderable.h"
|
||||||
#include "rendering_type.h"
|
#include "rendering_type.h"
|
||||||
|
@ -30,7 +31,7 @@ namespace simpleengine::gfx {
|
||||||
bool is_initialized = false;
|
bool is_initialized = false;
|
||||||
|
|
||||||
void check_if_initialized();
|
void check_if_initialized();
|
||||||
|
simpleengine::log::Logger logger;
|
||||||
public:
|
public:
|
||||||
std::queue<RenderingJob> transparent_render_queue;
|
std::queue<RenderingJob> transparent_render_queue;
|
||||||
std::queue<RenderingJob> other_render_queue;
|
std::queue<RenderingJob> other_render_queue;
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace simpleengine::gfx {
|
||||||
}
|
}
|
||||||
|
|
||||||
~VAO() {
|
~VAO() {
|
||||||
std::cout << "~vao(" << handle << ")" << std::endl;
|
// TODO: Anything to do here?
|
||||||
}
|
}
|
||||||
|
|
||||||
VAO& operator=(const VAO& other) {
|
VAO& operator=(const VAO& other) {
|
||||||
|
@ -30,9 +30,6 @@ namespace simpleengine::gfx {
|
||||||
handle = other.handle;
|
handle = other.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Copied " << handle << std::endl;
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace simpleengine::gfx {
|
||||||
}
|
}
|
||||||
|
|
||||||
~VBO() {
|
~VBO() {
|
||||||
std::cout << "~vbo(" << handle << ")" << std::endl;
|
// TODO: Anything to do here?
|
||||||
}
|
}
|
||||||
|
|
||||||
static VBO init(GLint type, bool dynamic) {
|
static VBO init(GLint type, bool dynamic) {
|
||||||
|
|
|
@ -14,6 +14,13 @@ namespace simpleengine::log {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<spdlog::logger> inner;
|
std::shared_ptr<spdlog::logger> inner;
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Logger object from a name
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
Logger(std::string name) {
|
Logger(std::string name) {
|
||||||
inner = spdlog::get(name);
|
inner = spdlog::get(name);
|
||||||
|
|
||||||
|
@ -22,101 +29,357 @@ namespace simpleengine::log {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Logger object using a spdlog::logger
|
||||||
|
*
|
||||||
|
* @param logger The inner spdlog::logger that this object will use
|
||||||
|
*/
|
||||||
Logger(std::shared_ptr<spdlog::logger> logger) : inner(logger) {
|
Logger(std::shared_ptr<spdlog::logger> logger) : inner(logger) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the inner spdlog logger object
|
||||||
|
*
|
||||||
|
* @return std::shared_ptr<spdlog::logger>
|
||||||
|
*/
|
||||||
std::shared_ptr<spdlog::logger> get_inner() {
|
std::shared_ptr<spdlog::logger> get_inner() {
|
||||||
return inner;
|
return inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the log level.
|
||||||
|
*
|
||||||
|
* @param lvl The level to set the log to
|
||||||
|
*/
|
||||||
void set_level(spdlog::level::level_enum lvl) {
|
void set_level(spdlog::level::level_enum lvl) {
|
||||||
inner->set_level(lvl);
|
inner->set_level(lvl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a message.
|
||||||
|
*
|
||||||
|
* @param lvl Level to log at
|
||||||
|
* @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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a formatted message.
|
||||||
|
*
|
||||||
|
* @tparam Args
|
||||||
|
* @param lvl Level to log at
|
||||||
|
* @param fmt The string that will be formatted
|
||||||
|
* @param args The arguments to format into the message.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
void log(spdlog::level::level_enum lvl, fmt::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
inner->log(lvl, fmt, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a trace message.
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @param msg The message that will be logged.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void trace(const T &msg) {
|
void trace(const T &msg) {
|
||||||
log(spdlog::level::trace, msg);
|
log(spdlog::level::trace, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a debug message.
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @param msg The message that will be logged.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void debug(const T &msg) {
|
void debug(const T &msg) {
|
||||||
log(spdlog::level::debug, msg);
|
log(spdlog::level::debug, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an info message.
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @param msg The message that will be logged.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void info(const T &msg) {
|
void info(const T &msg) {
|
||||||
log(spdlog::level::info, msg);
|
log(spdlog::level::info, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a warning message.
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @param msg The message that will be logged.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void warn(const T &msg) {
|
void warn(const T &msg) {
|
||||||
log(spdlog::level::warn, msg);
|
log(spdlog::level::warn, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an error message.
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @param msg The message that will be logged.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void error(const T &msg) {
|
void error(const T &msg) {
|
||||||
log(spdlog::level::err, msg);
|
log(spdlog::level::err, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a critical message.
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @param msg The message that will be logged.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void critical(const T &msg) {
|
void critical(const T &msg) {
|
||||||
log(spdlog::level::critical, msg);
|
log(spdlog::level::critical, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a trace message.
|
||||||
|
*
|
||||||
|
* @tparam Args
|
||||||
|
* @param fmt String that will be formatted
|
||||||
|
* @param args Arguments to format into the message
|
||||||
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void trace(spdlog::format_string_t<Args...> fmt, Args &&... args) {
|
void trace(fmt::format_string<Args...> fmt, Args &&... args) {
|
||||||
log(spdlog::level::trace, fmt, std::forward<Args>(args)...);
|
log(spdlog::level::trace, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a debug message.
|
||||||
|
*
|
||||||
|
* @tparam Args
|
||||||
|
* @param fmt String that will be formatted
|
||||||
|
* @param args Arguments to format into the message
|
||||||
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void debug(spdlog::format_string_t<Args...> fmt, Args &&... args) {
|
void debug(fmt::format_string<Args...> fmt, Args &&... args) {
|
||||||
log(spdlog::level::debug, fmt, std::forward<Args>(args)...);
|
log(spdlog::level::debug, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an info message.
|
||||||
|
*
|
||||||
|
* @tparam Args
|
||||||
|
* @param fmt String that will be formatted
|
||||||
|
* @param args Arguments to format into the message
|
||||||
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void info(spdlog::format_string_t<Args...> fmt, Args &&... args) {
|
void info(fmt::format_string<Args...> fmt, Args &&... args) {
|
||||||
log(spdlog::level::info, fmt, std::forward<Args>(args)...);
|
log(spdlog::level::info, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a warning message.
|
||||||
|
*
|
||||||
|
* @tparam Args
|
||||||
|
* @param fmt String that will be formatted
|
||||||
|
* @param args Arguments to format into the message
|
||||||
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void warn(spdlog::format_string_t<Args...> fmt, Args &&... args) {
|
void warn(fmt::format_string<Args...> fmt, Args &&... args) {
|
||||||
log(spdlog::level::warn, fmt, std::forward<Args>(args)...);
|
log(spdlog::level::warn, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an error message.
|
||||||
|
*
|
||||||
|
* @tparam Args
|
||||||
|
* @param fmt String that will be formatted
|
||||||
|
* @param args Arguments to format into the message
|
||||||
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void error(spdlog::format_string_t<Args...> fmt, Args &&... args) {
|
void error(fmt::format_string<Args...> fmt, Args &&... args) {
|
||||||
log(spdlog::level::err, fmt, std::forward<Args>(args)...);
|
log(spdlog::level::err, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a critical message.
|
||||||
|
*
|
||||||
|
* @tparam Args
|
||||||
|
* @param fmt String that will be formatted
|
||||||
|
* @param args Arguments to format into the message
|
||||||
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void critical(spdlog::format_string_t<Args...> fmt, Args &&... args) {
|
void critical(fmt::format_string<Args...> fmt, Args &&... args) {
|
||||||
log(spdlog::level::critical, fmt, std::forward<Args>(args)...);
|
log(spdlog::level::critical, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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:
|
||||||
/* LoggerManager() {
|
/**
|
||||||
spdlog::set_pattern("[%R - %D] [%l] [thread %t] [%n] %v");
|
* @brief Initialize the logger.
|
||||||
|
*
|
||||||
core_logger = std::make_shared<Logger>("Engine");
|
*/
|
||||||
} */
|
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the core log level.
|
||||||
|
*
|
||||||
|
* @param lvl
|
||||||
|
*/
|
||||||
static void set_level(spdlog::level::level_enum lvl);
|
static void set_level(spdlog::level::level_enum lvl);
|
||||||
|
|
||||||
static std::shared_ptr<Logger> get_core_logger();
|
/**
|
||||||
|
* @brief Get the core logger.
|
||||||
|
*
|
||||||
|
* @return Logger&
|
||||||
|
*/
|
||||||
|
static Logger& get_core_logger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a new logger.
|
||||||
|
*
|
||||||
|
* @param name The name of the logger
|
||||||
|
* @return Logger
|
||||||
|
*/
|
||||||
static Logger create_logger(std::string name);
|
static Logger create_logger(std::string name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get a logger using its name.
|
||||||
|
*
|
||||||
|
* @param name The name of the logger
|
||||||
|
* @return Logger
|
||||||
|
*/
|
||||||
static Logger get_logger(std::string name);
|
static Logger get_logger(std::string name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log macros
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log to a logger.
|
||||||
|
*
|
||||||
|
* @param logger_name The name of the logger to log to.
|
||||||
|
* @param level The level to log at.
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_LOG(logger_name, level, message, ...) simpleengine::log::LoggerManager::get_logger(logger_name).log(level, fmt::format(message, ##__VA_ARGS__));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log to the core logger.
|
||||||
|
*
|
||||||
|
* @param level The level to log at.
|
||||||
|
* @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__));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a critical message to a logger.
|
||||||
|
*
|
||||||
|
* @param logger_name The name of the logger to log to.
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_CRIT(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::critical, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a critical message to the core logger.
|
||||||
|
*
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_CCRIT(message, ...) SE_CLOG(spdlog::level::critical, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an error message to a logger.
|
||||||
|
*
|
||||||
|
* @param logger_name The name of the logger to log to.
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_ERROR(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::err, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an error message to the core logger.
|
||||||
|
*
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_CERROR(message, ...) SE_CLOG(spdlog::level::err, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a warning message to a logger.
|
||||||
|
*
|
||||||
|
* @param logger_name The name of the logger to log to.
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_WARN(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::warn, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a warning message to the core logger.
|
||||||
|
*
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_CWARN(message, ...) SE_CLOG(spdlog::level::warn, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an info message to a logger.
|
||||||
|
*
|
||||||
|
* @param logger_name The name of the logger to log to.
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_INFO(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::info, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log an info message to the core logger.
|
||||||
|
*
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_CINFO(message, ...) SE_CLOG(spdlog::level::info, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a debug message to a logger.
|
||||||
|
*
|
||||||
|
* @param logger_name The name of the logger to log to.
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_DEBUG(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::debug, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a debug message to the core logger.
|
||||||
|
*
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_CDEBUG(message, ...) SE_CLOG(spdlog::level::debug, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a trace message to a logger.
|
||||||
|
*
|
||||||
|
* @param logger_name The name of the logger to log to.
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_TRACE(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::trace, message, ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Log a trace message to the core logger.
|
||||||
|
*
|
||||||
|
* @param message The (to be) formatted message to log.
|
||||||
|
* @param ... The variables that will be formatted in the text.
|
||||||
|
*/
|
||||||
|
#define SE_CTRACE(message, ...) SE_CLOG(spdlog::level::trace, message, ##__VA_ARGS__);
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "event/event.h"
|
#include "event/event.h"
|
||||||
#include "gfx/shader.h"
|
#include "gfx/shader.h"
|
||||||
|
#include "log/logger.h"
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -99,7 +100,7 @@ namespace simpleengine {
|
||||||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
std::cerr << "Failed to link shader program!" << std::endl;
|
SE_CERROR("Failed to link shader program!");
|
||||||
throw gfx::ShaderException("Failed to link shader program!");
|
throw gfx::ShaderException("Failed to link shader program!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "ecs/component/mesh_component.h"
|
#include "ecs/component/mesh_component.h"
|
||||||
|
|
||||||
#include <glm/gtx/string_cast.hpp>
|
#include <glm/gtx/string_cast.hpp>
|
||||||
|
#include <spdlog/common.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <entt/entity/fwd.hpp>
|
#include <entt/entity/fwd.hpp>
|
||||||
|
@ -68,7 +69,7 @@ namespace simpleengine::ecs::system {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSystem::destroy() {
|
void SceneSystem::destroy() {
|
||||||
std::cout << "Destroying Scene..." << std::endl;
|
SE_DEBUG("scene", "Destroying Scene...");
|
||||||
entity_registry->get_inner().view<ModelComponent>().each([this](ModelComponent& model_component) {
|
entity_registry->get_inner().view<ModelComponent>().each([this](ModelComponent& model_component) {
|
||||||
for (auto& mesh : model_component.model.meshes) {
|
for (auto& mesh : model_component.model.meshes) {
|
||||||
mesh.destroy();
|
mesh.destroy();
|
||||||
|
|
|
@ -39,7 +39,7 @@ simpleengine::Game::Game(int w, int h, const std::string& window_name, const int
|
||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
|
|
||||||
if (glewInit() != GLEW_OK) {
|
if (glewInit() != GLEW_OK) {
|
||||||
std::cout << "Failed to initialize glew!" << std::endl;
|
SE_CERROR("Failed to initialize glew!");
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "gfx/rendering_type.h"
|
#include "gfx/rendering_type.h"
|
||||||
#include "gfx/texture.h"
|
#include "gfx/texture.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
#include "log/logger.h"
|
||||||
|
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
|
@ -38,7 +39,7 @@ namespace simpleengine::gfx {
|
||||||
const aiScene *scene = importer.ReadFile(path, aiProcess_GenNormals | aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_FlipUVs);
|
const aiScene *scene = importer.ReadFile(path, aiProcess_GenNormals | aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
|
||||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
|
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
|
||||||
std::cout << "ERROR::ASSIMP::" << importer.GetErrorString() << std::endl;
|
SE_CERROR("Assimp error when attempting to import \"{}\"", importer.GetErrorString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,8 +118,6 @@ namespace simpleengine::gfx {
|
||||||
gfx::Material mat(default_textures, rendering_type);
|
gfx::Material mat(default_textures, rendering_type);
|
||||||
|
|
||||||
if (mesh->mMaterialIndex >= 0) {
|
if (mesh->mMaterialIndex >= 0) {
|
||||||
std::cout << "TODO: Process model materials!" << std::endl;
|
|
||||||
|
|
||||||
std::unordered_map<aiTextureType, std::vector<std::shared_ptr<Texture>>> textures;
|
std::unordered_map<aiTextureType, std::vector<std::shared_ptr<Texture>>> textures;
|
||||||
aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];
|
aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];
|
||||||
|
|
||||||
|
@ -217,7 +216,7 @@ namespace simpleengine::gfx {
|
||||||
texture.path = texture_path;
|
texture.path = texture_path;
|
||||||
textures.emplace_back(std::make_shared<Texture>(texture));
|
textures.emplace_back(std::make_shared<Texture>(texture));
|
||||||
|
|
||||||
std::cout << "Texture full path: " << full_path << ", texture_path: " << texture_path << std::endl;
|
SE_CDEBUG("Loaded texture! Full path: {}, relative path: {}", full_path, texture_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return textures;
|
return textures;
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace simpleengine::gfx {
|
||||||
: rendering_type(rendering_type), rendering_mesh(&mesh), last_transform_mat(last_pos), transform_mat(position) {}
|
: rendering_type(rendering_type), rendering_mesh(&mesh), last_transform_mat(last_pos), transform_mat(position) {}
|
||||||
|
|
||||||
Renderer::Renderer(GLFWwindow *window, gfx::Shader shader, std::shared_ptr<Camera> camera)
|
Renderer::Renderer(GLFWwindow *window, gfx::Shader shader, std::shared_ptr<Camera> camera)
|
||||||
: window(window), shader(shader), camera(camera)/* , transparent_render_queue(CameraDistanceComparator(camera)) */ {}
|
: window(window), shader(shader), camera(camera), logger(log::LoggerManager::create_logger("render")) {}
|
||||||
|
|
||||||
Renderer::Renderer(GLFWwindow *window, GLuint shader_program, std::shared_ptr<Camera> camera)
|
Renderer::Renderer(GLFWwindow *window, GLuint shader_program, std::shared_ptr<Camera> camera)
|
||||||
: Renderer(window, gfx::Shader(shader_program), camera) {}
|
: Renderer(window, gfx::Shader(shader_program), camera) {}
|
||||||
|
@ -32,13 +32,13 @@ namespace simpleengine::gfx {
|
||||||
void debug_message_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
|
void debug_message_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
|
||||||
const GLchar *message, const void *userParam) {
|
const GLchar *message, const void *userParam) {
|
||||||
|
|
||||||
fprintf(stderr, "%s type = 0x%x, severity = 0x%x, message = %s\n",
|
SE_ERROR("render", "{} type = 0x%x, severity = 0x%x, message = {}",
|
||||||
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
|
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::check_if_initialized() {
|
void Renderer::check_if_initialized() {
|
||||||
if (!is_initialized) {
|
if (!is_initialized) {
|
||||||
std::cerr << "Renderer is not initialized!" << std::endl;
|
logger.critical("Renderer not initialized!"); // TODO: Automatic initialization
|
||||||
throw std::runtime_error("Renderer is not initialized!");
|
throw std::runtime_error("Renderer is not initialized!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ namespace simpleengine::gfx {
|
||||||
|
|
||||||
rendering_mesh->are_buffers_created = true;
|
rendering_mesh->are_buffers_created = true;
|
||||||
|
|
||||||
std::cout << "Created render job buffers" << std::endl;
|
logger.debug("Created render job buffers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +127,11 @@ namespace simpleengine::gfx {
|
||||||
|
|
||||||
this->is_initialized = true;
|
this->is_initialized = true;
|
||||||
|
|
||||||
std::cout << "Base Renderer initialized" << std::endl;
|
logger.debug("Base renderer initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::destroy() {
|
void Renderer::destroy() {
|
||||||
std::cout << "Destroying renderer..." << std::endl;
|
logger.debug("Destroying renderer");
|
||||||
|
|
||||||
shader.delete_program();
|
shader.delete_program();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "gfx/shader.h"
|
#include "gfx/shader.h"
|
||||||
|
#include "log/logger.h"
|
||||||
|
|
||||||
#include <glm/fwd.hpp>
|
#include <glm/fwd.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
@ -40,7 +41,7 @@ namespace simpleengine::gfx {
|
||||||
char log[512];
|
char log[512];
|
||||||
glGetShaderInfoLog(shd.shader, 512, NULL, log);
|
glGetShaderInfoLog(shd.shader, 512, NULL, log);
|
||||||
|
|
||||||
std::cerr << "Failed to load shader from source:" << std::endl << log << std::endl;
|
SE_CERROR("Failed to load shader from source:\n{}", log);
|
||||||
throw ShaderException("Failed to compile shader!");
|
throw ShaderException("Failed to compile shader!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ namespace simpleengine::gfx {
|
||||||
std::ifstream fstream(shader_path, std::ios::in);
|
std::ifstream fstream(shader_path, std::ios::in);
|
||||||
|
|
||||||
if (!fstream.is_open()) {
|
if (!fstream.is_open()) {
|
||||||
std::cerr << "Failed to open shader file: " << shader_path << std::endl;
|
SE_CERROR("Failed to open shader file: {}", shader_path);
|
||||||
throw ShaderException("Failed to open shader file!");
|
throw ShaderException("Failed to open shader file!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ namespace simpleengine::gfx {
|
||||||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
std::cerr << "Failed to link shader program!" << std::endl;
|
SE_CERROR("Failed to link shader program!");
|
||||||
throw ShaderException("Failed to link shader program!");
|
throw ShaderException("Failed to link shader program!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#include "gfx/texture.h"
|
#include "gfx/texture.h"
|
||||||
|
#include "log/logger.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
@ -27,10 +29,11 @@ namespace simpleengine::gfx {
|
||||||
unsigned char*img_data = stbi_load(path, &width, &height, &channels, 0);
|
unsigned char*img_data = stbi_load(path, &width, &height, &channels, 0);
|
||||||
if(!img_data) {
|
if(!img_data) {
|
||||||
const char* failure = stbi_failure_reason();
|
const char* failure = stbi_failure_reason();
|
||||||
std::cerr << "Failed to load texture! (" << failure << ")" << std::endl;
|
|
||||||
|
SE_CERROR("Failed to load texture! Reason: {}", failure);
|
||||||
throw std::runtime_error("Failed to load texture from memory!");
|
throw std::runtime_error("Failed to load texture from memory!");
|
||||||
}
|
}
|
||||||
std::cout << "Loaded image with a width of " << width << "px, a height of " << height << "px and " << channels << " channels" << std::endl;
|
SE_CDEBUG("Loading image! Width = {}px, height = {}px, channel count = {}", width, height, channels);
|
||||||
|
|
||||||
// Get the color type
|
// Get the color type
|
||||||
int color_format = 0;
|
int color_format = 0;
|
||||||
|
@ -41,7 +44,7 @@ namespace simpleengine::gfx {
|
||||||
} else if (channels == 4) {
|
} else if (channels == 4) {
|
||||||
color_format = GL_RGBA;
|
color_format = GL_RGBA;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Unknown texture color format with " << channels << " channels!" << std::endl;
|
SE_CERROR("Unknown texture color format with {} channels!", channels);
|
||||||
throw std::runtime_error("Unknown texture color format!");
|
throw std::runtime_error("Unknown texture color format!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +82,11 @@ namespace simpleengine::gfx {
|
||||||
unsigned char* img_data = stbi_load_from_memory(buffer, buffer_length, &width, &height, &channels, 0);
|
unsigned char* img_data = stbi_load_from_memory(buffer, buffer_length, &width, &height, &channels, 0);
|
||||||
if(!img_data) {
|
if(!img_data) {
|
||||||
const char* failure = stbi_failure_reason();
|
const char* failure = stbi_failure_reason();
|
||||||
std::cerr << "Failed to load texture! (" << failure << ")" << std::endl;
|
|
||||||
|
SE_CERROR("Failed to load texture! Reason: ", failure);
|
||||||
throw std::runtime_error("Failed to load texture from memory!");
|
throw std::runtime_error("Failed to load texture from memory!");
|
||||||
}
|
}
|
||||||
std::cout << "Loaded image with a width of " << width << "px, a height of " << height << "px and " << channels << " channels" << std::endl;
|
SE_CDEBUG("Loading image! Width = {}px, height = {}px, channel count = {}", width, height, channels);
|
||||||
|
|
||||||
// Get the color type
|
// Get the color type
|
||||||
int color_format = 0;
|
int color_format = 0;
|
||||||
|
@ -93,7 +97,7 @@ namespace simpleengine::gfx {
|
||||||
} else if (channels == 4) {
|
} else if (channels == 4) {
|
||||||
color_format = GL_RGBA;
|
color_format = GL_RGBA;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Unknown texture color format with " << channels << " channels!" << std::endl;
|
SE_CERROR("Unknown texture color format with {} channels!", channels);
|
||||||
throw std::runtime_error("Unknown texture color format!");
|
throw std::runtime_error("Unknown texture color format!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace simpleengine::log {
|
namespace simpleengine::log {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,7 @@ namespace simpleengine::log {
|
||||||
spdlog::set_level(lvl);
|
spdlog::set_level(lvl);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Logger> LoggerManager::core_logger;
|
Logger& LoggerManager::get_core_logger() {
|
||||||
|
|
||||||
std::shared_ptr<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);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue