Add Navigation function to get all navigation maps

Added new function that returns all created navigation map RIDs from the NavigationServer. The function returns both 2D and 3D created navigation maps as technically there is no distinction between them.

(cherry picked from commit c0fed1d4e8)
This commit is contained in:
smix8 2022-06-22 15:33:40 +02:00 committed by Rémi Verschelde
parent 7bcb9fddc9
commit 38ee593b76
8 changed files with 36 additions and 0 deletions

View File

@ -127,6 +127,12 @@
Destroys the given RID.
</description>
</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">
<return type="RID" />
<description>

View File

@ -126,6 +126,12 @@
Destroys the given RID.
</description>
</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">
<return type="RID" />
<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 (List<RID>::Element *E = maps_owned.front(); E; E = E->next()) {
all_map_rids.push_back(E->get());
}
}
return all_map_rids;
}
RID GodotNavigationServer::map_create() const {
GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
MutexLock lock(mut_this->operations_mutex);

View File

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

View File

@ -171,6 +171,8 @@ void Navigation2DServer::_emit_map_changed(RID p_map) {
}
void Navigation2DServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_maps"), &Navigation2DServer::get_maps);
ClassDB::bind_method(D_METHOD("map_create"), &Navigation2DServer::map_create);
ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &Navigation2DServer::map_set_active);
ClassDB::bind_method(D_METHOD("map_is_active", "nap"), &Navigation2DServer::map_is_active);
@ -232,6 +234,8 @@ Navigation2DServer::~Navigation2DServer() {
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_agents, RID, p_map, rid_to_rid);

View File

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

View File

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

View File

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