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::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 <typename T>

View File

@ -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());
}

View File

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

View File

@ -4,16 +4,12 @@
// =============================================
#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");
@ -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<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_);
}
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;
if (this == &_other)
return *this;
parent_context = std::move(_other.parent_context);
window = _other.window;
monitor = _other.monitor;

View File

@ -10,7 +10,6 @@
#include "context.h"
struct Window final {
Window(const std::string_view &_title, Context *_context, vk::Extent2D _extent, b8 _full_screen = false);
Window(const Window &_other) = delete;