#ifndef COMMON_H_ #define COMMON_H_ #include "VmaUsage.h" #ifdef _WIN32 #define MATHFU_COMPILE_WITHOUT_SIMD_SUPPORT #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef std::chrono::high_resolution_clock::time_point time_point; typedef std::chrono::high_resolution_clock::duration duration; #define ERR_GUARD_VULKAN(Expr) do { VkResult res__ = (Expr); if (res__ < 0) assert(0); } while(0) extern VkPhysicalDevice g_hPhysicalDevice; extern VkDevice g_hDevice; extern VmaAllocator g_hAllocator; extern bool g_MemoryAliasingWarningEnabled; inline float ToFloatSeconds(duration d) { return std::chrono::duration_cast>(d).count(); } template inline T ceil_div(T x, T y) { return (x+y-1) / y; } template static inline T align_up(T val, T align) { return (val + align - 1) / align * align; } class RandomNumberGenerator { public: RandomNumberGenerator() : m_Value{GetTickCount()} {} RandomNumberGenerator(uint32_t seed) : m_Value{seed} { } void Seed(uint32_t seed) { m_Value = seed; } uint32_t Generate() { return GenerateFast() ^ (GenerateFast() >> 7); } private: uint32_t m_Value; uint32_t GenerateFast() { return m_Value = (m_Value * 196314165 + 907633515); } }; void ReadFile(std::vector& out, const char* fileName); enum class CONSOLE_COLOR { INFO, NORMAL, WARNING, ERROR_, COUNT }; void SetConsoleColor(CONSOLE_COLOR color); void PrintMessage(CONSOLE_COLOR color, const char* msg); void PrintMessage(CONSOLE_COLOR color, const wchar_t* msg); inline void Print(const char* msg) { PrintMessage(CONSOLE_COLOR::NORMAL, msg); } inline void Print(const wchar_t* msg) { PrintMessage(CONSOLE_COLOR::NORMAL, msg); } inline void PrintWarning(const char* msg) { PrintMessage(CONSOLE_COLOR::WARNING, msg); } inline void PrintWarning(const wchar_t* msg) { PrintMessage(CONSOLE_COLOR::WARNING, msg); } inline void PrintError(const char* msg) { PrintMessage(CONSOLE_COLOR::ERROR_, msg); } inline void PrintError(const wchar_t* msg) { PrintMessage(CONSOLE_COLOR::ERROR_, msg); } void PrintMessageV(CONSOLE_COLOR color, const char* format, va_list argList); void PrintMessageV(CONSOLE_COLOR color, const wchar_t* format, va_list argList); void PrintMessageF(CONSOLE_COLOR color, const char* format, ...); void PrintMessageF(CONSOLE_COLOR color, const wchar_t* format, ...); void PrintWarningF(const char* format, ...); void PrintWarningF(const wchar_t* format, ...); void PrintErrorF(const char* format, ...); void PrintErrorF(const wchar_t* format, ...); void SaveFile(const wchar_t* filePath, const void* data, size_t dataSize); #endif // #ifdef _WIN32 #endif