1 #ifndef SHAREDDEFINES_H_
2 #define SHAREDDEFINES_H_
3 
4 #include <stdint.h>
5 #include <string>
6 #include <memory>
7 #include <assert.h>
8 #include <vector>
9 #include <list>
10 #include <map>
11 #include <tinyxml.h>
12 #include <Box2D/Box2D.h>
13 #include <algorithm>
14 #include <cmath>
15 
16 #include "Logger/Logger.h"
17 #include "Util/StringUtil.h"
18 #include "Util/Util.h"
19 #include "Util/Profilers.h"
20 #include "Interfaces.h"
21 #include "Events/EventMgr.h"
22 #include "XmlMacros.h"
23 #include "Interfaces.h"
24 #include "SoundStrings.h"
25 #include "Util/XmlUtil.h"
26 #include "ActorDefinitions.h"
27 
28 using std::shared_ptr;
29 using std::unique_ptr;
30 using std::weak_ptr;
31 using std::static_pointer_cast;
32 
33 typedef uint64_t uint64;
34 typedef uint32_t uint32;
35 typedef uint16_t uint16;
36 typedef uint8_t uint8;
37 typedef int64_t int64;
38 typedef int32_t int32;
39 typedef int16_t int16;
40 typedef int8_t int8;
41 
42 #ifndef SAFE_DELETE
43 #define SAFE_DELETE(ptr)       { if (ptr) { delete (ptr);     (ptr)=NULL; } }
44 #endif
45 
46 #ifndef SAFE_DELETE_ARRAY
47 #define SAFE_DELETE_ARRAY(ptr) { if (ptr) { delete[] (ptr);   (ptr)=NULL; } }
48 #endif
49 
50 #ifndef PROFILE_CPU
51 #define PROFILE_CPU(tag) CPU_PROFILER _CPU_PROFILER_(tag);
52 #endif
53 
54 #ifndef PROFILE_MEMORY
55 #define PROFILE_MEMORY(tag) MEMORY_PROFILER _MEMORY_PROFILER_(tag);
56 #endif
57 
58 #ifndef max
59 #define max(a, b) ((a) < (b) ? (b) : (a))
60 #endif
61 
62 // Resource caches
63 // Hardcoding this saves A LOT of headaches
64 #define ORIGINAL_RESOURCE "CLAW_REZ"
65 #define CUSTOM_RESOURCE   "ASSETS_ZIP"
66 
67 const uint32 INVALID_ACTOR_ID = 0;
68 const uint32 INVALID_GAME_VIEW_ID = 0xFFFFFFFF;
69 
70 struct Position2D
71 {
Position2DPosition2D72     Position2D(int32 posX, int32 posY) : x(posX), y(posY) { }
Position2DPosition2D73     Position2D() { x = 0; y = 0; }
74 
75     int32 x;
76     int32 y;
77 };
78 
79 enum Orientation
80 {
81     Orientation_Left,
82     Orientation_Right
83 };
84 
85 template<class T>
86 struct SortBy_SharedPtr_Content
87 {
operatorSortBy_SharedPtr_Content88     bool operator()(const shared_ptr<T> &lhs, const shared_ptr<T> &rhs) const
89     {
90         return *lhs < *rhs;
91     }
92 };
93 
94 template <class Type>
MakeStrongPtr(std::weak_ptr<Type> pWeakPtr)95 inline std::shared_ptr<Type> MakeStrongPtr(std::weak_ptr<Type> pWeakPtr)
96 {
97     if (!pWeakPtr.expired())
98         return std::shared_ptr<Type>(pWeakPtr);
99     else
100         return std::shared_ptr<Type>();
101 }
102 
103 template
104 <typename KeyType, typename ValueType>
GetValueFromMap(KeyType _key,const std::map<KeyType,ValueType> & _map)105 ValueType GetValueFromMap(KeyType _key, const std::map<KeyType, ValueType>& _map)
106 {
107     auto findIt = _map.find(_key);
108     assert(findIt != _map.end() && "Failed to locate value from map");
109 
110     return findIt->second;
111 }
112 
113 #endif
114