refactor: renamed lt_assert to ensure
This commit is contained in:
		
							parent
							
								
									e1fdeb2692
								
							
						
					
					
						commit
						0f3639e401
					
				
					 26 changed files with 48 additions and 47 deletions
				
			
		|  | @ -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) | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ struct FailedAssertion: std::exception | |||
| 
 | ||||
| 
 | ||||
| template<typename Expression_T, typename... Args> | ||||
| constexpr void lt_assert(Expression_T &&expression, std::format_string<Args...> fmt, Args &&...args) | ||||
| constexpr void ensure(Expression_T &&expression, std::format_string<Args...> fmt, Args &&...args) | ||||
| { | ||||
| 	if (!static_cast<bool>(expression)) | ||||
| 	{ | ||||
|  | @ -24,7 +24,7 @@ constexpr void lt_assert(Expression_T &&expression, std::format_string<Args...> | |||
| } | ||||
| 
 | ||||
| template<typename Expression_T> | ||||
| constexpr void lt_assert(Expression_T &&expression, const char *message) | ||||
| constexpr void ensure(Expression_T &&expression, const char *message) | ||||
| { | ||||
| 	if (!static_cast<bool>(expression)) | ||||
| 	{ | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| #include <debug/instrumentor.hpp> | ||||
| #include <logger/logger.hpp> | ||||
| 
 | ||||
| namespace lt { | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 {}; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,8 +12,8 @@ try | |||
| 
 | ||||
| 	application = lt::create_application(); | ||||
| 
 | ||||
| 	lt::lt_assert(application, "Failed to create application"); | ||||
| 	lt::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(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -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()); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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");
 | ||||
| 	} | ||||
|  |  | |||
|  | @ -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()) | ||||
|  |  | |||
|  | @ -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()) | ||||
|  |  | |||
|  | @ -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 {}; | ||||
|  |  | |||
|  | @ -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; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ auto Framebuffer::create( | |||
| 		);); | ||||
| 
 | ||||
| 	default: | ||||
| 		lt_assert( | ||||
| 		ensure( | ||||
| 		    false, | ||||
| 		    "Invalid/unsupported 'GraphicsAPI' {}", | ||||
| 		    static_cast<uint32_t>(GraphicsContext::get_graphics_api()) | ||||
|  |  | |||
|  | @ -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" | ||||
| 	); | ||||
|  |  | |||
|  | @ -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(); | ||||
| } | ||||
|  |  | |||
|  | @ -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 {}; | ||||
|  |  | |||
|  | @ -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 {}; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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),
 | ||||
|  |  | |||
|  | @ -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()) | ||||
|  |  | |||
|  | @ -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> { | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ namespace lt { | |||
| 		);); | ||||
| 
 | ||||
| 	default: | ||||
| 		lt_assert( | ||||
| 		ensure( | ||||
| 		    false, | ||||
| 		    "Invalid/unsupported 'GraphicsAPI' {}", | ||||
| 		    static_cast<uint32_t>(GraphicsContext::get_graphics_api()) | ||||
|  |  | |||
|  | @ -31,7 +31,7 @@ namespace lt { | |||
| 		);) | ||||
| 
 | ||||
| 		    default | ||||
| 		    : lt_assert( | ||||
| 		    : ensure( | ||||
| 		          false, | ||||
| 		          "Invalid/unsupported 'GraphicsAPI' {}", | ||||
| 		          static_cast<uint32_t>(GraphicsContext::get_graphics_api()) | ||||
|  |  | |||
|  | @ -30,7 +30,7 @@ auto VertexLayout::create( | |||
| 		);) | ||||
| 
 | ||||
| 		    default | ||||
| 		    : lt_assert( | ||||
| 		    : ensure( | ||||
| 		          false, | ||||
| 		          "Invalid/unsupported 'GraphicsAPI' {}", | ||||
| 		          static_cast<uint32_t>(GraphicsContext::get_graphics_api()) | ||||
|  |  | |||
|  | @ -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!" | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue