Format Code and cleanup.

This commit is contained in:
Anish Bhobe 2024-06-15 17:54:30 +02:00
parent a0a84f30f8
commit 8b0a7f2622
5 changed files with 29 additions and 40 deletions

View File

@ -93,7 +93,7 @@ using glm::mat2;
using glm::mat3; using glm::mat3;
using glm::mat4; using glm::mat4;
constexpr const char *PROJECT_NAME = "Aster"; constexpr auto *PROJECT_NAME = "Aster";
struct Version { struct Version {
u32 major; u32 major;
@ -103,13 +103,8 @@ struct Version {
constexpr Version VERSION = { constexpr Version VERSION = {
.major = 0, .major = 0,
.minor = 0, .minor = 1,
.patch = 1, .patch = 0,
};
enum class Error {
eUnknown = 1000,
eNoDevices = 1001,
}; };
template <typename T> template <typename T>

View File

@ -9,7 +9,7 @@
struct GlfwContext { struct GlfwContext {
static i32 post_error() noexcept { static i32 post_error() noexcept {
static const char* error_ = nullptr; static const char *error_ = nullptr;
const auto code = glfwGetError(&error_); const auto code = glfwGetError(&error_);
ERROR("GLFW {}", error_); ERROR("GLFW {}", error_);
return code; return code;
@ -18,7 +18,8 @@ struct GlfwContext {
inline static u32 count = 0; inline static u32 count = 0;
GlfwContext() { GlfwContext() {
if (count++ > 0) return; if (count++ > 0)
return;
if (glfwInit() == GLFW_FALSE) { if (glfwInit() == GLFW_FALSE) {
CRASH(post_error()); CRASH(post_error());
} }

View File

@ -15,8 +15,8 @@
#include <string> #include <string>
#define VULKAN_HPP_ASSERT(expr) DEBUG_IF(!(expr), "Vulkan assert failed") #define VULKAN_HPP_ASSERT(expr) DEBUG_IF(!(expr), "Vulkan assert failed")
#include <vulkan/vulkan.hpp>
#include <vk_mem_alloc.h> #include <vk_mem_alloc.h>
#include <vulkan/vulkan.hpp>
#define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__) #define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__)
[[nodiscard]] inline bool failed(const vk::Result _result) { [[nodiscard]] inline bool failed(const vk::Result _result) {

View File

@ -4,16 +4,12 @@
// ============================================= // =============================================
#include "window.h" #include "window.h"
#include "logger.h"
#include "context.h" #include "context.h"
#include "glfw_context.h" #include "glfw_context.h"
#include "logger.h"
Window::Window(const std::string_view& _title, Context* _context, vk::Extent2D _extent, b8 _full_screen) Window::Window(const std::string_view &_title, Context *_context, vk::Extent2D _extent, b8 _full_screen) :
: parent_context{ std::move(_context) } parent_context{ std::move(_context) }, extent{ _extent }, name{ _title }, full_screen{ _full_screen } {
, extent{ _extent }
, name{ _title }
, full_screen{ _full_screen } {
monitor = glfwGetPrimaryMonitor(); monitor = glfwGetPrimaryMonitor();
ERROR_IF(monitor == nullptr, "No monitor found"); ERROR_IF(monitor == nullptr, "No monitor found");
@ -24,7 +20,8 @@ Window::Window(const std::string_view& _title, Context* _context, vk::Extent2D _
glfwWindowHint(GLFW_CENTER_CURSOR, GLFW_TRUE); glfwWindowHint(GLFW_CENTER_CURSOR, GLFW_TRUE);
window = glfwCreateWindow(extent.width, extent.height, name.data(), full_screen ? monitor : nullptr, nullptr); 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) { if (window == nullptr) {
auto code = GlfwContext::post_error(); auto code = GlfwContext::post_error();
glfwTerminate(); glfwTerminate();
@ -38,20 +35,17 @@ Window::Window(const std::string_view& _title, Context* _context, vk::Extent2D _
VkSurfaceKHR surface_; VkSurfaceKHR surface_;
auto result = cast<vk::Result>(glfwCreateWindowSurface(cast<VkInstance>(_context->instance), window, nullptr, &surface_)); auto result = cast<vk::Result>(glfwCreateWindowSurface(cast<VkInstance>(_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_); surface = vk::SurfaceKHR(surface_);
} }
Window::Window(Window&& _other) noexcept: parent_context{ std::move(_other.parent_context) } Window::Window(Window &&_other) noexcept :
, window{ std::exchange(_other.window, nullptr) } 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 } {}
, 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 { Window &Window::operator=(Window &&_other) noexcept {
if (this == &_other) return *this; if (this == &_other)
return *this;
parent_context = std::move(_other.parent_context); parent_context = std::move(_other.parent_context);
window = _other.window; window = _other.window;
monitor = _other.monitor; monitor = _other.monitor;

View File

@ -10,13 +10,12 @@
#include "context.h" #include "context.h"
struct Window final { 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(const Window& _other) = delete; Window &operator=(const Window &_other) = delete;
Window(Window&& _other) noexcept; Window &operator=(Window &&_other) noexcept;
Window& operator=(const Window& _other) = delete;
Window& operator=(Window&& _other) noexcept;
~Window(); ~Window();
@ -29,7 +28,7 @@ struct Window final {
return !glfwWindowShouldClose(window); return !glfwWindowShouldClose(window);
} }
void set_window_size(const vk::Extent2D& _extent) noexcept { void set_window_size(const vk::Extent2D &_extent) noexcept {
extent = _extent; extent = _extent;
glfwSetWindowSize(window, extent.width, extent.height); glfwSetWindowSize(window, extent.width, extent.height);
} }
@ -39,10 +38,10 @@ struct Window final {
} }
// fields // fields
Context* parent_context{}; Context *parent_context{};
GLFWwindow* window{ nullptr }; GLFWwindow *window{ nullptr };
GLFWmonitor* monitor{ nullptr }; GLFWmonitor *monitor{ nullptr };
vk::SurfaceKHR surface; vk::SurfaceKHR surface;
vk::Extent2D extent; vk::Extent2D extent;
std::string name; std::string name;