diff --git a/main.c b/main.c index d6f8f2b..7fb3802 100644 --- a/main.c +++ b/main.c @@ -53,9 +53,6 @@ __declspec(dllexport) uint32_t AmdPowerXpressRequestHighPerformance = 0x00000001 #endif -#define STRINGIZE(x) STRINGIZE2(x) -#define STRINGIZE2(x) #x - #include "buff.h" #include "sokol_app.h" #pragma warning(push) diff --git a/utility.h b/utility.h index dc00fab..8f76ffb 100644 --- a/utility.h +++ b/utility.h @@ -1,43 +1,24 @@ #pragma once #include -#include -#ifdef WEB -#include -#define game_debugbreak() raise(SIGTRAP) - -#define game_assert_4127_push -#define game_assert_4127_pop +#define STRINGIZE(x) STRINGIZE2(x) +#define STRINGIZE2(x) #x +#ifdef WEB +#define assert_impl(cond, str) ((cond) || (EM_ASM({ assert(0, UTF8ToString($0) + UTF8ToString($1)); }, (__func__), (str)), 0)) #elif defined(DESKTOP) -#define game_debugbreak() __debugbreak() - -#define game_assert_4127_push __pragma(warning(push)) __pragma(warning(disable:4127)) -#define game_assert_4127_pop __pragma(warning(pop)) - +#define assert_impl(cond, str) ((cond) || (fputs("Assertion failed: " __FUNCTION__ str "\n", stderr), __debugbreak(), 0)) #else #error "Don't know how to assert for current platform configuration" -#define game_debugbreak() (void)(0) #endif -static void assert_impl(const char *func, const char *file, long line, const char *expression) -{ - fprintf(stderr, "Assert fail in %s(%s:%ld):\n \"%s\"\n", func, file, line, expression); -} - #ifdef NDEBUG -#define game_assert(cond) game_assert_4127_push do { (void)0; } while (0) game_assert_4127_pop +#define game_assert(cond) ((void)0) #else -#define game_assert(cond) game_assert_4127_push do { \ - if (!(cond)) { \ - assert_impl(__func__, __FILE__, __LINE__, #cond); \ - game_debugbreak(); \ - } \ -} while (0) game_assert_4127_pop +#define game_assert(cond) assert_impl(cond, "(" __FILE__ ":" STRINGIZE(__LINE__) "): \"" #cond "\"") #endif - #ifdef assert #undef assert #endif