#ifndef TOOLS_H_INCLUDE #define TOOLS_H_INCLUDE #define INTERNAL_BUILD 1 #include #include #include #ifdef _MSC_VER #endif #define _CRT_SECURE_NO_WARNINGS #ifdef PLATFORM_WIN32 #include inline void assertFuncProduction( const char *expression, const char *file_name, unsigned const line_number, const char *comment = "---") { char c[1024] = {}; sprintf(c, "Assertion failed\n\n" "File:\n" "%s\n\n" "Line:\n" "%u\n\n" "Expresion:\n" "%s\n\n" "Comment:\n" "%s" "\n\nPlease report this error to the developer.", file_name, line_number, expression, comment ); int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL | MB_ICONHAND | MB_OK | MB_SETFOREGROUND); switch (action) { case IDOK: { raise(SIGABRT); _exit(3); } default: { _exit(3); } } } inline void assertFuncInternal( const char *expression, const char *file_name, unsigned const line_number, const char *comment = "---") { char c[1024] = {}; sprintf(c, "Assertion failed\n\n" "File:\n" "%s\n\n" "Line:\n" "%u\n\n" "Expresion:\n" "%s\n\n" "Comment:\n" "%s" "\n\nPress retry to debug.", file_name, line_number, expression, comment ); int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SETFOREGROUND); switch (action) { case IDABORT: { raise(SIGABRT); _exit(3); } case IDRETRY: { __debugbreak(); return; } case IDIGNORE: { return; } default: { abort(); } } } #if INTERNAL_BUILD == 1 #define permaAssert(expression) (void)( \ (!!(expression)) || \ (assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__)), 0) \ ) #define permaAssertComment(expression, comment) (void)( \ (!!(expression)) || \ (assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \ ) #else #define permaAssert(expression) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \ ) #define permaAssertComment(expression, comment) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \ ) #endif #else inline void assertFuncProduction( const char *expression, const char *file_name, unsigned const line_number, const char *comment = "---") { raise(SIGABRT); } #define permaAssert(expression) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \ ) #define permaAssertComment(expression, comment) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0, comment) \ ) #endif #endif