15#define GLM_ENABLE_EXPERIMENTAL
19#include <unordered_map>
20#include <shared_mutex>
21#include <unordered_set>
100 constexpr static int FOREST_TREE_FREQUENCY = 12;
101 constexpr static int PLAIN_TREE_FREQUENCY = 120;
107 graph(
task::TaskGraph::create()),
108 light_graph(
task::TaskGraph::create()),
109 relief_graph(
task::TaskGraph::create()),
110 decorate_graph(
task::TaskGraph::create())
112 task::Task light_task = graph->emplace(light_graph).
Name(
"Light passes");
113 task::Task relief_task = graph->emplace(relief_graph).
Name(
"Relief passes");
114 task::Task decorate_task = graph->emplace(decorate_graph).
Name(
"Decoration passes");
115 relief_task.
precede(decorate_task);
116 decorate_task.
precede(light_task);
117 light_graph->emplace([]{});
118 relief_graph->emplace([]{});
119 decorate_graph->emplace([]{});
120 graph->emplace([]{});
122 std::shared_ptr<task::TaskGraph> graph;
123 std::shared_ptr<task::TaskGraph> light_graph;
124 std::shared_ptr<task::TaskGraph> relief_graph;
125 std::shared_ptr<task::TaskGraph> decorate_graph;
126 std::unordered_set<std::pair<glm::ivec3, Chunk::genLevel>> generated_chunk;
136 Perlin m_continentalness_perlin;
138 Perlin m_weirdness_perlin;
139 Perlin m_temperature_perlin;
149 float calculatePeaksAndValleys(
const float & weirdness);
150 float calculateHeightBias(
const float & erosion,
const float & PV);
151 float calculateBaseHeight(
152 const float & relief,
153 const float & continentalness,
155 const float & erosion);
156 int temperatureLevel(
const float & temperature);
157 int humidityLevel(
const float & humidity);
158 int continentalnessLevel(
const float & continentalness);
159 int erosionLevel(
const float & erosion);
160 int weirdnessLevel(
const float & weirdness);
161 int PVLevel(
const float & PV);
164 const int & continentalness,
166 const int & humidity,
167 const int & temperature,
168 const int & weirdness,
171 std::array<BlockType, CHUNK_Y_SIZE> getBlockColumn(
int baseHeight,
BiomeType biome);
172 void carve(std::array<BlockType, CHUNK_Y_SIZE> & blocks, glm::ivec3 pos);
183 void setupPass(genStruct & genData,
const glm::ivec3 & chunk_pos,
Chunk::genLevel gen_level);
184 void addPassToGraph(genStruct & genData, glm::ivec3 chunk_pos,
Chunk::genLevel gen_level);
186 void lightPass(
const glm::ivec3 & pos);
188 void reliefPass(
const glm::ivec3 & pos);
190 void newReliefPass(
const glm::ivec3 & pos);
195 float generateReliefValue(glm::ivec2 position);
197 void decoratePass(
const glm::ivec3 & pos);
201 void placeStructure(
ChunkMap & chunkGrid,
const glm::ivec3 & start_pos,
const StructureInfo & structure);
207 World(
bool save =
false);
238 std::shared_ptr<Chunk>
getChunk(
const glm::ivec3 & position);
239 void insertChunk(
const glm::ivec3 & position, std::shared_ptr<Chunk> chunk);
253 std::unordered_map<uint64_t, std::shared_ptr<Player>>
m_players;
256 std::unordered_map<uint64_t, std::shared_ptr<Mob>>
m_mobs;
260 std::unordered_map<glm::ivec3, std::shared_ptr<Chunk>>
m_chunks;
278 std::shared_ptr<Chunk>
getChunkNoLock(
const glm::ivec3 & position);
281 void insertChunkNoLock(
const glm::ivec3 & position, std::shared_ptr<Chunk> chunk);
299 std::unordered_set<glm::ivec3>
updateSkyLight(
const glm::ivec3 & block_position);
308 std::unordered_set<glm::ivec3>
updateBlockLight(
const glm::ivec3 & block_position);
std::unordered_map< glm::ivec3, std::shared_ptr< Chunk > > ChunkMap
Definition: Chunk.hpp:177
Type
Definition: Block.hpp:33
genLevel
Definition: Chunk.hpp:30
e_biome
Definition: Chunk.hpp:37
Definition: ExecutorAccessor.hpp:10
Perlin noise generator.
Definition: Perlin.hpp:23
a class to save and load chunks from the disk
Definition: Save.hpp:18
Definition: Structures.hpp:13
std::unordered_set< glm::ivec3 > ChunkGenList
Definition: World.hpp:30
~WorldGenerator()
Definition: WorldGenerator.cpp:37
std::shared_ptr< task::TaskGraph > getGenerationGraph(ChunkGenList &chunks_to_gen)
get the generation info for the given gen level and chunk position
Definition: WorldGenerator.cpp:362
WorldGenerator & getWorldGenerator()
Definition: World.cpp:14
ExecutorAccessor m_executor
Definition: World.hpp:263
TracyLockableN(std::mutex, m_chunks_mutex, "Chunks")
World & operator=(World &other)=delete
std::shared_ptr< Chunk > getChunkNoLock(const glm::ivec3 &position)
Get a chunk ptr without locking the chunks mutex.
Definition: World.cpp:47
TracyLockableN(std::mutex, m_players_mutex, "Players")
TracyLockableN(std::mutex, m_mobs_mutex, "Mobs")
WorldGenerator m_world_generator
Definition: World.hpp:266
void insertChunkNoLock(const glm::ivec3 &position, std::shared_ptr< Chunk > chunk)
Definition: World.cpp:72
std::unordered_set< glm::ivec3 > updateSkyLight(const glm::ivec3 &block_position)
Update the sky light of the chunk containing the block.
Definition: World.cpp:114
std::unique_ptr< Save > m_save
Definition: World.hpp:268
uint64_t m_mob_id
Definition: World.hpp:258
std::shared_ptr< Chunk > getChunk(const glm::ivec3 &position)
Get the Chunk object.
Definition: World.cpp:40
~World()
Definition: World.cpp:10
World(World &other)=delete
World(World &&other)=delete
std::unordered_set< glm::ivec3 > updateBlockLight(const glm::ivec3 &block_position)
Update the block light of the chunk containing the block.
Definition: World.cpp:328
std::unordered_map< uint64_t, std::shared_ptr< Player > > m_players
Definition: World.hpp:253
std::unordered_map< uint64_t, std::shared_ptr< Mob > > m_mobs
Definition: World.hpp:256
static glm::vec3 getBlockChunkPosition(const glm::vec3 &position)
will return the block position relative to the chunk
Definition: World.cpp:19
void unloadRegion(const glm::ivec2 region_pos)
Unloads all chunk inside a region, if save is enabled, will save the region in a region file.
Definition: World.cpp:88
void insertChunk(const glm::ivec3 &position, std::shared_ptr< Chunk > chunk)
Definition: World.cpp:66
static glm::vec3 getChunkPosition(const glm::vec3 &position)
will return the chunk position containing the block
Definition: World.cpp:32
World & operator=(World &&other)=delete
std::unordered_map< glm::ivec3, std::shared_ptr< Chunk > > m_chunks
Definition: World.hpp:260
Task & precede(Task &t)
add a precedence link from this task to
Definition: Task.hpp:28
Task & Name(const std::string &name)
Definition: Task.hpp:55
Definition: Executor.cpp:5