Ported: 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.
- smix8
38ee593b76
This commit is contained in:
Relintai 2022-07-29 17:49:24 +02:00
parent 0e32de0bad
commit f811d48449
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

@ -127,6 +127,18 @@ void PandemoniumNavigationServer::add_command(SetCommand *command) const {
}
}
Array PandemoniumNavigationServer::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 PandemoniumNavigationServer::map_create() const {
PandemoniumNavigationServer *mut_this = const_cast<PandemoniumNavigationServer *>(this);
MutexLock lock(mut_this->operations_mutex);

View File

@ -82,6 +82,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

@ -172,6 +172,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);
@ -233,6 +235,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

@ -52,6 +52,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

@ -36,6 +36,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

@ -58,6 +58,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;