From 8b0a7f2622e713a64f65bea0f61b448256a0df81 Mon Sep 17 00:00:00 2001 From: Anish Bhobe Date: Sat, 15 Jun 2024 17:54:30 +0200 Subject: [PATCH] Format Code and cleanup. --- aster_core/constants.h | 11 +++-------- aster_core/glfw_context.h | 5 +++-- aster_core/global.h | 2 +- aster_core/window.cpp | 32 +++++++++++++------------------- aster_core/window.h | 19 +++++++++---------- 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/aster_core/constants.h b/aster_core/constants.h index 63d298d..d3fbdc0 100644 --- a/aster_core/constants.h +++ b/aster_core/constants.h @@ -93,7 +93,7 @@ using glm::mat2; using glm::mat3; using glm::mat4; -constexpr const char *PROJECT_NAME = "Aster"; +constexpr auto *PROJECT_NAME = "Aster"; struct Version { u32 major; @@ -103,13 +103,8 @@ struct Version { constexpr Version VERSION = { .major = 0, - .minor = 0, - .patch = 1, -}; - -enum class Error { - eUnknown = 1000, - eNoDevices = 1001, + .minor = 1, + .patch = 0, }; template diff --git a/aster_core/glfw_context.h b/aster_core/glfw_context.h index 90f94e1..a33449a 100644 --- a/aster_core/glfw_context.h +++ b/aster_core/glfw_context.h @@ -9,7 +9,7 @@ struct GlfwContext { static i32 post_error() noexcept { - static const char* error_ = nullptr; + static const char *error_ = nullptr; const auto code = glfwGetError(&error_); ERROR("GLFW {}", error_); return code; @@ -18,7 +18,8 @@ struct GlfwContext { inline static u32 count = 0; GlfwContext() { - if (count++ > 0) return; + if (count++ > 0) + return; if (glfwInit() == GLFW_FALSE) { CRASH(post_error()); } diff --git a/aster_core/global.h b/aster_core/global.h index f1cf576..9cc74b2 100644 --- a/aster_core/global.h +++ b/aster_core/global.h @@ -15,8 +15,8 @@ #include #define VULKAN_HPP_ASSERT(expr) DEBUG_IF(!(expr), "Vulkan assert failed") -#include #include +#include #define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__) [[nodiscard]] inline bool failed(const vk::Result _result) { diff --git a/aster_core/window.cpp b/aster_core/window.cpp index 9c0e428..c307e4f 100644 --- a/aster_core/window.cpp +++ b/aster_core/window.cpp @@ -4,18 +4,14 @@ // ============================================= #include "window.h" -#include "logger.h" #include "context.h" #include "glfw_context.h" +#include "logger.h" -Window::Window(const std::string_view& _title, Context* _context, vk::Extent2D _extent, b8 _full_screen) - : parent_context{ std::move(_context) } - , extent{ _extent } - , name{ _title } - , full_screen{ _full_screen } { - +Window::Window(const std::string_view &_title, Context *_context, vk::Extent2D _extent, b8 _full_screen) : + parent_context{ std::move(_context) }, extent{ _extent }, name{ _title }, full_screen{ _full_screen } { monitor = glfwGetPrimaryMonitor(); - ERROR_IF(monitor == nullptr, "No monitor found"); + ERROR_IF(monitor == nullptr, "No monitor found"); i32 x_, y_, w_, h_; glfwGetMonitorWorkarea(monitor, &x_, &y_, &w_, &h_); @@ -24,7 +20,8 @@ Window::Window(const std::string_view& _title, Context* _context, vk::Extent2D _ glfwWindowHint(GLFW_CENTER_CURSOR, GLFW_TRUE); window = glfwCreateWindow(extent.width, extent.height, name.data(), full_screen ? monitor : nullptr, nullptr); - ERROR_IF(window == nullptr, "Window creation failed") ELSE_INFO("Window '{}' created with resolution '{}x{}'", name, extent.width, extent.height); + ERROR_IF(window == nullptr, "Window creation failed") + ELSE_INFO("Window '{}' created with resolution '{}x{}'", name, extent.width, extent.height); if (window == nullptr) { auto code = GlfwContext::post_error(); glfwTerminate(); @@ -38,20 +35,17 @@ Window::Window(const std::string_view& _title, Context* _context, vk::Extent2D _ VkSurfaceKHR surface_; auto result = cast(glfwCreateWindowSurface(cast(_context->instance), window, nullptr, &surface_)); - ERROR_IF(failed(result), "Failed to create Surface with {}", to_string(result)) THEN_CRASH(result) ELSE_INFO("Surface Created"); + ERROR_IF(failed(result), "Failed to create Surface with {}", to_string(result)) + THEN_CRASH(result) ELSE_INFO("Surface Created"); surface = vk::SurfaceKHR(surface_); } -Window::Window(Window&& _other) noexcept: parent_context{ std::move(_other.parent_context) } - , window{ std::exchange(_other.window, nullptr) } - , monitor{ _other.monitor } - , surface{ std::exchange(_other.surface, nullptr) } - , extent{ _other.extent } - , name{ std::move(_other.name) } - , full_screen{ _other.full_screen } {} +Window::Window(Window &&_other) noexcept : + parent_context{ std::move(_other.parent_context) }, window{ std::exchange(_other.window, nullptr) }, monitor{ _other.monitor }, surface{ std::exchange(_other.surface, nullptr) }, extent{ _other.extent }, name{ std::move(_other.name) }, full_screen{ _other.full_screen } {} -Window& Window::operator=(Window&& _other) noexcept { - if (this == &_other) return *this; +Window &Window::operator=(Window &&_other) noexcept { + if (this == &_other) + return *this; parent_context = std::move(_other.parent_context); window = _other.window; monitor = _other.monitor; diff --git a/aster_core/window.h b/aster_core/window.h index e4929b7..d2a3fc0 100644 --- a/aster_core/window.h +++ b/aster_core/window.h @@ -10,13 +10,12 @@ #include "context.h" struct Window final { + Window(const std::string_view &_title, Context *_context, vk::Extent2D _extent, b8 _full_screen = false); - Window(const std::string_view& _title, Context* _context, vk::Extent2D _extent, b8 _full_screen = false); - - Window(const Window& _other) = delete; - Window(Window&& _other) noexcept; - Window& operator=(const Window& _other) = delete; - Window& operator=(Window&& _other) noexcept; + Window(const Window &_other) = delete; + Window(Window &&_other) noexcept; + Window &operator=(const Window &_other) = delete; + Window &operator=(Window &&_other) noexcept; ~Window(); @@ -29,7 +28,7 @@ struct Window final { return !glfwWindowShouldClose(window); } - void set_window_size(const vk::Extent2D& _extent) noexcept { + void set_window_size(const vk::Extent2D &_extent) noexcept { extent = _extent; glfwSetWindowSize(window, extent.width, extent.height); } @@ -39,10 +38,10 @@ struct Window final { } // fields - Context* parent_context{}; + Context *parent_context{}; - GLFWwindow* window{ nullptr }; - GLFWmonitor* monitor{ nullptr }; + GLFWwindow *window{ nullptr }; + GLFWmonitor *monitor{ nullptr }; vk::SurfaceKHR surface; vk::Extent2D extent; std::string name;