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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,6 @@ class Terrain : public Node {
|
|||
GDCLASS(Terrain, Node);
|
||||
static void _bind_methods();
|
||||
void ready();
|
||||
void process();
|
||||
|
||||
void child_order_changed();
|
||||
void child_entered(Node *node);
|
||||
void child_exiting(Node *node);
|
||||
|
||||
void on_terrain_changed();
|
||||
|
||||
protected:
|
||||
void _notification(int what);
|
||||
|
|
@ -27,17 +20,20 @@ protected:
|
|||
|
||||
public:
|
||||
void construct_chunk_grid();
|
||||
void generate_meshes();
|
||||
void area_dirty(Vector2 from, Vector2 to);
|
||||
float height_at(Vector2 world_coordinate);
|
||||
void mesh_task_complete();
|
||||
|
||||
private:
|
||||
Timer *timer{ nullptr };
|
||||
Vector<TerrainChunkMesh *> workload{};
|
||||
Mutex workload_lock;
|
||||
bool threads_stop{ false };
|
||||
Vector<TerrainChunkMesh *> meshes{};
|
||||
Vector<TerrainModifier *> modifiers{};
|
||||
LocalVector<Thread> threads{};
|
||||
|
||||
size_t side_length{ 200 };
|
||||
size_t chunk_size{ 50 };
|
||||
size_t detail{ 1 };
|
||||
bool dirty{ false };
|
||||
size_t pending_tasks{ 0 };
|
||||
|
||||
public:
|
||||
void set_side_length(size_t length);
|
||||
|
|
@ -48,12 +44,4 @@ public:
|
|||
size_t get_detail() const;
|
||||
void set_thread_count(size_t num);
|
||||
size_t get_thread_count() const;
|
||||
|
||||
private:
|
||||
Vector<TerrainChunkMesh *> workload{};
|
||||
Mutex workload_lock;
|
||||
bool threads_stop{ false };
|
||||
Vector<TerrainChunkMesh *> meshes{};
|
||||
Vector<TerrainModifier *> modifiers{};
|
||||
LocalVector<Thread> threads{};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ void TerrainChunkMesh::_bind_methods() {}
|
|||
|
||||
void TerrainChunkMesh::apply_new_mesh() {
|
||||
set_mesh(this->new_mesh);
|
||||
this->terrain->mesh_task_complete();
|
||||
}
|
||||
|
||||
void TerrainChunkMesh::generate_vertices() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue