feat: bounds-based mesh reloading
This commit is contained in:
parent
953e4abe5b
commit
226c821454
7 changed files with 93 additions and 38 deletions
|
|
@ -78,6 +78,7 @@ void Terrain::construct_chunk_grid() {
|
|||
this->meshes.clear();
|
||||
size_t const chunks_per_side{ this->side_length / this->chunk_size };
|
||||
Vector3 const origin{ (float)this->chunk_size / 2.f, 0.f, (float)this->chunk_size / 2.f };
|
||||
this->workload_lock.lock();
|
||||
for (size_t y{ 0 }; y < chunks_per_side; ++y) {
|
||||
for (size_t x{ 0 }; x < chunks_per_side; ++x) {
|
||||
TerrainChunkMesh *chunk{ memnew(TerrainChunkMesh) };
|
||||
|
|
@ -88,8 +89,10 @@ void Terrain::construct_chunk_grid() {
|
|||
add_child(chunk);
|
||||
chunk->set_owner(this);
|
||||
this->meshes.push_back(chunk);
|
||||
this->workload.push_back(chunk);
|
||||
}
|
||||
}
|
||||
this->workload_lock.unlock();
|
||||
}
|
||||
|
||||
float Terrain::height_at(Vector2 world_coordinate) {
|
||||
|
|
@ -103,6 +106,16 @@ float Terrain::height_at(Vector2 world_coordinate) {
|
|||
return height;
|
||||
}
|
||||
|
||||
void Terrain::push_changed(Rect2 area) {
|
||||
for (TerrainChunkMesh *mesh : this->meshes) {
|
||||
this->workload_lock.lock();
|
||||
if (area.intersects(mesh->get_bounds()) && !this->workload.has(mesh)) {
|
||||
workload.push_back(mesh);
|
||||
}
|
||||
this->workload_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::set_side_length(size_t length) {
|
||||
this->side_length = length;
|
||||
if (is_inside_tree()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue