chore: modifiers are aware of parent terrain

This commit is contained in:
Sara Gerretsen 2026-02-25 20:21:13 +01:00
parent 80eb6ef4c0
commit 953e4abe5b
3 changed files with 18 additions and 6 deletions

View file

@ -9,16 +9,27 @@ void Terrain::_bind_methods() {
BIND_PROPERTY(Variant::INT, thread_count);
}
void Terrain::ready() {
construct_chunk_grid();
void Terrain::child_order_changed() {
this->modifiers.clear();
for (Variant var : get_children()) {
if (TerrainModifier * mod{ cast_to<TerrainModifier>(var) }) {
mod->set_terrain(this);
this->modifiers.push_back(mod);
}
}
}
void Terrain::_notification(int what) {
switch (what) {
default:
return;
case NOTIFICATION_ENTER_TREE:
if (!is_ready()) {
connect("child_order_changed", callable_mp(this, &self_type::child_order_changed));
}
return;
case NOTIFICATION_READY:
ready();
construct_chunk_grid();
return;
case NOTIFICATION_EXIT_TREE:
this->workload_lock.lock();