feat: tore out old generation triggers
This commit is contained in:
parent
51fe41eda0
commit
80eb6ef4c0
3 changed files with 8 additions and 106 deletions
|
|
@ -11,84 +11,15 @@ void Terrain::_bind_methods() {
|
|||
|
||||
void Terrain::ready() {
|
||||
construct_chunk_grid();
|
||||
generate_meshes();
|
||||
}
|
||||
|
||||
void Terrain::process() {
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
if (this->pending_tasks == 0 && this->dirty) {
|
||||
this->workload_lock.lock();
|
||||
if (this->workload.is_empty()) {
|
||||
this->dirty = false;
|
||||
this->workload.append_array(this->meshes);
|
||||
this->pending_tasks = this->workload.size();
|
||||
}
|
||||
this->workload_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::child_order_changed() {
|
||||
Callable on_changed_callable{ callable_mp(this, &self_type::on_terrain_changed) };
|
||||
// check if the modifiers actually changed
|
||||
if (is_ready()) {
|
||||
bool modified{ false };
|
||||
size_t idx{ 0 };
|
||||
for (Variant var : get_children()) {
|
||||
if (TerrainModifier * mod{ cast_to<TerrainModifier>(var) }) {
|
||||
if (modified) {
|
||||
this->modifiers.push_back(mod);
|
||||
} else if (idx >= this->modifiers.size() || mod != this->modifiers[idx]) {
|
||||
modified = true;
|
||||
this->modifiers.resize(idx);
|
||||
this->modifiers.push_back(mod);
|
||||
} else {
|
||||
idx++;
|
||||
}
|
||||
if (!mod->is_connected(TerrainModifier::sig_changed, on_changed_callable)) {
|
||||
mod->connect(TerrainModifier::sig_changed, on_changed_callable);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (modified && is_ready()) {
|
||||
on_terrain_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::child_exiting(Node *node) {
|
||||
if (TerrainModifier * mod{ cast_to<TerrainModifier>(node) }) {
|
||||
if (Engine::get_singleton()->is_editor_hint() && !is_queued_for_deletion()) {
|
||||
mod->disconnect(TerrainModifier::sig_changed, callable_mp(this, &self_type::on_terrain_changed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::on_terrain_changed() {
|
||||
if (is_queued_for_deletion() || !is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
generate_meshes();
|
||||
}
|
||||
|
||||
void Terrain::_notification(int what) {
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
if (!is_ready()) {
|
||||
connect("child_exiting_tree", callable_mp(this, &self_type::child_exiting));
|
||||
connect("child_order_changed", callable_mp(this, &self_type::child_order_changed));
|
||||
}
|
||||
return;
|
||||
case NOTIFICATION_READY:
|
||||
set_process(true);
|
||||
ready();
|
||||
return;
|
||||
case NOTIFICATION_PROCESS:
|
||||
process();
|
||||
return;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
this->workload_lock.lock();
|
||||
this->threads_stop = true;
|
||||
|
|
@ -150,10 +81,6 @@ void Terrain::construct_chunk_grid() {
|
|||
}
|
||||
}
|
||||
|
||||
void Terrain::generate_meshes() {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
float Terrain::height_at(Vector2 world_coordinate) {
|
||||
float height{ 0 };
|
||||
for (TerrainModifier *mod : this->modifiers) {
|
||||
|
|
@ -169,7 +96,6 @@ void Terrain::set_side_length(size_t length) {
|
|||
this->side_length = length;
|
||||
if (is_inside_tree()) {
|
||||
construct_chunk_grid();
|
||||
generate_meshes();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +107,6 @@ void Terrain::set_chunk_size(size_t size) {
|
|||
this->chunk_size = size;
|
||||
if (is_inside_tree()) {
|
||||
construct_chunk_grid();
|
||||
generate_meshes();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +118,6 @@ void Terrain::set_detail(size_t detail) {
|
|||
this->detail = detail;
|
||||
if (is_inside_tree()) {
|
||||
construct_chunk_grid();
|
||||
generate_meshes();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,12 +142,3 @@ void Terrain::set_thread_count(size_t num) {
|
|||
size_t Terrain::get_thread_count() const {
|
||||
return this->threads.size();
|
||||
}
|
||||
|
||||
void Terrain::mesh_task_complete() {
|
||||
this->pending_tasks--;
|
||||
if (this->pending_tasks == 0) {
|
||||
for (TerrainModifier *mod : this->modifiers) {
|
||||
mod->set_dirty(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue