2020-09-17 22:45:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CNProtocol.hpp"
|
2020-11-14 23:36:04 +00:00
|
|
|
#include "CNStructs.hpp"
|
2020-09-17 22:45:43 +00:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2020-10-01 01:44:37 +00:00
|
|
|
#include <tuple>
|
2020-11-18 00:07:04 +00:00
|
|
|
#include <algorithm>
|
2020-09-17 22:45:43 +00:00
|
|
|
|
|
|
|
class Chunk {
|
|
|
|
public:
|
|
|
|
std::set<CNSocket*> players;
|
|
|
|
std::set<int32_t> NPCs;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-09-17 22:45:43 +00:00
|
|
|
namespace ChunkManager {
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
2020-11-16 14:59:53 +00:00
|
|
|
extern std::map<ChunkPos, Chunk*> chunks;
|
2020-09-17 22:45:43 +00:00
|
|
|
|
2020-11-16 14:59:53 +00:00
|
|
|
void newChunk(ChunkPos pos);
|
2020-11-19 22:19:46 +00:00
|
|
|
void deleteChunk(ChunkPos pos);
|
2020-11-18 00:07:04 +00:00
|
|
|
|
|
|
|
void updatePlayerChunk(CNSocket* sock, ChunkPos from, ChunkPos to);
|
|
|
|
void updateNPCChunk(int32_t id, ChunkPos from, ChunkPos to);
|
|
|
|
|
|
|
|
void trackPlayer(ChunkPos chunkPos, CNSocket* sock);
|
|
|
|
void trackNPC(ChunkPos chunkPos, int32_t id);
|
|
|
|
void untrackPlayer(ChunkPos chunkPos, CNSocket* sock);
|
|
|
|
void untrackNPC(ChunkPos chunkPos, int32_t id);
|
|
|
|
|
|
|
|
void addPlayerToChunks(std::set<Chunk*> chnks, CNSocket* sock);
|
|
|
|
void addNPCToChunks(std::set<Chunk*> chnks, int32_t id);
|
|
|
|
void removePlayerFromChunks(std::set<Chunk*> chnks, CNSocket* sock);
|
|
|
|
void removeNPCFromChunks(std::set<Chunk*> chnks, int32_t id);
|
|
|
|
|
|
|
|
bool chunkExists(ChunkPos chunk);
|
|
|
|
void emptyChunk(ChunkPos chunkPos);
|
|
|
|
ChunkPos chunkPosAt(int posX, int posY, uint64_t instanceID);
|
|
|
|
std::set<Chunk*> getViewableChunks(ChunkPos chunkPos);
|
|
|
|
|
2020-11-16 14:59:53 +00:00
|
|
|
std::vector<ChunkPos> getChunksInMap(uint64_t mapNum);
|
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);
|
|
|
|
void destroyInstance(uint64_t);
|
2020-10-19 02:30:12 +00:00
|
|
|
void destroyInstanceIfEmpty(uint64_t);
|
2020-09-17 22:45:43 +00:00
|
|
|
}
|