diff options
author | Josh Jones <kilauea.jones@gmail.com> | 2022-09-30 23:49:39 -0600 |
---|---|---|
committer | Josh Jones <kilauea.jones@gmail.com> | 2022-12-10 12:03:06 -0800 |
commit | 5769b0e8d8db75ff500c979aa63d3f3428de526d (patch) | |
tree | ba0df7ba770e1fa1a9e3fbccd19e0cc781940bd3 /servers | |
parent | 39fe0bfdc3327d2b1f651739a918daea3ba241f5 (diff) |
Enable assigning an owner to navigation regions and links
This allows users of the server APIs to get back the nodes that created certain regions and links.
Diffstat (limited to 'servers')
-rw-r--r-- | servers/navigation_server_2d.cpp | 12 | ||||
-rw-r--r-- | servers/navigation_server_2d.h | 8 | ||||
-rw-r--r-- | servers/navigation_server_3d.cpp | 4 | ||||
-rw-r--r-- | servers/navigation_server_3d.h | 8 |
4 files changed, 32 insertions, 0 deletions
diff --git a/servers/navigation_server_2d.cpp b/servers/navigation_server_2d.cpp index 04e5d2f6a1..bfe95ddef1 100644 --- a/servers/navigation_server_2d.cpp +++ b/servers/navigation_server_2d.cpp @@ -152,6 +152,10 @@ static Variant var_to_var(const Variant &d) { return d; } +static ObjectID id_to_id(const ObjectID &id) { + return id; +} + static Ref<NavigationMesh> poly_to_mesh(Ref<NavigationPolygon> d) { if (d.is_valid()) { return d->get_mesh(); @@ -250,6 +254,8 @@ void NavigationServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer2D::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer2D::region_set_travel_cost); ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer2D::region_get_travel_cost); + ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer2D::region_set_owner_id); + ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer2D::region_get_owner_id); ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer2D::region_owns_point); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer2D::region_set_map); ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer2D::region_get_map); @@ -276,6 +282,8 @@ void NavigationServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer2D::link_get_enter_cost); ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer2D::link_set_travel_cost); ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer2D::link_get_travel_cost); + ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer2D::link_set_owner_id); + ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer2D::link_get_owner_id); ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer2D::agent_create); ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer2D::agent_set_map); @@ -348,6 +356,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); @@ -379,6 +389,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 NavigationServer2D::agent_create() const { RID agent = NavigationServer3D::get_singleton()->agent_create(); diff --git a/servers/navigation_server_2d.h b/servers/navigation_server_2d.h index 54cfc6b14e..4c78bc40c7 100644 --- a/servers/navigation_server_2d.h +++ b/servers/navigation_server_2d.h @@ -108,6 +108,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. @@ -160,6 +164,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/servers/navigation_server_3d.cpp b/servers/navigation_server_3d.cpp index cab8816747..31e8b9a864 100644 --- a/servers/navigation_server_3d.cpp +++ b/servers/navigation_server_3d.cpp @@ -69,6 +69,8 @@ void NavigationServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer3D::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer3D::region_set_travel_cost); ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer3D::region_get_travel_cost); + ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer3D::region_set_owner_id); + ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer3D::region_get_owner_id); ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer3D::region_owns_point); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer3D::region_set_map); ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer3D::region_get_map); @@ -96,6 +98,8 @@ void NavigationServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer3D::link_get_enter_cost); ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer3D::link_set_travel_cost); ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer3D::link_get_travel_cost); + ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer3D::link_set_owner_id); + ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer3D::link_get_owner_id); ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer3D::agent_create); ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer3D::agent_set_map); diff --git a/servers/navigation_server_3d.h b/servers/navigation_server_3d.h index 0f537383a2..31ae149aff 100644 --- a/servers/navigation_server_3d.h +++ b/servers/navigation_server_3d.h @@ -120,6 +120,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. @@ -175,6 +179,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; |