-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
54 lines (44 loc) · 1.25 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "utils.h"
#include "common.h"
#include "log.h"
#include "timer.h"
#include <windows.h>
TTimer gPerformanceTimer;
int Util_RandomInt( int min, int max ) {
return min + ( max - min ) * ( rand() / RAND_MAX );
}
float Util_RandomFloat( float min, float max ) {
return min + ( max - min ) * ( rand() / RAND_MAX );
}
void Util_Message( const char * format, ... ) {
va_list argumentList;
char buffer[4096];
va_start(argumentList, format);
vsprintf( buffer, format, argumentList);
va_end(argumentList);
#ifdef _WIN32
MessageBoxA( 0, buffer, "SYS_Message", MB_OK );
#endif
Log_Write( buffer );
}
void Util_RaiseError( const char * format, ... ) {
//__builtin_trap(); // raise breakpoint
va_list argumentList;
char buffer[4096];
va_start(argumentList, format );
vsprintf( buffer, format, argumentList);
va_end(argumentList);
#ifdef _WIN32
MessageBoxA( 0, buffer, "Error", MB_OK | MB_ICONERROR );
#endif
Log_Write( buffer );
/* free memory allocated in this process */
Memory_CollectGarbage();
exit( -1 );
}
void Util_BeginPerformanceMeasure() {
Timer_Create( &gPerformanceTimer );
}
float Util_EndPerformanceMeasure() {
return Timer_GetElapsedMilliseconds( &gPerformanceTimer );
}