Browse Source

Merge pull request #93583 from smix8/obstacle_monitor

Add navigation obstacles to performance monitor stats
Rémi Verschelde 1 year ago
parent
commit
dbf4be308c

+ 3 - 0
doc/classes/NavigationServer3D.xml

@@ -1167,5 +1167,8 @@
 		<constant name="INFO_EDGE_FREE_COUNT" value="8" enum="ProcessInfo">
 		<constant name="INFO_EDGE_FREE_COUNT" value="8" enum="ProcessInfo">
 			Constant to get the number of navigation mesh polygon edges that could not be merged but may be still connected by edge proximity or with links.
 			Constant to get the number of navigation mesh polygon edges that could not be merged but may be still connected by edge proximity or with links.
 		</constant>
 		</constant>
+		<constant name="INFO_OBSTACLE_COUNT" value="9" enum="ProcessInfo">
+			Constant to get the number of active navigation obstacles.
+		</constant>
 	</constants>
 	</constants>
 </class>
 </class>

+ 4 - 1
doc/classes/Performance.xml

@@ -221,7 +221,10 @@
 		<constant name="NAVIGATION_EDGE_FREE_COUNT" value="32" enum="Monitor">
 		<constant name="NAVIGATION_EDGE_FREE_COUNT" value="32" enum="Monitor">
 			Number of navigation mesh polygon edges that could not be merged in the [NavigationServer3D]. The edges still may be connected by edge proximity or with links.
 			Number of navigation mesh polygon edges that could not be merged in the [NavigationServer3D]. The edges still may be connected by edge proximity or with links.
 		</constant>
 		</constant>
-		<constant name="MONITOR_MAX" value="33" enum="Monitor">
+		<constant name="NAVIGATION_OBSTACLE_COUNT" value="33" enum="Monitor">
+			Number of active navigation obstacles in the [NavigationServer3D].
+		</constant>
+		<constant name="MONITOR_MAX" value="34" enum="Monitor">
 			Represents the size of the [enum Monitor] enum.
 			Represents the size of the [enum Monitor] enum.
 		</constant>
 		</constant>
 	</constants>
 	</constants>

+ 5 - 0
main/performance.cpp

@@ -91,6 +91,7 @@ void Performance::_bind_methods() {
 	BIND_ENUM_CONSTANT(NAVIGATION_EDGE_MERGE_COUNT);
 	BIND_ENUM_CONSTANT(NAVIGATION_EDGE_MERGE_COUNT);
 	BIND_ENUM_CONSTANT(NAVIGATION_EDGE_CONNECTION_COUNT);
 	BIND_ENUM_CONSTANT(NAVIGATION_EDGE_CONNECTION_COUNT);
 	BIND_ENUM_CONSTANT(NAVIGATION_EDGE_FREE_COUNT);
 	BIND_ENUM_CONSTANT(NAVIGATION_EDGE_FREE_COUNT);
+	BIND_ENUM_CONSTANT(NAVIGATION_OBSTACLE_COUNT);
 	BIND_ENUM_CONSTANT(MONITOR_MAX);
 	BIND_ENUM_CONSTANT(MONITOR_MAX);
 }
 }
 
 
@@ -141,6 +142,7 @@ String Performance::get_monitor_name(Monitor p_monitor) const {
 		PNAME("navigation/edges_merged"),
 		PNAME("navigation/edges_merged"),
 		PNAME("navigation/edges_connected"),
 		PNAME("navigation/edges_connected"),
 		PNAME("navigation/edges_free"),
 		PNAME("navigation/edges_free"),
+		PNAME("navigation/obstacles"),
 
 
 	};
 	};
 
 
@@ -225,6 +227,8 @@ double Performance::get_monitor(Monitor p_monitor) const {
 			return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
 			return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
 		case NAVIGATION_EDGE_FREE_COUNT:
 		case NAVIGATION_EDGE_FREE_COUNT:
 			return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
 			return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
+		case NAVIGATION_OBSTACLE_COUNT:
+			return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT);
 
 
 		default: {
 		default: {
 		}
 		}
@@ -272,6 +276,7 @@ Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const
 		MONITOR_TYPE_QUANTITY,
 		MONITOR_TYPE_QUANTITY,
 		MONITOR_TYPE_QUANTITY,
 		MONITOR_TYPE_QUANTITY,
 		MONITOR_TYPE_QUANTITY,
 		MONITOR_TYPE_QUANTITY,
+		MONITOR_TYPE_QUANTITY,
 
 
 	};
 	};
 
 

+ 1 - 0
main/performance.h

@@ -100,6 +100,7 @@ public:
 		NAVIGATION_EDGE_MERGE_COUNT,
 		NAVIGATION_EDGE_MERGE_COUNT,
 		NAVIGATION_EDGE_CONNECTION_COUNT,
 		NAVIGATION_EDGE_CONNECTION_COUNT,
 		NAVIGATION_EDGE_FREE_COUNT,
 		NAVIGATION_EDGE_FREE_COUNT,
+		NAVIGATION_OBSTACLE_COUNT,
 		MONITOR_MAX
 		MONITOR_MAX
 	};
 	};
 
 

+ 6 - 0
modules/navigation/3d/godot_navigation_server_3d.cpp

@@ -1298,6 +1298,7 @@ void GodotNavigationServer3D::process(real_t p_delta_time) {
 	int _new_pm_edge_merge_count = 0;
 	int _new_pm_edge_merge_count = 0;
 	int _new_pm_edge_connection_count = 0;
 	int _new_pm_edge_connection_count = 0;
 	int _new_pm_edge_free_count = 0;
 	int _new_pm_edge_free_count = 0;
+	int _new_pm_obstacle_count = 0;
 
 
 	// In c++ we can't be sure that this is performed in the main thread
 	// In c++ we can't be sure that this is performed in the main thread
 	// even with mutable functions.
 	// even with mutable functions.
@@ -1315,6 +1316,7 @@ void GodotNavigationServer3D::process(real_t p_delta_time) {
 		_new_pm_edge_merge_count += active_maps[i]->get_pm_edge_merge_count();
 		_new_pm_edge_merge_count += active_maps[i]->get_pm_edge_merge_count();
 		_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
 		_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
 		_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
 		_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
+		_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
 
 
 		// Emit a signal if a map changed.
 		// Emit a signal if a map changed.
 		const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
 		const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
@@ -1332,6 +1334,7 @@ void GodotNavigationServer3D::process(real_t p_delta_time) {
 	pm_edge_merge_count = _new_pm_edge_merge_count;
 	pm_edge_merge_count = _new_pm_edge_merge_count;
 	pm_edge_connection_count = _new_pm_edge_connection_count;
 	pm_edge_connection_count = _new_pm_edge_connection_count;
 	pm_edge_free_count = _new_pm_edge_free_count;
 	pm_edge_free_count = _new_pm_edge_free_count;
+	pm_obstacle_count = _new_pm_obstacle_count;
 }
 }
 
 
 void GodotNavigationServer3D::init() {
 void GodotNavigationServer3D::init() {
@@ -1566,6 +1569,9 @@ int GodotNavigationServer3D::get_process_info(ProcessInfo p_info) const {
 		case INFO_EDGE_FREE_COUNT: {
 		case INFO_EDGE_FREE_COUNT: {
 			return pm_edge_free_count;
 			return pm_edge_free_count;
 		} break;
 		} break;
+		case INFO_OBSTACLE_COUNT: {
+			return pm_obstacle_count;
+		} break;
 	}
 	}
 
 
 	return 0;
 	return 0;

+ 1 - 0
modules/navigation/3d/godot_navigation_server_3d.h

@@ -95,6 +95,7 @@ class GodotNavigationServer3D : public NavigationServer3D {
 	int pm_edge_merge_count = 0;
 	int pm_edge_merge_count = 0;
 	int pm_edge_connection_count = 0;
 	int pm_edge_connection_count = 0;
 	int pm_edge_free_count = 0;
 	int pm_edge_free_count = 0;
+	int pm_obstacle_count = 0;
 
 
 public:
 public:
 	GodotNavigationServer3D();
 	GodotNavigationServer3D();

+ 2 - 0
modules/navigation/nav_map.cpp

@@ -907,6 +907,7 @@ void NavMap::sync() {
 	int _new_pm_edge_merge_count = pm_edge_merge_count;
 	int _new_pm_edge_merge_count = pm_edge_merge_count;
 	int _new_pm_edge_connection_count = pm_edge_connection_count;
 	int _new_pm_edge_connection_count = pm_edge_connection_count;
 	int _new_pm_edge_free_count = pm_edge_free_count;
 	int _new_pm_edge_free_count = pm_edge_free_count;
+	int _new_pm_obstacle_count = obstacles.size();
 
 
 	// Check if we need to update the links.
 	// Check if we need to update the links.
 	if (regenerate_polygons) {
 	if (regenerate_polygons) {
@@ -1219,6 +1220,7 @@ void NavMap::sync() {
 	pm_edge_merge_count = _new_pm_edge_merge_count;
 	pm_edge_merge_count = _new_pm_edge_merge_count;
 	pm_edge_connection_count = _new_pm_edge_connection_count;
 	pm_edge_connection_count = _new_pm_edge_connection_count;
 	pm_edge_free_count = _new_pm_edge_free_count;
 	pm_edge_free_count = _new_pm_edge_free_count;
+	pm_obstacle_count = _new_pm_obstacle_count;
 }
 }
 
 
 void NavMap::_update_rvo_obstacles_tree_2d() {
 void NavMap::_update_rvo_obstacles_tree_2d() {

+ 2 - 0
modules/navigation/nav_map.h

@@ -123,6 +123,7 @@ class NavMap : public NavRid {
 	int pm_edge_merge_count = 0;
 	int pm_edge_merge_count = 0;
 	int pm_edge_connection_count = 0;
 	int pm_edge_connection_count = 0;
 	int pm_edge_free_count = 0;
 	int pm_edge_free_count = 0;
+	int pm_obstacle_count = 0;
 
 
 public:
 public:
 	NavMap();
 	NavMap();
@@ -216,6 +217,7 @@ public:
 	int get_pm_edge_merge_count() const { return pm_edge_merge_count; }
 	int get_pm_edge_merge_count() const { return pm_edge_merge_count; }
 	int get_pm_edge_connection_count() const { return pm_edge_connection_count; }
 	int get_pm_edge_connection_count() const { return pm_edge_connection_count; }
 	int get_pm_edge_free_count() const { return pm_edge_free_count; }
 	int get_pm_edge_free_count() const { return pm_edge_free_count; }
+	int get_pm_obstacle_count() const { return pm_obstacle_count; }
 
 
 private:
 private:
 	void compute_single_step(uint32_t index, NavAgent **agent);
 	void compute_single_step(uint32_t index, NavAgent **agent);

+ 1 - 0
servers/navigation_server_3d.cpp

@@ -216,6 +216,7 @@ void NavigationServer3D::_bind_methods() {
 	BIND_ENUM_CONSTANT(INFO_EDGE_MERGE_COUNT);
 	BIND_ENUM_CONSTANT(INFO_EDGE_MERGE_COUNT);
 	BIND_ENUM_CONSTANT(INFO_EDGE_CONNECTION_COUNT);
 	BIND_ENUM_CONSTANT(INFO_EDGE_CONNECTION_COUNT);
 	BIND_ENUM_CONSTANT(INFO_EDGE_FREE_COUNT);
 	BIND_ENUM_CONSTANT(INFO_EDGE_FREE_COUNT);
+	BIND_ENUM_CONSTANT(INFO_OBSTACLE_COUNT);
 }
 }
 
 
 NavigationServer3D *NavigationServer3D::get_singleton() {
 NavigationServer3D *NavigationServer3D::get_singleton() {

+ 1 - 0
servers/navigation_server_3d.h

@@ -369,6 +369,7 @@ public:
 		INFO_EDGE_MERGE_COUNT,
 		INFO_EDGE_MERGE_COUNT,
 		INFO_EDGE_CONNECTION_COUNT,
 		INFO_EDGE_CONNECTION_COUNT,
 		INFO_EDGE_FREE_COUNT,
 		INFO_EDGE_FREE_COUNT,
+		INFO_OBSTACLE_COUNT,
 	};
 	};
 
 
 	virtual int get_process_info(ProcessInfo p_info) const = 0;
 	virtual int get_process_info(ProcessInfo p_info) const = 0;