Leviathan  0.8.0.0
Leviathan game engine
Define.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2019 Henri Hyyryläinen
3 #pragma once
4 // ------------------------------------ //
5 #include "Include.h"
6 
8 #include "ForwardDeclarations.h"
9 
15 #define NETWORK_USE_SNAPSHOTS
16 
17 #include <string>
18 
19 namespace Leviathan {
20 
23 
27 
29 constexpr auto INTERPOLATION_TIME = 0.1f;
30 
33 constexpr auto HEARTBEATS_MILLISECOND = 180;
34 
35 constexpr auto DEFAULT_MAXCONNECT_TRIES = 5;
36 
37 constexpr auto MAX_SERVERCOMMAND_LENGTH = 550;
38 
40 
41 constexpr auto PACKET_LOST_AFTER_MILLISECONDS = 1000;
42 
44 
45 constexpr auto CRITICAL_PACKET_MAX_TRIES = 8;
46 
47 constexpr auto BITS_IN_BYTE = 8;
48 
50 constexpr float NORMALIZATION_TOLERANCE = 1e-6f;
51 
52 #ifdef LEVIATHAN_VERSION
53 constexpr double VERSION = LEVIATHAN_VERSION;
54 static const std::string VERSIONS = LEVIATHAN_VERSION_ANSIS;
55 
56 constexpr int VERSION_STABLE = LEVIATHAN_VERSION_STABLE;
57 constexpr int VERSION_MAJOR = LEVIATHAN_VERSION_MAJOR;
58 constexpr int VERSION_MINOR = LEVIATHAN_VERSION_MINOR;
59 constexpr int VERSION_PATCH = LEVIATHAN_VERSION_PATCH;
60 #endif // LEVIATHAN_VERSION
61 
62 constexpr auto MICROSECONDS_IN_SECOND = 1000000;
63 
64 #ifndef PI
65 constexpr float PI = 3.14159265f;
66 constexpr float HALF_PI = PI / 2;
67 #endif // PI
68 constexpr float DEGREES_TO_RADIANS = PI / 180.f;
69 constexpr float RADIANS_TO_DEGREES = 180.f / PI;
70 constexpr float EPSILON = 0.00000001f;
71 } // namespace Leviathan
72 
73 
74 // AngelScript type registration (that isn't ReferenceCounted)
75 #ifdef LEVIATHAN_USING_ANGELSCRIPT
76 #define REFERENCE_HANDLE_UNCOUNTED_TYPE(x) static constexpr auto ANGELSCRIPT_TYPE = #x "@";
77 // Appended @ because these are handle types
78 #define REFERENCE_HANDLE_UNCOUNTED_TYPE_NAMED(x, y) \
79  static constexpr auto ANGELSCRIPT_TYPE = #y "@";
80 #define VALUE_TYPE(x) static constexpr auto ANGELSCRIPT_TYPE = #x;
81 #define VALUE_TYPE_NAMED(x, y) static constexpr auto ANGELSCRIPT_TYPE = #y;
82 #else
83 #define REFERENCE_HANDLE_UNCOUNTED_TYPE(x)
84 #define REFERENCE_HANDLE_UNCOUNTED_TYPE_NAMED(x, y)
85 #define VALUE_TYPE(x)
86 #define VALUE_TYPE_NAMED(x)
87 #endif // LEVIATHAN_USING_ANGELSCRIPT
88 
89 // Logging macros //
90 #define LOG_INFO(x) Logger::Get()->Info(x);
91 #define LOG_WARNING(x) Logger::Get()->Warning(x);
92 #define LOG_ERROR(x) Logger::Get()->Error(x);
93 #define LOG_WRITE(x) Logger::Get()->Write(x);
94 #define LOG_FATAL(x) \
95  Logger::Get()->Fatal(x + (", at: " __FILE__ "(" + std::to_string(__LINE__) + ")"));
96 
97 // Assertions for controlled crashing
98 #ifndef LEVIATHAN_ASSERT
99 #include <stdlib.h>
100 #define LEVIATHAN_ASSERT(x, msg) \
101  { \
102  if(!(x)) { \
103  LOG_FATAL(msg); \
104  abort(); \
105  } \
106  };
107 #endif // LEVIATHAN_ASSERT
108 
109 #ifdef _MSC_VER
110 
111 #ifndef DEBUG_BREAK
112 #define DEBUG_BREAK __debugbreak();
113 #endif // DEBUG_BREAK
114 
115 #elif defined __linux
116 
117 // For making SIGINT work as debug break on linux //
118 #include <signal.h>
119 #ifndef DEBUG_BREAK
120 #define DEBUG_BREAK \
121  { \
122  LOG_WRITE("DEBUG_BREAK HIT! at:"); \
123  LOG_WRITE(__FILE__ "(" + std::to_string(__LINE__) + ")"); \
124  ::raise(SIGINT); \
125  }
126 #endif // DEBUG_BREAK
127 
128 #else
129 
130 #error "Debug break won't work"
131 
132 #endif
133 
134 #define SAFE_RELEASE(x) \
135  { \
136  if(x) { \
137  (x)->Release(); \
138  (x) = NULL; \
139  } \
140  }
141 #define SAFE_RELEASEDEL(x) \
142  { \
143  if(x) { \
144  (x)->Release(); \
145  delete(x); \
146  (x) = NULL; \
147  } \
148  }
149 #define SAFE_DELETE(x) \
150  { \
151  if(x) { \
152  delete(x); \
153  (x) = NULL; \
154  } \
155  }
156 #define SAFE_DELETE_ARRAY(x) \
157  { \
158  if(x) { \
159  delete[](x); \
160  (x) = NULL; \
161  } \
162  }
163 
164 #define SAFE_RELEASE_VECTOR(x) \
165  { \
166  for(auto iter = x.begin(); iter != x.end(); ++iter) \
167  if(*iter) { \
168  (*iter)->Release(); \
169  } \
170  x.clear(); \
171  }
172 
173 #define SAFE_DELETE_VECTOR(x) \
174  for(size_t vdind = 0; vdind < x.size(); ++vdind) { \
175  if(x[vdind]) { \
176  delete x[vdind]; \
177  } \
178  }; \
179  x.clear();
180 
181 #define UNUSED(x) ((void)x);
182 
183 
184 #ifndef RESTRICT
185 #define RESTRICT __restrict
186 #endif
187 
188 #include "Logger.h"
#define LEVIATHAN_VERSION_MINOR
Definition: Include.h:60
constexpr float HALF_PI
Definition: Define.h:66
#define LEVIATHAN_VERSION
Definition: Include.h:54
#define LEVIATHAN_VERSION_PATCH
Definition: Include.h:61
constexpr auto BASESENDABLE_STORED_RECEIVED_STATES
Definition: Define.h:39
constexpr auto BITS_IN_BYTE
Definition: Define.h:47
constexpr auto CRITICAL_PACKET_MAX_TRIES
Definition: Define.h:45
#define LEVIATHAN_VERSION_MAJOR
Definition: Include.h:59
constexpr auto INTERPOLATION_TIME
Time in seconds to interpolate entities between states.
Definition: Define.h:29
#define LEVIATHAN_VERSION_ANSIS
Definition: Include.h:56
constexpr auto DEFAULT_HEADLESS_TICK_INTERVAL
Number of milliseconds between engine ticks in headless mode (no gui)
Definition: Define.h:25
constexpr auto HEARTBEATS_MILLISECOND
Definition: Define.h:33
#define LEVIATHAN_VERSION_STABLE
Definition: Include.h:58
constexpr auto MAX_SERVERCOMMAND_LENGTH
Definition: Define.h:37
constexpr auto DEFAULT_MAXCONNECT_TRIES
Definition: Define.h:35
constexpr auto PACKET_LOST_AFTER_RECEIVED_NEWER
Definition: Define.h:43
constexpr float EPSILON
Definition: Define.h:70
constexpr float RADIANS_TO_DEGREES
Definition: Define.h:69
constexpr float PI
Definition: Define.h:65
constexpr float DEGREES_TO_RADIANS
Definition: Define.h:68
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:50
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
constexpr auto DEFAULT_HEADLESS_MAX_UPDATES_PER_SECOND
Max "FPS" in headless mode.
Definition: Define.h:22
constexpr auto MICROSECONDS_IN_SECOND
Definition: Define.h:62
constexpr auto PACKET_LOST_AFTER_MILLISECONDS
Definition: Define.h:41