Browse Source

Merge pull request #62312 from smix8/navigation_get_maps_4.x

Rémi Verschelde 3 years ago
parent
commit
462127eff0

+ 6 - 0
doc/classes/NavigationServer2D.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/NavigationServer3D.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>

+ 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 (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);

+ 2 - 0
modules/navigation/godot_navigation_server.h

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

+ 4 - 0
servers/navigation_server_2d.cpp

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

+ 2 - 0
servers/navigation_server_2d.h

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

+ 2 - 0
servers/navigation_server_3d.cpp

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

+ 2 - 0
servers/navigation_server_3d.h

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