diff options
author | Andrea Catania <info@andreacatania.com> | 2020-01-10 12:22:34 +0100 |
---|---|---|
committer | Andrea Catania <info@andreacatania.com> | 2020-02-10 14:38:52 +0100 |
commit | e6be3f68da4b88cb0c7d8c7464916235c73e1f92 (patch) | |
tree | 2e65162fd1937df8b4dcd80900dd5b9b4aac58d1 /modules/gridmap/grid_map.cpp | |
parent | 8cd5102c65269f1ec4968627ca71df550954d914 (diff) |
- Integrated NavigationServer and Navigation2DServer.
- Added Navigation Agents and Obstacles.
- Integrated Collision Avoidance.
This work has been kindly sponsored by IMVU.
Diffstat (limited to 'modules/gridmap/grid_map.cpp')
-rw-r--r-- | modules/gridmap/grid_map.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
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<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - navigation->navmesh_remove(E->get().id); - } - g.navmesh_ids.clear(); + for (Map<IndexKey, Octant::NavMesh>::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<IndexKey, Octant::NavMesh>::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<NavigationMesh> 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<IndexKey, Octant::NavMesh>::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<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - navigation->navmesh_remove(E->get().id); - } - g.navmesh_ids.clear(); + // Erase navigation + for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { + NavigationServer::get_singleton()->free(E->get().region); } + g.navmesh_ids.clear(); //erase multimeshes |