diff --git a/modules/terrain/terrain.cpp b/modules/terrain/terrain.cpp index a925b6b5..5ef9f828 100644 --- a/modules/terrain/terrain.cpp +++ b/modules/terrain/terrain.cpp @@ -31,8 +31,26 @@ void Terrain::update_meshes() { this->dirty_meshes_lock.unlock(); mesh->apply_new_mesh(); } - if (this->dirty_meshes.is_empty()) { - set_process(false); +} + +void Terrain::update_threads() { + this->workload_lock.lock(); + if (this->workload.is_empty()) { + this->threads_stop = true; + this->workload_lock.unlock(); + for (Thread &thread : this->threads) { + if (thread.is_started()) { + thread.wait_to_finish(); + } + } + } else { + this->threads_stop = false; + for (Thread &thread : this->threads) { + if (!thread.is_started()) { + thread.start(Terrain::generate_meshes_thread, this); + } + } + this->workload_lock.unlock(); } } @@ -50,6 +68,7 @@ void Terrain::_notification(int what) { return; case NOTIFICATION_PROCESS: update_meshes(); + update_threads(); return; case NOTIFICATION_EXIT_TREE: this->workload_lock.lock(); diff --git a/modules/terrain/terrain.h b/modules/terrain/terrain.h index 64177a7f..50cdea6b 100644 --- a/modules/terrain/terrain.h +++ b/modules/terrain/terrain.h @@ -13,6 +13,7 @@ class Terrain : public Node { static void _bind_methods(); void child_order_changed(); void update_meshes(); + void update_threads(); protected: void _notification(int what); diff --git a/project/scenes/terrain_test.tscn b/project/scenes/terrain_test.tscn index e9ebfc4b..bdf1f670 100644 --- a/project/scenes/terrain_test.tscn +++ b/project/scenes/terrain_test.tscn @@ -17,6 +17,11 @@ _limits = [0.0, 1.0, 0.0, 300.0] _data = [Vector2(0, 1), 0.0, -0.00018586064, 0, 0, Vector2(300, 0), 0.0, 0.0, 0, 0] point_count = 2 +[sub_resource type="Curve" id="Curve_o3i6r"] +_limits = [0.0, 1.0, 0.0, 100.0] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(52.483585, 0.53811765), -0.024930112, -0.024930112, 0, 0, Vector2(71.53754, 0.12219274), -0.012579738, -0.012579738, 0, 0, Vector2(100, 0), 0.0, 0.0, 0, 0] +point_count = 4 + [sub_resource type="Curve" id="Curve_kbmr5"] _limits = [0.0, 1.0, 0.0, 300.0] _data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(69.40413, 0.8155421), -0.008522048, -0.008522048, 0, 0, Vector2(124.08008, 0.34781557), -0.0070376517, -0.0070376517, 0, 0, Vector2(244.43303, 0), 0.00011380972, 0.0, 0, 0] @@ -35,29 +40,47 @@ chunk_size = 100 thread_count = 5 [node name="TerrainModifierPath2" type="TerrainModifierPath" parent="Terrain" unique_id=645020759] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 251.12363, 255.25969, 182.0507) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 251.12363, 255.25969, 248.8021) gizmo_extents = 100.0 curve_left = SubResource("Curve_w3uoq") [node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=59754729] gizmo_extents = 50.0 -[node name="TerrainModifierPathPoint5" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=460239910] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 101.51407, -59.121643, -89.72089) -gizmo_extents = 50.0 - -[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=94753507] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 274.68933, -82.27042, -75.669815) -gizmo_extents = 50.0 - -[node name="TerrainModifierPathPoint4" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=473450276] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 437.1725, -161.30762, -75.669815) -gizmo_extents = 50.0 - [node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=1474399635] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 595.01825, -141.92302, 42.69197) gizmo_extents = 50.0 +[node name="TerrainModifierPath4" type="TerrainModifierPath" parent="Terrain" unique_id=1865212969] +transform = Transform3D(0.17220415, 0, -0.9850613, 0, 1, 0, 0.9850613, 0, 0.17220415, 847.4274, 114.188705, 296.454) +gizmo_extents = 100.0 +curve_left = SubResource("Curve_w3uoq") + +[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath4" unique_id=1307746348] +gizmo_extents = 50.0 + +[node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath4" unique_id=331993744] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 595.01825, -12.977875, 42.69197) +gizmo_extents = 50.0 + +[node name="TerrainModifierPath3" type="TerrainModifierPath" parent="Terrain" unique_id=1721431246] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 482.5311, 36.249924, 85.91423) +curve_left = SubResource("Curve_o3i6r") + +[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=1744128498] + +[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=560389606] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 116.74786) + +[node name="TerrainModifierPathPoint4" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=221640403] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -32.71512, 229.67038) + +[node name="TerrainModifierPathPoint5" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=2015729881] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -77.74802, 319.90332) + +[node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=2010545766] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -120.10968, 381.31598) + [node name="TerrainModifierPath" type="TerrainModifierPath" parent="Terrain" unique_id=314094590] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1033.4109, 14.052078, 504.81018) gizmo_extents = 100.0