-
Notifications
You must be signed in to change notification settings - Fork 18
/
players.h
188 lines (161 loc) · 4.41 KB
/
players.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
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
#ifndef PLAYERS_H
#define PLAYERS_H
/*
* Here is the basic data for the players.
* It is used by the various features of the framework.
* Game specific functions are needed to be implemented
* to fill in the data.
*/
#include "math/mmath.h"
#include "utils/intersect.h"
#include "utils/shared_utils.h"
#include <string.h>
constexpr int PLAYER_CHUNKS = NumOfSIMD(MAX_PLAYERS);
const int NAME_LEN = 32;
const int MAX_HITBOXES = 16;
constexpr int HITBOX_CHUNKS = NumOfSIMD(MAX_HITBOXES);
#ifndef MULTIPOINT_COUNT
constexpr size_t MULTIPOINT_COUNT = 8;
#endif
using mvec3 = vec3soa<float, MULTIPOINT_COUNT>;
/*
UPDATED is set when EXISTS is set and something was updated
HITBOXES_UPDATED is set when all the hitbox data was updated (so that aimbot data is correct)
Other flags are self-explanatory
*/
enum Flags
{
EXISTS = (1 << 0),
UPDATED = (1 << 1),
ONGROUND = (1 << 2),
DUCKING = (1 << 3),
HITBOXES_UPDATED = (1 << 4),
FRIENDLY = (1 << 5)
};
enum Keys
{
ATTACK1 = (1 << 0),
ATTACK2 = (1 << 1),
JUMP = (1 << 2)
};
struct alignas(SIMD_COUNT * 4)
HitboxList
{
matrix<3,4> wm[MAX_HITBOXES];
vec3_t start[MAX_HITBOXES];
vec3_t end[MAX_HITBOXES];
float damageMul[MAX_HITBOXES];
float radius[MAX_HITBOXES];
mvec3 mpOffset[MAX_HITBOXES];
mvec3 mpDir[MAX_HITBOXES];
};
/*
All player data is sorted in some fashion.
To access the player by its internal ID, use the sortIDs member
Player instance should be kept externally as it may lead to invalid pointers on history worlds
*/
struct Players
{
vec3_t* boundsStart;
vec3_t* boundsEnd;
vec3_t* origin;
vec3_t* eyePos;
vec3_t* velocity;
CapsuleColliderSOA<SIMD_COUNT> (*colliders)[NumOfSIMD(MAX_HITBOXES)];
HitboxList* hitboxes;
int* flags;
int* health;
int* armor;
float* time;
char (*name)[NAME_LEN];
float* fov;
matrix<3,4> (*bones)[MAX_BONES];
//Used for sorting the player
int sortIDs[MAX_PLAYERS];
int unsortIDs[MAX_PLAYERS];
int count;
float globalTime;
static constexpr size_t sizePerPlayer = sizeof(boundsStart[0]) + sizeof(boundsEnd[0]) + sizeof(origin[0]) + sizeof(eyePos[0]) + sizeof(velocity[0]) + sizeof(colliders[0]) + sizeof(hitboxes[0]) + sizeof(flags[0]) + sizeof(health[0]) + sizeof(armor[0]) + sizeof(time[0]) + sizeof(name[0]) + sizeof(fov[0]) + sizeof(bones[0]);
static constexpr size_t extraAlignmentNeeds = alignof(vec3_t) * 5 + alignof(decltype(colliders[0])) + alignof(decltype(hitboxes[0])) + alignof(void*) + alignof(int) * 3 + alignof(float) + alignof(char*) + alignof(float) + alignof(decltype(bones));
const auto& operator=(Players& o)
{
memcpy(this, &o, sizeof(Players));
return *this;
}
int Resort(const Players& target, int id)
{
int uid = unsortIDs[id];
if (uid >= 0 && uid < MAX_PLAYERS) {
int sid = target.sortIDs[uid];
if (sid >= 0 && sid < MAX_PLAYERS && sid < target.count)
return sid;
}
return MAX_PLAYERS;
}
void FreeAll()
{
if (count && boundsStart) {
free((void*)boundsStart);
}
memset(this, 0, sizeof(*this));
memset(sortIDs, -1, sizeof(sortIDs));
memset(unsortIDs, -1, sizeof(sortIDs));
}
void Allocate(int cnt)
{
FreeAll();
count = cnt;
void* data = malloc(sizePerPlayer * count + extraAlignmentNeeds);
//We have to align some of the data
boundsStart = (vec3_t*)data;
boundsEnd = AlignUp(boundsStart + count);
origin = AlignUp(boundsEnd + count);
eyePos = AlignUp(origin + count);
velocity = AlignUp(eyePos + count);
colliders = AlignUp((decltype(colliders))(velocity + count));
hitboxes = AlignUp((decltype(hitboxes))(colliders + count));
flags = AlignUp((decltype(flags))(hitboxes + count));
health = AlignUp(flags + count);
armor = AlignUp(health + count);
time = AlignUp((decltype(time))(armor + count));
name = AlignUp((decltype(name))(time + count));
fov = AlignUp((decltype(fov))(name + count));
bones = AlignUp((decltype(bones))(fov + count));
memset(sortIDs, -1, sizeof(sortIDs));
memset(unsortIDs, -1, sizeof(sortIDs));
}
Players(int cnt)
{
Allocate(cnt);
}
Players()
{
memset(this, 0, sizeof(*this));
memset(sortIDs, -1, sizeof(sortIDs));
memset(unsortIDs, -1, sizeof(sortIDs));
}
~Players()
{
FreeAll();
}
};
struct alignas(SIMD_COUNT * 4)
LocalPlayer
{
vec3_t eyePos;
vec3_t angles;
vec3_t aimOffset;
vec3_t origin;
vec3_t velocity;
float time;
int weaponAmmo;
float weaponDamage;
float weaponPenetration;
float weaponArmorPenetration;
float weaponRange;
float weaponRangeModifier;
int keys;
int flags;
int ID;
};
#endif