Compare commits

...

2 commits

27 changed files with 71 additions and 52 deletions

View file

@ -1,3 +1,3 @@
add_library_module(lt_debug)
target_link_libraries(lt_debug INTERFACE logger)
target_precompile_headers(lt_debug INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp)
add_library_module(lt_debug instrumentor.cpp)
target_link_libraries(lt_debug PUBLIC logger)
target_precompile_headers(lt_debug PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp)

View file

@ -12,13 +12,25 @@ struct FailedAssertion: std::exception
}
};
#define lt_assert(x, ...) \
{ \
if (!(x)) \
{ \
log_crt(__VA_ARGS__); \
throw ::lt::FailedAssertion(__FILE__, __LINE__); \
} \
template<typename Expression_T, typename... Args>
constexpr void ensure(Expression_T &&expression, std::format_string<Args...> fmt, Args &&...args)
{
if (!static_cast<bool>(expression))
{
Logger::log(LogLvl::critical, fmt, std::forward<Args>(args)...);
throw ::lt::FailedAssertion(__FILE__, __LINE__);
}
}
template<typename Expression_T>
constexpr void ensure(Expression_T &&expression, const char *message)
{
if (!static_cast<bool>(expression))
{
Logger::log(LogLvl::critical, message);
throw ::lt::FailedAssertion(__FILE__, __LINE__);
}
}
} // namespace lt

View file

@ -1,4 +1,5 @@
#include <debug/instrumentor.hpp>
#include <logger/logger.hpp>
namespace lt {

View file

@ -90,7 +90,7 @@ auto Scene::get_entity_by_tag(const std::string &tag) -> Entity
return entity;
}
lt_assert(false, "Scene::get_entity_by_tag: failed to find entity by tag: {}", tag);
ensure(false, "Scene::get_entity_by_tag: failed to find entity by tag: {}", tag);
return {};
}

View file

@ -12,8 +12,8 @@ try
application = lt::create_application();
lt_assert(application, "Failed to create application");
lt_assert(application->sanity_check(), "Failed to verify the sanity of the application");
lt::ensure(application, "Failed to create application");
lt::ensure(application->sanity_check(), "Failed to verify the sanity of the application");
application->game_loop();

View file

@ -22,7 +22,7 @@ Application *Application::s_instance = nullptr;
Application::Application(): m_window(nullptr)
{
lt_assert(!s_instance, "Application constructed twice");
ensure(!s_instance, "Application constructed twice");
s_instance = this;
m_window = Window::create([this](auto &&PH1) { on_event(std::forward<decltype(PH1)>(PH1)); });
@ -62,7 +62,7 @@ Application::Application(): m_window(nullptr)
"TEXTURE_SHADER"),
}
);
lt_assert(m_graphics_context, "lWindow::lWindow: failed to create 'GraphicsContext'");
ensure(m_graphics_context, "lWindow::lWindow: failed to create 'GraphicsContext'");
m_user_interface = UserInterface::create(
(GLFWwindow *)m_window->get_handle(),
@ -173,13 +173,13 @@ void Application::on_event(const Event &event)
[[nodiscard]] auto Application::sanity_check() const -> bool
{
log_inf("Checking application sanity...");
lt_assert(s_instance, "Application not constructed!?");
lt_assert(m_window, "Window is not initialized");
lt_assert(m_user_interface, "User interface is not initialized");
lt_assert(m_graphics_context, "Graphics context is not initialized");
lt_assert(m_renderer, "Renderer is not initialized");
lt_assert(m_layer_stack, "Layer_stack is not initialized");
lt_assert(!m_layer_stack->is_empty(), "Layer_stack is empty");
ensure(s_instance, "Application not constructed!?");
ensure(m_window, "Window is not initialized");
ensure(m_user_interface, "User interface is not initialized");
ensure(m_graphics_context, "Graphics context is not initialized");
ensure(m_renderer, "Renderer is not initialized");
ensure(m_layer_stack, "Layer_stack is not initialized");
ensure(!m_layer_stack->is_empty(), "Layer_stack is empty");
log_inf("Logging application state...");
this->log_debug_data();

View file

@ -40,7 +40,7 @@ auto Layer::on_event(const Event &event) -> bool
case EventType::WindowGainFocus:
return on_window_gain_focus(dynamic_cast<const WindowGainFocusEvent &>(event));
default: lt_assert(false, "Invalid event: {}", event.get_info_lt_log());
default: ensure(false, "Invalid event: {}", event.get_info_lt_log());
}
}

View file

@ -53,6 +53,12 @@ public:
);
}
void static log(LogLvl lvl, const char *message)
{
instance().spd_logger->log((spdlog::level::level_enum)lvl, message);
}
private:
Logger();

View file

@ -46,7 +46,7 @@ EditorLayer::EditorLayer(const std::string &name)
else
{
auto serializer = SceneSerializer { m_scene };
lt_assert(serializer.deserialize(m_scene_dir), "Failed to de-serialize: {}", m_scene_dir);
ensure(serializer.deserialize(m_scene_dir), "Failed to de-serialize: {}", m_scene_dir);
// m_camera_entity = m_scene->GetEntityByTag("Game Camera");
}

View file

@ -22,7 +22,7 @@ auto Blender::create(const Ref<SharedContext> & /*sharedContext*/) -> Scope<Blen
);)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())

View file

@ -30,7 +30,7 @@ auto ConstantBuffer::create(
);)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
@ -59,7 +59,7 @@ auto VertexBuffer::create(
);)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
@ -86,7 +86,7 @@ auto IndexBuffer::create(
);)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())

View file

@ -48,8 +48,8 @@ dxShader::dxShader(
);
// check
lt_assert(!vsErr.Get(), "Vertex shader compile error: {}", (char *)vsErr->GetBufferPointer());
lt_assert(!psErr.Get(), "Pixels shader compile error: {}", (char *)psErr->GetBufferPointer());
ensure(!vsErr.Get(), "Vertex shader compile error: {}", (char *)vsErr->GetBufferPointer());
ensure(!psErr.Get(), "Pixels shader compile error: {}", (char *)psErr->GetBufferPointer());
// create shaders
auto hr = HRESULT {};

View file

@ -28,7 +28,7 @@ dxVertexLayout::dxVertexLayout(
}
auto dxpShader = std::dynamic_pointer_cast<dxShader>(shader);
lt_assert(dxpShader, "Failed to cast 'Shader' to 'dxShader'");
ensure(dxpShader, "Failed to cast 'Shader' to 'dxShader'");
// create input layout (vertex layout)
auto hr = HRESULT {};
@ -88,7 +88,7 @@ auto dxVertexLayout::get_dxgi_format(VertexElementType type) -> DXGI_FORMAT
case lt::VertexElementType::Float3: return DXGI_FORMAT_R32G32B32_FLOAT;
case lt::VertexElementType::Float4: return DXGI_FORMAT_R32G32B32A32_FLOAT;
default: lt_assert(false, "Invalid 'VertexElementType'"); return DXGI_FORMAT_UNKNOWN;
default: ensure(false, "Invalid 'VertexElementType'"); return DXGI_FORMAT_UNKNOWN;
}
}

View file

@ -26,7 +26,7 @@ auto Framebuffer::create(
););
default:
lt_assert(
ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())

View file

@ -85,7 +85,7 @@ void glFramebuffer::resize(const glm::uvec2 &size)
// m_specification.width, m_specification.height); glFramebufferTexture2D(GL_FRAMEBUFFER,
// GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_depth_stencil_attachment_id, 0);
lt_assert(
ensure(
(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE),
"Framebuffer is incomplete"
);

View file

@ -16,7 +16,7 @@ glGraphicsContext::glGraphicsContext(GLFWwindow *windowHandle): m_window_handle(
{
m_graphics_api = GraphicsAPI::OpenGL;
glfwMakeContextCurrent(windowHandle);
lt_assert(gladLoadGL(glfwGetProcAddress), "Failed to initialize opengl (glad)");
ensure(gladLoadGL(glfwGetProcAddress), "Failed to initialize opengl (glad)");
set_debug_message_callback();
}

View file

@ -58,7 +58,7 @@ auto glTexture::get_texture() -> void *
case 3u: return GL_RGB;
case 2u: return GL_RG;
case 1u: return GL_RED;
default: lt_assert(false, "Invalid number of components: {}", num_components);
default: ensure(false, "Invalid number of components: {}", num_components);
}
return {};
@ -73,7 +73,7 @@ auto glTexture::get_texture() -> void *
case 3u: return GL_RGB8;
case 2u: return GL_RG8;
case 1u: return GL_R8;
default: lt_assert(false, "Invalid number of components: {}", num_components);
default: ensure(false, "Invalid number of components: {}", num_components);
}
return {};

View file

@ -12,11 +12,11 @@ glVertexLayout::glVertexLayout(
: m_array_id(NULL)
{
// check
lt_assert(
ensure(
std::dynamic_pointer_cast<glVertexBuffer>(buffer),
"Failed to cast 'VertexBuffer' to 'glVertexBuffer'"
);
lt_assert(!elements.empty(), "'elements' is empty");
ensure(!elements.empty(), "'elements' is empty");
// local
auto elementsDesc = std::vector<glVertexElementDesc> {};
@ -140,7 +140,7 @@ auto glVertexLayout::get_element_desc(VertexElementType type, unsigned int offse
case VertexElementType::Float4:
return { .type = GL_FLOAT, .count = 4u, .typeSize = sizeof(GLfloat), .offset = offset };
default: lt_assert(false, "Invalid 'VertexElementType'"); return {};
default: ensure(false, "Invalid 'VertexElementType'"); return {};
}
}

View file

@ -42,7 +42,7 @@ auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *window_handle) -> Scop
break;)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
// TODO(Light): Stringifier::graphics_api_to_string(api),

View file

@ -24,7 +24,7 @@ auto RenderCommand::create(GLFWwindow *windowHandle, const Ref<SharedContext> &
);)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())

View file

@ -43,7 +43,7 @@ Renderer::Renderer(
, m_target_framebuffer(nullptr)
{
lt_assert(!s_context, "An instance of 'renderer' already exists, do not construct this class!");
ensure(!s_context, "An instance of 'renderer' already exists, do not construct this class!");
s_context = this;
m_view_projection_buffer = ConstantBuffer::create(
@ -151,7 +151,7 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &texture)
{
lt_assert(texture, "Texture passed to renderer::draw_quad_impl");
ensure(texture, "Texture passed to renderer::draw_quad_impl");
texture->bind();
auto map = std::span<TextureRendererProgram::TextureVertexData> {
@ -189,7 +189,7 @@ void Renderer::draw_quad_impl(
const Ref<Texture> &texture
)
{
lt_assert(texture, "Texture passed to renderer::draw_quad_impl");
ensure(texture, "Texture passed to renderer::draw_quad_impl");
texture->bind();
auto map = std::span<TintedTextureRendererProgram::TintedTextureVertexData> {

View file

@ -33,7 +33,7 @@ namespace lt {
););
default:
lt_assert(
ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())

View file

@ -31,7 +31,7 @@ namespace lt {
);)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())

View file

@ -30,7 +30,7 @@ auto VertexLayout::create(
);)
default
: lt_assert(
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())

View file

@ -37,7 +37,7 @@ auto UserInterface::create(GLFWwindow *windowHandle, Ref<SharedContext> sharedCo
case GraphicsAPI::DirectX: lt_win(scopeUserInterface = create_scope<dxUserInterface>();) break;
default:
lt_assert(
ensure(
false,
"UserInterface::create: invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
@ -58,7 +58,7 @@ UserInterface::UserInterface()
)
// NOLINTEND
{
lt_assert(
ensure(
!s_context,
"UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not "
"construct this class!"

View file

@ -21,7 +21,7 @@ lWindow::lWindow(std::function<void(Event &)> callback)
: m_event_callback(std::move(std::move(callback)))
{
// init glfw
lt_assert(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'");
ensure(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'");
// create window
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
@ -30,7 +30,7 @@ lWindow::lWindow(std::function<void(Event &)> callback)
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
m_handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
lt_assert(m_handle, "lWindow::lWindow: failed to create 'GLFWwindow'");
ensure(m_handle, "lWindow::lWindow: failed to create 'GLFWwindow'");
glfwSetWindowUserPointer(m_handle, &m_event_callback);
bind_glfw_events();