5 #include "EegeoPlatformMacros.h"
7 #include "AssertHandler.h"
8 #include "FatalErrorHandler.h"
9 #include "TtyHandler.h"
17 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Wlong-long"
21 #if defined (EEGEO_WIN)
22 typedef unsigned int uint;
24 typedef unsigned long long UInt64;
25 typedef long long unsigned int u64;
26 typedef unsigned int u32;
27 typedef unsigned short u16;
28 typedef unsigned char u8;
29 typedef long long signed int s64;
30 typedef signed int s32;
31 typedef signed short s16;
32 typedef signed char s8;
34 #pragma clang diagnostic pop
36 #if defined (EEGEO_DROID) || defined (EEGEO_WIN)
37 typedef unsigned char Byte;
38 #elif defined EEGEO_IOS
40 #elif defined OVR_OS_MAC
41 typedef unsigned char Byte;
42 #elif defined EEGEO_OSX
44 #elif defined EMSCRIPTEN
45 typedef unsigned char Byte;
46 typedef unsigned int uint;
49 #if defined (EEGEO_WIN)
50 #include "EegeoWindowsGuard.h"
53 #pragma clang diagnostic push
54 #pragma clang diagnostic ignored "-Wvariadic-macros"
55 #pragma clang diagnostic ignored "-Wgnu"
57 #define EEGEO_CLICKABLE_DEBUG_OUTPUT_ON_WINDOWS
59 #if defined(EEGEO_WIN) && defined(EEGEO_CLICKABLE_DEBUG_OUTPUT_ON_WINDOWS)
60 #define Eegeo_TTY(...) Eegeo::TtyHandler::HandleClickableTty(__FILE__, __LINE__, __VA_ARGS__)
61 #define Eegeo_ERROR(...) Eegeo::TtyHandler::HandleClickableTty(__FILE__, __LINE__, __VA_ARGS__)
63 #define Eegeo_TTY(...) Eegeo::TtyHandler::HandleTty(__VA_ARGS__)
64 #define Eegeo_ERROR(...) Eegeo::TtyHandler::HandleTty(__VA_ARGS__)
68 #if defined(EEGEO_UNITY)
69 #define Eegeo_GRAPHICS_ASSERT(...)
71 #define Eegeo_GRAPHICS_ASSERT Eegeo_ASSERT
74 #if defined (ENABLE_ASSERT)
75 #define Eegeo_ASSERT(x, ...) if(!(x)) { Eegeo::Assert(__FILE__, __LINE__, ##__VA_ARGS__); }
77 #define Eegeo_ASSERT(x, ...)
81 #define Eegeo_ASSERT_SLOW Eegeo_ASSERT
83 #define Eegeo_ASSERT_SLOW(x, ...)
85 #pragma clang diagnostic pop
87 #if defined (EEGEO_WIN)
88 #define Eegeo_STATIC_ASSERT( condition, name )
92 #define Eegeo_STATIC_ASSERT( condition, name ) typedef char assert_failed_ ## name [ (condition) ? 1 : -1 ] __attribute__((unused));
95 #define Eegeo_TRACE() Eegeo_TTY("Trace %s(%d)", __FILE__, __LINE__);
97 #define Eegeo_EXIT(x) Eegeo::FatalError(x)
103 #if defined(Eegeo_NOISY_NEW_ALL)
104 #include "DebugValues.h"
105 #define Eegeo_LOG_ALLOCATIONS Eegeo::Debug::DebugValues::loggingAllocations
106 #define Eegeo_NEW(type) (!Eegeo_LOG_ALLOCATIONS ? 0 : Eegeo_TTY("Scalar new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type
107 #define Eegeo_DELETE if(Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Scalar delete at %s :: %d\n", __FILE__, __LINE__);} delete
108 #define Eegeo_ARRAY_NEW(type, num) (!Eegeo_LOG_ALLOCATIONS ? 0 : Eegeo_TTY("Array new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type[num]
109 #define Eegeo_ARRAY_DELETE if(Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Array delete at %s :: %d\n", __FILE__, __LINE__);} delete[]
110 #elif defined(Eegeo_NOISY_NEW_MAIN_THREAD)
111 #include "DebugValues.h"
112 #define Eegeo_LOG_ALLOCATIONS Eegeo::Debug::DebugValues::loggingAllocations
113 #include "ThreadHelpers.h"
114 #define Eegeo_MAIN_THREAD Eegeo::Helpers::ThreadHelpers::IsMainThread()
115 #define Eegeo_NEW(type) ((!Eegeo_MAIN_THREAD || !Eegeo_LOG_ALLOCATIONS) ? 0 : Eegeo_TTY("Scalar new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type
116 #define Eegeo_DELETE if(Eegeo_MAIN_THREAD && Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Scalar delete at %s :: %d\n", __FILE__, __LINE__);} delete
117 #define Eegeo_ARRAY_NEW(type, num) ((!Eegeo_MAIN_THREAD || !Eegeo_LOG_ALLOCATIONS) ? 0 : Eegeo_TTY("Array new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type[num]
118 #define Eegeo_ARRAY_DELETE if(Eegeo_MAIN_THREAD && Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Array delete at %s :: %d\n", __FILE__, __LINE__);} delete[]
119 #elif defined(Eegeo_MEMORY_TRACKING_NEW)
121 #include "AllocHelper.h"
123 #define Eegeo_TYPE_TO_STRING(...) typeid(__VA_ARGS__).name()
125 #define Eegeo_NEW(...) (Eegeo::AllocHelper(Eegeo_TYPE_TO_STRING(__VA_ARGS__), __FILE__, __LINE__)) << new (__VA_ARGS__)
126 #define Eegeo_DELETE delete
128 #define Eegeo_ARRAY_NEW(type, num) (Eegeo::AllocHelper(Eegeo_TYPE_TO_STRING(type), __FILE__, __LINE__, (int)(num))) << new type[num]
129 #define Eegeo_ARRAY_DELETE delete[]
131 #define Eegeo_NEW(type) new type
132 #define Eegeo_DELETE delete
133 #define Eegeo_ARRAY_NEW(type, num) new type[num]
134 #define Eegeo_ARRAY_DELETE delete[]
137 #if defined(__GNUC__) || defined(__MINGW32__)
138 #define EEGEO_ALIGNED(N) __attribute__ ((aligned (N)))
139 #elif defined(_MSC_VER)
140 #define EEGEO_ALIGNED(N) __declspec(align(N))
142 #define EEGEO_ALIGNED(N)
145 #define CHECK_CASTS 0
151 template<
typename T,
typename U>
154 T t =
dynamic_cast<T
>(u);
155 Eegeo_ASSERT(t != NULL,
"Object of type %s is not an instance of type %s.\n",
typeid(U).name(),
typeid(T).name());
162 template<
typename T,
typename U>
165 return static_cast<T
>(u);