Fix navigation debug not toggleable in scripts

Fixes that navigation debug was not toggleable in script while even the docs mentioned it.
This commit is contained in:
smix8 2023-02-13 12:17:24 +01:00
parent aa6ec76317
commit aecad7bb25
7 changed files with 60 additions and 22 deletions

View File

@ -126,6 +126,12 @@
Destroys the given RID. Destroys the given RID.
</description> </description>
</method> </method>
<method name="get_debug_enabled" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] when the NavigationServer has debug enabled.
</description>
</method>
<method name="get_maps" qualifiers="const"> <method name="get_maps" qualifiers="const">
<return type="RID[]" /> <return type="RID[]" />
<description> <description>
@ -520,6 +526,13 @@
Sets the [param travel_cost] for this [param region]. Sets the [param travel_cost] for this [param region].
</description> </description>
</method> </method>
<method name="set_debug_enabled">
<return type="void" />
<param index="0" name="enabled" type="bool" />
<description>
If [code]true[/code] enables debug mode on the NavigationServer.
</description>
</method>
</methods> </methods>
<signals> <signals>
<signal name="map_changed"> <signal name="map_changed">

View File

@ -126,6 +126,12 @@
Destroys the given RID. Destroys the given RID.
</description> </description>
</method> </method>
<method name="get_debug_enabled" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] when the NavigationServer has debug enabled.
</description>
</method>
<method name="get_maps" qualifiers="const"> <method name="get_maps" qualifiers="const">
<return type="RID[]" /> <return type="RID[]" />
<description> <description>
@ -575,6 +581,13 @@
Control activation of this server. Control activation of this server.
</description> </description>
</method> </method>
<method name="set_debug_enabled">
<return type="void" />
<param index="0" name="enabled" type="bool" />
<description>
If [code]true[/code] enables debug mode on the NavigationServer.
</description>
</method>
</methods> </methods>
<signals> <signals>
<signal name="map_changed"> <signal name="map_changed">

View File

@ -152,14 +152,15 @@ void NavigationServer2D::_emit_map_changed(RID p_map) {
emit_signal(SNAME("map_changed"), p_map); emit_signal(SNAME("map_changed"), p_map);
} }
#ifdef DEBUG_ENABLED
void NavigationServer2D::set_debug_enabled(bool p_enabled) { void NavigationServer2D::set_debug_enabled(bool p_enabled) {
NavigationServer3D::get_singleton()->set_debug_enabled(p_enabled); NavigationServer3D::get_singleton()->set_debug_enabled(p_enabled);
} }
bool NavigationServer2D::get_debug_enabled() const { bool NavigationServer2D::get_debug_enabled() const {
return NavigationServer3D::get_singleton()->get_debug_enabled(); return NavigationServer3D::get_singleton()->get_debug_enabled();
} }
#ifdef DEBUG_ENABLED
void NavigationServer2D::set_debug_navigation_edge_connection_color(const Color &p_color) { void NavigationServer2D::set_debug_navigation_edge_connection_color(const Color &p_color) {
NavigationServer3D::get_singleton()->set_debug_navigation_edge_connection_color(p_color); NavigationServer3D::get_singleton()->set_debug_navigation_edge_connection_color(p_color);
} }
@ -341,6 +342,9 @@ void NavigationServer2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer2D::free); ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer2D::free);
ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer2D::set_debug_enabled);
ClassDB::bind_method(D_METHOD("get_debug_enabled"), &NavigationServer2D::get_debug_enabled);
ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map"))); ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map")));
ADD_SIGNAL(MethodInfo("navigation_debug_changed")); ADD_SIGNAL(MethodInfo("navigation_debug_changed"));

View File

@ -234,10 +234,10 @@ public:
NavigationServer2D(); NavigationServer2D();
virtual ~NavigationServer2D(); virtual ~NavigationServer2D();
#ifdef DEBUG_ENABLED
void set_debug_enabled(bool p_enabled); void set_debug_enabled(bool p_enabled);
bool get_debug_enabled() const; bool get_debug_enabled() const;
#ifdef DEBUG_ENABLED
void set_debug_navigation_edge_connection_color(const Color &p_color); void set_debug_navigation_edge_connection_color(const Color &p_color);
Color get_debug_navigation_edge_connection_color() const; Color get_debug_navigation_edge_connection_color() const;

View File

@ -116,6 +116,9 @@ void NavigationServer3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_active", "active"), &NavigationServer3D::set_active); ClassDB::bind_method(D_METHOD("set_active", "active"), &NavigationServer3D::set_active);
ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer3D::set_debug_enabled);
ClassDB::bind_method(D_METHOD("get_debug_enabled"), &NavigationServer3D::get_debug_enabled);
ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map"))); ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map")));
ADD_SIGNAL(MethodInfo("navigation_debug_changed")); ADD_SIGNAL(MethodInfo("navigation_debug_changed"));
@ -184,6 +187,24 @@ NavigationServer3D::~NavigationServer3D() {
singleton = nullptr; singleton = nullptr;
} }
void NavigationServer3D::set_debug_enabled(bool p_enabled) {
#ifdef DEBUG_ENABLED
if (debug_enabled != p_enabled) {
debug_dirty = true;
}
debug_enabled = p_enabled;
if (debug_dirty) {
call_deferred("_emit_navigation_debug_changed_signal");
}
#endif // DEBUG_ENABLED
}
bool NavigationServer3D::get_debug_enabled() const {
return debug_enabled;
}
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
void NavigationServer3D::_emit_navigation_debug_changed_signal() { void NavigationServer3D::_emit_navigation_debug_changed_signal() {
if (debug_dirty) { if (debug_dirty) {
@ -533,22 +554,6 @@ bool NavigationServer3D::get_debug_navigation_enable_link_connections_xray() con
return debug_navigation_enable_link_connections_xray; return debug_navigation_enable_link_connections_xray;
} }
void NavigationServer3D::set_debug_enabled(bool p_enabled) {
if (debug_enabled != p_enabled) {
debug_dirty = true;
}
debug_enabled = p_enabled;
if (debug_dirty) {
call_deferred("_emit_navigation_debug_changed_signal");
}
}
bool NavigationServer3D::get_debug_enabled() const {
return debug_enabled;
}
void NavigationServer3D::set_debug_navigation_enable_agent_paths(const bool p_value) { void NavigationServer3D::set_debug_navigation_enable_agent_paths(const bool p_value) {
if (debug_navigation_enable_agent_paths != p_value) { if (debug_navigation_enable_agent_paths != p_value) {
debug_dirty = true; debug_dirty = true;

View File

@ -274,9 +274,13 @@ public:
virtual int get_process_info(ProcessInfo p_info) const = 0; virtual int get_process_info(ProcessInfo p_info) const = 0;
#ifdef DEBUG_ENABLED void set_debug_enabled(bool p_enabled);
bool get_debug_enabled() const;
private: private:
bool debug_enabled = false; bool debug_enabled = false;
#ifdef DEBUG_ENABLED
bool debug_dirty = true; bool debug_dirty = true;
void _emit_navigation_debug_changed_signal(); void _emit_navigation_debug_changed_signal();
@ -313,9 +317,6 @@ private:
Ref<StandardMaterial3D> debug_navigation_agent_path_point_material; Ref<StandardMaterial3D> debug_navigation_agent_path_point_material;
public: public:
void set_debug_enabled(bool p_enabled);
bool get_debug_enabled() const;
void set_debug_navigation_edge_connection_color(const Color &p_color); void set_debug_navigation_edge_connection_color(const Color &p_color);
Color get_debug_navigation_edge_connection_color() const; Color get_debug_navigation_edge_connection_color() const;

View File

@ -112,6 +112,8 @@ public:
void process(real_t delta_time) override {} void process(real_t delta_time) override {}
NavigationUtilities::PathQueryResult _query_path(const NavigationUtilities::PathQueryParameters &p_parameters) const override { return NavigationUtilities::PathQueryResult(); } NavigationUtilities::PathQueryResult _query_path(const NavigationUtilities::PathQueryParameters &p_parameters) const override { return NavigationUtilities::PathQueryResult(); }
int get_process_info(ProcessInfo p_info) const override { return 0; } int get_process_info(ProcessInfo p_info) const override { return 0; }
void set_debug_enabled(bool p_enabled) {}
bool get_debug_enabled() const { return false; }
}; };
#endif // NAVIGATION_SERVER_3D_DUMMY_H #endif // NAVIGATION_SERVER_3D_DUMMY_H