@@ -13,11 +13,12 @@ using namespace Chunking;
13
13
* The initial chunkPos value before a player is placed into the world.
14
14
*/
15
15
const ChunkPos Chunking::INVALID_CHUNK = {};
16
- constexpr size_t MAX_PC_PER_AROUND = (CN_PACKET_BUFFER_SIZE - sizeof (int32_t )) / sizeof (sPCAppearanceData );
17
- constexpr size_t MAX_NPC_PER_AROUND = (CN_PACKET_BUFFER_SIZE - sizeof (int32_t )) / sizeof (sNPCAppearanceData );
18
- constexpr size_t MAX_SHINY_PER_AROUND = (CN_PACKET_BUFFER_SIZE - sizeof (int32_t )) / sizeof (sShinyAppearanceData );
19
- constexpr size_t MAX_TRANSPORTATION_PER_AROUND = (CN_PACKET_BUFFER_SIZE - sizeof (int32_t )) / sizeof (sTransportationAppearanceData );
20
- constexpr size_t MAX_IDS_PER_AROUND_DEL = (CN_PACKET_BUFFER_SIZE - sizeof (int32_t )) / sizeof (int32_t );
16
+ constexpr size_t MAX_PC_PER_AROUND = (CN_PACKET_BUFFER_SIZE - 3 * sizeof (int32_t )) / sizeof (sPCAppearanceData );
17
+ constexpr size_t MAX_NPC_PER_AROUND = (CN_PACKET_BUFFER_SIZE - 3 * sizeof (int32_t )) / sizeof (sNPCAppearanceData );
18
+ constexpr size_t MAX_SHINY_PER_AROUND = (CN_PACKET_BUFFER_SIZE - 3 * sizeof (int32_t )) / sizeof (sShinyAppearanceData );
19
+ constexpr size_t MAX_TRANSPORTATION_PER_AROUND = (CN_PACKET_BUFFER_SIZE - 3 * sizeof (int32_t )) / sizeof (sTransportationAppearanceData );
20
+ constexpr size_t MAX_IDS_PER_AROUND_DEL = (CN_PACKET_BUFFER_SIZE - 3 * sizeof (int32_t )) / sizeof (int32_t );
21
+ constexpr size_t MAX_TRANSPORTATION_IDS_PER_AROUND_DEL = MAX_IDS_PER_AROUND_DEL - 1 ; // 1 less for eTT
21
22
22
23
std::map<ChunkPos, Chunk*> Chunking::chunks;
23
24
@@ -83,7 +84,7 @@ void Chunking::untrackEntity(ChunkPos chunkPos, const EntityRef ref) {
83
84
}
84
85
85
86
template <class T , size_t N>
86
- static void sendAroundPacket (const EntityRef recipient, std::vector<Bucket<T, N>>& buckets, uint32_t packetId) {
87
+ static void sendAroundPackets (const EntityRef recipient, std::vector<Bucket<T, N>>& buckets, uint32_t packetId) {
87
88
assert (recipient.kind == EntityKind::PLAYER);
88
89
89
90
uint8_t pktBuf[CN_PACKET_BUFFER_SIZE];
@@ -100,7 +101,7 @@ static void sendAroundPacket(const EntityRef recipient, std::vector<Bucket<T, N>
100
101
}
101
102
102
103
template <size_t N>
103
- static void sendAroundDelPacket (const EntityRef recipient, std::vector<Bucket<int32_t , N>>& buckets, bool isTransportation , uint32_t packetId) {
104
+ static void sendAroundDelPackets (const EntityRef recipient, std::vector<Bucket<int32_t , N>>& buckets, uint32_t packetId) {
104
105
assert (recipient.kind == EntityKind::PLAYER);
105
106
106
107
uint8_t pktBuf[CN_PACKET_BUFFER_SIZE];
@@ -110,7 +111,7 @@ static void sendAroundDelPacket(const EntityRef recipient, std::vector<Bucket<in
110
111
assert (count <= N);
111
112
112
113
size_t baseSize;
113
- if (isTransportation ) {
114
+ if (packetId == P_FE2CL_AROUND_DEL_TRANSPORTATION ) {
114
115
sP_FE2CL_AROUND_DEL_TRANSPORTATION * pkt = (sP_FE2CL_AROUND_DEL_TRANSPORTATION *)pktBuf;
115
116
pkt->eTT = 3 ;
116
117
pkt->iCnt = count;
@@ -131,23 +132,21 @@ static void sendAroundDelPacket(const EntityRef recipient, std::vector<Bucket<in
131
132
template <class T , size_t N>
132
133
static void bufferAppearanceData (std::vector<Bucket<T, N>>& buckets, const T& data) {
133
134
if (buckets.empty ())
134
- buckets.push_back (Bucket<T, N>());
135
- Bucket<T, N>& bucket = buckets[buckets.size () - 1 ];
136
- assert (!bucket.isFull ());
135
+ buckets.push_back ({});
136
+ auto & bucket = buckets[buckets.size () - 1 ];
137
137
bucket.add (data);
138
138
if (bucket.isFull ())
139
- buckets.push_back (Bucket<T, N>() );
139
+ buckets.push_back ({} );
140
140
}
141
141
142
142
template <size_t N>
143
143
static void bufferIdForDisappearance (std::vector<Bucket<int32_t , N>>& buckets, int32_t id) {
144
144
if (buckets.empty ())
145
- buckets.push_back (Bucket<int32_t , N>());
146
- Bucket<int32_t , N>& bucket = buckets[buckets.size () - 1 ];
147
- assert (!bucket.isFull ());
145
+ buckets.push_back ({});
146
+ auto & bucket = buckets[buckets.size () - 1 ];
148
147
bucket.add (id);
149
148
if (bucket.isFull ())
150
- buckets.push_back (Bucket< int32_t , N>() );
149
+ buckets.push_back ({} );
151
150
}
152
151
153
152
void Chunking::addEntityToChunks (std::set<Chunk*> chnks, const EntityRef ref) {
@@ -177,8 +176,7 @@ void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef ref) {
177
176
sNPCAppearanceData npcData;
178
177
sShinyAppearanceData eggData;
179
178
sTransportationAppearanceData busData;
180
- switch (otherRef.kind )
181
- {
179
+ switch (otherRef.kind ) {
182
180
case EntityKind::PLAYER:
183
181
pcData = dynamic_cast <Player*>(other)->getAppearanceData ();
184
182
bufferAppearanceData (pcAppearances, pcData);
@@ -216,17 +214,16 @@ void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef ref) {
216
214
}
217
215
}
218
216
219
- if (ref.kind != EntityKind::PLAYER)
220
- return ; // nothing to send
221
-
222
- if (!pcAppearances.empty ())
223
- sendAroundPacket (ref, pcAppearances, P_FE2CL_PC_AROUND);
224
- if (!npcAppearances.empty ())
225
- sendAroundPacket (ref, npcAppearances, P_FE2CL_NPC_AROUND);
226
- if (!shinyAppearances.empty ())
227
- sendAroundPacket (ref, shinyAppearances, P_FE2CL_SHINY_AROUND);
228
- if (!transportationAppearances.empty ())
229
- sendAroundPacket (ref, transportationAppearances, P_FE2CL_TRANSPORTATION_AROUND);
217
+ if (ref.kind == EntityKind::PLAYER) {
218
+ if (!pcAppearances.empty ())
219
+ sendAroundPackets (ref, pcAppearances, P_FE2CL_PC_AROUND);
220
+ if (!npcAppearances.empty ())
221
+ sendAroundPackets (ref, npcAppearances, P_FE2CL_NPC_AROUND);
222
+ if (!shinyAppearances.empty ())
223
+ sendAroundPackets (ref, shinyAppearances, P_FE2CL_SHINY_AROUND);
224
+ if (!transportationAppearances.empty ())
225
+ sendAroundPackets (ref, transportationAppearances, P_FE2CL_TRANSPORTATION_AROUND);
226
+ }
230
227
}
231
228
232
229
void Chunking::removeEntityFromChunks (std::set<Chunk*> chnks, const EntityRef ref) {
@@ -236,7 +233,7 @@ void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef re
236
233
std::vector<Bucket<int32_t , MAX_IDS_PER_AROUND_DEL>> pcDisappearances;
237
234
std::vector<Bucket<int32_t , MAX_IDS_PER_AROUND_DEL>> npcDisappearances;
238
235
std::vector<Bucket<int32_t , MAX_IDS_PER_AROUND_DEL>> shinyDisappearances;
239
- std::vector<Bucket<int32_t , MAX_IDS_PER_AROUND_DEL - 1 >> transportationDisappearances;
236
+ std::vector<Bucket<int32_t , MAX_TRANSPORTATION_IDS_PER_AROUND_DEL >> transportationDisappearances;
240
237
for (Chunk *chunk : chnks) {
241
238
for (const EntityRef otherRef : chunk->entities ) {
242
239
// skip oneself
@@ -253,8 +250,7 @@ void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef re
253
250
// notify this *player* of the departure of all visible Entities
254
251
if (ref.kind == EntityKind::PLAYER && other->isExtant ()) {
255
252
int32_t id;
256
- switch (otherRef.kind )
257
- {
253
+ switch (otherRef.kind ) {
258
254
case EntityKind::PLAYER:
259
255
id = dynamic_cast <Player*>(other)->iID ;
260
256
bufferIdForDisappearance (pcDisappearances, id);
@@ -286,17 +282,16 @@ void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef re
286
282
}
287
283
}
288
284
289
- if (ref.kind != EntityKind::PLAYER)
290
- return ; // nothing to send
291
-
292
- if (!pcDisappearances.empty ())
293
- sendAroundDelPacket (ref, pcDisappearances, false , P_FE2CL_AROUND_DEL_PC);
294
- if (!npcDisappearances.empty ())
295
- sendAroundDelPacket (ref, npcDisappearances, false , P_FE2CL_AROUND_DEL_NPC);
296
- if (!shinyDisappearances.empty ())
297
- sendAroundDelPacket (ref, shinyDisappearances, false , P_FE2CL_AROUND_DEL_SHINY);
298
- if (!transportationDisappearances.empty ())
299
- sendAroundDelPacket (ref, transportationDisappearances, true , P_FE2CL_AROUND_DEL_TRANSPORTATION);
285
+ if (ref.kind == EntityKind::PLAYER) {
286
+ if (!pcDisappearances.empty ())
287
+ sendAroundDelPackets (ref, pcDisappearances, P_FE2CL_AROUND_DEL_PC);
288
+ if (!npcDisappearances.empty ())
289
+ sendAroundDelPackets (ref, npcDisappearances, P_FE2CL_AROUND_DEL_NPC);
290
+ if (!shinyDisappearances.empty ())
291
+ sendAroundDelPackets (ref, shinyDisappearances, P_FE2CL_AROUND_DEL_SHINY);
292
+ if (!transportationDisappearances.empty ())
293
+ sendAroundDelPackets (ref, transportationDisappearances, P_FE2CL_AROUND_DEL_TRANSPORTATION);
294
+ }
300
295
}
301
296
302
297
static void emptyChunk (ChunkPos chunkPos) {
0 commit comments