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