diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/Debugging/Errors.cpp | 11 | ||||
| -rw-r--r-- | src/common/Debugging/Errors.h | 4 | ||||
| -rw-r--r-- | src/common/Utilities/Util.cpp | 7 | ||||
| -rw-r--r-- | src/common/Utilities/Util.h | 3 |
4 files changed, 20 insertions, 5 deletions
diff --git a/src/common/Debugging/Errors.cpp b/src/common/Debugging/Errors.cpp index 45f130ceb3b..4c7e91a8219 100644 --- a/src/common/Debugging/Errors.cpp +++ b/src/common/Debugging/Errors.cpp @@ -59,10 +59,15 @@ void Assert(char const* file, int line, char const* function, char const* messag exit(1); } -void Fatal(char const* file, int line, char const* function, char const* message) +void Fatal(char const* file, int line, char const* function, char const* message, ...) { - fprintf(stderr, "\n%s:%i in %s FATAL ERROR:\n %s\n", - file, line, function, message); + va_list args; + va_start(args, message); + + fprintf(stderr, "\n%s:%i in %s FATAL ERROR:\n ", file, line, function); + vfprintf(stderr, message, args); + fprintf(stderr, "\n"); + fflush(stderr); std::this_thread::sleep_for(std::chrono::seconds(10)); *((volatile int*)NULL) = 0; diff --git a/src/common/Debugging/Errors.h b/src/common/Debugging/Errors.h index 3ceaf2c328f..9e526933acc 100644 --- a/src/common/Debugging/Errors.h +++ b/src/common/Debugging/Errors.h @@ -26,7 +26,7 @@ namespace Trinity DECLSPEC_NORETURN void Assert(char const* file, int line, char const* function, char const* message) ATTR_NORETURN; DECLSPEC_NORETURN void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...) ATTR_NORETURN ATTR_PRINTF(5, 6); - DECLSPEC_NORETURN void Fatal(char const* file, int line, char const* function, char const* message) ATTR_NORETURN; + DECLSPEC_NORETURN void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_NORETURN ATTR_PRINTF(4, 5); DECLSPEC_NORETURN void Error(char const* file, int line, char const* function, char const* message) ATTR_NORETURN; @@ -45,7 +45,7 @@ namespace Trinity #endif #define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond, ##__VA_ARGS__); } while(0) ASSERT_END -#define WPFatal(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END +#define WPFatal(cond, ...) ASSERT_BEGIN do { if (!(cond)) Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0) ASSERT_END #define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END #define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END #define WPAbort() ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 33c273fb05f..9f61dd12e4c 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -58,6 +58,13 @@ uint32 urand(uint32 min, uint32 max) return GetRng()->URandom(min, max); } +uint32 urandms(uint32 min, uint32 max) +{ + ASSERT(max >= min); + ASSERT(INT_MAX/IN_MILLISECONDS >= max); + return GetRng()->URandom(min * IN_MILLISECONDS, max * IN_MILLISECONDS); +} + float frand(float min, float max) { ASSERT(max >= min); diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 6a872b44a60..b748e83408b 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -82,6 +82,9 @@ int32 irand(int32 min, int32 max); /* Return a random number in the range min..max (inclusive). */ uint32 urand(uint32 min, uint32 max); +/* Return a random millisecond value between min and max seconds. Functionally equivalent to urand(min*IN_MILLISECONDS, max*IN_MILLISECONDS). */ +uint32 urandms(uint32 min, uint32 max); + /* Return a random number in the range 0 .. UINT32_MAX. */ uint32 rand32(); |
