forked from pioneerspacesim/pioneer
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.h
73 lines (60 loc) · 1.85 KB
/
utils.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _UTILS_H
#define _UTILS_H
#include <string>
#include <vector>
#include <stdio.h>
#include <stdarg.h>
#include <GL/glew.h>
#include "libs.h"
#ifndef __GNUC__
#define __attribute(x)
#endif /* __GNUC__ */
// GCC warns when a function marked __attribute((noreturn)) actually returns a value
// but other compilers which don't see the noreturn attribute of course require that
// a function with a non-void return type should return something.
#ifndef __GNUC__
#define RETURN_ZERO_NONGNU_ONLY return 0;
#else
#define RETURN_ZERO_NONGNU_ONLY
#endif
void Error(const char *format, ...) __attribute((format(printf,1,2))) __attribute((noreturn));
void Warning(const char *format, ...) __attribute((format(printf,1,2)));
void SilentWarning(const char *format, ...) __attribute((format(printf,1,2)));
std::string string_join(std::vector<std::string> &v, std::string sep);
std::string format_date(double time);
std::string format_date_only(double time);
std::string format_distance(double dist);
std::string format_money(Sint64 money);
static inline Sint64 isqrt(Sint64 a)
{
Sint64 ret=0;
Sint64 s;
Sint64 ret_sq=-a-1;
for(s=62; s>=0; s-=2){
Sint64 b;
ret+= ret;
b=ret_sq + ((2*ret+1)<<s);
if(b<0){
ret_sq=b;
ret++;
}
}
return ret;
}
void Screendump(const char* destFile, const int w, const int h);
// find string in bigger string, ignoring case
const char *pi_strcasestr(const char *haystack, const char *needle);
// add a few things that MSVC is missing
#ifdef _MSC_VER
// round & roundf. taken from http://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/auxiliary/util/u_math.h
static inline double round(double x)
{
return x >= 0.0 ? floor(x + 0.5) : ceil(x - 0.5);
}
static inline float roundf(float x)
{
return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f);
}
#endif /* _MSC_VER */
void hexdump(const unsigned char *buf, int bufsz);
#endif /* _UTILS_H */