diff --git a/aster_core/aster.cpp b/aster_core/aster.cpp index f6c5b4d..5574ad8 100644 --- a/aster_core/aster.cpp +++ b/aster_core/aster.cpp @@ -5,8 +5,8 @@ int main(int, char **) { GlfwContext glfw = {}; - Context context = {"Aster", VERSION}; - Window window = {"Aster1", &context, { 640, 480 }}; + Context context = { "Aster", VERSION }; + Window window = { "Aster1", &context, { 640, 480 } }; while (window.poll()) { } diff --git a/aster_core/context.cpp b/aster_core/context.cpp index 6018bf7..a4ea9fc 100644 --- a/aster_core/context.cpp +++ b/aster_core/context.cpp @@ -52,9 +52,7 @@ void Context::init(const std::string_view &_app_name, const Version &_app_versio }; u32 glfw_extension_count = 0; - const char **glfw_extensions = nullptr; - - glfw_extensions = glfwGetRequiredInstanceExtensions(&glfw_extension_count); + const char **glfw_extensions = glfwGetRequiredInstanceExtensions(&glfw_extension_count); std::vector vulkan_extensions(glfw_extensions, glfw_extensions + glfw_extension_count); if (enable_validation_layers) { vulkan_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); @@ -76,7 +74,7 @@ void Context::init(const std::string_view &_app_name, const Version &_app_versio } }; } catch (const std::exception &err) { ERROR("Failed to create Vulkan instance with "s + err.what()); - throw err; + throw; } INFO("Instance Created."); @@ -86,7 +84,7 @@ void Context::init(const std::string_view &_app_name, const Version &_app_versio debug_messenger = vk::raii::DebugUtilsMessengerEXT{ instance, debug_messenger_create_info }; } catch (const std::exception &err) { ERROR("Debug Messenger creation failed with "s + err.what()); - throw err; + throw; } INFO("Debug Messenger Created."); } diff --git a/aster_core/device.cpp b/aster_core/device.cpp index 2f211a9..369adbd 100644 --- a/aster_core/device.cpp +++ b/aster_core/device.cpp @@ -13,12 +13,16 @@ #include Device::Device(Device &&_other) noexcept : - physical_device{ _other.physical_device }, device{ std::exchange(_other.device, nullptr) }, queues{ _other.queues }, allocator{ std::exchange(_other.allocator, nullptr) }, name{ std::move(_other.name) } {} + physical_device{ std::move(_other.physical_device) }, + device{ std::exchange(_other.device, nullptr) }, + queues{ _other.queues }, + allocator{ std::exchange(_other.allocator, nullptr) }, + name{ std::move(_other.name) } {} Device &Device::operator=(Device &&_other) noexcept { if (this == &_other) return *this; - physical_device = _other.physical_device; + physical_device = std::move(_other.physical_device); device = std::exchange(_other.device, nullptr); queues = _other.queues; allocator = std::exchange(_other.allocator, nullptr); @@ -41,6 +45,7 @@ Device::Device(const std::string_view &_name, Context *_context, const PhysicalD std::array queue_priority = { 1.0f, 1.0f, 1.0f, 1.0f }; std::vector queue_create_infos; + queue_create_infos.reserve(unique_queue_families.size()); for (auto &[index_, count_] : unique_queue_families) { queue_create_infos.push_back({ .queueFamilyIndex = index_, @@ -60,7 +65,7 @@ Device::Device(const std::string_view &_name, Context *_context, const PhysicalD }); } catch (const std::exception &err) { ERROR("Failed to create a logical device with "s + err.what()); - throw err; + throw; } INFO("Logical Device Created!"); @@ -70,7 +75,8 @@ Device::Device(const std::string_view &_name, Context *_context, const PhysicalD .instance = *_context->instance, }; - auto result = cast(vmaCreateAllocator(&allocator_create_info, &allocator)); + allocator = nullptr; + const auto result = cast(vmaCreateAllocator(&allocator_create_info, &allocator)); if (failed(result)) { ERROR("Memory allocator creation failed with "s + vk::to_string(result)); throw std::runtime_error("Memory allocator creation failed with "s + vk::to_string(result)); diff --git a/aster_core/device.h b/aster_core/device.h index f664193..0f65458 100644 --- a/aster_core/device.h +++ b/aster_core/device.h @@ -27,7 +27,6 @@ struct SubmitTask; class Device { public: - Device(const Device &_other) = delete; Device(Device &&_other) noexcept; Device &operator=(const Device &_other) = delete; diff --git a/aster_core/glfw_context.h b/aster_core/glfw_context.h index d251e1d..8bfd5d4 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 "s + 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 fbb0c36..9f6c163 100644 --- a/aster_core/global.h +++ b/aster_core/global.h @@ -10,10 +10,10 @@ #include "logger.h" #include +#include #include #include #include -#include #define VULKAN_HPP_ASSERT(expr) DEBUG_IF(!(expr), "Vulkan assert failed") #include diff --git a/aster_core/logger.cpp b/aster_core/logger.cpp index cdc2f6b..c976134 100644 --- a/aster_core/logger.cpp +++ b/aster_core/logger.cpp @@ -5,13 +5,4 @@ #include "logger.h" -Logger g_logger = Logger(); - -/* Credits to Const-me */ -//namespace eastl { -// void __cdecl AssertionFailure(const char* af) -// { -// ERROR(af); -// __debugbreak(); -// } -//} +auto g_logger = Logger(); diff --git a/aster_core/logger.h b/aster_core/logger.h index 895c175..bb50ca5 100644 --- a/aster_core/logger.h +++ b/aster_core/logger.h @@ -36,6 +36,7 @@ struct Logger { return "[DEBUG]:"; if constexpr (LogLevel == LogType::eVerbose) return "[VERB]: "; + return ""; } template @@ -50,6 +51,7 @@ struct Logger { return ANSI_White; if constexpr (LogLevel == LogType::eVerbose) return ANSI_Blue; + return ""; } template @@ -65,7 +67,7 @@ struct Logger { } template - void log_cond(const char *_expr_str, const std::string_view &_message, const char *_loc, u32 _line) const { + void log_cond(const char *_expr_str, const std::string_view &_message, const char *_loc, const u32 _line) const { if (cast(LogLevel) <= minimum_logging_level) { printf("%s%s (%s) %s%s| at %s:%u%s\n", to_color_cstr(), to_cstr(), _expr_str, _message.data(), ANSI_Black, _loc, _line, ANSI_Reset); } diff --git a/aster_core/physical_device.cpp b/aster_core/physical_device.cpp index 54e1776..9d88e3b 100644 --- a/aster_core/physical_device.cpp +++ b/aster_core/physical_device.cpp @@ -51,9 +51,9 @@ QueueFamilyIndices PhysicalDevice::get_queue_families(const Window *_window, con continue; } } - } catch (const std::exception& err) { + } catch (const std::exception &err) { ERROR("Failure in finding surface support, all possibilities fatal. Failed with "s + err.what()); - throw err; + throw; } ++family_index; diff --git a/aster_core/physical_device.h b/aster_core/physical_device.h index 0b71f76..4cad5ce 100644 --- a/aster_core/physical_device.h +++ b/aster_core/physical_device.h @@ -47,5 +47,5 @@ struct PhysicalDevice { } private: - [[nodiscard]] static QueueFamilyIndices get_queue_families(const Window * _window, const vk::raii::PhysicalDevice* _device) ; + [[nodiscard]] static QueueFamilyIndices get_queue_families(const Window *_window, const vk::raii::PhysicalDevice *_device); };