From 8d78a8183865bfcfbd1a656f863ec0577b70a07c Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 27 Dec 2020 14:44:25 +0100 Subject: [PATCH] Improve on the logging system, add assertions.h --- inferno/src/inferno/application.cpp | 11 +- inferno/src/inferno/assertions.h | 62 +++++++ inferno/src/inferno/core.h | 37 +--- inferno/src/inferno/entrypoint.h | 3 - inferno/src/inferno/file.cpp | 5 +- inferno/src/inferno/file.h | 5 +- inferno/src/inferno/log.cpp | 234 +++++++++++++++++++++++-- inferno/src/inferno/log.h | 214 +++++++++++++++------- inferno/src/inferno/render/buffer.cpp | 7 +- inferno/src/inferno/render/context.cpp | 11 +- inferno/src/inferno/render/shader.cpp | 5 +- inferno/src/inferno/settings.cpp | 6 +- inferno/src/inferno/window.cpp | 5 +- 13 files changed, 471 insertions(+), 134 deletions(-) create mode 100644 inferno/src/inferno/assertions.h diff --git a/inferno/src/inferno/application.cpp b/inferno/src/inferno/application.cpp index 58a8677..0b6a4d5 100644 --- a/inferno/src/inferno/application.cpp +++ b/inferno/src/inferno/application.cpp @@ -1,6 +1,7 @@ #include #include "inferno/application.h" +#include "inferno/assertions.h" #include "inferno/core.h" #include "inferno/event/applicationevent.h" #include "inferno/event/event.h" @@ -19,7 +20,7 @@ namespace Inferno { Application::Application() { - NF_CORE_ASSERT(!s_instance, "Application already exists!"); + ASSERT(!s_instance, "Application already exists!"); s_instance = this; // Initialize Settings @@ -62,7 +63,7 @@ namespace Inferno { void Application::run() { - NF_CORE_LOG("Application startup"); + dbg() << "Application startup"; while(!glfwWindowShouldClose(m_window->getWindow())) { @@ -81,7 +82,7 @@ namespace Inferno { m_window->update(); } - NF_CORE_LOG("Application shutdown"); + dbg() << "Application shutdown"; } void Application::onEvent(Event &e) @@ -96,7 +97,7 @@ namespace Inferno { // Suppress unused warning (void)e; - NF_CORE_INFO("WindowCloseEvent triggered"); + dbg(Log::Info) << "WindowCloseEvent triggered"; glfwSetWindowShouldClose(m_window->getWindow(), GL_TRUE); @@ -108,7 +109,7 @@ namespace Inferno { // Suppress unused warning (void)e; - NF_CORE_INFO("WindowResizeEvent %dx%d triggered", e.getWidth(), e.getHeight()); + dbg(Log::Info) << "WindowResizeEvent %dx%d triggered", e.getWidth(), e.getHeight(); m_window->getContext()->setViewport(0, 0, e.getWidth(), e.getHeight()); diff --git a/inferno/src/inferno/assertions.h b/inferno/src/inferno/assertions.h new file mode 100644 index 0000000..291cd02 --- /dev/null +++ b/inferno/src/inferno/assertions.h @@ -0,0 +1,62 @@ +#ifndef ASSERTIONS_H +#define ASSERTIONS_H + +#include // raise + +#include "inferno/core.h" +#include "inferno/log.h" + +#ifndef NDEBUG + #define NF_ENABLE_ASSERTS +#endif + +// Asserts +#ifdef NF_ENABLE_ASSERTS + // Check if SIGTRAP is available + #ifdef SIGTRAP + #define ABORT_SIGNAL SIGTRAP + #else + #define ABORT_SIGNAL SIGABRT + #endif + + // Non-standard function macro + #ifdef GCC + #define FUNCTION_MACRO __PRETTY_FUNCTION__ + #elif MSVC + #define FUNCTION_MACRO __FUNCSIG__ + #endif + + // ##__VA_ARGS__ is a non-standard GCC extension, C++20 introduces __VA_OPT__ + // https://stackoverflow.com/questions/52891546/what-does-va-args-mean + #define ASSERT(cond, ...) static_cast(cond) ? (void)0 : __assertion_failed(#cond, __FILE__, __LINE__, FUNCTION_MACRO, ##__VA_ARGS__) + #define ASSERT_NOT_REACHED() ASSERT(false) +#else + #define ASSERT(cond, ...) + #define ASSERT_NOT_REACHED() CRASH() +#endif + +#define CRASH() raise(SIGABRT) + +namespace Inferno { + + #ifdef NF_ENABLE_ASSERTS + template + void __assertion_failed(const char* message, const char* file, unsigned line, const char* function, const P&... parameters) + { + dbg(Log::Danger, false) << "ASSERTION FAILED: " << message; + + if (sizeof...(P) > 0) { + dbg(Log::Danger, false) << ", \""; + dbgln(Log::Danger, false, parameters...); + dbg(Log::Danger, false) << "\""; + } + + dbg(Log::Danger) << "\n\t" << file << ":" << line << ": " << function; + + raise(ABORT_SIGNAL); + } + #endif + +} + +#endif // ASSERTIONS_H diff --git a/inferno/src/inferno/core.h b/inferno/src/inferno/core.h index 5b117a3..e3f7266 100644 --- a/inferno/src/inferno/core.h +++ b/inferno/src/inferno/core.h @@ -1,40 +1,21 @@ #ifndef CORE_H #define CORE_H -#include // raise -#include // sprintf -#include // strlen #include // std::bind #define BIT(x) (1 << x) #define NF_BIND_EVENT(f) std::bind(&f, this, std::placeholders::_1) -// Debugging defines -#ifndef NDEBUG - #define NF_ENABLE_ASSERTS -#endif - -// Asserts -#ifdef NF_ENABLE_ASSERTS - // Check if SIGTRAP is available - #ifdef SIGTRAP - #define ABORT_SIGNAL SIGTRAP - #else - #define ABORT_SIGNAL SIGABRT - #endif - - #define NF_ASSERT(x, y, ...) if(!(x)) { \ - char buffer[15 + strlen(y)]; \ - sprintf(buffer, "Assert: {%%s}, %s", y); \ - NF_DANGER(buffer, #x, ##__VA_ARGS__); raise(ABORT_SIGNAL); } - #define NF_CORE_ASSERT(x, y, ...) if(!(x)) { \ - char buffer[15 + strlen(y)]; \ - sprintf(buffer, "Assert: {%%s}, %s", y); \ - NF_CORE_DANGER(buffer, #x, ##__VA_ARGS__); raise(ABORT_SIGNAL); } -#else - #define NF_ASSERT(x, y) - #define NF_CORE_ASSERT(x, y) +// Compiler +#if defined(__clang__) + #define GCC +#elif defined(__INTEL_COMPILER) // Supports some GCC extensions + #define GCC +#elif defined(__GNUG__) || (defined(__GNUC__) && defined(__cplusplus)) + #define GCC +#elif defined(_MSC_VER) + #define MSVC #endif #endif // CORE_H diff --git a/inferno/src/inferno/entrypoint.h b/inferno/src/inferno/entrypoint.h index 16cb3c4..625228b 100644 --- a/inferno/src/inferno/entrypoint.h +++ b/inferno/src/inferno/entrypoint.h @@ -16,9 +16,6 @@ int main(int argc, char* argv[]) (void)argc; (void)argv; - // Initialize Log - Inferno::Log::initialize(); - // Start application auto app = Inferno::createApplication(); app->run(); diff --git a/inferno/src/inferno/file.cpp b/inferno/src/inferno/file.cpp index 7c69671..5ef0c08 100644 --- a/inferno/src/inferno/file.cpp +++ b/inferno/src/inferno/file.cpp @@ -1,6 +1,7 @@ #include // std::ios #include // std::make_unique +#include "inferno/assertions.h" #include "inferno/file.h" namespace Inferno { @@ -9,7 +10,7 @@ namespace Inferno { { // Create input stream object and open file std::ifstream file(path.c_str()); - NF_CORE_ASSERT(file.is_open(), "File could not open! %s", path.c_str()); + ASSERT(file.is_open(), "File could not open! {}", path.c_str()); // Check if file exists if (!file.is_open()) { @@ -20,7 +21,7 @@ namespace Inferno { file.seekg(0, std::ios::end); int length = file.tellg(); file.seekg(0, std::ios::beg); - NF_CORE_ASSERT(length != -1, "File could not determine length! %s", path.c_str()); + ASSERT(length != -1, "File could not determine length! {}", path.c_str()); // Check for valid file length if (length == -1) { diff --git a/inferno/src/inferno/file.h b/inferno/src/inferno/file.h index e2219a9..2c683ae 100644 --- a/inferno/src/inferno/file.h +++ b/inferno/src/inferno/file.h @@ -5,6 +5,7 @@ #include // std::setfill, std::setw #include // std::string +#include "inferno/assertions.h" #include "inferno/core.h" #include "inferno/log.h" @@ -18,7 +19,7 @@ namespace Inferno { static void ioRead(T &t, const std::string &path) { std::ifstream file(path); - NF_CORE_ASSERT(file.is_open(), "File could not open! %s", path.c_str()); + ASSERT(file.is_open(), "File could not open! {}", path.c_str()); if (file.is_open()) { file >> t; @@ -30,7 +31,7 @@ namespace Inferno { static void ioWrite(T &t, const std::string &path) { std::ofstream file (path); - NF_CORE_ASSERT(file.is_open(), "File could not open! %s", path.c_str()); + ASSERT(file.is_open(), "File could not open! {}", path.c_str()); if (file.is_open()) { // Write file with single tabs, nicely formatted diff --git a/inferno/src/inferno/log.cpp b/inferno/src/inferno/log.cpp index 1af8e6b..2a371f9 100644 --- a/inferno/src/inferno/log.cpp +++ b/inferno/src/inferno/log.cpp @@ -1,32 +1,242 @@ +#include "inferno/assertions.h" #include "inferno/log.h" +#include // strlen +#include // std::string +#include // std::string_view + namespace Inferno { - // Reserve memory - std::shared_ptr Log::m_coreLogger; - std::shared_ptr Log::m_gameLogger; + const LogStream& operator<<(const LogStream& stream, const char* value) + { + stream.write(value, strlen(value)); + return stream; + } + + const LogStream& operator<<(const LogStream& stream, const unsigned char* value) + { + stream.write(value, strlen((const char*)value)); + return stream; + } + + const LogStream& operator<<(const LogStream& stream, const std::string& value) + { + stream.write(value.c_str(), value.length()); + return stream; + } + + const LogStream& operator<<(const LogStream& stream, const std::string_view& value) + { + stream.write(value.data(), value.length()); + return stream; + } + + const LogStream& operator<<(const LogStream& stream, char value) + { + stream.write(&value, 1); + return stream; + } + + const LogStream& operator<<(const LogStream& stream, unsigned char value) + { + stream.write(&value, 1); + return stream; + } + + const LogStream& operator<<(const LogStream& stream, int value) + { + // return stream << std::to_string(value); + + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%d", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, long int value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%ld", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, long long int value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%lld", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, unsigned int value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%u", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, long unsigned int value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%lu", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, long long unsigned int value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%llu", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, double value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%.4f", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, float value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%.4f", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, const void* value) + { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%p", value); + return stream << buffer; + } + + const LogStream& operator<<(const LogStream& stream, bool value) + { + return stream << (value ? "true": "false"); + } + + const LogStream& operator<<(const LogStream& stream, Log value) + { + switch (value) { + case Log::Log: + return stream << "Log"; + case Log::Info: + return stream << "Info"; + case Log::Warn: + return stream << "Warn"; + case Log::Danger: + return stream << "Danger"; + case Log::Success: + return stream << "Success"; + default: + ASSERT_NOT_REACHED(); + return stream; + } + } // ----------------------------------------- - void Log::initialize() + DebugLogStream dbg() { - // Create engine Logger - m_coreLogger = std::make_shared("Inferno"); - // Create game Logger - m_gameLogger = std::make_shared("Game"); + return {}; + } + + DebugLogStream dbg(bool newline) + { + return DebugLogStream(newline); + } - NF_CORE_INFO("Log initialized"); + DebugLogStream dbg(Log type) + { + return DebugLogStream(type); + } + + DebugLogStream dbg(Log type, bool newline) + { + return DebugLogStream(type, newline); + } + + void dbgln(Log type, bool newline) { + (void)type; + dbg(newline); + } + + void dbgln(const char* format) + { + dbg() << format; + } + + void dbgln(Log type, const char* format) + { + dbg(type) << format; + } + + void dbgln(Log type, bool newline, const char* format) + { + dbg(type, newline) << format; + } + + void dbgln(std::string format) + { + dbg() << format; + } + + void dbgln(Log type, std::string format) + { + dbg(type) << format; + } + + void dbgln(Log type, bool newline, std::string format) + { + dbg(type, newline) << format; + } + + void dbgln(std::string_view format) + { + dbg() << format; + } + + void dbgln(Log type, std::string_view format) + { + dbg(type) << format; + } + + void dbgln(Log type, bool newline, std::string_view format) + { + dbg(type, newline) << format; } // ----------------------------------------- - Logger::Logger(const char* name) : - m_name(name) + DebugLogStream::~DebugLogStream() { + if (m_type != Log::Log) { + write("\033[0m", 4); + } + + if (m_newline) { + char newline = '\n'; + write(&newline, 1); + } } - Logger::~Logger() + void DebugLogStream::color() const { + const char* color = ""; + if (m_type == Log::Info) { + color = "\x1B[34m"; + } + else if (m_type == Log::Warn) { + color = "\x1B[33m"; + } + else if (m_type == Log::Danger) { + color = "\x1B[31m"; + } + else if (m_type == Log::Success) { + color = "\x1B[32m"; + } + + if (color[0] != '\0') { + write(color, 5); + } } } diff --git a/inferno/src/inferno/log.h b/inferno/src/inferno/log.h index 7c7bad7..19166bd 100644 --- a/inferno/src/inferno/log.h +++ b/inferno/src/inferno/log.h @@ -1,91 +1,171 @@ #ifndef LOG_H #define LOG_H -#include // printf, sprintf -#include // strlen -#include // std::shared_ptr -#include // std::string +#include // printf +#include // std::string +#include // std::string_view namespace Inferno { - class Logger; - - class Log { - public: - -// ----------------------------------------- - - static void initialize(); - -// ----------------------------------------- - - inline static std::shared_ptr &getCoreLogger() { return m_coreLogger; } - inline static std::shared_ptr &getGameLogger() { return m_gameLogger; } - - private: - static std::shared_ptr m_coreLogger; - static std::shared_ptr m_gameLogger; + enum class Log { + Log, + Info, + Warn, + Danger, + Success, }; - class Logger { - public: - Logger(const char* name); - ~Logger(); - - template - void print(const char* color, const char* format, A... arguments) - { - char buffer[10 + strlen(color) + strlen(m_name) + strlen(format)]; - sprintf(buffer, "%s%s: %s\033[0m\n", color, m_name, format); - printf(buffer, arguments...); - } +// ---------------------------------------- - template - void log(const char* format, A... arguments) - { - this->print("", format, arguments...); - } + class LogStream { + public: + LogStream() {} + virtual ~LogStream() {} - template - void info(const char* format, A... arguments) - { - this->print("\x1B[34m", format, arguments...); - } + virtual void write(const char* characters, int length) const = 0; + virtual void write(const unsigned char* characters, int length) const = 0; + }; - template - void warn(const char* format, A... arguments) - { - this->print("\x1B[33m", format, arguments...); - } +// ---------------------------------------- - template - void danger(const char* format, A... arguments) + class DebugLogStream final : public LogStream{ + public: + DebugLogStream(): + m_newline(true), m_type(Log::Log) {} + DebugLogStream(bool newline): + m_newline(newline), m_type(Log::Log) {} + DebugLogStream(Log type): + m_newline(true), m_type(type) { color(); } + DebugLogStream(Log type, bool newline): + m_newline(newline), m_type(type) { color(); } + virtual ~DebugLogStream() override; + + void color() const; + + virtual void write(const char* characters, int length) const override { - this->print("\x1B[31m", format, arguments...); + for (int i = 0; i < length; i++) { + printf("%c", characters[i]); + } } - template - void success(const char* format, A... arguments) + virtual void write(const unsigned char* characters, int length) const override { - this->print("\x1B[32m", format, arguments...); + for (int i = 0; i < length; i++) { + printf("%c", characters[i]); + } } private: - const char* m_name; + bool m_newline; + Log m_type; }; -} +// ---------------------------------------- + + const LogStream& operator<<(const LogStream& stream, const char* value); + const LogStream& operator<<(const LogStream& stream, const std::string& value); + const LogStream& operator<<(const LogStream& stream, const std::string_view& value); + const LogStream& operator<<(const LogStream& stream, char value); + const LogStream& operator<<(const LogStream& stream, unsigned char value); + const LogStream& operator<<(const LogStream& stream, const unsigned char* value); + const LogStream& operator<<(const LogStream& stream, int value); + const LogStream& operator<<(const LogStream& stream, long int value); + const LogStream& operator<<(const LogStream& stream, long long int value); + const LogStream& operator<<(const LogStream& stream, unsigned int value); + const LogStream& operator<<(const LogStream& stream, long unsigned int value); + const LogStream& operator<<(const LogStream& stream, long long unsigned int value); + const LogStream& operator<<(const LogStream& stream, double value); + const LogStream& operator<<(const LogStream& stream, float value); + const LogStream& operator<<(const LogStream& stream, const void* value); + const LogStream& operator<<(const LogStream& stream, bool value); + const LogStream& operator<<(const LogStream& stream, Log value); + +// ---------------------------------------- + + DebugLogStream dbg(); + DebugLogStream dbg(bool newline); + DebugLogStream dbg(Log type); + DebugLogStream dbg(Log type, bool newline); + + void dbgln(Log type, bool newline); + void dbgln(const char* format); + void dbgln(Log type, const char* format); + void dbgln(Log type, bool newline, const char* format); + void dbgln(std::string format); + void dbgln(Log type, std::string format); + void dbgln(Log type, bool newline, std::string format); + void dbgln(std::string_view format); + void dbgln(Log type, std::string_view format); + void dbgln(Log type, bool newline, std::string_view format); + + template + void dbgln(const char* format, T value, const P&... parameters) + { + dbgln(Log::Log, true, format, value, parameters...); + } + + template + void dbgln(Log type, const char* format, T value, const P&... parameters) + { + dbgln(type, true, format, value, parameters...); + } + + // https://en.cppreference.com/w/cpp/language/parameter_pack#Example + template + void dbgln(Log type, bool newline, const char* format, T value, const P&... parameters) + { + std::string_view view { format }; + + uint32_t i = 0; + while(format[i] != '\0') { + + if (format[i] == '{' && format[i + 1] == '}') { + dbg(type, false) << view.substr(0, i) << value; + dbgln(type, newline, format + i + 2, parameters...); + return; + } + + i++; + } + } + + template + void dbgln(std::string format, T value, const P&... parameters) + { + dbgln(format.c_str(), value, parameters...); + } + + template + void dbgln(Log type, std::string format, T value, const P&... parameters) + { + dbgln(type, format.c_str(), value, parameters...); + } + + template + void dbgln(Log type, bool newline, std::string format, T value, const P&... parameters) + { + dbgln(type, newline, format.c_str(), value, parameters...); + } + + template + void dbgln(std::string_view format, T value, const P&... parameters) + { + dbgln(format.data(), value, parameters...); + } + + template + void dbgln(Log type, std::string_view format, T value, const P&... parameters) + { + dbgln(type, format.data(), value, parameters...); + } + + template + void dbgln(Log type, bool newline, std::string_view format, T value, const P&... parameters) + { + dbgln(type, newline, format.data(), value, parameters...); + } -#define NF_CORE_LOG(...) Inferno::Log::getCoreLogger()->log(__VA_ARGS__) -#define NF_CORE_INFO(...) Inferno::Log::getCoreLogger()->info(__VA_ARGS__) -#define NF_CORE_WARN(...) Inferno::Log::getCoreLogger()->warn(__VA_ARGS__) -#define NF_CORE_DANGER(...) Inferno::Log::getCoreLogger()->danger(__VA_ARGS__) -#define NF_CORE_SUCCESS(...) Inferno::Log::getCoreLogger()->success(__VA_ARGS__) - -#define NF_LOG(...) Inferno::Log::getGameLogger()->log(__VA_ARGS__) -#define NF_INFO(...) Inferno::Log::getGameLogger()->info(__VA_ARGS__) -#define NF_WARN(...) Inferno::Log::getGameLogger()->warn(__VA_ARGS__) -#define NF_DANGER(...) Inferno::Log::getGameLogger()->danger(__VA_ARGS__) -#define NF_SUCCESS(...) Inferno::Log::getGameLogger()->success(__VA_ARGS__) +} #endif // LOG_H diff --git a/inferno/src/inferno/render/buffer.cpp b/inferno/src/inferno/render/buffer.cpp index dd69008..d119421 100644 --- a/inferno/src/inferno/render/buffer.cpp +++ b/inferno/src/inferno/render/buffer.cpp @@ -1,5 +1,6 @@ #include +#include "inferno/assertions.h" #include "inferno/core.h" #include "inferno/log.h" #include "inferno/render/buffer.h" @@ -48,7 +49,7 @@ namespace Inferno { case BufferElementType::Vec4: return sizeof(float) * 4; }; - NF_CORE_ASSERT(false, "BufferElement unknown BufferElementType size!"); + ASSERT(false, "BufferElement unknown BufferElementType size!"); return 0; } @@ -68,7 +69,7 @@ namespace Inferno { case BufferElementType::Vec4: return 4; }; - NF_CORE_ASSERT(false, "BufferElement unknown BufferElementType count!"); + ASSERT(false, "BufferElement unknown BufferElementType count!"); return 0; } @@ -88,7 +89,7 @@ namespace Inferno { case BufferElementType::Vec4: return GL_FLOAT; }; - NF_CORE_ASSERT(false, "BufferElement unknown BufferElementType GL!"); + ASSERT(false, "BufferElement unknown BufferElementType GL!"); return 0; } diff --git a/inferno/src/inferno/render/context.cpp b/inferno/src/inferno/render/context.cpp index 558a517..412e659 100644 --- a/inferno/src/inferno/render/context.cpp +++ b/inferno/src/inferno/render/context.cpp @@ -1,6 +1,7 @@ #include #include +#include "inferno/assertions.h" #include "inferno/core.h" #include "inferno/log.h" #include "inferno/render/context.h" @@ -20,13 +21,13 @@ namespace Inferno { // Initialize glad glfwMakeContextCurrent(m_window); int glad = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); - NF_CORE_ASSERT(glad, "Failed to initialize glad!"); + ASSERT(glad, "Failed to initialize glad!"); // Log OpenGL properties - NF_CORE_INFO("OpenGL Info:"); - NF_CORE_INFO(" Vendor: %s", glGetString(GL_VENDOR)); - NF_CORE_INFO(" Renderer: %s", glGetString(GL_RENDERER)); - NF_CORE_INFO(" Version: %s", glGetString(GL_VERSION)); + dbg(Log::Info) << "OpenGL Info:"; + dbg(Log::Info) << " Vendor: " << glGetString(GL_VENDOR); + dbg(Log::Info) << " Renderer: " << glGetString(GL_RENDERER); + dbg(Log::Info) << " Version: " << glGetString(GL_VERSION); Window &w = *(Window*)glfwGetWindowUserPointer(m_window); diff --git a/inferno/src/inferno/render/shader.cpp b/inferno/src/inferno/render/shader.cpp index a2d5054..11e6e06 100644 --- a/inferno/src/inferno/render/shader.cpp +++ b/inferno/src/inferno/render/shader.cpp @@ -2,6 +2,7 @@ #include +#include "inferno/assertions.h" #include "inferno/core.h" #include "inferno/file.h" #include "inferno/log.h" @@ -129,10 +130,10 @@ namespace Inferno { ? glGetShaderInfoLog(check, maxLength, nullptr, &infoLog[0]) : glGetProgramInfoLog(check, maxLength, nullptr, &infoLog[0]); - NF_CORE_WARN("Shader %s", infoLog.data()); + dbg(Log::Warn) << "Shader " << infoLog.data(); } - NF_CORE_ASSERT(success == GL_TRUE, "Shader program creation failed!") + ASSERT(success == GL_TRUE, "Shader program creation failed!"); return success; } diff --git a/inferno/src/inferno/settings.cpp b/inferno/src/inferno/settings.cpp index f39787b..c1573e9 100644 --- a/inferno/src/inferno/settings.cpp +++ b/inferno/src/inferno/settings.cpp @@ -34,7 +34,7 @@ namespace Inferno { m_properties.window.vsync = json["window"]["vsync"].get(); } catch (...) { - NF_CORE_WARN("Settings syntax error: using default values"); + dbg(Log::Warn) << "Settings syntax error: using default values"; } } @@ -50,7 +50,7 @@ namespace Inferno { nlohmann::json json; File::ioRead(json, m_path); - NF_CORE_INFO("Settings loaded"); + dbg(Log::Info) << "Settings loaded"; return json; } @@ -65,7 +65,7 @@ namespace Inferno { json["window"]["vsync"] = m_properties.window.vsync; File::ioWrite(json, m_path); - NF_CORE_INFO("Settings saved"); + dbg(Log::Info) << "Settings saved"; return true; } diff --git a/inferno/src/inferno/window.cpp b/inferno/src/inferno/window.cpp index c41822e..7d7faaf 100644 --- a/inferno/src/inferno/window.cpp +++ b/inferno/src/inferno/window.cpp @@ -2,6 +2,7 @@ #include +#include "inferno/assertions.h" #include "inferno/core.h" #include "inferno/event/applicationevent.h" #include "inferno/event/keyevent.h" @@ -55,7 +56,7 @@ namespace Inferno { // Create GLFW window m_window = glfwCreateWindow(width, height, title, nullptr, nullptr); s_windowCount++; - NF_CORE_ASSERT(m_window, "Failed to create GLFW window!"); + ASSERT(m_window, "Failed to create GLFW window!"); // Set windowed/fullscreen/borderless this->setWindowMonitor(); @@ -72,7 +73,7 @@ namespace Inferno { // Error callback glfwSetErrorCallback([](int error, const char* description) { - NF_CORE_LOG("GLFW Error %d: %s", error, description); + dbgln("GLFW Error {}: {}", error, description); }); // Window close callback