Sync with master

This commit is contained in:
gsemaj 2022-07-30 22:50:03 -07:00 committed by gsemaj
parent 343668fbcd
commit 829f75112c
No known key found for this signature in database
GPG Key ID: 24B96BAA40497929
6 changed files with 22 additions and 30 deletions

View File

@ -26,7 +26,7 @@ static void newChunk(ChunkPos pos) {
// add the chunk to the cache of all players and NPCs in the surrounding chunks
std::set<Chunk*> surroundings = getViewableChunks(pos);
for (Chunk* c : surroundings)
for (const EntityRef& ref : c->entities)
for (const EntityRef ref : c->entities)
ref.getEntity()->viewableChunks.insert(chunk);
}
@ -41,14 +41,14 @@ static void deleteChunk(ChunkPos pos) {
// remove the chunk from the cache of all players and NPCs in the surrounding chunks
std::set<Chunk*> surroundings = getViewableChunks(pos);
for(Chunk* c : surroundings)
for (const EntityRef& ref : c->entities)
for (const EntityRef ref : c->entities)
ref.getEntity()->viewableChunks.erase(chunk);
chunks.erase(pos); // remove from map
delete chunk; // free from memory
}
void Chunking::trackEntity(ChunkPos chunkPos, const EntityRef& ref) {
void Chunking::trackEntity(ChunkPos chunkPos, const EntityRef ref) {
if (!chunkExists(chunkPos))
return; // shouldn't happen
@ -58,7 +58,7 @@ void Chunking::trackEntity(ChunkPos chunkPos, const EntityRef& ref) {
chunks[chunkPos]->nplayers++;
}
void Chunking::untrackEntity(ChunkPos chunkPos, const EntityRef& ref) {
void Chunking::untrackEntity(ChunkPos chunkPos, const EntityRef ref) {
if (!chunkExists(chunkPos))
return; // do nothing if chunk doesn't even exist
@ -75,13 +75,13 @@ void Chunking::untrackEntity(ChunkPos chunkPos, const EntityRef& ref) {
deleteChunk(chunkPos);
}
void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef ref) {
Entity *ent = ref.getEntity();
bool alive = ent->isExtant();
// TODO: maybe optimize this, potentially using AROUND packets?
for (Chunk *chunk : chnks) {
for (const EntityRef& otherRef : chunk->entities) {
for (const EntityRef otherRef : chunk->entities) {
// skip oneself
if (ref == otherRef)
continue;
@ -107,13 +107,13 @@ void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
}
}
void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef ref) {
Entity *ent = ref.getEntity();
bool alive = ent->isExtant();
// TODO: same as above
for (Chunk *chunk : chnks) {
for (const EntityRef& otherRef : chunk->entities) {
for (const EntityRef otherRef : chunk->entities) {
// skip oneself
if (ref == otherRef)
continue;
@ -154,7 +154,7 @@ static void emptyChunk(ChunkPos chunkPos) {
// unspawn all of the mobs/npcs
std::set refs(chunk->entities);
for (const EntityRef& ref : refs) {
for (const EntityRef ref : refs) {
if (ref.kind == EntityKind::PLAYER)
assert(0);
@ -163,7 +163,7 @@ static void emptyChunk(ChunkPos chunkPos) {
}
}
void Chunking::updateEntityChunk(const EntityRef& ref, ChunkPos from, ChunkPos to) {
void Chunking::updateEntityChunk(const EntityRef ref, ChunkPos from, ChunkPos to) {
Entity* ent = ref.getEntity();
// move to other chunk's player set
@ -267,7 +267,7 @@ void Chunking::createInstance(uint64_t instanceID) {
std::cout << "Creating instance " << instanceID << std::endl;
for (ChunkPos &coords : templateChunks) {
for (const EntityRef& ref : chunks[coords]->entities) {
for (const EntityRef ref : chunks[coords]->entities) {
if (ref.kind == EntityKind::PLAYER)
continue;

View File

@ -1,13 +1,11 @@
#pragma once
#include "Entities.hpp"
#include "EntityRef.hpp"
#include <set>
#include <map>
#include <vector>
struct EntityRef;
class Chunk {
public:
std::set<EntityRef> entities;
@ -34,13 +32,13 @@ namespace Chunking {
extern const ChunkPos INVALID_CHUNK;
void updateEntityChunk(const EntityRef& ref, ChunkPos from, ChunkPos to);
void updateEntityChunk(const EntityRef ref, ChunkPos from, ChunkPos to);
void trackEntity(ChunkPos chunkPos, const EntityRef& ref);
void untrackEntity(ChunkPos chunkPos, const EntityRef& ref);
void trackEntity(ChunkPos chunkPos, const EntityRef ref);
void untrackEntity(ChunkPos chunkPos, const EntityRef ref);
void addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref);
void removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef& ref);
void addEntityToChunks(std::set<Chunk*> chnks, const EntityRef ref);
void removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef ref);
bool chunkExists(ChunkPos chunk);
ChunkPos chunkPosAt(int posX, int posY, uint64_t instanceID);

View File

@ -1,19 +1,16 @@
#pragma once
#include "core/Core.hpp"
#include "Chunking.hpp"
#include "EntityRef.hpp"
#include "Buffs.hpp"
#include "Chunking.hpp"
#include "Groups.hpp"
#include <set>
#include <map>
#include <functional>
/* forward declaration(s) */
class Chunk;
struct Group;
enum class AIState {
INACTIVE,
ROAMING,

View File

@ -4,6 +4,7 @@
#include "Player.hpp"
#include "PlayerManager.hpp"
#include "Entities.hpp"
/*
* NOTE: Variadic response packets that list group members are technically

View File

@ -1,13 +1,8 @@
#pragma once
#include "Entities.hpp"
#include "EntityRef.hpp"
#include <vector>
#include <map>
#include <list>
/* forward declaration(s) */
struct Player;
struct Group {
std::vector<EntityRef> members;

View File

@ -5,6 +5,7 @@
#include "Transport.hpp"
#include "Chunking.hpp"
#include "Entities.hpp"
#include <map>
#include <unordered_map>