2020-09-17 22:45:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-07-31 05:50:03 +00:00
|
|
|
#include "EntityRef.hpp"
|
2020-09-17 22:45:43 +00:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2022-07-16 23:19:40 +00:00
|
|
|
#include <vector>
|
2020-09-17 22:45:43 +00:00
|
|
|
|
|
|
|
class Chunk {
|
|
|
|
public:
|
2021-03-21 01:42:45 +00:00
|
|
|
std::set<EntityRef> entities;
|
|
|
|
int nplayers = 0;
|
2020-09-17 22:45:43 +00:00
|
|
|
};
|
|
|
|
|
2022-07-22 00:40:33 +00:00
|
|
|
// to help the readability of ChunkPos
|
|
|
|
typedef std::tuple<int, int, uint64_t> _ChunkPos;
|
|
|
|
|
|
|
|
class ChunkPos : public _ChunkPos {
|
|
|
|
public:
|
|
|
|
ChunkPos() : _ChunkPos(0, 0, (uint64_t) -1) {}
|
|
|
|
ChunkPos(int x, int y, uint64_t inst) : _ChunkPos(x, y, inst) {}
|
|
|
|
};
|
|
|
|
|
2020-10-01 01:44:37 +00:00
|
|
|
enum {
|
2020-10-19 17:26:14 +00:00
|
|
|
INSTANCE_OVERWORLD, // default instance every player starts in
|
|
|
|
INSTANCE_IZ, // these aren't actually used
|
|
|
|
INSTANCE_UNIQUE // these aren't actually used
|
2020-10-01 01:44:37 +00:00
|
|
|
};
|
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
namespace Chunking {
|
2020-11-16 14:59:53 +00:00
|
|
|
extern std::map<ChunkPos, Chunk*> chunks;
|
2020-09-17 22:45:43 +00:00
|
|
|
|
2022-07-22 00:40:33 +00:00
|
|
|
extern const ChunkPos INVALID_CHUNK;
|
|
|
|
|
2022-07-31 05:50:03 +00:00
|
|
|
void updateEntityChunk(const EntityRef ref, ChunkPos from, ChunkPos to);
|
2020-11-18 00:07:04 +00:00
|
|
|
|
2022-07-31 05:50:03 +00:00
|
|
|
void trackEntity(ChunkPos chunkPos, const EntityRef ref);
|
|
|
|
void untrackEntity(ChunkPos chunkPos, const EntityRef ref);
|
2020-11-18 00:07:04 +00:00
|
|
|
|
2022-07-31 05:50:03 +00:00
|
|
|
void addEntityToChunks(std::set<Chunk*> chnks, const EntityRef ref);
|
|
|
|
void removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef ref);
|
2020-11-18 00:07:04 +00:00
|
|
|
|
|
|
|
bool chunkExists(ChunkPos chunk);
|
|
|
|
ChunkPos chunkPosAt(int posX, int posY, uint64_t instanceID);
|
|
|
|
std::set<Chunk*> getViewableChunks(ChunkPos chunkPos);
|
2021-05-06 15:41:24 +00:00
|
|
|
std::vector<ChunkPos> getChunksInMap(uint64_t mapNum);
|
2020-11-18 00:07:04 +00:00
|
|
|
|
2020-11-19 22:19:46 +00:00
|
|
|
bool inPopulatedChunks(std::set<Chunk*>* chnks);
|
2020-10-13 03:42:47 +00:00
|
|
|
void createInstance(uint64_t);
|
2020-10-19 02:30:12 +00:00
|
|
|
void destroyInstanceIfEmpty(uint64_t);
|
2020-09-17 22:45:43 +00:00
|
|
|
}
|