forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathElunaUtility.h
119 lines (100 loc) · 3.39 KB
/
ElunaUtility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (C) 2010 - 2020 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef _ELUNA_UTIL_H
#define _ELUNA_UTIL_H
#include <unordered_map>
#include <unordered_set>
#include <mutex>
#include <memory>
#include "Common.h"
#include "SharedDefines.h"
#include "ObjectGuid.h"
#include "QueryResult.h"
#include "Log.h"
typedef QueryResult ElunaQuery;
#define ELUNA_LOG_INFO(...) TC_LOG_INFO("eluna", __VA_ARGS__);
#define ELUNA_LOG_ERROR(...) TC_LOG_ERROR("eluna", __VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) TC_LOG_DEBUG("eluna", __VA_ARGS__);
#define GET_GUID GetGUID
#define HIGHGUID_PLAYER HighGuid::Player
#define HIGHGUID_UNIT HighGuid::Creature
#define HIGHGUID_ITEM HighGuid::Item
#define HIGHGUID_GAMEOBJECT HighGuid::GameObject
#define HIGHGUID_PET HighGuid::Pet
#define HIGHGUID_TRANSPORT HighGuid::Transport
#define HIGHGUID_VEHICLE HighGuid::Vehicle
#define HIGHGUID_DYNAMICOBJECT HighGuid::DynamicObject
#define HIGHGUID_CORPSE HighGuid::Corpse
#define HIGHGUID_GROUP HighGuid::Party
class Unit;
class WorldObject;
struct FactionTemplateEntry;
namespace ElunaUtil
{
uint32 GetCurrTime();
uint32 GetTimeDiff(uint32 oldMSTime);
class ObjectGUIDCheck
{
public:
ObjectGUIDCheck(ObjectGuid guid);
bool operator()(WorldObject* object);
ObjectGuid _guid;
};
// Binary predicate to sort WorldObjects based on the distance to a reference WorldObject
class ObjectDistanceOrderPred
{
public:
ObjectDistanceOrderPred(WorldObject const* pRefObj, bool ascending = true);
bool operator()(WorldObject const* pLeft, WorldObject const* pRight) const;
WorldObject const* m_refObj;
const bool m_ascending;
};
// Doesn't get self
class WorldObjectInRangeCheck
{
public:
WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range,
uint16 typeMask = 0, uint32 entry = 0, uint32 hostile = 0, uint32 dead = 0);
WorldObject const& GetFocusObject() const;
bool operator()(WorldObject* u);
WorldObject const* const i_obj;
Unit const* i_obj_unit;
FactionTemplateEntry const* i_obj_fact;
uint32 const i_hostile; // 0 both, 1 hostile, 2 friendly
uint32 const i_entry;
float i_range;
uint16 const i_typeMask;
uint32 const i_dead; // 0 both, 1 alive, 2 dead
bool const i_nearest;
};
/*
* Usage:
* Inherit this class, then when needing lock, use
* Guard guard(GetLock());
*
* The lock is automatically released at end of scope
*/
class Lockable
{
public:
typedef std::mutex LockType;
typedef std::lock_guard<LockType> Guard;
LockType& GetLock() { return _lock; }
private:
LockType _lock;
};
/*
* Encodes `data` in Base-64 and store the result in `output`.
*/
void EncodeData(const unsigned char* data, size_t input_length, std::string& output);
/*
* Decodes `data` from Base-64 and returns a pointer to the result, or `NULL` on error.
*
* The returned result buffer must be `delete[]`ed by the caller.
*/
unsigned char* DecodeData(const char* data, size_t *output_length);
};
#endif