Merge pull request #62312 from smix8/navigation_get_maps_4.x

This commit is contained in:
Rémi Verschelde 2022-06-23 16:14:12 +02:00 committed by GitHub
commit 462127eff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 0 deletions

View File

@ -127,6 +127,12 @@
Destroys the given RID. Destroys the given RID.
</description> </description>
</method> </method>
<method name="get_maps" qualifiers="const">
<return type="Array" />
<description>
Returns all created navigation map [RID]s on the NavigationServer. This returns both 2D and 3D created navigation maps as there is technically no distinction between them.
</description>
</method>
<method name="map_create" qualifiers="const"> <method name="map_create" qualifiers="const">
<return type="RID" /> <return type="RID" />
<description> <description>

View File

@ -127,6 +127,12 @@
Destroys the given RID. Destroys the given RID.
</description> </description>
</method> </method>
<method name="get_maps" qualifiers="const">
<return type="Array" />
<description>
Returns all created navigation map [RID]s on the NavigationServer. This returns both 2D and 3D created navigation maps as there is technically no distinction between them.
</description>
</method>
<method name="map_create" qualifiers="const"> <method name="map_create" qualifiers="const">
<return type="RID" /> <return type="RID" />
<description> <description>

View File

@ -123,6 +123,18 @@ void GodotNavigationServer::add_command(SetCommand *command) const {
} }
} }
Array GodotNavigationServer::get_maps() const {
Array all_map_rids;
List<RID> maps_owned;
map_owner.get_owned_list(&maps_owned);
if (maps_owned.size()) {
for (const RID &E : maps_owned) {
all_map_rids.push_back(E);
}
}
return all_map_rids;
}
RID GodotNavigationServer::map_create() const { RID GodotNavigationServer::map_create() const {
GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
MutexLock lock(mut_this->operations_mutex); MutexLock lock(mut_this->operations_mutex);

View File

@ -85,6 +85,8 @@ public:
void add_command(SetCommand *command) const; void add_command(SetCommand *command) const;
virtual Array get_maps() const override;
virtual RID map_create() const override; virtual RID map_create() const override;
COMMAND_2(map_set_active, RID, p_map, bool, p_active); COMMAND_2(map_set_active, RID, p_map, bool, p_active);
virtual bool map_is_active(RID p_map) const override; virtual bool map_is_active(RID p_map) const override;

View File

@ -159,6 +159,8 @@ void NavigationServer2D::_emit_map_changed(RID p_map) {
} }
void NavigationServer2D::_bind_methods() { void NavigationServer2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_maps"), &NavigationServer2D::get_maps);
ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer2D::map_create); ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer2D::map_create);
ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer2D::map_set_active); ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer2D::map_set_active);
ClassDB::bind_method(D_METHOD("map_is_active", "nap"), &NavigationServer2D::map_is_active); ClassDB::bind_method(D_METHOD("map_is_active", "nap"), &NavigationServer2D::map_is_active);
@ -217,6 +219,8 @@ NavigationServer2D::~NavigationServer2D() {
singleton = nullptr; singleton = nullptr;
} }
Array FORWARD_0_C(get_maps);
Array FORWARD_1_C(map_get_regions, RID, p_map, rid_to_rid); Array FORWARD_1_C(map_get_regions, RID, p_map, rid_to_rid);
Array FORWARD_1_C(map_get_agents, RID, p_map, rid_to_rid); Array FORWARD_1_C(map_get_agents, RID, p_map, rid_to_rid);

View File

@ -53,6 +53,8 @@ public:
/// MUST be used in single thread! /// MUST be used in single thread!
static NavigationServer2D *get_singleton_mut() { return singleton; } static NavigationServer2D *get_singleton_mut() { return singleton; }
virtual Array get_maps() const;
/// Create a new map. /// Create a new map.
virtual RID map_create() const; virtual RID map_create() const;

View File

@ -33,6 +33,8 @@
NavigationServer3D *NavigationServer3D::singleton = nullptr; NavigationServer3D *NavigationServer3D::singleton = nullptr;
void NavigationServer3D::_bind_methods() { void NavigationServer3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_maps"), &NavigationServer3D::get_maps);
ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer3D::map_create); ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer3D::map_create);
ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer3D::map_set_active); ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer3D::map_set_active);
ClassDB::bind_method(D_METHOD("map_is_active", "nap"), &NavigationServer3D::map_is_active); ClassDB::bind_method(D_METHOD("map_is_active", "nap"), &NavigationServer3D::map_is_active);

View File

@ -56,6 +56,8 @@ public:
/// MUST be used in single thread! /// MUST be used in single thread!
static NavigationServer3D *get_singleton_mut(); static NavigationServer3D *get_singleton_mut();
virtual Array get_maps() const = 0;
/// Create a new map. /// Create a new map.
virtual RID map_create() const = 0; virtual RID map_create() const = 0;