diff options
Diffstat (limited to 'modules/gdnavigation')
-rw-r--r-- | modules/gdnavigation/gd_navigation_server.cpp | 51 | ||||
-rw-r--r-- | modules/gdnavigation/gd_navigation_server.h | 9 | ||||
-rw-r--r-- | modules/gdnavigation/nav_map.cpp | 7 | ||||
-rw-r--r-- | modules/gdnavigation/navigation_mesh_editor_plugin.cpp | 13 | ||||
-rw-r--r-- | modules/gdnavigation/navigation_mesh_editor_plugin.h | 6 | ||||
-rw-r--r-- | modules/gdnavigation/navigation_mesh_generator.cpp | 2 | ||||
-rw-r--r-- | modules/gdnavigation/navigation_mesh_generator.h | 2 |
7 files changed, 45 insertions, 45 deletions
diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index 1f1783802d..4db10cda78 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -115,30 +115,27 @@ GdNavigationServer::GdNavigationServer() : NavigationServer(), - commands_mutex(Mutex::create()), - operations_mutex(Mutex::create()), active(true) { } GdNavigationServer::~GdNavigationServer() { - memdelete(operations_mutex); - memdelete(commands_mutex); + flush_queries(); } void GdNavigationServer::add_command(SetCommand *command) const { auto mut_this = const_cast<GdNavigationServer *>(this); - commands_mutex->lock(); - mut_this->commands.push_back(command); - commands_mutex->unlock(); + { + MutexLock lock(commands_mutex); + mut_this->commands.push_back(command); + } } RID GdNavigationServer::map_create() const { auto mut_this = const_cast<GdNavigationServer *>(this); - mut_this->operations_mutex->lock(); + MutexLock lock(mut_this->operations_mutex); NavMap *space = memnew(NavMap); RID rid = map_owner.make_rid(space); space->set_self(rid); - mut_this->operations_mutex->unlock(); return rid; } @@ -241,11 +238,10 @@ RID GdNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_ RID GdNavigationServer::region_create() const { auto mut_this = const_cast<GdNavigationServer *>(this); - mut_this->operations_mutex->lock(); + MutexLock lock(mut_this->operations_mutex); NavRegion *reg = memnew(NavRegion); RID rid = region_owner.make_rid(reg); reg->set_self(rid); - mut_this->operations_mutex->unlock(); return rid; } @@ -297,11 +293,10 @@ void GdNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p RID GdNavigationServer::agent_create() const { auto mut_this = const_cast<GdNavigationServer *>(this); - mut_this->operations_mutex->lock(); + MutexLock lock(mut_this->operations_mutex); RvoAgent *agent = memnew(RvoAgent()); RID rid = agent_owner.make_rid(agent); agent->set_self(rid); - mut_this->operations_mutex->unlock(); return rid; } @@ -469,28 +464,32 @@ COMMAND_1(free, RID, p_object) { void GdNavigationServer::set_active(bool p_active) const { auto mut_this = const_cast<GdNavigationServer *>(this); - mut_this->operations_mutex->lock(); + MutexLock lock(mut_this->operations_mutex); mut_this->active = p_active; - mut_this->operations_mutex->unlock(); } -void GdNavigationServer::step(real_t p_delta_time) { - if (!active) { - return; - } - - // With c++ we can't be 100% sure this is called in single thread so use the mutex. - commands_mutex->lock(); - operations_mutex->lock(); +void GdNavigationServer::flush_queries() { + // In c++ we can't be sure that this is performed in the main thread + // even with mutable functions. + MutexLock lock(commands_mutex); + MutexLock lock2(operations_mutex); for (size_t i(0); i < commands.size(); i++) { commands[i]->exec(this); memdelete(commands[i]); } commands.clear(); - operations_mutex->unlock(); - commands_mutex->unlock(); +} + +void GdNavigationServer::process(real_t p_delta_time) { + flush_queries(); + + if (!active) { + return; + } - // These are internal operations so don't need to be shielded. + // In c++ we can't be sure that this is performed in the main thread + // even with mutable functions. + MutexLock lock(operations_mutex); for (int i(0); i < active_maps.size(); i++) { active_maps[i]->sync(); active_maps[i]->step(p_delta_time); diff --git a/modules/gdnavigation/gd_navigation_server.h b/modules/gdnavigation/gd_navigation_server.h index 7fa5979c31..e9f5c1ffe6 100644 --- a/modules/gdnavigation/gd_navigation_server.h +++ b/modules/gdnavigation/gd_navigation_server.h @@ -61,7 +61,6 @@ void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) class GdNavigationServer; -class Mutex; struct SetCommand { virtual ~SetCommand() {} @@ -69,9 +68,9 @@ struct SetCommand { }; class GdNavigationServer : public NavigationServer { - Mutex *commands_mutex; + Mutex commands_mutex; /// Mutex used to make any operation threadsafe. - Mutex *operations_mutex; + Mutex operations_mutex; std::vector<SetCommand *> commands; @@ -131,7 +130,9 @@ public: COMMAND_1(free, RID, p_object); virtual void set_active(bool p_active) const; - virtual void step(real_t p_delta_time); + + void flush_queries(); + virtual void process(real_t p_delta_time); }; #undef COMMAND_1 diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp index d3e2f8f388..c3880f89b6 100644 --- a/modules/gdnavigation/nav_map.cpp +++ b/modules/gdnavigation/nav_map.cpp @@ -545,8 +545,11 @@ void NavMap::add_region(NavRegion *p_region) { } void NavMap::remove_region(NavRegion *p_region) { - regions.push_back(p_region); - regenerate_links = true; + std::vector<NavRegion *>::iterator it = std::find(regions.begin(), regions.end(), p_region); + if (it != regions.end()) { + regions.erase(it); + regenerate_links = true; + } } bool NavMap::has_agent(RvoAgent *agent) const { diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp index 28fe0bfd06..5c298ae9e4 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp +++ b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp @@ -84,7 +84,7 @@ void NavigationMeshEditor::_clear_pressed() { } } -void NavigationMeshEditor::edit(NavigationMeshInstance *p_nav_mesh_instance) { +void NavigationMeshEditor::edit(NavigationRegion *p_nav_mesh_instance) { if (p_nav_mesh_instance == NULL || node == p_nav_mesh_instance) { return; @@ -94,9 +94,6 @@ void NavigationMeshEditor::edit(NavigationMeshInstance *p_nav_mesh_instance) { } void NavigationMeshEditor::_bind_methods() { - - ClassDB::bind_method("_bake_pressed", &NavigationMeshEditor::_bake_pressed); - ClassDB::bind_method("_clear_pressed", &NavigationMeshEditor::_clear_pressed); } NavigationMeshEditor::NavigationMeshEditor() { @@ -107,13 +104,13 @@ NavigationMeshEditor::NavigationMeshEditor() { bake_hbox->add_child(button_bake); button_bake->set_toggle_mode(true); button_bake->set_text(TTR("Bake NavMesh")); - button_bake->connect_compat("pressed", this, "_bake_pressed"); + button_bake->connect("pressed", callable_mp(this, &NavigationMeshEditor::_bake_pressed)); button_reset = memnew(ToolButton); bake_hbox->add_child(button_reset); // No button text, we only use a revert icon which is set when entering the tree. button_reset->set_tooltip(TTR("Clear the navigation mesh.")); - button_reset->connect_compat("pressed", this, "_clear_pressed"); + button_reset->connect("pressed", callable_mp(this, &NavigationMeshEditor::_clear_pressed)); bake_info = memnew(Label); bake_hbox->add_child(bake_info); @@ -128,12 +125,12 @@ NavigationMeshEditor::~NavigationMeshEditor() { void NavigationMeshEditorPlugin::edit(Object *p_object) { - navigation_mesh_editor->edit(Object::cast_to<NavigationMeshInstance>(p_object)); + navigation_mesh_editor->edit(Object::cast_to<NavigationRegion>(p_object)); } bool NavigationMeshEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("NavigationMeshInstance"); + return p_object->is_class("NavigationRegion"); } void NavigationMeshEditorPlugin::make_visible(bool p_visible) { diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.h b/modules/gdnavigation/navigation_mesh_editor_plugin.h index f5833f3d7f..7c3faebf57 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.h +++ b/modules/gdnavigation/navigation_mesh_editor_plugin.h @@ -36,7 +36,7 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" -class NavigationMeshInstance; +class NavigationRegion; class NavigationMeshEditor : public Control { friend class NavigationMeshEditorPlugin; @@ -50,7 +50,7 @@ class NavigationMeshEditor : public Control { ToolButton *button_reset; Label *bake_info; - NavigationMeshInstance *node; + NavigationRegion *node; void _bake_pressed(); void _clear_pressed(); @@ -61,7 +61,7 @@ protected: void _notification(int p_option); public: - void edit(NavigationMeshInstance *p_nav_mesh_instance); + void edit(NavigationRegion *p_nav_mesh_instance); NavigationMeshEditor(); ~NavigationMeshEditor(); }; diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/gdnavigation/navigation_mesh_generator.cpp index 7f8761dac8..e7038b38a2 100644 --- a/modules/gdnavigation/navigation_mesh_generator.cpp +++ b/modules/gdnavigation/navigation_mesh_generator.cpp @@ -42,10 +42,10 @@ #include "scene/resources/concave_polygon_shape.h" #include "scene/resources/convex_polygon_shape.h" #include "scene/resources/cylinder_shape.h" -#include "scene/resources/plane_shape.h" #include "scene/resources/primitive_meshes.h" #include "scene/resources/shape.h" #include "scene/resources/sphere_shape.h" +#include "scene/resources/world_margin_shape.h" #include "modules/modules_enabled.gen.h" #ifdef TOOLS_ENABLED diff --git a/modules/gdnavigation/navigation_mesh_generator.h b/modules/gdnavigation/navigation_mesh_generator.h index 27a56e1d7a..d1f2e4b56f 100644 --- a/modules/gdnavigation/navigation_mesh_generator.h +++ b/modules/gdnavigation/navigation_mesh_generator.h @@ -33,7 +33,7 @@ #ifndef _3D_DISABLED -#include "scene/3d/navigation_mesh_instance.h" +#include "scene/3d/navigation_region.h" #include <Recast.h> |