7#include <condition_variable>
8#include <unordered_map>
9#include <unordered_set>
15#define CHUNK_Y_SIZE 512
16#define CHUNK_X_SIZE 16
17#define CHUNK_Z_SIZE 16
18#define BLOCKS_PER_CHUNK CHUNK_Y_SIZE * CHUNK_X_SIZE * CHUNK_Z_SIZE
19#define CHUNK_SIZE_IVEC3 glm::ivec3(CHUNK_X_SIZE, CHUNK_Y_SIZE, CHUNK_Z_SIZE)
20#define CHUNK_SIZE_VEC3 glm::vec3(CHUNK_X_SIZE, CHUNK_Y_SIZE, CHUNK_Z_SIZE)
22glm::ivec3
getChunkPos(
const glm::ivec3 & block_pos);
68 typedef std::array<BlockInfo::Type, BLOCKS_PER_CHUNK>
BlockArray;
69 typedef std::array<uint8_t, BLOCKS_PER_CHUNK>
LightArray;
70 typedef std::array<uint8_t, CHUNK_X_SIZE * CHUNK_Z_SIZE>
HeightArray;
73 typedef std::array<biomeInfo, CHUNK_X_SIZE * CHUNK_Z_SIZE>
BiomeArray;
77 Chunk(glm::ivec3 position);
94 void setBlockColumn(
const int &
x,
const int &
z,
const std::array<BlockInfo::Type, CHUNK_Y_SIZE> & column);
95 void setBlockColumn(
const glm::ivec2 & pos,
const std::array<BlockInfo::Type, CHUNK_Y_SIZE> & column);
99 uint8_t
getLight(
const int &
x,
const int &
y,
const int &
z)
const;
100 uint8_t
getLight(
const glm::ivec3 & position)
const;
101 void setLight(
const int &
x,
const int &
y,
const int &
z, uint8_t light);
102 void setLight(
const glm::ivec3 & position, uint8_t light);
104 uint8_t
getSkyLight(
const int &
x,
const int &
y,
const int &
z)
const;
105 uint8_t
getSkyLight(
const glm::ivec3 & position)
const;
106 void setSkyLight(
const int &
x,
const int &
y,
const int &
z, uint8_t light);
107 void setSkyLight(
const glm::ivec3 & position, uint8_t light);
111 void setBlockLight(
const int &
x,
const int &
y,
const int &
z, uint8_t light);
112 void setBlockLight(
const glm::ivec3 & position, uint8_t light);
126 uint8_t
getHeight(
const int &
x,
const int &
z)
const;
127 uint8_t
getHeight(
const glm::ivec2 & position)
const;
128 void setHeight(
const int &
x,
const int &
z, uint8_t height);
129 void setHeight(
const glm::ivec2 & position, uint8_t height);
137 const int &
x()
const {
return position.x;};
138 const int &
y()
const {
return position.y;};
139 const int &
z()
const {
return position.z;};
142 void setMeshID(
const uint64_t & mesh_id);
154 static int toIndex(
const int &
x,
const int &
y,
const int &
z);
155 static glm::ivec3
toCoord(
const int & index);
163 std::atomic<bool> meshed =
false;
165 std::atomic<uint64_t> m_mesh_id;
166 mutable TracyLockableN (std::mutex, m_mesh_id_mutex,
"Mesh ID");
172 int load_level = std::numeric_limits<int>::max();
173 int highest_load_level = 0;
177typedef std::unordered_map<glm::ivec3, std::shared_ptr<Chunk>>
ChunkMap;
186 return std::hash<uint16_t>()(
static_cast<uint16_t
>(level));
191 struct hash<
std::pair<glm::ivec3, Chunk::genLevel>>
193 std::size_t
operator()(
const std::pair<glm::ivec3, Chunk::genLevel> & pair)
const
195 return std::hash<glm::ivec3>()(pair.first) ^ std::hash<Chunk::genLevel>()(pair.second);
211 void deserialize(
const char * data,
const size_t & size);
glm::ivec3 getChunkPos(const glm::ivec3 &block_pos)
Definition: Chunk.cpp:374
Chunk::e_biome BiomeType
Definition: Chunk.hpp:178
std::unordered_map< glm::ivec3, std::shared_ptr< Chunk > > ChunkMap
Definition: Chunk.hpp:177
glm::ivec3 getBlockChunkPos(const glm::ivec3 &block_pos)
Definition: Chunk.cpp:393
Type
Definition: Block.hpp:33
void setBlockLight(const int &x, const int &y, const int &z, uint8_t light)
Definition: Chunk.cpp:206
std::unordered_set< uint64_t > observing_player_ids
Definition: Chunk.hpp:161
const int & x() const
Definition: Chunk.hpp:137
LightArray & getLight()
Definition: Chunk.cpp:137
static glm::ivec2 toBiomeCoord(int index)
Definition: Chunk.cpp:247
std::array< uint8_t, BLOCKS_PER_CHUNK > LightArray
Definition: Chunk.hpp:69
const int & y() const
Definition: Chunk.hpp:138
static glm::ivec3 toCoord(const int &index)
Definition: Chunk.cpp:366
uint8_t getSkyLight(const int &x, const int &y, const int &z) const
Definition: Chunk.cpp:172
Chunk & operator=(const Chunk &other)=delete
Chunk(const Chunk &other)=delete
BlockArray & getBlocks()
Definition: Chunk.cpp:89
std::array< uint8_t, CHUNK_X_SIZE *CHUNK_Z_SIZE > HeightArray
Definition: Chunk.hpp:70
genLevel
Definition: Chunk.hpp:30
static constexpr size_t DATA_SIZE
Definition: Chunk.hpp:75
void setSkyLight(const int &x, const int &y, const int &z, uint8_t light)
Definition: Chunk.cpp:183
static int toIndex(const int &x, const int &y, const int &z)
Definition: Chunk.cpp:361
HeightArray & getHeights()
Definition: Chunk.cpp:265
std::array< biomeInfo, CHUNK_X_SIZE *CHUNK_Z_SIZE > BiomeArray
Definition: Chunk.hpp:73
Status status
Definition: Chunk.hpp:159
BiomeArray & getBiomes()
Definition: Chunk.cpp:217
void setBiome(const int &x, const int &z, const biomeInfo &biome)
Definition: Chunk.cpp:237
void setGenLevel(const genLevel &level)
Definition: Chunk.cpp:356
uint8_t getHeight(const int &x, const int &z) const
Definition: Chunk.cpp:275
bool isMeshed() const
Definition: Chunk.cpp:325
void setMeshID(const uint64_t &mesh_id)
Definition: Chunk.cpp:320
biomeInfo getBiome(const int &x, const int &z) const
Definition: Chunk.cpp:227
int getHighestLoadLevel() const
Definition: Chunk.cpp:340
void setBlock(const int &x, const int &y, const int &z, BlockInfo::Type block)
Definition: Chunk.cpp:111
uint64_t getMeshID() const
Definition: Chunk.cpp:315
void setHeight(const int &x, const int &z, uint8_t height)
Definition: Chunk.cpp:285
genLevel getGenLevel() const
Definition: Chunk.cpp:351
Chunk(Chunk &&other)=delete
void setPosition(const glm::ivec3 &position)
Definition: Chunk.cpp:310
void setLoadLevel(const int &load_level)
Definition: Chunk.cpp:344
BlockInfo::Type getBlock(const int &x, const int &y, const int &z) const
Definition: Chunk.cpp:99
std::unordered_set< uint64_t > entity_ids
Definition: Chunk.hpp:160
Chunk & operator=(const Chunk &&other)=delete
std::array< BlockInfo::Type, BLOCKS_PER_CHUNK > BlockArray
Definition: Chunk.hpp:68
e_biome
Definition: Chunk.hpp:37
void setBlockColumn(const int &x, const int &z, const std::array< BlockInfo::Type, CHUNK_Y_SIZE > &column)
Definition: Chunk.cpp:124
const glm::ivec3 & getPosition() const
Definition: Chunk.cpp:305
void setLight(const int &x, const int &y, const int &z, uint8_t light)
Definition: Chunk.cpp:159
~Chunk()
Definition: Chunk.cpp:84
static int toBiomeIndex(int x, int z)
Definition: Chunk.cpp:255
int getLoadLevel() const
Definition: Chunk.cpp:335
void setMeshed(bool meshed)
Definition: Chunk.cpp:330
uint8_t getBlockLight(const int &x, const int &y, const int &z) const
Definition: Chunk.cpp:195
static int toHeightIndex(const int &x, const int &z)
Definition: Chunk.cpp:295
const int & z() const
Definition: Chunk.hpp:139
Definition: Status.hpp:10
Definition: ObjLoader.hpp:65
Definition: Chunk.hpp:201
Chunk::LightArray light
Definition: Chunk.hpp:214
Chunk::genLevel gen_level
Definition: Chunk.hpp:217
ChunkData & operator=(ChunkData &&other)=default
std::vector< char > serialize() const
Definition: ChunkData.cpp:15
Chunk::BiomeArray biome
Definition: Chunk.hpp:215
Chunk::HeightArray height
Definition: Chunk.hpp:216
ChunkData(const ChunkData &other)=default
void deserialize(const char *data, const size_t &size)
Definition: ChunkData.cpp:48
static constexpr size_t DATA_SIZE
Definition: Chunk.hpp:219
ChunkData(ChunkData &&other)=default
glm::ivec3 position
Definition: Chunk.hpp:218
Chunk::BlockArray blocks
Definition: Chunk.hpp:213
ChunkData & operator=(const ChunkData &other)=default
bool operator==(const biomeInfo &other) const =default
float continentalness
Definition: Chunk.hpp:59
biomeInfo(const biomeInfo &other)=default
float PV
Definition: Chunk.hpp:64
e_biome biome
Definition: Chunk.hpp:65
float weirdness
Definition: Chunk.hpp:63
bool isCoast
Definition: Chunk.hpp:58
biomeInfo & operator=(const biomeInfo &other)=default
float temperature
Definition: Chunk.hpp:62
float erosion
Definition: Chunk.hpp:60
biomeInfo(biomeInfo &&other)=default
biomeInfo & operator=(biomeInfo &&other)=default
float humidity
Definition: Chunk.hpp:61
bool isOcean
Definition: Chunk.hpp:57
bool isLand
Definition: Chunk.hpp:56
std::size_t operator()(const Chunk::genLevel &level) const
Definition: Chunk.hpp:184
std::size_t operator()(const std::pair< glm::ivec3, Chunk::genLevel > &pair) const
Definition: Chunk.hpp:193