diff --git a/doc/classes/Navigation2DServer.xml b/doc/classes/Navigation2DServer.xml index 9b3bc25bf..ce2698c8d 100644 --- a/doc/classes/Navigation2DServer.xml +++ b/doc/classes/Navigation2DServer.xml @@ -173,6 +173,13 @@ Returns the navigation layers for this [code]link[/code]. + + + + + Returns the [code]ObjectID[/code] of the object which manages this link. + + @@ -234,6 +241,14 @@ Set the links's navigation layers. This allows selecting links from a path request (when using [method NavigationServer2D.map_get_path]). + + + + + + Set the [code]ObjectID[/code] of the object which manages this link. + + @@ -447,6 +462,13 @@ Returns the region's navigation layers. + + + + + Returns the [code]ObjectID[/code] of the object which manages this region. + + @@ -496,6 +518,14 @@ Sets the navigation mesh for the region. + + + + + + Set the [code]ObjectID[/code] of the object which manages this region. + + diff --git a/doc/classes/NavigationServer.xml b/doc/classes/NavigationServer.xml index 3b355d9ba..a2b4ef9b8 100644 --- a/doc/classes/NavigationServer.xml +++ b/doc/classes/NavigationServer.xml @@ -181,6 +181,13 @@ Returns the navigation layers for this [code]link[/code]. + + + + + Returns the [code]ObjectID[/code] of the object which manages this link. + + @@ -242,6 +249,14 @@ Set the links's navigation layers. This allows selecting links from a path request (when using [method NavigationServer3D.map_get_path]). + + + + + + Set the [code]ObjectID[/code] of the object which manages this link. + + @@ -497,6 +512,13 @@ Returns the region's navigation layers. + + + + + Returns the [code]ObjectID[/code] of the object which manages this region. + + @@ -546,6 +568,14 @@ Sets the navigation mesh for the region. + + + + + + Set the [code]ObjectID[/code] of the object which manages this region. + + diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 984bdf56c..6980e5fa1 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -582,6 +582,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) { if (bake_navigation) { RID region = NavigationServer::get_singleton()->region_create(); + NavigationServer::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer::get_singleton()->region_set_navigation_layers(region, navigation_layers); NavigationServer::get_singleton()->region_set_navmesh(region, navmesh); NavigationServer::get_singleton()->region_set_transform(region, get_global_transform() * nm.xform); @@ -700,6 +701,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { Ref nm = mesh_library->get_item_navmesh(cell_map[E->key()].item); if (nm.is_valid()) { RID region = NavigationServer::get_singleton()->region_create(); + NavigationServer::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer::get_singleton()->region_set_navigation_layers(region, navigation_layers); NavigationServer::get_singleton()->region_set_navmesh(region, nm); NavigationServer::get_singleton()->region_set_transform(region, get_global_transform() * E->get().xform); diff --git a/modules/navigation/pandemonium_navigation_2d_server.cpp b/modules/navigation/pandemonium_navigation_2d_server.cpp index f3dd123bb..c6d2b270d 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.cpp +++ b/modules/navigation/pandemonium_navigation_2d_server.cpp @@ -52,9 +52,9 @@ return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0)); \ } -#define FORWARD_1_R_C(CONV_R, FUNC_NAME, T_0, D_0, CONV_0) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0) \ - const { \ +#define FORWARD_1_R_C(CONV_R, FUNC_NAME, T_0, D_0, CONV_0) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0) \ + const { \ return CONV_R(NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0))); \ } @@ -243,6 +243,8 @@ void FORWARD_2_C(region_set_enter_cost, RID, p_region, real_t, p_enter_cost, rid real_t FORWARD_1_C(region_get_enter_cost, RID, p_region, rid_to_rid); void FORWARD_2_C(region_set_travel_cost, RID, p_region, real_t, p_travel_cost, rid_to_rid, real_to_real); real_t FORWARD_1_C(region_get_travel_cost, RID, p_region, rid_to_rid); +void FORWARD_2_C(region_set_owner_id, RID, p_region, ObjectID, p_owner_id, rid_to_rid, id_to_id); +ObjectID FORWARD_1_C(region_get_owner_id, RID, p_region, rid_to_rid); bool FORWARD_2_C(region_owns_point, RID, p_region, const Vector2 &, p_point, rid_to_rid, v2_to_v3); void FORWARD_2_C(region_set_map, RID, p_region, RID, p_map, rid_to_rid, rid_to_rid); @@ -274,6 +276,8 @@ void FORWARD_2_C(link_set_enter_cost, RID, p_link, real_t, p_enter_cost, rid_to_ real_t FORWARD_1_C(link_get_enter_cost, RID, p_link, rid_to_rid); void FORWARD_2_C(link_set_travel_cost, RID, p_link, real_t, p_travel_cost, rid_to_rid, real_to_real); real_t FORWARD_1_C(link_get_travel_cost, RID, p_link, rid_to_rid); +void FORWARD_2_C(link_set_owner_id, RID, p_link, ObjectID, p_owner_id, rid_to_rid, id_to_id); +ObjectID FORWARD_1_C(link_get_owner_id, RID, p_link, rid_to_rid); RID PandemoniumNavigation2DServer::agent_create() const { RID agent = NavigationServer::get_singleton()->agent_create(); diff --git a/modules/navigation/pandemonium_navigation_2d_server.h b/modules/navigation/pandemonium_navigation_2d_server.h index 067f729a8..b061ec94c 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.h +++ b/modules/navigation/pandemonium_navigation_2d_server.h @@ -102,6 +102,10 @@ public: virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const; virtual real_t region_get_travel_cost(RID p_region) const; + /// Set the node which manages this region. + virtual void region_set_owner_id(RID p_region, ObjectID p_owner_id) const; + virtual ObjectID region_get_owner_id(RID p_region) const; + virtual bool region_owns_point(RID p_region, const Vector2 &p_point) const; /// Set the map of this region. @@ -154,6 +158,10 @@ public: virtual void link_set_travel_cost(RID p_link, real_t p_travel_cost) const; virtual real_t link_get_travel_cost(RID p_link) const; + /// Set the node which manages this link. + virtual void link_set_owner_id(RID p_link, ObjectID p_owner_id) const; + virtual ObjectID link_get_owner_id(RID p_link) const; + /// Creates the agent. virtual RID agent_create() const; diff --git a/modules/navigation/pandemonium_navigation_server.cpp b/modules/navigation/pandemonium_navigation_server.cpp index 5afcb4a39..7e883c56e 100644 --- a/modules/navigation/pandemonium_navigation_server.cpp +++ b/modules/navigation/pandemonium_navigation_server.cpp @@ -412,6 +412,20 @@ real_t PandemoniumNavigationServer::region_get_travel_cost(RID p_region) const { return region->get_travel_cost(); } +COMMAND_2(region_set_owner_id, RID, p_region, ObjectID, p_owner_id) { + NavRegion *region = region_owner.getornull(p_region); + ERR_FAIL_COND(region == nullptr); + + region->set_owner_id(p_owner_id); +} + +ObjectID PandemoniumNavigationServer::region_get_owner_id(RID p_region) const { + const NavRegion *region = region_owner.getornull(p_region); + ERR_FAIL_COND_V(region == nullptr, ObjectID()); + + return region->get_owner_id(); +} + bool PandemoniumNavigationServer::region_owns_point(RID p_region, const Vector3 &p_point) const { const NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(region == nullptr, false); @@ -589,6 +603,20 @@ real_t PandemoniumNavigationServer::link_get_travel_cost(const RID p_link) const return link->get_travel_cost(); } +COMMAND_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id) { + NavLink *link = link_owner.getornull(p_link); + ERR_FAIL_COND(link == nullptr); + + link->set_owner_id(p_owner_id); +} + +ObjectID PandemoniumNavigationServer::link_get_owner_id(RID p_link) const { + const NavLink *link = link_owner.getornull(p_link); + ERR_FAIL_COND_V(link == nullptr, ObjectID()); + + return link->get_owner_id(); +} + RID PandemoniumNavigationServer::agent_create() const { PandemoniumNavigationServer *mut_this = const_cast(this); MutexLock lock(mut_this->operations_mutex); diff --git a/modules/navigation/pandemonium_navigation_server.h b/modules/navigation/pandemonium_navigation_server.h index d151c789b..96e47b883 100644 --- a/modules/navigation/pandemonium_navigation_server.h +++ b/modules/navigation/pandemonium_navigation_server.h @@ -135,6 +135,8 @@ public: virtual real_t region_get_enter_cost(RID p_region) const; COMMAND_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost); virtual real_t region_get_travel_cost(RID p_region) const; + COMMAND_2(region_set_owner_id, RID, p_region, ObjectID, p_owner_id); + virtual ObjectID region_get_owner_id(RID p_region) const; virtual bool region_owns_point(RID p_region, const Vector3 &p_point) const; @@ -164,6 +166,8 @@ public: virtual real_t link_get_enter_cost(RID p_link) const; COMMAND_2(link_set_travel_cost, RID, p_link, real_t, p_travel_cost); virtual real_t link_get_travel_cost(RID p_link) const; + COMMAND_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id); + virtual ObjectID link_get_owner_id(RID p_link) const; virtual RID agent_create() const; COMMAND_2(agent_set_map, RID, p_agent, RID, p_map); diff --git a/modules/navigation_dummy/dummy_navigation_2d_server.h b/modules/navigation_dummy/dummy_navigation_2d_server.h index 14a73caca..65561ac61 100644 --- a/modules/navigation_dummy/dummy_navigation_2d_server.h +++ b/modules/navigation_dummy/dummy_navigation_2d_server.h @@ -38,6 +38,8 @@ public: virtual real_t region_get_enter_cost(RID p_region) const { return 0; } virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const {} virtual real_t region_get_travel_cost(RID p_region) const { return 0; } + virtual void region_set_owner_id(RID p_region, ObjectID p_owner_id) const {} + virtual ObjectID region_get_owner_id(RID p_region) const { return 0; } virtual bool region_owns_point(RID p_region, const Vector2 &p_point) const { return false; } virtual void region_set_map(RID p_region, RID p_map) const {} virtual RID region_get_map(RID p_region) const { return RID(); } @@ -64,6 +66,8 @@ public: virtual real_t link_get_enter_cost(RID p_link) const { return 0; } virtual void link_set_travel_cost(RID p_link, real_t p_travel_cost) const {} virtual real_t link_get_travel_cost(RID p_link) const { return 0; } + virtual void link_set_owner_id(RID p_link, ObjectID p_owner_id) const {} + virtual ObjectID link_get_owner_id(RID p_link) const { return 0; } virtual RID agent_create() const { return RID(); } virtual void agent_set_map(RID p_agent, RID p_map) const {} diff --git a/modules/navigation_dummy/dummy_navigation_server.h b/modules/navigation_dummy/dummy_navigation_server.h index c3a64c115..b48b5af9d 100644 --- a/modules/navigation_dummy/dummy_navigation_server.h +++ b/modules/navigation_dummy/dummy_navigation_server.h @@ -40,6 +40,8 @@ public: virtual real_t region_get_enter_cost(RID p_region) const { return 0; } virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const {} virtual real_t region_get_travel_cost(RID p_region) const { return 0; } + virtual void region_set_owner_id(RID p_region, ObjectID p_owner_id) const {} + virtual ObjectID region_get_owner_id(RID p_region) const { return 0; } virtual bool region_owns_point(RID p_region, const Vector3 &p_point) const { return false; } virtual void region_set_map(RID p_region, RID p_map) const {} virtual RID region_get_map(RID p_region) const { return RID(); } @@ -66,6 +68,8 @@ public: virtual real_t link_get_enter_cost(RID p_link) const { return 0; } virtual void link_set_travel_cost(RID p_link, real_t p_travel_cost) const {} virtual real_t link_get_travel_cost(RID p_link) const { return 0; } + virtual void link_set_owner_id(RID p_link, ObjectID p_owner_id) const {} + virtual ObjectID link_get_owner_id(RID p_link) const { return 0; } virtual RID agent_create() const { return RID(); } virtual void agent_set_map(RID p_agent, RID p_map) const {} diff --git a/modules/tile_map/tile_map.cpp b/modules/tile_map/tile_map.cpp index 8a15ed0e7..9d06bee27 100644 --- a/modules/tile_map/tile_map.cpp +++ b/modules/tile_map/tile_map.cpp @@ -679,6 +679,7 @@ void TileMap::update_dirty_quadrants() { _fix_cell_transform(xform, c, npoly_ofs, s); RID region = Navigation2DServer::get_singleton()->region_create(); + Navigation2DServer::get_singleton()->region_set_owner_id(region, get_instance_id()); if (navigation) { Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); } else { diff --git a/scene/2d/navigation_link_2d.cpp b/scene/2d/navigation_link_2d.cpp index 981c8e229..e0c607408 100644 --- a/scene/2d/navigation_link_2d.cpp +++ b/scene/2d/navigation_link_2d.cpp @@ -332,7 +332,7 @@ NavigationLink2D::NavigationLink2D() { travel_cost = 1.0; link = Navigation2DServer::get_singleton()->link_create(); - //Navigation2DServer::get_singleton()->link_set_owner_id(link, get_instance_id()); + Navigation2DServer::get_singleton()->link_set_owner_id(link, get_instance_id()); set_notify_transform(true); } diff --git a/scene/2d/navigation_polygon_instance.cpp b/scene/2d/navigation_polygon_instance.cpp index d6083c8be..147da821c 100644 --- a/scene/2d/navigation_polygon_instance.cpp +++ b/scene/2d/navigation_polygon_instance.cpp @@ -394,7 +394,7 @@ NavigationPolygonInstance::NavigationPolygonInstance() { navigation_layers = 1; baking_started = false; - + Navigation2DServer::get_singleton()->region_set_owner_id(region, get_instance_id()); Navigation2DServer::get_singleton()->region_set_enter_cost(region, get_enter_cost()); Navigation2DServer::get_singleton()->region_set_travel_cost(region, get_travel_cost()); diff --git a/scene/3d/navigation_link_3d.cpp b/scene/3d/navigation_link_3d.cpp index a49bbc4f7..11773f192 100644 --- a/scene/3d/navigation_link_3d.cpp +++ b/scene/3d/navigation_link_3d.cpp @@ -240,7 +240,7 @@ void NavigationLink3D::_notification(int p_what) { NavigationLink3D::NavigationLink3D() { link = NavigationServer::get_singleton()->link_create(); - //NavigationServer::get_singleton()->link_set_owner_id(link, get_instance_id()); + NavigationServer::get_singleton()->link_set_owner_id(link, get_instance_id()); set_notify_transform(true); } diff --git a/scene/3d/navigation_mesh_instance.cpp b/scene/3d/navigation_mesh_instance.cpp index b77e0dd3b..edd66c68c 100644 --- a/scene/3d/navigation_mesh_instance.cpp +++ b/scene/3d/navigation_mesh_instance.cpp @@ -404,6 +404,7 @@ NavigationMeshInstance::NavigationMeshInstance() { baking_started = false; region = NavigationServer::get_singleton()->region_create(); + NavigationServer::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer::get_singleton()->region_set_enter_cost(region, get_enter_cost()); NavigationServer::get_singleton()->region_set_travel_cost(region, get_travel_cost()); enabled = true; diff --git a/servers/navigation_2d_server.cpp b/servers/navigation_2d_server.cpp index 753878606..701c95c4f 100644 --- a/servers/navigation_2d_server.cpp +++ b/servers/navigation_2d_server.cpp @@ -65,6 +65,8 @@ void Navigation2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &Navigation2DServer::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &Navigation2DServer::region_set_travel_cost); ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &Navigation2DServer::region_get_travel_cost); + ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &Navigation2DServer::region_set_owner_id); + ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &Navigation2DServer::region_get_owner_id); ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &Navigation2DServer::region_owns_point); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &Navigation2DServer::region_set_map); ClassDB::bind_method(D_METHOD("region_get_map", "region"), &Navigation2DServer::region_get_map); @@ -91,6 +93,8 @@ void Navigation2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &Navigation2DServer::link_get_enter_cost); ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &Navigation2DServer::link_set_travel_cost); ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &Navigation2DServer::link_get_travel_cost); + ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &Navigation2DServer::link_set_owner_id); + ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &Navigation2DServer::link_get_owner_id); ClassDB::bind_method(D_METHOD("agent_create"), &Navigation2DServer::agent_create); ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &Navigation2DServer::agent_set_map); diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h index 8572303dd..55ce17430 100644 --- a/servers/navigation_2d_server.h +++ b/servers/navigation_2d_server.h @@ -113,6 +113,10 @@ public: virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const = 0; virtual real_t region_get_travel_cost(RID p_region) const = 0; + /// Set the node which manages this region. + virtual void region_set_owner_id(RID p_region, ObjectID p_owner_id) const = 0; + virtual ObjectID region_get_owner_id(RID p_region) const = 0; + virtual bool region_owns_point(RID p_region, const Vector2 &p_point) const = 0; /// Set the map of this region. @@ -165,6 +169,10 @@ public: virtual void link_set_travel_cost(RID p_link, real_t p_travel_cost) const = 0; virtual real_t link_get_travel_cost(RID p_link) const = 0; + /// Set the node which manages this link. + virtual void link_set_owner_id(RID p_link, ObjectID p_owner_id) const = 0; + virtual ObjectID link_get_owner_id(RID p_link) const = 0; + /// Creates the agent. virtual RID agent_create() const = 0; diff --git a/servers/navigation_server.cpp b/servers/navigation_server.cpp index 04527c0a8..5f6f89819 100644 --- a/servers/navigation_server.cpp +++ b/servers/navigation_server.cpp @@ -81,6 +81,8 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer::region_set_travel_cost); ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer::region_get_travel_cost); + ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer::region_set_owner_id); + ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer::region_get_owner_id); ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer::region_owns_point); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer::region_set_map); ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer::region_get_map); @@ -110,6 +112,8 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer::link_get_enter_cost); ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer::link_set_travel_cost); ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer::link_get_travel_cost); + ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer::link_set_owner_id); + ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer::link_get_owner_id); ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer::agent_create); ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer::agent_set_map); diff --git a/servers/navigation_server.h b/servers/navigation_server.h index b0e6e2f75..fefd24ca2 100644 --- a/servers/navigation_server.h +++ b/servers/navigation_server.h @@ -129,6 +129,10 @@ public: virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const = 0; virtual real_t region_get_travel_cost(RID p_region) const = 0; + /// Set the node which manages this region. + virtual void region_set_owner_id(RID p_region, ObjectID p_owner_id) const = 0; + virtual ObjectID region_get_owner_id(RID p_region) const = 0; + virtual bool region_owns_point(RID p_region, const Vector3 &p_point) const = 0; /// Set the map of this region. @@ -181,6 +185,10 @@ public: virtual void link_set_travel_cost(RID p_link, real_t p_travel_cost) const = 0; virtual real_t link_get_travel_cost(RID p_link) const = 0; + /// Set the node which manages this link. + virtual void link_set_owner_id(RID p_link, ObjectID p_owner_id) const = 0; + virtual ObjectID link_get_owner_id(RID p_link) const = 0; + /// Creates the agent. virtual RID agent_create() const = 0;