mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-11 14:43:34 +00:00
adding async chunk generation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef WORLD_H
|
||||
#define WORLD_H
|
||||
|
||||
#include <atomic>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <ScopGraphics.h>
|
||||
@@ -8,7 +9,16 @@
|
||||
#include <Chunk.h>
|
||||
#include <Utils.h>
|
||||
|
||||
constexpr std::uint8_t RENDER_DISTANCE = 1;
|
||||
constexpr std::uint8_t RENDER_DISTANCE = 10;
|
||||
constexpr std::uint8_t RENDER_DISTANCE_HALF = RENDER_DISTANCE / 2;
|
||||
constexpr std::uint8_t CHUNKS_UPLOAD_PER_FRAME = 1;
|
||||
|
||||
enum class GenerationState: std::uint8_t
|
||||
{
|
||||
Ready,
|
||||
Working,
|
||||
Finished,
|
||||
};
|
||||
|
||||
class World
|
||||
{
|
||||
@@ -22,15 +32,18 @@ class World
|
||||
~World() = default;
|
||||
|
||||
private:
|
||||
void GenerateWorld();
|
||||
void UnloadChunks(Scop::Vec2i current_chunk_position);
|
||||
void GenerateWorld(Scop::Vec2i current_chunk_position);
|
||||
void Upload();
|
||||
|
||||
private:
|
||||
std::unordered_map<Scop::Vec2i, Chunk> m_chunks;
|
||||
ThreadSafeQueue<std::reference_wrapper<Chunk>> m_chunks_to_upload;
|
||||
std::shared_ptr<Scop::Material> p_block_material;
|
||||
Scop::Narrator& m_narrator;
|
||||
Scop::Scene& m_scene;
|
||||
Scop::Vec2i m_previous_chunk_position;
|
||||
std::atomic<GenerationState> m_generation_status = GenerationState::Ready;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user