// ============================================= // Aster: global.h // Copyright (c) 2020-2024 Anish Bhobe // ============================================= #pragma once #include "config.h" #include "constants.h" #include "logger.h" #include #include #include // Macros that can collide with functions. #if defined(max) #undef max #endif #if defined(min) #undef min #endif #define VULKAN_HPP_ASSERT(expr) DEBUG_IF(!(expr), "Vulkan assert failed") #include #include #include #include constexpr u32 ASTER_API_VERSION = VK_API_VERSION_1_3; #define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__) #define FORCE_TODO static_assert(false) [[nodiscard]] inline bool Failed(const vk::Result result) { return result != vk::Result::eSuccess; } using NameString = eastl::fixed_string; template struct std::hash> // NOLINT(*-dcl58-cpp) { [[nodiscard]] usize operator()(const vk::Flags &val) { return std::hash()(Cast(val)); } }; template [[nodiscard]] usize HashAny(const T &val) { return std::hash>()(val); } [[nodiscard]] inline usize HashCombine(const usize hash0, const usize hash1) { constexpr usize saltValue = 0x9e3779b9; const usize tempVar = hash1 + saltValue + (hash0 << 6) + (hash0 >> 2); return hash0 ^ tempVar; } struct Time { static constexpr f64 cMaxDelta = 0.1; inline static f64 m_Elapsed{Qnan}; inline static f64 m_Delta{Qnan}; static void Init() { WARN_IF(!std::isnan(m_Elapsed), "Time already init."); m_Elapsed = glfwGetTime(); m_Delta = 1.0 / 60.0; } static void Update() { ERROR_IF(std::isnan(m_Elapsed), "Time not init."); const auto newElapsed = glfwGetTime(); m_Delta = std::clamp(newElapsed - m_Elapsed, 0.0, cMaxDelta); m_Elapsed = newElapsed; } }; [[nodiscard]] inline usize ClosestMultiple(const usize val, const usize of) { return of * ((val + of - 1) / of); } template <> struct fmt::formatter : nested_formatter { auto // ReSharper disable once CppInconsistentNaming format(vk::Result result, format_context &ctx) const { return write_padded(ctx, [this, result](auto out) { return v10::format_to(out, "{}", nested(to_string(result))); }); } }; template struct fmt::formatter> : nested_formatter { auto // ReSharper disable once CppInconsistentNaming format(const eastl::fixed_string &str, format_context &ctx) const { return write_padded(ctx, [this, str](auto out) { return v10::format_to(out, "{}", nested(str.c_str())); }); } };