|
|
@ -1,43 +1,24 @@
|
|
|
|
#pragma once
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WEB
|
|
|
|
#define STRINGIZE(x) STRINGIZE2(x)
|
|
|
|
#include <signal.h>
|
|
|
|
#define STRINGIZE2(x) #x
|
|
|
|
#define game_debugbreak() raise(SIGTRAP)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define game_assert_4127_push
|
|
|
|
|
|
|
|
#define game_assert_4127_pop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WEB
|
|
|
|
|
|
|
|
#define assert_impl(cond, str) ((cond) || (EM_ASM({ assert(0, UTF8ToString($0) + UTF8ToString($1)); }, (__func__), (str)), 0))
|
|
|
|
#elif defined(DESKTOP)
|
|
|
|
#elif defined(DESKTOP)
|
|
|
|
#define game_debugbreak() __debugbreak()
|
|
|
|
#define assert_impl(cond, str) ((cond) || (fputs("Assertion failed: " __FUNCTION__ str "\n", stderr), __debugbreak(), 0))
|
|
|
|
|
|
|
|
|
|
|
|
#define game_assert_4127_push __pragma(warning(push)) __pragma(warning(disable:4127))
|
|
|
|
|
|
|
|
#define game_assert_4127_pop __pragma(warning(pop))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#error "Don't know how to assert for current platform configuration"
|
|
|
|
#error "Don't know how to assert for current platform configuration"
|
|
|
|
#define game_debugbreak() (void)(0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#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
|
|
|
|
#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
|
|
|
|
#else
|
|
|
|
#define game_assert(cond) game_assert_4127_push do { \
|
|
|
|
#define game_assert(cond) assert_impl(cond, "(" __FILE__ ":" STRINGIZE(__LINE__) "): \"" #cond "\"")
|
|
|
|
if (!(cond)) { \
|
|
|
|
|
|
|
|
assert_impl(__func__, __FILE__, __LINE__, #cond); \
|
|
|
|
|
|
|
|
game_debugbreak(); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
} while (0) game_assert_4127_pop
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef assert
|
|
|
|
#ifdef assert
|
|
|
|
#undef assert
|
|
|
|
#undef assert
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|