OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
global.h
Go to the documentation of this file.
1 
7 #ifndef _GLOBAL_H_
8 #define _GLOBAL_H_
9 
10 #include "config.h"
11 
12 void renderFrame();
13 
14 // Actions that can be bound to a key and sent to the game engine
15 typedef enum {
19 
29 
30  ActionEventCount // Should always be at the end
31 } ActionEvents;
32 
33 // Keys available for binding
34 typedef enum {
35  // Keyboard
36  zeroKey = '0', oneKey = '1', twoKey = '2',
37  threeKey = '3', fourKey = '4', fiveKey = '5',
38  sixKey = '6', sevenKey = '7', eightKey = '8',
39  nineKey = '9', aKey = 'a', bKey = 'b',
40  cKey = 'c', dKey = 'd', eKey = 'e', fKey = 'f',
41  gKey = 'g', hKey = 'h', iKey = 'i', jKey = 'j',
42  kKey = 'k', lKey = 'l', mKey = 'm', nKey = 'n',
43  oKey = 'o', pKey = 'p', qKey = 'q', rKey = 'r',
44  sKey = 's', tKey = 't', uKey = 'u', vKey = 'v',
45  wKey = 'w', xKey = 'x', yKey = 'y', zKey = 'z',
55 
56  // Mouse
59 
60  // Game Controller
65 
66  unknownKey // Should always be at the end
68 
69 // Globally include OpenGL header
70 #ifdef __APPLE__
71 #include <OpenGL/gl3.h>
72 #else // __APPLE__
73 #ifdef _WIN32
74 #include <GL/glew.h>
75 #include <GL/wglew.h>
76 #pragma comment(lib, "glew32.lib")
77 #else // _WIN32
78 #include <GL/gl.h>
80 #include <GL/glext.h>
81 #endif // _WIN32
82 #endif // __APPLE__
83 
89 #define NDEBUG
90 #include <glm/glm.hpp>
91 
92 // If available, use our own assert that prints the call stack
93 #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
94 
95 #ifndef NODEBUG
96 
97 #include <iostream>
98 #include <execinfo.h>
99 
100 template<typename T, typename U>
101 [[noreturn]] void assertEqualImplementation(const char* exp, T a, U b, const char* file, int line,
102  const char* str = nullptr) {
103  const unsigned int maxSize = 128;
104  void* callstack[maxSize];
105  int frames = backtrace(callstack, maxSize);
106  char** strs = backtrace_symbols(callstack, frames);
107 
108  std::cout << std::endl << "assertion failed:" << std::endl;
109  std::cout << "\t" << exp << std::endl;
110  if (str != nullptr)
111  std::cout << "\t(" << a << " " << str << " " << b << ")" << std::endl;
112  std::cout << "in " << file << ":" << line << std::endl << std::endl;
113 
114  for (int i = 0; i < frames; i++)
115  std::cout << strs[i] << std::endl;
116 
117  delete [] strs;
118  abort();
119 }
120 
121 // Evaluating x or y could have side-effects
122 // So we only do it once!
123 
124 #define assert(x) { \
125  auto assertEvalTemp = x; \
126  if (!assertEvalTemp) \
127  assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \
128 }
129 
130 #define assertEqual(x, y) { \
131  auto assertEvalTemp = x; \
132  auto assertEvalTemp2 = y; \
133  if (assertEvalTemp != assertEvalTemp2) \
134  assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \
135  __FILE__, __LINE__, "!="); \
136 }
137 
138 #define assertNotEqual(x, y) { \
139  auto assertEvalTemp = x; \
140  auto assertEvalTemp2 = y; \
141  if (assertEvalTemp == assertEvalTemp2) \
142  assertEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \
143  __FILE__, __LINE__, "=="); \
144 }
145 
146 #define assertLessThan(x, y) { \
147  auto assertEvalTemp = x; \
148  auto assertEvalTemp2 = y; \
149  if (assertEvalTemp >= assertEvalTemp2) \
150  assertEqualImplementation(#x " < " #y, assertEvalTemp, assertEvalTemp2, \
151  __FILE__, __LINE__, ">="); \
152 }
153 
154 #define assertLessThanEqual(x, y) { \
155  auto assertEvalTemp = x; \
156  auto assertEvalTemp2 = y; \
157  if (assertEvalTemp > assertEvalTemp2) \
158  assertEqualImplementation(#x " <= " #y, assertEvalTemp, assertEvalTemp2, \
159  __FILE__, __LINE__, ">"); \
160 }
161 
162 #define assertGreaterThan(x, y) { \
163  auto assertEvalTemp = x; \
164  auto assertEvalTemp2 = y; \
165  if (assertEvalTemp <= assertEvalTemp2) \
166  assertEqualImplementation(#x " > " #y, assertEvalTemp, assertEvalTemp2, \
167  __FILE__, __LINE__, "<="); \
168 }
169 
170 #define assertGreaterThanEqual(x, y) { \
171  auto assertEvalTemp = x; \
172  auto assertEvalTemp2 = y; \
173  if (assertEvalTemp < assertEvalTemp2) \
174  assertEqualImplementation(#x " >= " #y, assertEvalTemp, assertEvalTemp2, \
175  __FILE__, __LINE__, "<"); \
176 }
177 
178 #else // NODEBUG
179 
180 #define assert(x)
181 #define assertEqual(x, y)
182 #define assertNotEqual(x, y)
183 #define assertLessThan(x, y)
184 #define assertLessThanEqual(x, y)
185 #define assertGreaterThan(x, y)
186 #define assertGreaterThanEqual(x, y)
187 
188 #endif // NODEBUG
189 
190 #else // EXECINFO
191 
192 // Fall back to the default C assert
193 #include <cassert>
194 #define assertEqual(x, y) assert((x) == (y))
195 #define assertNotEqual(x, y) assert((x) != (y))
196 #define assertLessThan(x, y) assert((x) < (y))
197 #define assertLessThanEqual(x, y) assert((x) <= (y))
198 #define assertGreaterThan(x, y) assert((x) > (y))
199 #define assertGreaterThanEqual(x, y) assert((x) >= (y))
200 
201 #endif // EXECINFO
202 
203 #endif // _GLOBAL_H_
204 
Definition: global.h:48
Definition: global.h:61
Definition: global.h:48
Definition: global.h:61
Definition: global.h:44
Definition: global.h:63
Definition: global.h:43
Definition: global.h:49
Definition: global.h:40
Definition: global.h:61
Definition: global.h:41
Definition: global.h:36
Definition: global.h:49
Definition: global.h:40
void assertEqualImplementation(const char *exp, T a, U b, const char *file, int line, const char *str=nullptr)
Definition: global.h:101
KeyboardButton
Definition: global.h:34
Definition: global.h:45
Definition: global.h:36
Definition: global.h:36
Definition: global.h:47
void renderFrame()
Definition: main.cpp:147
Definition: global.h:37
Definition: global.h:42
Definition: global.h:43
Definition: global.h:45
Definition: global.h:44
Definition: global.h:49
Definition: global.h:45
Definition: global.h:39
Definition: global.h:37
ActionEvents
Definition: global.h:15
Definition: global.h:45
Definition: global.h:63
Definition: global.h:43
Definition: global.h:39
Definition: global.h:47
Definition: global.h:49
Definition: global.h:48
Definition: global.h:42
Definition: global.h:50
Definition: global.h:42
Definition: global.h:52
Definition: global.h:41
Definition: global.h:49
Definition: global.h:48
Definition: global.h:42
Definition: global.h:48
Definition: global.h:48
Definition: global.h:41
Definition: global.h:61
Definition: global.h:54
Definition: global.h:47
Definition: global.h:39
Definition: global.h:49
Definition: global.h:49
Definition: global.h:47
Definition: global.h:40
Definition: global.h:63
Definition: global.h:38
Definition: global.h:43
Definition: global.h:40
Definition: global.h:44
Definition: global.h:44
Definition: global.h:41