Browse Source

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 c0fed1d4e886539a533fc77e58bd4c2e1ae17597)
smix8 3 years ago
parent
commit
38ee593b76

+ 6 - 0
doc/classes/Navigation2DServer.xml

@@ -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>

+ 6 - 0
doc/classes/NavigationServer.xml

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

+ 12 - 0
modules/navigation/godot_navigation_server.cpp

@@ -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 {
 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);

+ 2 - 0
modules/navigation/godot_navigation_server.h

@@ -83,6 +83,8 @@ public:
 
 
 	void add_command(SetCommand *command) const;
 	void add_command(SetCommand *command) const;
 
 
+	virtual Array get_maps() const;
+
 	virtual RID map_create() const;
 	virtual RID map_create() const;
 	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;
 	virtual bool map_is_active(RID p_map) const;

+ 4 - 0
servers/navigation_2d_server.cpp

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

+ 2 - 0
servers/navigation_2d_server.h

@@ -53,6 +53,8 @@ public:
 	/// MUST be used in single thread!
 	/// MUST be used in single thread!
 	static Navigation2DServer *get_singleton_mut() { return singleton; }
 	static Navigation2DServer *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;
 
 

+ 2 - 0
servers/navigation_server.cpp

@@ -33,6 +33,8 @@
 NavigationServer *NavigationServer::singleton = nullptr;
 NavigationServer *NavigationServer::singleton = nullptr;
 
 
 void NavigationServer::_bind_methods() {
 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_create"), &NavigationServer::map_create);
 	ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer::map_set_active);
 	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);
 	ClassDB::bind_method(D_METHOD("map_is_active", "nap"), &NavigationServer::map_is_active);

+ 2 - 0
servers/navigation_server.h

@@ -56,6 +56,8 @@ public:
 	/// MUST be used in single thread!
 	/// MUST be used in single thread!
 	static NavigationServer *get_singleton_mut();
 	static NavigationServer *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;