gwnavruntime/base/types.h Source File

types.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 #ifndef Navigation_Types_H
9 #define Navigation_Types_H
10 
11 
13 
14 #if defined(KY_OS_XBOX360)
15 # include <ppcintrinsics.h>
16 #endif
17 
18 #if defined(KY_OS_PS3)
19 # include <ppu_intrinsics.h>
20 #else
21 # include <math.h>
22 #endif
23 
24 // KY_NO_LOG_OUTPUT is different from KY_NO_DEBUG_OUTPUT
25 // => KY_NO_DEBUG_OUTPUT disables KY_DEBUG_XXX macros
26 // => KY_NO_LOG_OUTPUT disables all KY_LOG_XXX macros and Kaim::LogStream() <<
27 #if defined(KY_BUILD_SHIPPING)
28 # define KY_NO_LOG_OUTPUT
29 #endif
30 
31 //------------------------------------------------------------------------------------------------
32 // WIN32/64 (KY_OS_WIN32 means 32bits and 64bits)
33 #if defined (KY_OS_WIN32)
34 
35 typedef int KyInt32;
36 typedef unsigned int KyUInt32;
37 typedef __int64 KyInt64;
38 typedef unsigned __int64 KyUInt64;
39 typedef short KyInt16;
40 typedef unsigned short KyUInt16;
41 typedef unsigned char KyUInt8;
42 typedef signed char KyInt8;
43 typedef float KyFloat32;
44 typedef double KyFloat64;
45 
46 #endif
47 
48 
49 //------------------------------------------------------------------------------------------------
50 // XBOX360
51 #if defined(KY_OS_XBOX360)
52 
53 typedef int KyInt32;
54 typedef unsigned int KyUInt32;
55 typedef __int64 KyInt64;
56 typedef unsigned __int64 KyUInt64;
57 typedef short KyInt16;
58 typedef unsigned short KyUInt16;
59 typedef unsigned char KyUInt8;
60 typedef signed char KyInt8;
61 typedef float KyFloat32;
62 typedef double KyFloat64;
63 
64 #endif
65 
66 //------------------------------------------------------------------------------------------------
67 // WII
68 #if defined (KY_OS_WIIU)
69 
70 typedef int KyInt32;
71 typedef unsigned int KyUInt32;
72 typedef long long KyInt64;
73 typedef unsigned long long KyUInt64;
74 typedef short KyInt16;
75 typedef unsigned short KyUInt16;
76 typedef unsigned char KyUInt8;
77 typedef signed char KyInt8;
78 typedef float KyFloat32;
79 typedef double KyFloat64;
80 
81 #endif
82 
83 //-----------------------------------------------------------------------------------------------
84 // LINUX64
85 #if defined(KY_OS_LINUX) && defined(KY_64BIT_POINTERS)
86 
87 typedef int KyInt32;
88 typedef unsigned int KyUInt32;
89 typedef long KyInt64;
90 typedef unsigned long KyUInt64;
91 typedef short KyInt16;
92 typedef unsigned short KyUInt16;
93 typedef unsigned char KyUInt8;
94 typedef signed char KyInt8;
95 typedef float KyFloat32;
96 typedef double KyFloat64;
97 
98 #endif
99 
100 //-----------------------------------------------------------------------------------------------
101 // LINUX32
102 
103 #if defined(KY_OS_LINUX) && !defined(KY_64BIT_POINTERS)
104 
105 typedef int KyInt32;
106 typedef unsigned int KyUInt32;
107 typedef long long KyInt64;
108 typedef unsigned long long KyUInt64;
109 typedef short KyInt16;
110 typedef unsigned short KyUInt16;
111 typedef unsigned char KyUInt8;
112 typedef signed char KyInt8;
113 typedef float KyFloat32;
114 typedef double KyFloat64;
115 
116 #endif
117 
118 //-----------------------------------------------------------------------------------------------
119 // MAC64
120 #if defined(KY_OS_MAC) && defined(KY_64BIT_POINTERS)
121 
122 typedef int KyInt32;
123 typedef unsigned int KyUInt32;
124 typedef long KyInt64;
125 typedef unsigned long KyUInt64;
126 typedef short KyInt16;
127 typedef unsigned short KyUInt16;
128 typedef unsigned char KyUInt8;
129 typedef signed char KyInt8;
130 typedef float KyFloat32;
131 typedef double KyFloat64;
132 
133 #endif
134 
135 //-----------------------------------------------------------------------------------------------
136 // MAC32
137 #if defined (KY_OS_MAC) && !defined(KY_64BIT_POINTERS)
138 
139 typedef int KyInt32;
140 typedef unsigned int KyUInt32;
141 typedef long long KyInt64;
142 typedef unsigned long long KyUInt64;
143 typedef short KyInt16;
144 typedef unsigned short KyUInt16;
145 typedef unsigned char KyUInt8;
146 typedef signed char KyInt8;
147 typedef float KyFloat32;
148 typedef double KyFloat64;
149 
150 #endif
151 
152 //-----------------------------------------------------------------------------------------------
153 // iPhone
154 #if defined (KY_OS_IPHONE)
155 
156 typedef int KyInt32;
157 typedef unsigned int KyUInt32;
158 typedef long long KyInt64;
159 typedef unsigned long long KyUInt64;
160 typedef short KyInt16;
161 typedef unsigned short KyUInt16;
162 typedef unsigned char KyUInt8;
163 typedef signed char KyInt8;
164 typedef float KyFloat32;
165 typedef double KyFloat64;
166 
167 #endif
168 
169 //-----------------------------------------------------------------------------------------------
170 // NGP
171 #if defined (KY_OS_PSVITA)
172 
173 typedef int KyInt32;
174 typedef unsigned int KyUInt32;
175 typedef long long KyInt64;
176 typedef unsigned long long KyUInt64;
177 typedef short KyInt16;
178 typedef unsigned short KyUInt16;
179 typedef unsigned char KyUInt8;
180 typedef signed char KyInt8;
181 typedef float KyFloat32;
182 typedef double KyFloat64;
183 
184 #endif
185 
186 
187 //-----------------------------------------------------------------------------------------------
188 // PS3
189 #if defined (KY_OS_PS3)
190 
191 typedef int KyInt32;
192 typedef unsigned int KyUInt32;
193 typedef long long KyInt64;
194 typedef unsigned long long KyUInt64;
195 typedef short KyInt16;
196 typedef unsigned short KyUInt16;
197 typedef unsigned char KyUInt8;
198 typedef signed char KyInt8;
199 typedef float KyFloat32;
200 typedef double KyFloat64;
201 
202 #endif
203 
204 //-----------------------------------------------------------------------------------------------
205 // ORBIS
206 #if defined (KY_OS_ORBIS)
207 
208 typedef int KyInt32;
209 typedef unsigned int KyUInt32;
210 typedef long long KyInt64;
211 typedef unsigned long long KyUInt64;
212 typedef short KyInt16;
213 typedef unsigned short KyUInt16;
214 typedef unsigned char KyUInt8;
215 typedef signed char KyInt8;
216 typedef float KyFloat32;
217 typedef double KyFloat64;
218 
219 #endif
220 
221 
222 //----------------------------------------------------------------------------------------
223 // types MAXVAL and MINVAL
224 #define KyInt32MAXVAL 0x7FFFFFFF
225 #define KyInt32MINVAL 0x80000000
226 #define KyUInt32MAXVAL 0xFFFFFFFF
227 #define KyFloat32MAXVAL 3.402823466e+38f
228 #define KyInt16MAXVAL 0x7FFF
229 #define KyInt16MINVAL 0x8000
230 #define KyUInt16MAXVAL 0xFFFF
231 #define KyInt8MAXVAL 0x7F
232 #define KyInt8MINVAL 0x80
233 #define KyUInt8MAXVAL 0xFF
234 #define KyInt64MAXVAL 0x7FFFFFFFFFFFFFFFLL
235 #define KyUInt64MAXVAL 0xFFFFFFFFFFFFFFFFULL
236 
237 
238 //----------------------------------------------------------------------------------------
239 // KY_PERF_MARKERS_ENABLED
240 #if defined(KY_BUILD_RELEASE)
241 # define KY_PERF_MARKERS_ENABLED
242 #endif
243 
244 
245 //----------------------------------------------------------------------------------------
246 // KY_NULL
247 #define KY_NULL 0
248 
249 
250 //----------------------------------------------------------------------------------------
251 // KyResult, KY_ERROR, KY_SUCCESS, KY_FAILED(), KY_SUCCEEDED()
252 
255 
256 namespace Kaim
257 {
258 namespace Result
259 {
260  static const KyResult Success = 1;
261  static const KyResult Failure = 0;
262 
265  inline bool Check(KyResult result) { return result == Success; }
266 
268  inline bool Fail(KyResult result) { return result == Failure; }
269 }
270 }
271 
272 #define KY_ERROR Kaim::Result::Failure
273 #define KY_SUCCESS Kaim::Result::Success
274 #define KY_FAILED(expression) (Kaim::Result::Fail(expression))
275 #define KY_SUCCEEDED(expression) (Kaim::Result::Check(expression))
276 
277 // Returns KY_ERROR if expression == KY_ERROR
278 #define KY_FORWARD_ERROR_NO_LOG(expression) { KyResult result = (expression); if (result == KY_ERROR) { return result; }}
279 
280 
281 
282 //----------------------------------------------------------------------------------------
283 // KY_DEPRECATED
286 #ifndef KY_DEPRECATED
287 # if (defined (KY_OS_WIN32) || defined (KY_OS_XBOX360)) && !defined (KY_CC_GNU)
288 # define KY_DEPRECATED(f) __declspec(deprecated) f
289 # elif defined(KY_OS_LINUX) || defined(KY_OS_MAC) || defined (KY_OS_PS3) || defined (KY_CC_GNU)
290 # define KY_DEPRECATED(f) f __attribute__ ((deprecated))
291 # else
292 # define KY_DEPRECATED(f) f
293 # endif
294 #endif
295 
296 #if 0 // Following shows how to use macro KY_DEPRECATED
297 // ------------ Correct way ------------
298 void func1(int) {}
299 KY_DEPRECATED (void func1(int));
300 struct A
301 {
302  KY_DEPRECATED(void f()) {}
303 };
304 KY_DEPRECATED(struct) B {};
305 typedef KY_DEPRECATED(typeA typeB); // makes typeB deprecated
306 // ------------ Incorrect way ------------
307 // KY_DEPRECATED (void func2(int)) {} // Doesn't work with gcc (function-definition)
308 class C
309 {
310  void f() {}
311 };
312 // KY_DEPRECATED(void C::f()); // Doesn't work with msvc (error C2761: member function redeclaration not allowed)
313 // KY_DEPRECATED(struct D) {}; // Doesn't work with gcc
314 // struct KY_DEPRECATED(E) {}; // Doesn't work with gcc
315 #endif
316 
317 
318 //----------------------------------------------------------------------------------------
319 // KY_MACRO_START KY_MACRO_END
320 #if defined(KY_CC_MSVC)
321 # define KY_MACRO_START \
322  do { \
323  KY_PUSH_COMPILE_WARNING \
324  KY_PRAGMA_WARNING_DISABLE(4127)
325 # define KY_MACRO_END \
326  } while(0) \
327  KY_POP_COMPILE_WARNING
328 #else
329 # define KY_MACRO_START do {
330 # define KY_MACRO_END } while(0)
331 #endif
332 
333 
334 //----------------------------------------------------------------------------------------
335 // KY_DISABLE_ALIGN_WARNING_START KY_DISABLE_ALIGN_WARNING_END
336 #if defined(KY_CC_MSVC)
337 # define KY_DISABLE_ALIGN_WARNING_START KY_PUSH_COMPILE_WARNING KY_PRAGMA_WARNING_DISABLE(4324) // structure was padded due to __declspec(align())
338 # define KY_DISABLE_ALIGN_WARNING_END KY_POP_COMPILE_WARNING
339 #else
340 # define KY_DISABLE_ALIGN_WARNING_START
341 # define KY_DISABLE_ALIGN_WARNING_END
342 #endif
343 
344 
345 //----------------------------------------------------------------------------------------
346 // KY_FORCE_ALIGNMENT
347 #if (defined (KY_OS_WIN32) || defined (KY_OS_XBOX360)) && !defined (KY_CC_GNU)
348 # define KY_FORCE_ALIGNMENT(alignment, declaration) __declspec(align(alignment)) declaration
349 #elif defined(KY_OS_LINUX) || defined(KY_OS_MAC) || defined (KY_OS_PS3) || defined (KY_OS_WII) || defined (KY_CC_GNU) || defined (KY_OS_PSVITA)
350 # define KY_FORCE_ALIGNMENT(alignment, declaration) declaration __attribute__((aligned(alignment)))
351 #endif
352 
353 
354 //----------------------------------------------------------------------------------------
355 // ArraySize
356 namespace Kaim
357 {
359 template<typename T, KyUInt32 N>
360 KY_INLINE KyUInt32 ArraySize(T (&) [N]) { return N; }
361 }
362 
363 //----------------------------------------------------------------------------------------
364 // trigonometry
365 namespace Kaim
366 {
367 
369 static const KyFloat32 KY_PI = 3.14159265f;
372 static const KyFloat32 KY_2_PI = 2.0f * KY_PI;
375 const KyFloat32 KY_PI_DIVIDED_BY_180 = KY_PI / 180.0f;
378 inline KyFloat32 GetRadiansFromDegrees(KyFloat32 degrees) { return degrees * KY_PI_DIVIDED_BY_180; }
380 }
381 
382 
383 //----------------------------------------------------------------------------------------
384 // KY_CLASS_WITHOUT_COPY
386 #define KY_CLASS_WITHOUT_COPY(ClassName) \
387 private: \
388  ClassName(const ClassName& rhs); \
389  ClassName& operator=(const ClassName& rhs);
390 
391 
392 //----------------------------------------------------------------------------------------
393 // #### Usage for non-template class or functions :
394 // # Due to MSVC8, this usage can't be applied for template functions and classes,
395 // # even though it works fine on all other platforms, so in these situations please use the other usage listed after.
396 // class MyClass { void MyFunc(); }
397 // void MyClass::MyFunc()
398 // {
399 // KY_EXIT_SCOPE_BEGIN(MyClass)
400 // self->DoSomeCleaningWhenReturningFromMyFunc();
401 // KY_EXIT_SCOPE_END
402 // ...
403 // }
404 //
405 // #### Usage for template functions :
406 // class MyClass { template<typename T> void MyFunc(); }
407 //
408 // KY_EXIT_CLASS_SCOPE_BEGIN(MyClass, MyFunc)
409 // self->DoSomeCleaningWhenReturningFromMyFunc();
410 // KY_EXIT_CLASS_SCOPE_END
411 //
412 // template<typename T>
413 // void MyClass::MyFunc()
414 // {
415 // KY_EXIT_SCOPE_INSTANCE(MyClass, MyFunc)
416 // ...
417 // }
418 //
419 // #### Usage for template class :
420 // template<class T>
421 // class MyClass { void MyFunc(); }
422 //
423 // KY_EXIT_CLASS_TEMPLATE_SCOPE_BEGIN(MyClass, MyFunc, T)
424 // self->DoSomeCleaningWhenReturningFromMyFunc();
425 // KY_EXIT_CLASS_SCOPE_END
426 //
427 // template<class T>
428 // void MyClass<T>::MyFunc()
429 // {
430 // KY_EXIT_SCOPE_TEMPLATE_INSTANCE(MyClass, MyFunc, T)
431 // ...
432 // }
433 //
434 // ### Usage in all other cases:
435 // Write your class by hand.
436 
437 // Used by other macros
438 #define KY_EXIT_CLASS_TEMPLATE_SCOPE_BASE(classname, functionname, templateDeclareParam, templateUseParam) \
439 template templateDeclareParam \
440 struct classname##_##functionname##_OnExit { \
441  classname templateUseParam * self; \
442  classname##_##functionname##_OnExit(classname templateUseParam * self_) : self(self_) {} \
443  ~classname##_##functionname##_OnExit() \
444  {
445 
446 // To use with template class
447 #define KY_EXIT_CLASS_TEMPLATE_SCOPE_BEGIN(classname, functionname, templateParamName) \
448 KY_EXIT_CLASS_TEMPLATE_SCOPE_BASE(classname, functionname, <typename templateParamName>, <templateParamName>)
449 
450 
451 // To use with template function
452 #define KY_EXIT_CLASS_SCOPE_BEGIN(classname, functionname) \
453 struct classname##_##functionname##_OnExit { \
454  classname* self; \
455  classname##_##functionname##_OnExit(classname* self_) : self(self_) {} \
456  ~classname##_##functionname##_OnExit() \
457  {
458 
459 #define KY_EXIT_CLASS_SCOPE_END \
460  } \
461 }; \
462 
463 // To use in function of template class
464 #define KY_EXIT_SCOPE_TEMPLATE_INSTANCE(classname, functionname, templateParamName) \
465 classname##_##functionname##_OnExit <templateParamName> classname##_##functionname##_OnExit_Instance(this);
466 
467 // To use in template function
468 #define KY_EXIT_SCOPE_INSTANCE(classname, functionname) \
469 classname##_##functionname##_OnExit classname##_##functionname##_OnExit_Instance(this);
470 
471 // To use in non-template function of non-template class
472 #define KY_EXIT_SCOPE_BEGIN(classname) \
473 KY_EXIT_CLASS_SCOPE_BEGIN(classname, local)
474 
475 // To use in non-template function of non-template class
476 #define KY_EXIT_SCOPE_END(classname) \
477 KY_EXIT_CLASS_SCOPE_END \
478 KY_EXIT_SCOPE_INSTANCE(classname, local)
479 
480 
481 
482 //----------------------------------------------------------------------------------------
484 // The Ctor is declared but not defined on purpose since this class is not intended to be instantiated
485 // It will cause an error during link like this :
486 // error LNK2019: unresolved external symbol "private: __cdecl ClassName::ClassName(void)"
487 #define KY_TRAVERSE_LOGIC(ClassName, costMode, canEnterMode) \
488 private: \
489  ClassName(); \
490  KY_CLASS_WITHOUT_COPY(ClassName) \
491  /* For checking Obsolete Functions, cf. TraverseLogicObsoleteChecker */ \
492  friend class TraverseLogicObsoleteChecker; \
493  typedef ClassName<canEnterMode> BaseClass; \
494 public: \
495  typedef costMode CostMultiplierUsage; \
496  typedef canEnterMode CanEnterNavTagMode; \
497 private:
498 
499 
500 #endif // Navigation_Types_H
static const KyFloat32 KY_PI
Stores the value of pi.
Definition: types.h:370
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
static const KyResult Failure
Indicates that the requested operation could not be successfully completed. This return indicates the...
Definition: types.h:261
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
unsigned __int64 KyUInt64
Type used internally to represent an unsigned 64-bit integer.
Definition: types.h:38
unsigned char KyUInt8
Type used internally to represent an unsigned 8-bit integer.
Definition: types.h:41
bool Fail(KyResult result)
Returns true if the specified result code indicates that the requested operation failed.
Definition: types.h:268
Definition: gamekitcrowddispersion.h:20
#define KY_DEPRECATED(f)
Macro to mark a function, class or method as deprecated.
Definition: types.h:289
KyUInt32 ArraySize(T(&)[N])
Returns the size of a fixed-size array.
Definition: types.h:361
unsigned short KyUInt16
Type used internally to represent an unsigned 16-bit integer.
Definition: types.h:40
const KyFloat32 KY_PI_DIVIDED_BY_180
Stores the value of KY_PI divided by 180.
Definition: types.h:376
signed char KyInt8
Type used internally to represent an 8-bit integer.
Definition: types.h:42
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
static const KyFloat32 KY_2_PI
Stores the value of twice pi.
Definition: types.h:373
static const KyResult Success
Indicates that the requested operation was successfully completed.
Definition: types.h:260
bool Check(KyResult result)
Returns true if the specified result code indicates that the requested operation successfully complet...
Definition: types.h:265
double KyFloat64
Type used internally to represent a 64-bit floating-point number.
Definition: types.h:44
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
short KyInt16
Type used internally to represent a 16-bit integer.
Definition: types.h:39
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
KyFloat32 GetRadiansFromDegrees(KyFloat32 degrees)
Returns angle in radians converted from angle in degrees.
Definition: types.h:379