diff --git a/src/Chunking.cpp b/src/Chunking.cpp index 71ce013..65231fe 100644 --- a/src/Chunking.cpp +++ b/src/Chunking.cpp @@ -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 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 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 chnks, const EntityRef& ref) { +void Chunking::addEntityToChunks(std::set 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 chnks, const EntityRef& ref) { } } -void Chunking::removeEntityFromChunks(std::set chnks, const EntityRef& ref) { +void Chunking::removeEntityFromChunks(std::set 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; diff --git a/src/Chunking.hpp b/src/Chunking.hpp index 3673638..4b4cee0 100644 --- a/src/Chunking.hpp +++ b/src/Chunking.hpp @@ -1,13 +1,11 @@ #pragma once -#include "Entities.hpp" +#include "EntityRef.hpp" #include #include #include -struct EntityRef; - class Chunk { public: std::set 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 chnks, const EntityRef& ref); - void removeEntityFromChunks(std::set chnks, const EntityRef& ref); + void addEntityToChunks(std::set chnks, const EntityRef ref); + void removeEntityFromChunks(std::set chnks, const EntityRef ref); bool chunkExists(ChunkPos chunk); ChunkPos chunkPosAt(int posX, int posY, uint64_t instanceID); diff --git a/src/Entities.hpp b/src/Entities.hpp index 9078d4f..28a47c0 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -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 #include #include -/* forward declaration(s) */ -class Chunk; -struct Group; - enum class AIState { INACTIVE, ROAMING, diff --git a/src/Groups.cpp b/src/Groups.cpp index 2ba539b..ac58d6e 100644 --- a/src/Groups.cpp +++ b/src/Groups.cpp @@ -4,6 +4,7 @@ #include "Player.hpp" #include "PlayerManager.hpp" +#include "Entities.hpp" /* * NOTE: Variadic response packets that list group members are technically diff --git a/src/Groups.hpp b/src/Groups.hpp index d8ddd67..b8a1782 100644 --- a/src/Groups.hpp +++ b/src/Groups.hpp @@ -1,13 +1,8 @@ #pragma once -#include "Entities.hpp" +#include "EntityRef.hpp" #include -#include -#include - -/* forward declaration(s) */ -struct Player; struct Group { std::vector members; diff --git a/src/NPCManager.hpp b/src/NPCManager.hpp index 5009e3c..c8738d0 100644 --- a/src/NPCManager.hpp +++ b/src/NPCManager.hpp @@ -5,6 +5,7 @@ #include "Transport.hpp" #include "Chunking.hpp" +#include "Entities.hpp" #include #include