From e6be3f68da4b88cb0c7d8c7464916235c73e1f92 Mon Sep 17 00:00:00 2001 From: Andrea Catania Date: Fri, 10 Jan 2020 12:22:34 +0100 Subject: - Integrated NavigationServer and Navigation2DServer. - Added Navigation Agents and Obstacles. - Integrated Collision Avoidance. This work has been kindly sponsored by IMVU. --- modules/gridmap/grid_map.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'modules/gridmap/grid_map.cpp') diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 3d40220869..1e73a715db 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -36,6 +36,7 @@ #include "scene/resources/mesh_library.h" #include "scene/resources/surface_tool.h" #include "scene/scene_string_names.h" +#include "servers/navigation_server.h" #include "servers/visual_server.h" bool GridMap::_set(const StringName &p_name, const Variant &p_value) { @@ -418,12 +419,10 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } //erase navigation - if (navigation) { - for (Map::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - navigation->navmesh_remove(E->get().id); - } - g.navmesh_ids.clear(); + for (Map::Element *E = g.navmesh_ids.front(); E; E = E->next()) { + NavigationServer::get_singleton()->free(E->get().region); } + g.navmesh_ids.clear(); //erase multimeshes @@ -498,9 +497,11 @@ bool GridMap::_octant_update(const OctantKey &p_key) { nm.xform = xform * mesh_library->get_item_navmesh_transform(c.item); if (navigation) { - nm.id = navigation->navmesh_add(navmesh, xform, this); - } else { - nm.id = -1; + RID region = NavigationServer::get_singleton()->region_create(); + NavigationServer::get_singleton()->region_set_navmesh(region, navmesh); + NavigationServer::get_singleton()->region_set_transform(region, navigation->get_global_transform() * nm.xform); + NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + nm.region = region; } g.navmesh_ids[E->get()] = nm; } @@ -591,10 +592,14 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { if (navigation && mesh_library.is_valid()) { for (Map::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (cell_map.has(F->key()) && F->get().id < 0) { + if (cell_map.has(F->key()) && F->get().region.is_valid() == false) { Ref nm = mesh_library->get_item_navmesh(cell_map[F->key()].item); if (nm.is_valid()) { - F->get().id = navigation->navmesh_add(nm, F->get().xform, this); + RID region = NavigationServer::get_singleton()->region_create(); + NavigationServer::get_singleton()->region_set_navmesh(region, nm); + NavigationServer::get_singleton()->region_set_transform(region, navigation->get_global_transform() * F->get().xform); + NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + F->get().region = region; } } } @@ -620,9 +625,9 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { if (navigation) { for (Map::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (F->get().id >= 0) { - navigation->navmesh_remove(F->get().id); - F->get().id = -1; + if (F->get().region.is_valid()) { + NavigationServer::get_singleton()->free(F->get().region); + F->get().region = RID(); } } } @@ -640,13 +645,11 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { PhysicsServer::get_singleton()->free(g.static_body); - //erase navigation - if (navigation) { - for (Map::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - navigation->navmesh_remove(E->get().id); - } - g.navmesh_ids.clear(); + // Erase navigation + for (Map::Element *E = g.navmesh_ids.front(); E; E = E->next()) { + NavigationServer::get_singleton()->free(E->get().region); } + g.navmesh_ids.clear(); //erase multimeshes -- cgit v1.2.3