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