1 #pragma once
2
3 /** Debugging stuff and other miscellaneous utilities.
4 */
5
6 /*#ifndef DEBUGprintf
7 #define DEBUGprintf(x) if( !DEBUG || x > DEBUGLEVEL ) ((void)0); else log
8 #endif*/
9
10 const bool LOGGING = true; // enable logging even for release builds, for now
11
12 #ifndef LOG
13 #define LOG if( !LOGGING ) ((void)0); else log
14 #endif
15
16 void initFolderPaths();
17 const char *getApplicationFilename(const char *name, bool survive_uninstall);
18 void initLogFile();
19 void cleanupLogFile();
20 bool log(const char *text,...);
21
22 #ifndef ASSERT
23 #define ASSERT(test) { \
24 bool v = test; \
25 if( v ) \
26 ((void)0); \
27 else { \
28 LOG("ASSERTION FAILED:\n"); \
29 LOG("%s\n", #test); \
30 LOG("File: %s\n", __FILE__); \
31 LOG("Line: %d\n", __LINE__); \
32 assert(test); \
33 } \
34 }
35 #endif
36
37 #ifdef _DEBUG
38 #define T_ASSERT( x ) ASSERT( x )
39 #else
40 #define T_ASSERT( x )
41 #endif
42
43 /*
44 int *assert_crash = NULL; \
45 *assert_crash = 0; \
46 */
47
48 #ifndef ASSERT_ANY_EPOCH
49 #define ASSERT_ANY_EPOCH(epoch) ASSERT( epoch >= 0 && epoch < n_epochs_c );
50 #endif
51
52 #ifndef ASSERT_EPOCH
53 #define ASSERT_EPOCH(epoch) ASSERT( epoch >= 0 && epoch < n_epochs_c );
54 #endif
55
56 #ifndef ASSERT_S_EPOCH
57 #define ASSERT_S_EPOCH(epoch) ASSERT( epoch >= game_g->getStartEpoch() && epoch <= n_epochs_c );
58 #endif
59
60 #ifndef ASSERT_R_EPOCH
61 #define ASSERT_R_EPOCH(r_epoch) ASSERT( r_epoch >= 0 && r_epoch < 4 );
62 #endif
63
64 #ifndef ASSERT_SHIELD
65 #define ASSERT_SHIELD(shield) ASSERT( shield >= 0 && shield < n_shields_c );
66 #endif
67
68 #ifndef ASSERT_ELEMENT_ID
69 #define ASSERT_ELEMENT_ID(id) ASSERT( id >= 0 && id < N_ID );
70 #endif
71
72 #ifndef ASSERT_PLAYER
73 //#define ASSERT_PLAYER(player) ASSERT( player >= 0 && player < n_players_c && players[player] != NULL );
74 #define ASSERT_PLAYER(player) ASSERT( game_g->validPlayer(player) );
75 #endif
76
77 #ifndef ASSERT_DIFFICULTY
78 #define ASSERT_DIFFICULTY(difficulty) ASSERT( validDifficulty(difficulty) );
79 #endif
80
81 class Rect2D {
82 public:
83 int x, y, w, h;
Rect2D()84 Rect2D() {
85 set(0,0,0,0);
86 }
Rect2D(int x,int y,int w,int h)87 Rect2D(int x,int y,int w,int h) {
88 set(x,y,w,h);
89 }
set(int x,int y,int w,int h)90 void set(int x,int y,int w,int h) {
91 this->x = x;
92 this->y = y;
93 this->w = w;
94 this->h = h;
95 }
getRight()96 int getRight() const {
97 return x + w;
98 }
getBottom()99 int getBottom() const {
100 return y + h;
101 }
102 };
103
104 int poisson(int mean_ticks_per_event,int time_interval);
105
106 int n_digits(int number);
107
108 void textLines(int *n_lines,int *max_wid,const char *text, int lower_w, int upper_w);
109
110 float perlin_noise2(float vec[2]);
111
112 #include <vector>
113 using std::vector;
114
115 template<class T>
remove_vec(vector<T> * vec,const T & value)116 bool remove_vec(vector<T> *vec,const T& value) {
117 for(unsigned int i=0;i<vec->size();i++) {
118 if( vec->at(i) == value ) {
119 vec->erase(vec->begin() + i);
120 return true;
121 }
122 }
123 return false;
124 }
125
126 #if defined(AROS) || defined(__MORPHOS__)
127
128 void getAROSScreenSize(int *user_width, int *user_height);
129
130 #endif
131