mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-17 16:17:02 +08:00
fix: missing face culling for old chunks during generation
This commit is contained in:
@@ -13,7 +13,10 @@ class World;
|
||||
class Chunk {
|
||||
private:
|
||||
std::atomic<bool> m_dirty {false};
|
||||
|
||||
std::atomic<bool> m_need_upload{true};
|
||||
std::atomic<bool> m_is_on_gen_vertex_data {false};
|
||||
std::atomic<size_t> m_vertex_sum = 0;
|
||||
std::mutex m_vertexs_data_mutex;
|
||||
static constexpr int SIZE_X = CHUCK_SIZE;
|
||||
static constexpr int SIZE_Y = WORLD_SIZE_Y;
|
||||
static constexpr int SIZE_Z = CHUCK_SIZE;
|
||||
@@ -39,8 +42,8 @@ public:
|
||||
~Chunk();
|
||||
Chunk(const Chunk&) = delete;
|
||||
Chunk& operator=(const Chunk&) = delete;
|
||||
Chunk(Chunk&&);
|
||||
Chunk& operator=(Chunk&&);
|
||||
Chunk(Chunk&&) noexcept;
|
||||
Chunk& operator=(Chunk&&) noexcept;
|
||||
|
||||
Biome get_biome() const;
|
||||
|
||||
@@ -58,11 +61,14 @@ public:
|
||||
void upload_to_gpu();
|
||||
|
||||
GLuint get_vbo() const;
|
||||
const std::vector<Vertex>& get_vertex_data() const;
|
||||
size_t get_vertex_sum() const;
|
||||
|
||||
bool is_dirty() const;
|
||||
void mark_dirty();
|
||||
|
||||
bool is_need_upload() const;
|
||||
void need_upload();
|
||||
|
||||
void set_chunk_block(int index, unsigned id);
|
||||
|
||||
};
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <thread>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <unordered_set>
|
||||
#include <Cubed/AABB.hpp>
|
||||
#include <Cubed/gameplay/chunk.hpp>
|
||||
|
||||
@@ -20,7 +20,11 @@ struct ChunkRenderSnapshot {
|
||||
class Player;
|
||||
|
||||
class World {
|
||||
private:
|
||||
private:
|
||||
using ChunkPtrUpdateList = std::vector<std::pair<ChunkPos, Chunk*>>;
|
||||
using ChunkUpdateList = std::vector<std::pair<ChunkPos, Chunk>>;
|
||||
using ConstChunkMap = std::unordered_map<ChunkPos, const Chunk*, ChunkPos::Hash>;
|
||||
using ChunkPosSet = std::unordered_set<ChunkPos, ChunkPos::Hash>;
|
||||
glm::vec3 m_gen_player_pos{0.0f, 0.0f, 0.0f};
|
||||
std::unordered_map<ChunkPos , Chunk, ChunkPos::Hash> m_chunks;
|
||||
std::unordered_map<std::size_t, Player> m_players;
|
||||
@@ -43,7 +47,11 @@ private:
|
||||
std::vector<std::pair<ChunkPos, Chunk>> m_new_chunk_queue;
|
||||
|
||||
void gen_chunks_internal();
|
||||
|
||||
void sync_player_pos(glm::vec3& player_pos);
|
||||
void compute_required_chunks(ChunkPosSet& required_chunks);
|
||||
void sync_and_collect_missing_chunks(std::vector<ChunkPos>& , const ChunkPosSet&);
|
||||
void build_neighbor_context_for_new_chunks(ConstChunkMap& new_chunks_neighbor, ChunkPtrUpdateList& affected_neighbor, const ChunkUpdateList& new_chunks);
|
||||
void build_neighbor_context_for_affected_neighbors(ChunkPtrUpdateList&, ConstChunkMap&);
|
||||
void start_gen_thread();
|
||||
void stop_gen_thread();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user