-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.hpp
204 lines (173 loc) · 5.05 KB
/
main.hpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#pragma once
#include "./Singleton.hpp"
#include "sdk.hpp"
#include "component.hpp"
#include "Server/Components/Pickups/pickups.hpp"
#include "Server/Components/Objects/objects.hpp"
#include "Server/Components/TextLabels/textlabels.hpp"
#include "Server/Components/Vehicles/vehicles.hpp"
#include "Server/Components/Checkpoints/checkpoints.hpp"
#include "Server/Components/Actors/actors.hpp"
namespace ompgdk
{
class GDKManager : public Singleton<GDKManager>
{
public:
/// Initialize open.mp gdk
void Init(ICore* c, IComponentList* clist);
/// Get open.mp core instance
ICore* GetCore()
{
return core;
}
/// Get player pool
IPlayerPool* GetPlayers()
{
return players;
}
/// Get an open.mp component
template<typename ComponentType>
ComponentType* GetComponent()
{
return componentList->queryComponent<ComponentType>();
}
/// Get pickups component
IPickupsComponent* GetPickups()
{
return pickups;
}
/// Get objects component
IObjectsComponent* GetObjects()
{
return objects;
}
/// Get vehicles component
IVehiclesComponent* GetVehicles()
{
return vehicles;
}
/// Get textlabels component
ITextLabelsComponent* GetTextLabels()
{
return textlabels;
}
/// Get actors component
IActorsComponent* GetActors()
{
return actors;
}
private:
ICore* core = nullptr;
IComponentList* componentList = nullptr;
IPlayerPool* players = nullptr;
IPickupsComponent* pickups = nullptr;
IObjectsComponent* objects = nullptr;
ITextLabelsComponent* textlabels = nullptr;
IVehiclesComponent* vehicles = nullptr;
IActorsComponent* actors = nullptr;
};
/// Get player from players pool
inline IPlayer* GetPlayer(int playerid)
{
IPlayerPool* pool = GDKManager::Get()->GetPlayers();
if (pool == nullptr)
{
return nullptr;
}
return pool->get(playerid);
}
/// Get player from players pool
template<typename PlayerDataType>
inline PlayerDataType* GetPlayerData(int playerid)
{
IPlayer* player = ompgdk::GetPlayer(playerid);
if (player == nullptr)
{
return nullptr;
}
return queryExtension<PlayerDataType>(*player);
}
/// Get player entity using provided player id and entity id
template<typename PlayerEntityPoolType, typename EntityType>
inline EntityType* GetPlayerEntity(int playerid, int entity_id)
{
PlayerEntityPoolType* pool = ompgdk::GetPlayerData<PlayerEntityPoolType>(playerid);
if (pool == nullptr)
{
return nullptr;
}
return pool->get(entity_id);
}
/// Get entity using provided entity id
template<typename EntityType, typename EntityPoolType>
inline EntityType* GetEntity(int entity_id)
{
EntityPoolType* pool = GDKManager::Get()->GetComponent<EntityPoolType>();
if (pool == nullptr)
{
return nullptr;
}
return pool->get(entity_id);
}
/// Just a dummy function and it returns nullptr, overloads will do the job
template<typename EntityType>
inline EntityType* GetEntity(int entity_id)
{
return nullptr;
}
template<>
inline IPickup* GetEntity<IPickup>(int entity_id)
{
IPickupsComponent* pickups = GDKManager::Get()->GetPickups();
if (pickups == nullptr)
{
return nullptr;
}
return pickups->get(entity_id);
}
template<>
inline IVehicle* GetEntity<IVehicle>(int entity_id)
{
IVehiclesComponent* vehicles = GDKManager::Get()->GetVehicles();
if (vehicles == nullptr)
{
return nullptr;
}
return vehicles->get(entity_id);
}
template<>
inline IActor* GetEntity<IActor>(int entity_id)
{
IActorsComponent* actors = GDKManager::Get()->GetActors();
if (actors == nullptr)
{
return nullptr;
}
return actors->get(entity_id);
}
template<>
inline IObject* GetEntity<IObject>(int entity_id)
{
IObjectsComponent* objects = GDKManager::Get()->GetObjects();
if (objects == nullptr)
{
return nullptr;
}
return objects->get(entity_id);
}
/// Get player using provided player id, return fail_ret if not available
#define GET_PLAYER_CHECKED(player_output, playerid, fail_ret) \
IPlayer* player_output = ompgdk::GetPlayer(playerid); \
if(player_output == nullptr) return fail_ret;
/// Get player object, return fail_ret if not available
#define GET_PLAYER_OBJECT_CHECKED(object_output, playerid, objectid, fail_ret) \
IPlayerObject* object_output = ompgdk::GetPlayerEntity<IPlayerObjectData, IPlayerObject>(playerid, objectid); \
if(object_output == nullptr) return fail_ret;
/// Get player textlabels, return fail_ret if not available
#define GET_PLAYER_TEXT_LABEL_CHECKED(text_label_output, playerid, textlabelid, fail_ret) \
IPlayerTextLabel* text_label_output = ompgdk::GetPlayerEntity<IPlayerTextLabelData, IPlayerTextLabel>(playerid, textlabelid); \
if(text_label_output == nullptr) return fail_ret;
#define GET_ENTITY_CHECKED(entity_output, entity_type, entity_id, fail_ret) \
entity_type* entity_output = ompgdk::GetEntity<entity_type>(entity_id); \
if(entity_output == nullptr) return fail_ret;
}