refactor: logger
This commit is contained in:
parent
2e05d871eb
commit
834402c1b8
31 changed files with 295 additions and 260 deletions
|
@ -38,43 +38,74 @@ constexpr std::unique_ptr<t> make_scope(t *rawPointer)
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
||||||
//========== PLATFORM ==========//
|
|
||||||
#define lt_win(x) // windows
|
#define lt_win(x) // windows
|
||||||
#define lt_lin(x) // linux
|
#define lt_lin(x) // linux
|
||||||
#define lt_mac(x) // mac
|
#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)
|
#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)
|
#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)
|
#elif defined(LIGHT_PLATFORM_MAC)
|
||||||
#error "Unsupported platform: MAC"
|
|
||||||
#define lt_mac(x) x
|
#define lt_mac(x) x
|
||||||
|
constexpr auto platform = Platform::mac;
|
||||||
|
constexpr auto platform_name = "mac";
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error "Unsupported platform: Unknown"
|
#error "Unsupported platform: Unknown"
|
||||||
#endif
|
|
||||||
//========== PLATFORM ==========//
|
|
||||||
|
|
||||||
//====================================================================== OPERATIONS
|
#endif
|
||||||
//======================================================================//
|
|
||||||
/* assertions */
|
|
||||||
|
} // namespace constants
|
||||||
|
|
||||||
|
template<typename T = void>
|
||||||
|
concept is_linux = true;
|
||||||
|
|
||||||
|
auto linux_only(auto value)
|
||||||
|
requires is_linux<void>
|
||||||
|
{
|
||||||
|
if constexpr (is_linux)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define lt_assert(x, ...) \
|
#define lt_assert(x, ...) \
|
||||||
{ \
|
{ \
|
||||||
if (!(x)) \
|
if (!(x)) \
|
||||||
{ \
|
{ \
|
||||||
lt_log(critical, __VA_ARGS__); \
|
log_crt(__VA_ARGS__); \
|
||||||
lt_debug_trap(); \
|
lt_debug_trap(); \
|
||||||
throw ::Light::FailedAssertion(__FILE__, __LINE__); \
|
throw ::Light::FailedAssertion(__FILE__, __LINE__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bit-wise */
|
/* bit-wise */
|
||||||
#define bit(x) 1 << x
|
constexpr auto bit(auto x)
|
||||||
|
{
|
||||||
|
return 1 << x;
|
||||||
|
}
|
||||||
|
|
||||||
/* token */
|
/* token */
|
||||||
#define lt_pair_token_value_to_name(token) { token, #token }
|
#define lt_pair_token_value_to_name(token) { token, #token }
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
#include <engine/engine.hpp>
|
#include <engine/engine.hpp>
|
||||||
|
|
||||||
// to be defined in client project
|
// to be defined in client project
|
||||||
extern Light::Application *Light::create_application();
|
extern auto Light::create_application() -> Light::Scope<Light::Application>;
|
||||||
|
|
||||||
// #todo: use windows specific stuff
|
// #todo: use windows specific stuff
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Light::Application *application = nullptr;
|
auto application = Light::Scope<Light::Application> {};
|
||||||
int exitCode = 0;
|
int exitCode = 0;
|
||||||
|
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
|
@ -24,26 +24,26 @@ int main(int argc, char *argv[])
|
||||||
lt_assert(application, "Light::Application is not intialized");
|
lt_assert(application, "Light::Application is not intialized");
|
||||||
|
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
lt_log(info, "argv[{}]: {}", i, argv[i]);
|
log_inf("argv[{}]: {}", i, argv[i]);
|
||||||
|
|
||||||
application->game_loop();
|
application->game_loop();
|
||||||
}
|
}
|
||||||
// failed engine assertion
|
// failed engine assertion
|
||||||
catch (Light::FailedAssertion)
|
catch (Light::FailedAssertion)
|
||||||
{
|
{
|
||||||
lt_log(critical, "Terminating due to unhandled 'FailedEngineAssertion'");
|
log_crt("Terminating due to unhandled 'FailedEngineAssertion'");
|
||||||
exitCode = -1;
|
exitCode = -1;
|
||||||
}
|
}
|
||||||
// gl exception
|
// gl exception
|
||||||
catch (Light::glException)
|
catch (Light::glException)
|
||||||
{
|
{
|
||||||
lt_log(critical, "Terminating due to unhandled 'glException'");
|
log_crt("Terminating due to unhandled 'glException'");
|
||||||
exitCode = -3;
|
exitCode = -3;
|
||||||
}
|
}
|
||||||
// dx exception
|
// dx exception
|
||||||
catch (Light::dxException)
|
catch (Light::dxException)
|
||||||
{
|
{
|
||||||
lt_log(critical, "Terminating due to unhandled 'dxException'");
|
log_crt("Terminating due to unhandled 'dxException'");
|
||||||
exitCode = -4;
|
exitCode = -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,12 +56,12 @@ int main(int argc, char *argv[])
|
||||||
#include <engine/engine.hpp>
|
#include <engine/engine.hpp>
|
||||||
|
|
||||||
// to be defined in client project
|
// to be defined in client project
|
||||||
extern Light::Application *Light::create_application();
|
extern auto Light::create_application() -> Light::Scope<Light::Application>;
|
||||||
|
|
||||||
// #todo: use linux specific stuff
|
// #todo: use linux specific stuff
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Light::Application *application = nullptr;
|
auto application = Light::Scope<Light::Application> {};
|
||||||
int exitCode = 0;
|
int exitCode = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -74,17 +74,16 @@ int main(int argc, char *argv[])
|
||||||
// failed engine assertion
|
// failed engine assertion
|
||||||
catch (Light::FailedAssertion)
|
catch (Light::FailedAssertion)
|
||||||
{
|
{
|
||||||
lt_log(critical, "Exitting due to unhandled 'FailedEngineAssertion'");
|
log_crt("Exitting due to unhandled 'FailedEngineAssertion'");
|
||||||
exitCode = -1;
|
exitCode = -1;
|
||||||
}
|
}
|
||||||
// gl exception
|
// gl exception
|
||||||
catch (Light::glException)
|
catch (Light::glException)
|
||||||
{
|
{
|
||||||
lt_log(critical, "main: exitting due to unhandled 'glException'");
|
log_crt("main: exitting due to unhandled 'glException'");
|
||||||
exitCode = -3;
|
exitCode = -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete application;
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ static inline void lt_debug_trap(void)
|
||||||
#elif defined(LIGHT_DIST)
|
#elif defined(LIGHT_DIST)
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define lt_debug_trap() \
|
#define lt_debug_trap() \
|
||||||
lt_log(critical, \
|
log_crt( \
|
||||||
"DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
"DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||||
__FUNCSIG__, \
|
__FUNCSIG__, \
|
||||||
__FILE__, \
|
__FILE__, \
|
||||||
|
@ -135,13 +135,13 @@ static inline void lt_debug_trap(void)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define lt_debug_trap() \
|
#define lt_debug_trap() \
|
||||||
lt_log(critical, "DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#else /* !defined(LIGHT_DIST) */
|
#else /* !defined(LIGHT_DIST) */
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define lt_debug_trap() \
|
#define lt_debug_trap() \
|
||||||
lt_log(critical, \
|
log_crt( \
|
||||||
"DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
"DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||||
__FUNCSIG__, \
|
__FUNCSIG__, \
|
||||||
__FILE__, \
|
__FILE__, \
|
||||||
|
@ -149,7 +149,7 @@ static inline void lt_debug_trap(void)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define lt_debug_trap() \
|
#define lt_debug_trap() \
|
||||||
lt_log(critical, "DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,9 +31,11 @@ protected:
|
||||||
Scope<Window> m_window;
|
Scope<Window> m_window;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Application *s_context;
|
void on_event(const Event &event);
|
||||||
|
|
||||||
Scope<logger> m_logger;
|
void log_debug_data();
|
||||||
|
|
||||||
|
static Application *s_context;
|
||||||
|
|
||||||
Scope<Instrumentor> m_instrumentor;
|
Scope<Instrumentor> m_instrumentor;
|
||||||
|
|
||||||
|
@ -42,12 +44,8 @@ private:
|
||||||
Scope<Input> m_input;
|
Scope<Input> m_input;
|
||||||
|
|
||||||
Scope<ResourceManager> m_resource_manager;
|
Scope<ResourceManager> m_resource_manager;
|
||||||
|
|
||||||
void on_event(const Event &event);
|
|
||||||
|
|
||||||
void log_debug_data();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Application *create_application();
|
extern Light::Scope<Application> create_application();
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -1,57 +1,101 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef LIGHT_LOGGER_H
|
|
||||||
#define LIGHT_LOGGER_H
|
|
||||||
|
|
||||||
#include <engine/base/base.hpp>
|
#include <any>
|
||||||
|
#include <format>
|
||||||
|
#include <memory>
|
||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#define LT_LOG_FILE_LOCATION "Logs/logger.txt"
|
/** @brief Severity of a log message.
|
||||||
|
*
|
||||||
#ifndef LIGHT_DIST
|
* @note Values reflect spdlog::lvl
|
||||||
#define lt_log(logLevel, ...) \
|
*/
|
||||||
SPDLOG_LOGGER_CALL( \
|
enum class LogLvl : uint8_t
|
||||||
::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
|
|
||||||
{
|
{
|
||||||
public:
|
/** Lowest and most vebose log level, for tracing execution paths and events */
|
||||||
static Scope<logger> create();
|
trace = 0,
|
||||||
|
|
||||||
static auto get_engine_logger() -> Ref<spdlog::logger>
|
/** Vebose log level, for enabling temporarily to debug */
|
||||||
{
|
debug = 1,
|
||||||
return s_context->m_engine_logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto get_file_logger() -> Ref<spdlog::logger>
|
/** General information */
|
||||||
{
|
info = 2,
|
||||||
return s_context->m_file_logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_debug_data();
|
/** Things we should to be aware of and edge cases */
|
||||||
|
warn = 3,
|
||||||
|
|
||||||
private:
|
/** Defects, bugs and undesired behaviour */
|
||||||
static logger *s_context;
|
error = 4,
|
||||||
|
|
||||||
Ref<spdlog::logger> m_engine_logger, m_file_logger;
|
/** Unrecoverable errors */
|
||||||
|
critical = 5,
|
||||||
|
|
||||||
std::string m_log_file_path;
|
/** No logging */
|
||||||
|
off = 6,
|
||||||
logger();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Light
|
namespace spdlog {
|
||||||
|
class logger;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
/** Responsible for logging */
|
||||||
|
class Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void static show_imgui_window();
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void static log(LogLvl lvl, std::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
instance().spd_logger->log(
|
||||||
|
(spdlog::level::level_enum)lvl,
|
||||||
|
std::format(fmt, std::forward<Args>(args)...)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Logger();
|
||||||
|
|
||||||
|
~Logger();
|
||||||
|
|
||||||
|
auto static instance() -> Logger &;
|
||||||
|
|
||||||
|
std::shared_ptr<spdlog::logger> spd_logger;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void log_trc(std::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
Logger::log(LogLvl::trace, fmt, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void log_dbg(std::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
Logger::log(LogLvl::debug, fmt, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void log_inf(std::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
Logger::log(LogLvl::info, fmt, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void log_wrn(std::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
Logger::log(LogLvl::warn, fmt, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void log_err(std::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
Logger::log(LogLvl::error, fmt, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void log_crt(std::format_string<Args...> fmt, Args &&...args)
|
||||||
|
{
|
||||||
|
Logger::log(LogLvl::critical, fmt, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <engine/layer/layer.hpp>
|
#include <engine/layer/layer.hpp>
|
||||||
#include <engine/time/timer.hpp>
|
#include <engine/time/timer.hpp>
|
||||||
#include <engine/user_interface/user_interface.hpp>
|
#include <engine/user_interface/user_interface.hpp>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
@ -22,7 +23,6 @@ Application::Application()
|
||||||
lt_assert(!s_context, "Repeated singleton construction");
|
lt_assert(!s_context, "Repeated singleton construction");
|
||||||
s_context = this;
|
s_context = this;
|
||||||
|
|
||||||
m_logger = logger::create();
|
|
||||||
log_debug_data();
|
log_debug_data();
|
||||||
|
|
||||||
m_instrumentor = Instrumentor::create();
|
m_instrumentor = Instrumentor::create();
|
||||||
|
@ -38,8 +38,8 @@ Application::Application()
|
||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
{
|
{
|
||||||
lt_log(trace, "Application::~Application()");
|
log_trc("Application::~Application()");
|
||||||
m_instrumentor->end_session(); // ProfileResults_Termination //
|
m_instrumentor->end_session();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::game_loop()
|
void Application::game_loop()
|
||||||
|
@ -48,14 +48,13 @@ void Application::game_loop()
|
||||||
lt_assert(!m_layer_stack->is_empty(), "layer_stack is empty");
|
lt_assert(!m_layer_stack->is_empty(), "layer_stack is empty");
|
||||||
|
|
||||||
// log debug data
|
// log debug data
|
||||||
m_logger->log_debug_data();
|
|
||||||
m_window->get_graphics_context()->log_debug_data();
|
m_window->get_graphics_context()->log_debug_data();
|
||||||
m_window->get_graphics_context()->get_user_interface()->log_debug_data();
|
m_window->get_graphics_context()->get_user_interface()->log_debug_data();
|
||||||
|
|
||||||
// reveal window
|
// reveal window
|
||||||
m_window->set_visibility(true);
|
m_window->set_visibility(true);
|
||||||
|
|
||||||
m_instrumentor->end_session(); // ProfileResults_GameLoop //
|
m_instrumentor->end_session();
|
||||||
m_instrumentor->begin_session("Logs/ProfileResults_GameLoop.json");
|
m_instrumentor->begin_session("Logs/ProfileResults_GameLoop.json");
|
||||||
|
|
||||||
/* game loop */
|
/* game loop */
|
||||||
|
@ -102,7 +101,7 @@ void Application::game_loop()
|
||||||
delta_timer.update();
|
delta_timer.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_instrumentor->end_session(); // ProfileResults_GameLoop //
|
m_instrumentor->end_session();
|
||||||
m_instrumentor->begin_session("Logs/ProfileResults_Termination.json");
|
m_instrumentor->begin_session("Logs/ProfileResults_Termination.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,25 +128,30 @@ void Application::on_event(const Event &event)
|
||||||
{
|
{
|
||||||
m_input->on_event(event);
|
m_input->on_event(event);
|
||||||
|
|
||||||
if (!m_input->is_receiving_game_events()) // return if the event is an input event and
|
if (!m_input->is_receiving_game_events())
|
||||||
// 'Input' has disabled the game events
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* layers */
|
for (auto &it : std::ranges::reverse_view(*m_layer_stack))
|
||||||
for (auto it = m_layer_stack->rbegin(); it != m_layer_stack->rend(); it++)
|
{
|
||||||
if ((*it)->on_event(event))
|
if (it->on_event(event))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Application::log_debug_data()
|
void Application::log_debug_data()
|
||||||
{
|
{
|
||||||
// #todo: log more information
|
// #todo: log more information
|
||||||
lt_log(info, "________________________________________");
|
log_inf("________________________________________");
|
||||||
lt_log(info, "Platform::");
|
log_inf("Platform::");
|
||||||
lt_log(info, " OS: {}", LT_BUILD_PLATFORM);
|
log_inf(" Platform name: {}", constants::platform_name);
|
||||||
lt_log(info, " DIR: {}", std::filesystem::current_path().generic_string());
|
log_inf(" Platform identifier: {}", std::to_underlying(constants::platform));
|
||||||
lt_log(info, "________________________________________");
|
log_inf(" CWD: {}", std::filesystem::current_path().generic_string());
|
||||||
|
log_inf("________________________________________");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -10,25 +10,25 @@ namespace Light {
|
||||||
|
|
||||||
FailedAssertion::FailedAssertion(const char *file, int line)
|
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)
|
glException::glException(unsigned int source, unsigned int type, unsigned int id, const char *msg)
|
||||||
{
|
{
|
||||||
// #todo: improve
|
// #todo: improve
|
||||||
lt_log(critical, "________________________________________");
|
log_crt("________________________________________");
|
||||||
lt_log(critical, "glException::glException::");
|
log_crt("glException::glException::");
|
||||||
// lt_log(critical, " Severity: {}",
|
// log_crt(" Severity: {}",
|
||||||
// Stringifier::glDebugMsgSeverity(GL_DEBUG_SEVERITY_HIGH));
|
// Stringifier::glDebugMsgSeverity(GL_DEBUG_SEVERITY_HIGH));
|
||||||
lt_log(critical, " Source : {}", Stringifier::glDebugMsgSource(source));
|
log_crt(" Source : {}", Stringifier::glDebugMsgSource(source));
|
||||||
lt_log(critical, " Type : {}", Stringifier::glDebugMsgType(type));
|
log_crt(" Type : {}", Stringifier::glDebugMsgType(type));
|
||||||
lt_log(critical, " ID : {}", id);
|
log_crt(" ID : {}", id);
|
||||||
// lt_log(critical, " Vendor : {}", glGetString(GL_VENDOR));
|
// log_crt(" Vendor : {}", glGetString(GL_VENDOR));
|
||||||
// lt_log(critical, " renderer: {}", glGetString(GL_RENDERER));
|
// log_crt(" renderer: {}", glGetString(GL_RENDERER));
|
||||||
// lt_log(critical, " Version : {}", glGetString(GL_VERSION));
|
// log_crt(" Version : {}", glGetString(GL_VERSION));
|
||||||
// lt_log(critical, " critical, SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
// log_crt(" critical, SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||||
lt_log(critical, " {}", msg);
|
log_crt(" {}", msg);
|
||||||
lt_log(critical, "________________________________________");
|
log_crt("________________________________________");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
|
@ -46,11 +46,11 @@ dxException::dxException(long hr, const char *file, int line)
|
||||||
);
|
);
|
||||||
|
|
||||||
// #todo: improve
|
// #todo: improve
|
||||||
lt_log(critical, "________________________________________");
|
log_crt("________________________________________");
|
||||||
lt_log(critical, "dxException::dxException::");
|
log_crt("dxException::dxException::");
|
||||||
lt_log(critical, " File: {}, Line: {}", file, line);
|
log_crt(" File: {}, Line: {}", file, line);
|
||||||
lt_log(critical, " {}", message);
|
log_crt(" {}", message);
|
||||||
lt_log(critical, "________________________________________");
|
log_crt("________________________________________");
|
||||||
|
|
||||||
LocalFree(message);
|
LocalFree(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ void Instrumentor::begin_session_impl(const std::string &outputPath)
|
||||||
void Instrumentor::end_session_impl()
|
void Instrumentor::end_session_impl()
|
||||||
{
|
{
|
||||||
if (m_current_session_count == 0u)
|
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;
|
m_current_session_count = 0u;
|
||||||
|
|
||||||
|
|
|
@ -1,54 +1,21 @@
|
||||||
#include <engine/debug/logger.hpp>
|
#include <engine/debug/logger.hpp>
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace Light {
|
Logger::Logger(): spd_logger(spdlog::stdout_color_mt("Logger"))
|
||||||
|
|
||||||
logger *logger::s_context = nullptr;
|
|
||||||
|
|
||||||
auto logger::create() -> Scope<logger>
|
|
||||||
{
|
{
|
||||||
return make_scope<logger>(new logger());
|
spd_logger->set_pattern("%^%v%$");
|
||||||
|
spd_logger->set_level(spdlog::level::level_enum::trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger::logger()
|
Logger::~Logger()
|
||||||
: m_engine_logger(nullptr)
|
|
||||||
, m_file_logger(nullptr)
|
|
||||||
, m_log_file_path(LT_LOG_FILE_LOCATION)
|
|
||||||
{
|
{
|
||||||
lt_assert(!s_context, "An instance of 'logger' already exists, do not construct this class!");
|
spdlog::drop_all();
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger::log_debug_data()
|
auto Logger::instance() -> Logger &
|
||||||
{
|
{
|
||||||
// #todo: improve
|
static auto logger = Logger {};
|
||||||
lt_log(info, "________________________________________");
|
return logger;
|
||||||
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, "________________________________________");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
|
||||||
|
|
|
@ -23,14 +23,15 @@ auto Framebuffer::create(
|
||||||
lt_win(return create_ref<dxFramebuffer>(
|
lt_win(return create_ref<dxFramebuffer>(
|
||||||
specification,
|
specification,
|
||||||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||||
);)
|
););
|
||||||
|
|
||||||
default
|
default:
|
||||||
: lt_assert(
|
lt_assert(
|
||||||
false,
|
false,
|
||||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||||
);
|
);
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
|
||||||
// advance
|
// advance
|
||||||
if (!m_quad_renderer.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();
|
flush_scene();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,11 +155,7 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture)
|
||||||
// advance
|
// advance
|
||||||
if (!m_texture_renderer.advance())
|
if (!m_texture_renderer.advance())
|
||||||
{
|
{
|
||||||
lt_log(
|
log_wrn("Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES);
|
||||||
warn,
|
|
||||||
"Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}",
|
|
||||||
LT_MAX_TEXTURE_RENDERER_VERTICES
|
|
||||||
);
|
|
||||||
flush_scene();
|
flush_scene();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,11 +197,7 @@ void Renderer::draw_quad_impl(
|
||||||
// advance
|
// advance
|
||||||
if (!m_tinted_texture_renderer.advance())
|
if (!m_tinted_texture_renderer.advance())
|
||||||
{
|
{
|
||||||
lt_log(
|
log_wrn("Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES);
|
||||||
warn,
|
|
||||||
"Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}",
|
|
||||||
LT_MAX_TEXTURE_RENDERER_VERTICES
|
|
||||||
);
|
|
||||||
flush_scene();
|
flush_scene();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ auto QuadRendererProgram::advance() -> bool
|
||||||
|
|
||||||
if (m_map_current >= m_map_end)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ auto TextureRendererProgram::advance() -> bool
|
||||||
{
|
{
|
||||||
if (m_map_current + 4 >= m_map_end)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ auto TintedTextureRendererProgram::advance() -> bool
|
||||||
|
|
||||||
if (m_map_current >= m_map_end)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@ auto Shader::create(
|
||||||
vertexFile,
|
vertexFile,
|
||||||
pixelFile,
|
pixelFile,
|
||||||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||||
);)
|
););
|
||||||
|
|
||||||
default
|
default:
|
||||||
: lt_assert(
|
lt_assert(
|
||||||
false,
|
false,
|
||||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||||
|
|
|
@ -36,7 +36,7 @@ void LayerStack::attach_layer_impl(Layer *layer)
|
||||||
m_begin = m_layers.begin();
|
m_begin = m_layers.begin();
|
||||||
m_end = m_layers.end();
|
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)
|
void LayerStack::detach_layer_impl(Layer *layer)
|
||||||
|
@ -46,7 +46,7 @@ void LayerStack::detach_layer_impl(Layer *layer)
|
||||||
m_begin = m_layers.begin();
|
m_begin = m_layers.begin();
|
||||||
m_end = m_layers.end();
|
m_end = m_layers.end();
|
||||||
|
|
||||||
lt_log(trace, "Detached [{}]", layer->get_name());
|
log_trc("Detached [{}]", layer->get_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -118,7 +118,7 @@ dxIndexBuffer::dxIndexBuffer(
|
||||||
// check
|
// check
|
||||||
if (count % 6 != 0)
|
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(
|
lt_log(
|
||||||
warn,
|
warn,
|
||||||
"Adding {} to 'count' -> {}",
|
"Adding {} to 'count' -> {}",
|
||||||
|
|
|
@ -78,7 +78,7 @@ void dxFramebuffer::bind_as_target(const glm::vec4 &clearColor)
|
||||||
|
|
||||||
void dxFramebuffer::bind_as_resource()
|
void dxFramebuffer::bind_as_resource()
|
||||||
{
|
{
|
||||||
lt_log(err, "NO_IMPLEMENT");
|
log_err("NO_IMPLEMENT");
|
||||||
}
|
}
|
||||||
|
|
||||||
void dxFramebuffer::resize(const glm::uvec2 &size)
|
void dxFramebuffer::resize(const glm::uvec2 &size)
|
||||||
|
|
|
@ -156,10 +156,10 @@ void dxGraphicsContext::log_debug_data()
|
||||||
DXGIAdapter->release();
|
DXGIAdapter->release();
|
||||||
|
|
||||||
// #todo: log more information
|
// #todo: log more information
|
||||||
lt_log(info, "________________________________________");
|
log_inf("________________________________________");
|
||||||
lt_log(info, "dxGraphicsContext:");
|
log_inf("dxGraphicsContext:");
|
||||||
lt_log(info, " renderer: {}", adapterDesc);
|
log_inf(" renderer: {}", adapterDesc);
|
||||||
lt_log(info, "________________________________________");
|
log_inf("________________________________________");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -15,8 +15,8 @@ void dxRenderCommand::swap_buffers()
|
||||||
{
|
{
|
||||||
if (hr == DXGI_ERROR_DEVICE_REMOVED)
|
if (hr == DXGI_ERROR_DEVICE_REMOVED)
|
||||||
{
|
{
|
||||||
lt_log(critical, "dxRenderCommand::swap_buffers: DeviceRemoved:");
|
log_crt("dxRenderCommand::swap_buffers: DeviceRemoved:");
|
||||||
lt_log(critical, " {}", m_context->get_device()->GetDeviceRemovedReason());
|
log_crt(" {}", m_context->get_device()->GetDeviceRemovedReason());
|
||||||
throw dxException(hr, __FILE__, __LINE__);
|
throw dxException(hr, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,12 @@ void dxUserInterface::end()
|
||||||
void dxUserInterface::log_debug_data()
|
void dxUserInterface::log_debug_data()
|
||||||
{
|
{
|
||||||
// #todo: improve
|
// #todo: improve
|
||||||
lt_log(info, "________________________________________");
|
log_inf("________________________________________");
|
||||||
lt_log(info, "UserInterface::");
|
log_inf("UserInterface::");
|
||||||
lt_log(info, " API : ImGui");
|
log_inf(" API : ImGui");
|
||||||
lt_log(info, " Version: {}", ImGui::GetVersion());
|
log_inf(" Version: {}", ImGui::GetVersion());
|
||||||
lt_log(info, " GraphicsAPI : DirectX");
|
log_inf(" GraphicsAPI : DirectX");
|
||||||
lt_log(info, "________________________________________");
|
log_inf("________________________________________");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -80,13 +80,8 @@ glIndexBuffer::glIndexBuffer(unsigned int *indices, unsigned int count): m_buffe
|
||||||
// check
|
// check
|
||||||
if (count % 6 != 0)
|
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(
|
log_wrn("Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6)));
|
||||||
warn,
|
|
||||||
"Adding {} to 'count' -> {}",
|
|
||||||
(6 - (count % 6)),
|
|
||||||
count + (6 - (count % 6))
|
|
||||||
);
|
|
||||||
count = count + (6 - (count % 6));
|
count = count + (6 - (count % 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ void glFramebuffer::bind_as_target(const glm::vec4 &clearColor)
|
||||||
|
|
||||||
void glFramebuffer::bind_as_resource()
|
void glFramebuffer::bind_as_resource()
|
||||||
{
|
{
|
||||||
lt_log(err, "NO_IMPLEMENT!");
|
log_err("NO_IMPLEMENT!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void glFramebuffer::resize(const glm::uvec2 &size)
|
void glFramebuffer::resize(const glm::uvec2 &size)
|
||||||
|
|
|
@ -16,13 +16,8 @@ namespace Light {
|
||||||
|
|
||||||
glGraphicsContext::glGraphicsContext(GLFWwindow *windowHandle): m_window_handle(windowHandle)
|
glGraphicsContext::glGraphicsContext(GLFWwindow *windowHandle): m_window_handle(windowHandle)
|
||||||
{
|
{
|
||||||
// set 'GraphicsAPI'
|
|
||||||
m_graphics_api = GraphicsAPI::OpenGL;
|
m_graphics_api = GraphicsAPI::OpenGL;
|
||||||
|
|
||||||
// make context current
|
|
||||||
glfwMakeContextCurrent(windowHandle);
|
glfwMakeContextCurrent(windowHandle);
|
||||||
|
|
||||||
// load opengl (glad)
|
|
||||||
lt_assert(gladLoadGL(glfwGetProcAddress), "Failed to initialize opengl (glad)");
|
lt_assert(gladLoadGL(glfwGetProcAddress), "Failed to initialize opengl (glad)");
|
||||||
|
|
||||||
set_debug_message_callback();
|
set_debug_message_callback();
|
||||||
|
@ -30,13 +25,10 @@ glGraphicsContext::glGraphicsContext(GLFWwindow *windowHandle): m_window_handle(
|
||||||
|
|
||||||
void glGraphicsContext::log_debug_data()
|
void glGraphicsContext::log_debug_data()
|
||||||
{
|
{
|
||||||
// #todo: log more information
|
log_inf("________________________________________");
|
||||||
lt_log(info, "________________________________________");
|
log_inf("GraphicsContext::");
|
||||||
lt_log(info, "GraphicsContext::");
|
log_inf(" API : OpenGL");
|
||||||
lt_log(info, " API : OpenGL");
|
log_inf("________________________________________");
|
||||||
// lt_log(info, " Version : {}", glGetString(GL_VERSION));
|
|
||||||
// lt_log(info, " renderer: {}", glGetString(GL_RENDERER));
|
|
||||||
lt_log(info, "________________________________________");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void glGraphicsContext::set_debug_message_callback()
|
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_MEDIUM:
|
||||||
case GL_DEBUG_SEVERITY_LOW:
|
case GL_DEBUG_SEVERITY_LOW:
|
||||||
lt_log(warn,
|
log_wrn(
|
||||||
"glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
"glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||||
Stringifier::glDebugMsgSeverity(severity),
|
Stringifier::glDebugMsgSeverity(severity),
|
||||||
Stringifier::glDebugMsgSource(source),
|
Stringifier::glDebugMsgSource(source),
|
||||||
Stringifier::glDebugMsgType(type),
|
Stringifier::glDebugMsgType(type),
|
||||||
id);
|
id
|
||||||
lt_log(warn, " {}", message);
|
);
|
||||||
|
log_wrn(" {}", message);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||||
lt_log(trace,
|
log_wrn(
|
||||||
"Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
"Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||||
Stringifier::glDebugMsgSeverity(severity),
|
Stringifier::glDebugMsgSeverity(severity),
|
||||||
Stringifier::glDebugMsgSource(source),
|
Stringifier::glDebugMsgSource(source),
|
||||||
Stringifier::glDebugMsgType(type),
|
Stringifier::glDebugMsgType(type),
|
||||||
id);
|
id
|
||||||
lt_log(trace, " {}", message);
|
);
|
||||||
|
log_trc(" {}", message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,8 +61,8 @@ void glShader::un_bind()
|
||||||
// // log error
|
// // log error
|
||||||
// if (result.GetCompilationStatus() != shaderc_compilation_status_success)
|
// if (result.GetCompilationStatus() != shaderc_compilation_status_success)
|
||||||
// {
|
// {
|
||||||
// lt_log(err, "Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ?
|
// log_err("Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ?
|
||||||
// "vertex" : "pixel", file.GetPath()); lt_log(err, " {}", result.GetErrorMessage());
|
// "vertex" : "pixel", file.GetPath()); log_err(" {}", result.GetErrorMessage());
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// return result;
|
// return result;
|
||||||
|
@ -94,8 +94,7 @@ auto glShader::compile_shader(std::string source, Shader::Stage stage) -> unsign
|
||||||
auto *errorLog = (char *)alloca(logLength);
|
auto *errorLog = (char *)alloca(logLength);
|
||||||
glGetShaderInfoLog(shader, logLength, &logLength, &errorLog[0]);
|
glGetShaderInfoLog(shader, logLength, &logLength, &errorLog[0]);
|
||||||
|
|
||||||
lt_log(
|
log_err(
|
||||||
err,
|
|
||||||
"glShader::glShader: failed to compile {} shader:\n {}",
|
"glShader::glShader: failed to compile {} shader:\n {}",
|
||||||
stage == Shader::Stage::VERTEX ? "Vertex" : "Pixel",
|
stage == Shader::Stage::VERTEX ? "Vertex" : "Pixel",
|
||||||
errorLog
|
errorLog
|
||||||
|
@ -114,7 +113,7 @@ auto glShader::compile_shader(std::string source, Shader::Stage stage) -> unsign
|
||||||
char *infoLog = (char *)alloca(logLength);
|
char *infoLog = (char *)alloca(logLength);
|
||||||
glGetShaderInfoLog(shader, logLength, &logLength, &infoLog[0]);
|
glGetShaderInfoLog(shader, logLength, &logLength, &infoLog[0]);
|
||||||
|
|
||||||
lt_log(warn, infoLog);
|
log_wrn("Shader info: {}", infoLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,12 +51,12 @@ void glUserInterface::end()
|
||||||
void glUserInterface::log_debug_data()
|
void glUserInterface::log_debug_data()
|
||||||
{
|
{
|
||||||
// #todo: improve
|
// #todo: improve
|
||||||
lt_log(info, "________________________________________");
|
log_inf("________________________________________");
|
||||||
lt_log(info, "UserInterface::");
|
log_inf("UserInterface::");
|
||||||
lt_log(info, " API : ImGui");
|
log_inf(" API : ImGui");
|
||||||
lt_log(info, " Version: {}", ImGui::GetVersion());
|
log_inf(" Version: {}", ImGui::GetVersion());
|
||||||
lt_log(info, " GraphicsAPI : OpenGL");
|
log_inf(" GraphicsAPI : OpenGL");
|
||||||
lt_log(info, "________________________________________");
|
log_inf("________________________________________");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -93,12 +93,12 @@ auto Scene::get_entity_by_tag(const std::string &tag) -> Entity
|
||||||
});
|
});
|
||||||
|
|
||||||
if (entity.is_valid())
|
if (entity.is_valid())
|
||||||
return entity;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
lt_assert("Scene::get_entity_by_tag: failed to find entity by tag: {}", tag);
|
return entity;
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lt_assert(false, "Scene::get_entity_by_tag: failed to find entity by tag: {}", tag);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Scene::create_entity_with_uuid(
|
auto Scene::create_entity_with_uuid(
|
||||||
|
|
|
@ -39,9 +39,9 @@ auto FileManager::read_text_file(const std::string &path) -> BasicFileHandle
|
||||||
// check
|
// check
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
lt_log(warn, "Failed to load text file: {}", path);
|
log_wrn("Failed to load text file: {}", path);
|
||||||
file.close();
|
file.close();
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch file size
|
// fetch file size
|
||||||
|
@ -50,7 +50,9 @@ auto FileManager::read_text_file(const std::string &path) -> BasicFileHandle
|
||||||
file.seekg(0, std::ios::beg);
|
file.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
if (!size)
|
if (!size)
|
||||||
lt_log(warn, "Empty text file: {}", path);
|
{
|
||||||
|
log_wrn("Empty text file: {}", path);
|
||||||
|
}
|
||||||
|
|
||||||
// read file
|
// read file
|
||||||
auto *data = new uint8_t[size];
|
auto *data = new uint8_t[size];
|
||||||
|
@ -75,15 +77,18 @@ auto FileManager::read_image_file(const std::string &path, int32_t desiredCompon
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (!pixels)
|
if (!pixels)
|
||||||
lt_log(warn, "Failed to load image file: <{}>", path);
|
{
|
||||||
|
log_wrn("Failed to load image file: <{}>", path);
|
||||||
|
}
|
||||||
else if (fetchedComponents != desiredComponents)
|
else if (fetchedComponents != desiredComponents)
|
||||||
lt_log(
|
{
|
||||||
warn,
|
log_wrn(
|
||||||
"Mismatch of fetched/desired components: <{}> ({}/{})",
|
"Mismatch of fetched/desired components: <{}> ({}/{})",
|
||||||
name + '.' + extension,
|
name + '.' + extension,
|
||||||
fetchedComponents,
|
fetchedComponents,
|
||||||
desiredComponents
|
desiredComponents
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return ImageFileHandle(
|
return ImageFileHandle(
|
||||||
pixels,
|
pixels,
|
||||||
|
|
|
@ -77,7 +77,7 @@ void ResourceManager::release_texture_impl(const std::string &name)
|
||||||
{
|
{
|
||||||
if (!m_textures[name])
|
if (!m_textures[name])
|
||||||
{
|
{
|
||||||
lt_log(warn, "Failed to find texture named: {}", name);
|
log_wrn("Failed to find texture named: {}", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,9 @@ void SceneSerializer::serialize(const std::string &filePath)
|
||||||
{
|
{
|
||||||
auto entity = Entity { static_cast<entt::entity>(entityID), m_scene.get() };
|
auto entity = Entity { static_cast<entt::entity>(entityID), m_scene.get() };
|
||||||
if (!entity.is_valid())
|
if (!entity.is_valid())
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
serialize_entity(out, entity);
|
serialize_entity(out, entity);
|
||||||
};
|
};
|
||||||
|
@ -98,30 +100,32 @@ void SceneSerializer::serialize(const std::string &filePath)
|
||||||
|
|
||||||
auto fout = std::ofstream { filePath };
|
auto fout = std::ofstream { filePath };
|
||||||
if (!fout.is_open())
|
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();
|
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 {};
|
auto ss = std::stringstream {};
|
||||||
ss << stream.rdbuf();
|
ss << stream.rdbuf();
|
||||||
|
|
||||||
auto data = YAML::Load(ss.str());
|
auto data = YAML::Load(ss.str());
|
||||||
if (!data["Scene"])
|
if (!data["Scene"])
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto sceneName = data["Scene"].as<std::string>();
|
auto sceneName = data["Scene"].as<std::string>();
|
||||||
lt_log(trace, "Deserializing scene: '{}'", sceneName);
|
log_trc("Deserializing scene: '{}'", sceneName);
|
||||||
|
|
||||||
auto entities = data["Entities"];
|
auto entities = data["Entities"];
|
||||||
if (entities)
|
if (entities)
|
||||||
{
|
{
|
||||||
/* #TEMPORARY SOLUTION# */
|
|
||||||
auto texturePaths = std::unordered_set<std::string> {};
|
auto texturePaths = std::unordered_set<std::string> {};
|
||||||
/* #TEMPORARY SOLUTION# */
|
|
||||||
|
|
||||||
for (auto entity : entities)
|
for (auto entity : entities)
|
||||||
{
|
{
|
||||||
|
@ -130,14 +134,16 @@ auto SceneSerializer::deserialize(const std::string &filePath) -> bool
|
||||||
auto name = std::string {};
|
auto name = std::string {};
|
||||||
auto tagComponent = entity["TagComponent"];
|
auto tagComponent = entity["TagComponent"];
|
||||||
if (tagComponent)
|
if (tagComponent)
|
||||||
|
{
|
||||||
name = tagComponent["Tag"].as<std::string>();
|
name = tagComponent["Tag"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
lt_log(trace, "Deserialized entity '{}' : '{}'", uuid, name);
|
log_trc("Deserialized entity '{}' : '{}'", uuid, name);
|
||||||
|
|
||||||
auto deserializedEntity = m_scene->create_entity_with_uuid(name, uuid);
|
auto deserializedEntity = m_scene->create_entity_with_uuid(name, uuid);
|
||||||
|
|
||||||
auto gg = deserializedEntity.get_component<TagComponent>();
|
auto gg = deserializedEntity.get_component<TagComponent>();
|
||||||
lt_log(trace, gg.tag);
|
log_trc("tag: {}", gg.tag);
|
||||||
auto transformComponent = entity["TransformComponent"];
|
auto transformComponent = entity["TransformComponent"];
|
||||||
if (transformComponent)
|
if (transformComponent)
|
||||||
{
|
{
|
||||||
|
@ -217,12 +223,12 @@ auto SceneSerializer::deserialize(const std::string &filePath) -> bool
|
||||||
|
|
||||||
void SceneSerializer::serialize_binary(const std::string &filePath)
|
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
|
auto SceneSerializer::deserialize_binary(const std::string &filePath) -> bool
|
||||||
{
|
{
|
||||||
lt_log(err, "NO_IMPLEMENT");
|
log_err("NO_IMPLEMENT");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ void AssetBrowserPanel::on_user_interface_update()
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
auto serializer = SceneSerializer { m_active_scene };
|
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());
|
serializer.deserialize(path.string());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue