mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-21 18:17:03 +08:00
feat(gameplay): add temporary chunk flag to prevent path clearing
This commit is contained in:
@@ -24,7 +24,8 @@ private:
|
||||
std::atomic<bool> m_need_upload{true};
|
||||
std::atomic<bool> m_is_on_gen_vertex_data{false};
|
||||
std::atomic<bool> m_gening{false};
|
||||
std::atomic<bool> m_gen_finish{false};
|
||||
std::atomic<bool> m_temp_chunk{false};
|
||||
|
||||
std::atomic<BiomeType> m_biome = BiomeType::PLAIN;
|
||||
std::mutex m_vertexs_data_mutex;
|
||||
|
||||
@@ -56,7 +57,7 @@ private:
|
||||
BlockType id);
|
||||
|
||||
public:
|
||||
Chunk(World& world, ChunkPos chunk_pos);
|
||||
Chunk(World& world, ChunkPos chunk_pos, bool temp_chunk = false);
|
||||
~Chunk();
|
||||
Chunk(const Chunk&) = delete;
|
||||
Chunk& operator=(const Chunk&) = delete;
|
||||
@@ -128,8 +129,7 @@ public:
|
||||
void set_chunk_block(int index, unsigned id);
|
||||
// ensure thread safe!
|
||||
void gen_chunk();
|
||||
|
||||
bool is_gen_finish() const;
|
||||
bool is_temp_chunk() const;
|
||||
ChunkPos chunk_pos() const;
|
||||
BiomeType biome() const;
|
||||
void biome(BiomeType b);
|
||||
|
||||
@@ -49,11 +49,13 @@ void CaveCarver::try_to_add_path(const ChunkPos& chunk_pos,
|
||||
|
||||
void CaveCarver::cleanup_finished_caves() {
|
||||
std::vector<unsigned int> finished_keys;
|
||||
|
||||
for (const auto& pair : m_paths) {
|
||||
if (pair.second.is_finished()) {
|
||||
finished_keys.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& key : finished_keys) {
|
||||
m_paths.erase(key);
|
||||
}
|
||||
@@ -61,4 +63,5 @@ void CaveCarver::cleanup_finished_caves() {
|
||||
|
||||
int CaveCarver::cave_sum() const { return m_paths.size(); }
|
||||
float& CaveCarver::cave_probability() { return m_cave_probability; }
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
Chunk::Chunk(World& world, ChunkPos chunk_pos)
|
||||
: m_chunk_pos(chunk_pos), m_world(world) {
|
||||
Chunk::Chunk(World& world, ChunkPos chunk_pos, bool temp_chunk)
|
||||
: m_temp_chunk(temp_chunk), m_chunk_pos(chunk_pos), m_world(world) {
|
||||
for (int i = 0; i < VERTEX_DATA_SUM; i++) {
|
||||
m_vertex_data.emplace_back(m_world);
|
||||
}
|
||||
@@ -466,7 +466,7 @@ void Chunk::gen_chunk() {
|
||||
}
|
||||
std::vector<Chunk> neighbor;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
neighbor.emplace_back(m_world, m_chunk_pos + CHUNK_DIR[i]);
|
||||
neighbor.emplace_back(m_world, m_chunk_pos + CHUNK_DIR[i], true);
|
||||
}
|
||||
for (auto& chunk : neighbor) {
|
||||
chunk.gen_phase_one();
|
||||
@@ -488,9 +488,9 @@ void Chunk::gen_chunk() {
|
||||
neightbor_blocks[i] = neighbor[i].get_chunk_blocks();
|
||||
}
|
||||
gen_vertex_data(neightbor_blocks);
|
||||
m_gen_finish = true;
|
||||
}
|
||||
bool Chunk::is_gen_finish() const { return m_gen_finish.load(); }
|
||||
// Logger::info("Cross Sum {}", m_cross_vertices_sum.load());
|
||||
|
||||
bool Chunk::is_temp_chunk() const { return m_temp_chunk.load(); }
|
||||
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -734,7 +734,9 @@ void ChunkGenerator::generate_cave() {
|
||||
return;
|
||||
blocks[idx] = 0;
|
||||
});
|
||||
path.clear_chunk(chunk_pos);
|
||||
if (!m_chunk.is_temp_chunk()) {
|
||||
path.clear_chunk(chunk_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,8 +767,11 @@ void ChunkGenerator::generate_river() {
|
||||
}
|
||||
blocks[idx] = 7;
|
||||
});
|
||||
path.clear_chunk(chunk_pos);
|
||||
if (!m_chunk.is_temp_chunk()) {
|
||||
path.clear_chunk(chunk_pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_river) {
|
||||
m_chunk.biome(RIVER);
|
||||
}
|
||||
|
||||
@@ -46,11 +46,13 @@ void RiverWorm::try_to_add_path(const ChunkPos& chunk_pos,
|
||||
|
||||
void RiverWorm::cleanup_finished_rivers() {
|
||||
std::vector<unsigned> finished_keys;
|
||||
|
||||
for (const auto& pair : m_paths) {
|
||||
if (pair.second.is_finished()) {
|
||||
finished_keys.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& key : finished_keys) {
|
||||
m_paths.erase(key);
|
||||
}
|
||||
@@ -58,4 +60,5 @@ void RiverWorm::cleanup_finished_rivers() {
|
||||
|
||||
int RiverWorm::river_sum() const { return m_paths.size(); }
|
||||
float& RiverWorm::river_probability() { return m_probability; }
|
||||
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user