mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-16 19:20:05 +00:00
Sync with master
This commit is contained in:
parent
ec71fd8f46
commit
751fd4fd9d
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "Player.hpp"
|
||||
#include "PlayerManager.hpp"
|
||||
#include "Entities.hpp"
|
||||
|
||||
/*
|
||||
* NOTE: Variadic response packets that list group members are technically
|
||||
|
@ -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;
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "Transport.hpp"
|
||||
#include "Chunking.hpp"
|
||||
#include "Entities.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
Loading…
Reference in New Issue
Block a user