Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Replace NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED with a signal

kobewi117e977b25d3
diff --git a/main/main.cpp b/main/main.cpp
index c2618e2636c..c3ab40e503e 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -4437,7 +4437,12 @@ int Main::start() {
if (sml) {
#ifdef DEBUG_ENABLED
if (debug_collisions) {
- sml->set_debug_collisions_hint(true);
+#ifndef PHYSICS_2D_DISABLED
+ PhysicsServer2D::get_singleton()->debug_set_enabled(true);
+#endif
+#ifndef PHYSICS_3D_DISABLED
+ PhysicsServer3D::get_singleton()->debug_set_enabled(true);
+#endif
}
if (debug_paths) {
sml->set_debug_paths_hint(true);
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp
index d36bc9253bc..28b0e322f66 100644
--- a/modules/csg/csg_shape.cpp
+++ b/modules/csg/csg_shape.cpp
@@ -869,6 +869,16 @@ void CSGShape3D::_build_surfaces_default(CSGBrush *p_brush, Vector<CSGShape3D::S
}
}
+void CSGShape3D::_physics_debug_changed() {
+#if defined(DEBUG_ENABLED) && !defined(PHYSICS_3D_DISABLED)
+ if (_is_debug_collision_shape_visible()) {
+ _update_debug_collision_shape();
+ } else {
+ _clear_debug_collision_shape();
+ }
+#endif
+}
+
Ref<ArrayMesh> CSGShape3D::bake_static_mesh() {
Ref<ArrayMesh> baked_mesh;
if (is_root_shape() && root_mesh.is_valid()) {
@@ -923,7 +933,7 @@ Ref<ConcavePolygonShape3D> CSGShape3D::bake_collision_shape() {
}
bool CSGShape3D::_is_debug_collision_shape_visible() {
- return !Engine::get_singleton()->is_editor_hint() && is_inside_tree() && get_tree()->is_debugging_collisions_hint();
+ return !Engine::get_singleton()->is_editor_hint() && is_inside_tree() && PhysicsServer3D::get_singleton()->debug_is_enabled();
}
void CSGShape3D::_update_debug_collision_shape() {
@@ -1062,14 +1072,6 @@ void CSGShape3D::_notification(int p_what) {
}
_on_transform_changed();
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- if (_is_debug_collision_shape_visible()) {
- _update_debug_collision_shape();
- } else {
- _clear_debug_collision_shape();
- }
- } break;
#endif // PHYSICS_3D_DISABLED
}
}
@@ -1224,6 +1226,10 @@ void CSGShape3D::_bind_methods() {
CSGShape3D::CSGShape3D() {
set_notify_local_transform(true);
+
+#if defined(DEBUG_ENABLED) && !defined(PHYSICS_3D_DISABLED)
+ PhysicsServer3D::get_singleton()->connect("_debug_changed", callable_mp(this, &CSGShape3D::_physics_debug_changed));
+#endif
}
CSGShape3D::~CSGShape3D() {
diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h
index 86fe5053bfb..85c05008c61 100644
--- a/modules/csg/csg_shape.h
+++ b/modules/csg/csg_shape.h
@@ -109,6 +109,7 @@ private:
void _build_surfaces_smoothed(CSGBrush *p_brush, Vector<ShapeUpdateSurface> &r_surfaces, Vector<int> &r_face_count);
void _build_surfaces_default(CSGBrush *p_brush, Vector<ShapeUpdateSurface> &r_surfaces, Vector<int> &r_face_count);
+ void _physics_debug_changed();
protected:
void _notification(int p_what);
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index 1b3282fb7aa..2ba113b011b 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -563,8 +563,7 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
bool debug_collisions = false;
switch (collision_visibility_mode) {
case DEBUG_VISIBILITY_MODE_DEFAULT: {
- SceneTree *st = SceneTree::get_singleton();
- debug_collisions = st && !Engine::get_singleton()->is_editor_hint() && st->is_debugging_collisions_hint();
+ debug_collisions = !Engine::get_singleton()->is_editor_hint() && PhysicsServer3D::get_singleton()->debug_is_enabled();
} break;
case DEBUG_VISIBILITY_MODE_FORCE_HIDE: {
debug_collisions = false;
@@ -1282,10 +1281,6 @@ void GridMap::_notification(int p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
_update_visibility();
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- _recreate_octant_data();
- } break;
}
}
@@ -1919,6 +1914,10 @@ GridMap::GridMap() {
NavigationServer3D::get_singleton()->connect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed));
NavigationServer3D::get_singleton()->connect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections));
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
+
+#if defined(DEBUG_ENABLED) && !defined(PHYSICS_3D_DISABLED)
+ PhysicsServer3D::get_singleton()->connect("_debug_changed", callable_mp(this, &GridMap::_recreate_octant_data));
+#endif
}
#ifndef NAVIGATION_3D_DISABLED
diff --git a/modules/tilemap/tile_map_layer.cpp b/modules/tilemap/tile_map_layer.cpp
index 416474c80d0..ca3a17be222 100644
--- a/modules/tilemap/tile_map_layer.cpp
+++ b/modules/tilemap/tile_map_layer.cpp
@@ -205,6 +205,12 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
_debug_was_cleaned_up = false;
}
+void TileMapLayer::_physics_debug_changed() {
+#ifndef PHYSICS_2D_DISABLED
+ dirty.flags[DIRTY_FLAGS_LAYER_COLLISION_VISIBILITY_MODE] = true;
+ _queue_internal_update();
+#endif
+}
#endif // DEBUG_ENABLED
Color TileMapLayer::_highlight_color(const Color &p_modulate) const {
@@ -1083,7 +1089,7 @@ void TileMapLayer::_physics_draw_quadrant_debug(const RID &p_canvas_item, DebugQ
bool show_collision = false;
switch (collision_visibility_mode) {
case TileMapLayer::DEBUG_VISIBILITY_MODE_DEFAULT:
- show_collision = !Engine::get_singleton()->is_editor_hint() && get_tree()->is_debugging_collisions_hint();
+ show_collision = !Engine::get_singleton()->is_editor_hint() && PhysicsServer2D::get_singleton()->debug_is_enabled();
break;
case TileMapLayer::DEBUG_VISIBILITY_MODE_FORCE_HIDE:
show_collision = false;
@@ -2153,11 +2159,6 @@ void TileMapLayer::_notification(int p_what) {
dirty.flags[DIRTY_FLAGS_LAYER_VISIBILITY] = true;
_queue_internal_update();
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- dirty.flags[DIRTY_FLAGS_LAYER_COLLISION_VISIBILITY_MODE] = true;
- _queue_internal_update();
- } break;
}
_rendering_notification(p_what);
@@ -3592,6 +3593,10 @@ void TileMapLayer::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
TileMapLayer::TileMapLayer() {
set_notify_transform(true);
+
+#if defined(DEBUG_ENABLED) && !defined(PHYSICS_2D_DISABLED)
+ PhysicsServer2D::get_singleton()->connect("_debug_changed", callable_mp(this, &TileMapLayer::_physics_debug_changed));
+#endif
}
TileMapLayer::~TileMapLayer() {
diff --git a/modules/tilemap/tile_map_layer.h b/modules/tilemap/tile_map_layer.h
index d5a6d4b72ac..b5ef0a06637 100644
--- a/modules/tilemap/tile_map_layer.h
+++ b/modules/tilemap/tile_map_layer.h
@@ -445,8 +445,7 @@ private:
HashMap<Vector2i, Ref<DebugQuadrant>> debug_quadrant_map;
bool _debug_was_cleaned_up = true;
void _debug_update(bool p_force_cleanup);
- void _debug_quadrants_update_cell(CellData &r_cell_data);
- void _get_debug_quadrant_for_cell(const Vector2i &p_coords);
+ void _physics_debug_changed();
#endif // DEBUG_ENABLED
HashMap<Vector2i, Ref<RenderingQuadrant>> rendering_quadrant_map;
diff --git a/scene/2d/physics/collision_polygon_2d.cpp b/scene/2d/physics/collision_polygon_2d.cpp
index 5b22777e14a..eea6d0b1c99 100644
--- a/scene/2d/physics/collision_polygon_2d.cpp
+++ b/scene/2d/physics/collision_polygon_2d.cpp
@@ -32,12 +32,14 @@
#include "core/config/engine.h"
#include "core/math/geometry_2d.h"
+#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "scene/2d/physics/area_2d.h"
#include "scene/2d/physics/collision_object_2d.h"
#include "scene/main/scene_tree.h"
#include "scene/resources/2d/concave_polygon_shape_2d.h"
#include "scene/resources/2d/convex_polygon_shape_2d.h"
+#include "servers/physics_2d/physics_server_2d.h"
void CollisionPolygon2D::_build_polygon() {
collision_object->shape_owner_clear_shapes(owner_id);
@@ -129,7 +131,7 @@ void CollisionPolygon2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
ERR_FAIL_COND(!is_inside_tree());
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
break;
}
@@ -170,10 +172,6 @@ void CollisionPolygon2D::_notification(int p_what) {
draw_primitive(pts, cols, Vector<Vector2>()); //small arrow
}
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- queue_redraw();
- } break;
}
}
@@ -347,4 +345,8 @@ void CollisionPolygon2D::_bind_methods() {
CollisionPolygon2D::CollisionPolygon2D() {
set_notify_local_transform(true);
set_hide_clip_children(true);
+
+#ifdef DEBUG_ENABLED
+ PhysicsServer2D::get_singleton()->connect("_debug_changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+#endif
}
diff --git a/scene/2d/physics/collision_shape_2d.cpp b/scene/2d/physics/collision_shape_2d.cpp
index bde83bbb210..0b0e468ecff 100644
--- a/scene/2d/physics/collision_shape_2d.cpp
+++ b/scene/2d/physics/collision_shape_2d.cpp
@@ -38,6 +38,7 @@
#include "scene/main/scene_tree.h"
#include "scene/resources/2d/concave_polygon_shape_2d.h"
#include "scene/resources/2d/convex_polygon_shape_2d.h"
+#include "servers/physics_2d/physics_server_2d.h"
void CollisionShape2D::_shape_changed() {
queue_redraw();
@@ -90,7 +91,7 @@ void CollisionShape2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
ERR_FAIL_COND(!is_inside_tree());
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
break;
}
@@ -135,10 +136,6 @@ void CollisionShape2D::_notification(int p_what) {
draw_primitive(pts, cols, Vector<Vector2>());
}
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- queue_redraw();
- } break;
}
}
@@ -334,4 +331,8 @@ CollisionShape2D::CollisionShape2D() {
set_notify_local_transform(true);
set_hide_clip_children(true);
debug_color = _get_default_debug_color();
+
+#ifdef DEBUG_ENABLED
+ PhysicsServer2D::get_singleton()->connect("_debug_changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+#endif
}
diff --git a/scene/2d/physics/joints/damped_spring_joint_2d.cpp b/scene/2d/physics/joints/damped_spring_joint_2d.cpp
index 7381df7381e..1c595801796 100644
--- a/scene/2d/physics/joints/damped_spring_joint_2d.cpp
+++ b/scene/2d/physics/joints/damped_spring_joint_2d.cpp
@@ -43,7 +43,7 @@ void DampedSpringJoint2D::_notification(int p_what) {
break;
}
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
break;
}
diff --git a/scene/2d/physics/joints/groove_joint_2d.cpp b/scene/2d/physics/joints/groove_joint_2d.cpp
index 5787b08ec02..5983a0d97d6 100644
--- a/scene/2d/physics/joints/groove_joint_2d.cpp
+++ b/scene/2d/physics/joints/groove_joint_2d.cpp
@@ -43,7 +43,7 @@ void GrooveJoint2D::_notification(int p_what) {
break;
}
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
break;
}
diff --git a/scene/2d/physics/joints/joint_2d.cpp b/scene/2d/physics/joints/joint_2d.cpp
index e4d1d8938fe..a8e265bb4d3 100644
--- a/scene/2d/physics/joints/joint_2d.cpp
+++ b/scene/2d/physics/joints/joint_2d.cpp
@@ -34,6 +34,7 @@
#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "scene/2d/physics/physics_body_2d.h"
+#include "scene/main/scene_tree.h"
#include "servers/physics_2d/physics_server_2d.h"
void Joint2D::_disconnect_signals() {
@@ -189,10 +190,6 @@ void Joint2D::_notification(int p_what) {
}
_update_joint(true);
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- queue_redraw();
- } break;
}
}
@@ -257,6 +254,10 @@ void Joint2D::_bind_methods() {
Joint2D::Joint2D() {
joint = PhysicsServer2D::get_singleton()->joint_create();
set_hide_clip_children(true);
+
+#ifdef DEBUG_ENABLED
+ PhysicsServer2D::get_singleton()->connect("_debug_changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+#endif
}
Joint2D::~Joint2D() {
diff --git a/scene/2d/physics/joints/pin_joint_2d.cpp b/scene/2d/physics/joints/pin_joint_2d.cpp
index d95a9a1a4ce..b113810bb8a 100644
--- a/scene/2d/physics/joints/pin_joint_2d.cpp
+++ b/scene/2d/physics/joints/pin_joint_2d.cpp
@@ -33,7 +33,6 @@
#include "core/config/engine.h"
#include "core/object/class_db.h"
#include "scene/2d/physics/physics_body_2d.h"
-#include "scene/main/scene_tree.h"
#include "servers/physics_2d/physics_server_2d.h"
void PinJoint2D::_notification(int p_what) {
@@ -43,7 +42,7 @@ void PinJoint2D::_notification(int p_what) {
break;
}
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
break;
}
diff --git a/scene/2d/physics/ray_cast_2d.cpp b/scene/2d/physics/ray_cast_2d.cpp
index f8786caad7d..177dbc61380 100644
--- a/scene/2d/physics/ray_cast_2d.cpp
+++ b/scene/2d/physics/ray_cast_2d.cpp
@@ -31,6 +31,7 @@
#include "ray_cast_2d.h"
#include "core/config/engine.h"
+#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "scene/2d/physics/collision_object_2d.h"
#include "scene/main/scene_tree.h"
@@ -40,7 +41,7 @@
void RayCast2D::set_target_position(const Vector2 &p_point) {
target_position = p_point;
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || PhysicsServer2D::get_singleton()->debug_is_enabled())) {
queue_redraw();
}
}
@@ -168,7 +169,7 @@ void RayCast2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
ERR_FAIL_COND(!is_inside_tree());
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
break;
}
_draw_debug_shape();
@@ -180,10 +181,6 @@ void RayCast2D::_notification(int p_what) {
}
_update_raycast_state();
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- queue_redraw();
- } break;
}
}
@@ -380,4 +377,8 @@ void RayCast2D::_bind_methods() {
RayCast2D::RayCast2D() {
set_hide_clip_children(true);
+
+#ifdef DEBUG_ENABLED
+ PhysicsServer2D::get_singleton()->connect("_debug_changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+#endif
}
diff --git a/scene/2d/physics/shape_cast_2d.cpp b/scene/2d/physics/shape_cast_2d.cpp
index 4604085c3cc..325d5c90fec 100644
--- a/scene/2d/physics/shape_cast_2d.cpp
+++ b/scene/2d/physics/shape_cast_2d.cpp
@@ -41,7 +41,7 @@
void ShapeCast2D::set_target_position(const Vector2 &p_point) {
target_position = p_point;
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || PhysicsServer2D::get_singleton()->debug_is_enabled())) {
queue_redraw();
}
}
@@ -225,7 +225,7 @@ void ShapeCast2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
#ifdef TOOLS_ENABLED
ERR_FAIL_COND(!is_inside_tree());
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
break;
}
if (shape.is_null()) {
@@ -283,10 +283,6 @@ void ShapeCast2D::_notification(int p_what) {
}
_update_shapecast_state();
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- queue_redraw();
- } break;
}
}
@@ -488,4 +484,8 @@ void ShapeCast2D::_bind_methods() {
ShapeCast2D::ShapeCast2D() {
set_hide_clip_children(true);
+
+#ifdef DEBUG_ENABLED
+ PhysicsServer2D::get_singleton()->connect("_debug_changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+#endif
}
diff --git a/scene/2d/physics/touch_screen_button.cpp b/scene/2d/physics/touch_screen_button.cpp
index 292cee42878..d15d9bd974c 100644
--- a/scene/2d/physics/touch_screen_button.cpp
+++ b/scene/2d/physics/touch_screen_button.cpp
@@ -39,6 +39,10 @@
#include "servers/display/accessibility_server.h"
#include "servers/display/display_server.h"
+#if defined(DEBUG_ENABLED) && !defined(PHYSICS_2D_DISABLED)
+#include "servers/physics_2d/physics_server_2d.h"
+#endif
+
void TouchScreenButton::set_texture_normal(const Ref<Texture2D> &p_texture) {
if (texture_normal == p_texture) {
return;
@@ -161,10 +165,11 @@ void TouchScreenButton::_notification(int p_what) {
}
}
+#if defined(DEBUG_ENABLED) && !defined(PHYSICS_2D_DISABLED)
if (!shape_visible) {
return;
}
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint() && !PhysicsServer2D::get_singleton()->debug_is_enabled()) {
return;
}
if (shape.is_valid()) {
@@ -178,6 +183,7 @@ void TouchScreenButton::_notification(int p_what) {
draw_set_transform_matrix(get_canvas_transform().translated_local(pos));
shape->draw(get_canvas_item(), draw_col);
}
+#endif
} break;
case NOTIFICATION_ENTER_TREE: {
@@ -217,10 +223,6 @@ void TouchScreenButton::_notification(int p_what) {
_release();
}
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- queue_redraw();
- } break;
}
}
@@ -462,4 +464,8 @@ void TouchScreenButton::_bind_methods() {
TouchScreenButton::TouchScreenButton() {
unit_rect.instantiate();
unit_rect->set_size(Vector2(1, 1));
+
+#if defined(DEBUG_ENABLED) && !defined(PHYSICS_2D_DISABLED)
+ PhysicsServer2D::get_singleton()->connect("_debug_changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+#endif
}
diff --git a/scene/3d/physics/collision_object_3d.cpp b/scene/3d/physics/collision_object_3d.cpp
index caeddb9743a..1b5842867fb 100644
--- a/scene/3d/physics/collision_object_3d.cpp
+++ b/scene/3d/physics/collision_object_3d.cpp
@@ -140,17 +140,6 @@ void CollisionObject3D::_notification(int p_what) {
case NOTIFICATION_ENABLED: {
_apply_enabled();
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- if (_are_collision_shapes_visible()) {
- for (const KeyValue<uint32_t, ShapeData> &E : shapes) {
- debug_shapes_to_update.insert(E.key);
- }
- _update_debug_shapes();
- } else {
- _clear_debug_shapes();
- }
- } break;
}
}
@@ -362,7 +351,7 @@ void CollisionObject3D::_update_pickable() {
}
bool CollisionObject3D::_are_collision_shapes_visible() {
- return is_inside_tree() && get_tree()->is_debugging_collisions_hint() && !Engine::get_singleton()->is_editor_hint();
+ return is_inside_tree() && PhysicsServer3D::get_singleton()->debug_is_enabled() && !Engine::get_singleton()->is_editor_hint();
}
void CollisionObject3D::_update_shape_data(uint32_t p_owner) {
@@ -447,6 +436,17 @@ void CollisionObject3D::_clear_debug_shapes() {
debug_shapes_count = 0;
}
+void CollisionObject3D::_physics_debug_changed() {
+ if (_are_collision_shapes_visible()) {
+ for (const KeyValue<uint32_t, ShapeData> &E : shapes) {
+ debug_shapes_to_update.insert(E.key);
+ }
+ _update_debug_shapes();
+ } else {
+ _clear_debug_shapes();
+ }
+}
+
void CollisionObject3D::_on_transform_changed() {
if (debug_shapes_count > 0 && !debug_shape_old_transform.is_equal_approx(get_global_transform())) {
debug_shape_old_transform = get_global_transform();
@@ -739,6 +739,10 @@ CollisionObject3D::CollisionObject3D(RID p_rid, bool p_area) {
PhysicsServer3D::get_singleton()->body_attach_object_instance_id(rid, get_instance_id());
PhysicsServer3D::get_singleton()->body_set_mode(rid, body_mode);
}
+
+#ifdef DEBUG_ENABLED
+ PhysicsServer3D::get_singleton()->connect("_debug_changed", callable_mp(this, &CollisionObject3D::_physics_debug_changed));
+#endif
}
void CollisionObject3D::set_capture_input_on_drag(bool p_capture) {
diff --git a/scene/3d/physics/collision_object_3d.h b/scene/3d/physics/collision_object_3d.h
index 5380440c1f7..beac29247fd 100644
--- a/scene/3d/physics/collision_object_3d.h
+++ b/scene/3d/physics/collision_object_3d.h
@@ -95,6 +95,7 @@ private:
void _shape_changed(const Ref<Shape3D> &p_shape);
void _update_debug_shapes();
void _clear_debug_shapes();
+ void _physics_debug_changed();
void _apply_disabled();
void _apply_enabled();
diff --git a/scene/3d/physics/ray_cast_3d.cpp b/scene/3d/physics/ray_cast_3d.cpp
index 44165b00984..f76d2a421dd 100644
--- a/scene/3d/physics/ray_cast_3d.cpp
+++ b/scene/3d/physics/ray_cast_3d.cpp
@@ -31,6 +31,7 @@
#include "ray_cast_3d.h"
#include "core/config/engine.h"
+#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "scene/3d/physics/collision_object_3d.h"
#include "scene/main/scene_tree.h"
@@ -124,7 +125,7 @@ void RayCast3D::set_enabled(bool p_enabled) {
collided = false;
}
- if (is_inside_tree() && get_tree()->is_debugging_collisions_hint()) {
+ if (is_inside_tree() && PhysicsServer3D::get_singleton()->debug_is_enabled()) {
if (p_enabled) {
_update_debug_shape();
} else {
@@ -173,7 +174,7 @@ void RayCast3D::_notification(int p_what) {
set_physics_process_internal(false);
}
- if (get_tree()->is_debugging_collisions_hint()) {
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled()) {
_update_debug_shape();
}
@@ -209,7 +210,7 @@ void RayCast3D::_notification(int p_what) {
bool prev_collision_state = collided;
_update_raycast_state();
- if (get_tree()->is_debugging_collisions_hint()) {
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled()) {
if (prev_collision_state != collided) {
_update_debug_shape_material(true);
}
@@ -218,14 +219,6 @@ void RayCast3D::_notification(int p_what) {
}
}
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- if (get_tree()->is_debugging_collisions_hint()) {
- _update_debug_shape();
- } else {
- _clear_debug_shape();
- }
- } break;
}
}
@@ -570,5 +563,16 @@ void RayCast3D::_clear_debug_shape() {
}
}
+void RayCast3D::_physics_debug_changed() {
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled()) {
+ _update_debug_shape();
+ } else {
+ _clear_debug_shape();
+ }
+}
+
RayCast3D::RayCast3D() {
+#ifdef DEBUG_ENABLED
+ PhysicsServer3D::get_singleton()->connect("_debug_changed", callable_mp(this, &RayCast3D::_physics_debug_changed));
+#endif
}
diff --git a/scene/3d/physics/ray_cast_3d.h b/scene/3d/physics/ray_cast_3d.h
index 8e7365ada4c..a265cbd89c4 100644
--- a/scene/3d/physics/ray_cast_3d.h
+++ b/scene/3d/physics/ray_cast_3d.h
@@ -65,6 +65,7 @@ class RayCast3D : public Node3D {
void _update_debug_shape_material(bool p_check_collision = false);
void _update_debug_shape_vertices();
void _clear_debug_shape();
+ void _physics_debug_changed();
bool collide_with_areas = false;
bool collide_with_bodies = true;
diff --git a/scene/3d/physics/shape_cast_3d.cpp b/scene/3d/physics/shape_cast_3d.cpp
index 13fad237440..f40f86ec29c 100644
--- a/scene/3d/physics/shape_cast_3d.cpp
+++ b/scene/3d/physics/shape_cast_3d.cpp
@@ -52,7 +52,7 @@ void ShapeCast3D::_notification(int p_what) {
set_physics_process_internal(false);
}
- if (get_tree()->is_debugging_collisions_hint()) {
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled()) {
_update_debug_shape();
}
@@ -88,7 +88,7 @@ void ShapeCast3D::_notification(int p_what) {
bool prev_collision_state = collided;
_update_shapecast_state();
- if (get_tree()->is_debugging_collisions_hint()) {
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled()) {
if (prev_collision_state != collided) {
_update_debug_shape_material(true);
}
@@ -103,14 +103,6 @@ void ShapeCast3D::_notification(int p_what) {
}
}
} break;
-
- case NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED: {
- if (get_tree()->is_debugging_collisions_hint()) {
- _update_debug_shape();
- } else {
- _clear_debug_shape();
- }
- } break;
}
}
@@ -216,7 +208,7 @@ void ShapeCast3D::set_enabled(bool p_enabled) {
collided = false;
}
- if (is_inside_tree() && get_tree()->is_debugging_collisions_hint()) {
+ if (is_inside_tree() && PhysicsServer3D::get_singleton()->debug_is_enabled()) {
if (p_enabled) {
_update_debug_shape();
} else {
@@ -231,7 +223,7 @@ bool ShapeCast3D::is_enabled() const {
void ShapeCast3D::set_target_position(const Vector3 &p_point) {
target_position = p_point;
- if (is_inside_tree() && get_tree()->is_debugging_collisions_hint()) {
+ if (is_inside_tree() && PhysicsServer3D::get_singleton()->debug_is_enabled()) {
_update_debug_shape();
}
update_gizmos();
@@ -344,7 +336,7 @@ void ShapeCast3D::resource_changed(Ref<Resource> p_res) {
void ShapeCast3D::_shape_changed() {
update_gizmos();
bool is_editor = Engine::get_singleton()->is_editor_hint();
- if (is_inside_tree() && (is_editor || get_tree()->is_debugging_collisions_hint())) {
+ if (is_inside_tree() && (is_editor || PhysicsServer3D::get_singleton()->debug_is_enabled())) {
_update_debug_shape();
}
}
@@ -363,7 +355,7 @@ void ShapeCast3D::set_shape(const Ref<Shape3D> &p_shape) {
}
bool is_editor = Engine::get_singleton()->is_editor_hint();
- if (is_inside_tree() && (is_editor || get_tree()->is_debugging_collisions_hint())) {
+ if (is_inside_tree() && (is_editor || PhysicsServer3D::get_singleton()->debug_is_enabled())) {
_update_debug_shape();
}
update_gizmos();
@@ -656,3 +648,17 @@ void ShapeCast3D::_clear_debug_shape() {
debug_mesh = Ref<ArrayMesh>();
}
}
+
+void ShapeCast3D::_physics_debug_changed() {
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled()) {
+ _update_debug_shape();
+ } else {
+ _clear_debug_shape();
+ }
+}
+
+ShapeCast3D::ShapeCast3D() {
+#ifdef DEBUG_ENABLED
+ PhysicsServer3D::get_singleton()->connect("_debug_changed", callable_mp(this, &ShapeCast3D::_physics_debug_changed));
+#endif
+}
diff --git a/scene/3d/physics/shape_cast_3d.h b/scene/3d/physics/shape_cast_3d.h
index 1482250bb60..2aa22010471 100644
--- a/scene/3d/physics/shape_cast_3d.h
+++ b/scene/3d/physics/shape_cast_3d.h
@@ -66,6 +66,7 @@ class ShapeCast3D : public Node3D {
void _update_debug_shape_material(bool p_check_collision = false);
void _update_debug_shape_vertices();
void _clear_debug_shape();
+ void _physics_debug_changed();
// Result
int max_results = 32;
@@ -143,4 +144,6 @@ public:
void clear_exceptions();
virtual PackedStringArray get_configuration_warnings() const override;
+
+ ShapeCast3D();
};
diff --git a/scene/3d/physics/spring_arm_3d.cpp b/scene/3d/physics/spring_arm_3d.cpp
index f49f03bef82..59b17de3d36 100644
--- a/scene/3d/physics/spring_arm_3d.cpp
+++ b/scene/3d/physics/spring_arm_3d.cpp
@@ -36,6 +36,7 @@
#include "scene/main/scene_tree.h"
#include "scene/resources/3d/shape_3d.h"
#include "servers/physics_3d/direct_states/physics_direct_space_state_3d.h"
+#include "servers/physics_3d/physics_server_3d.h"
void SpringArm3D::_notification(int p_what) {
switch (p_what) {
@@ -87,7 +88,7 @@ real_t SpringArm3D::get_length() const {
}
void SpringArm3D::set_length(real_t p_length) {
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || PhysicsServer3D::get_singleton()->debug_is_enabled())) {
update_gizmos();
}
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index 6dbbf6481cc..a0dd64fef05 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -65,6 +65,14 @@
#include "scene/debugger/runtime_node_select.h"
#endif
+#ifndef PHYSICS_2D_DISABLED
+#include "servers/physics_2d/physics_server_2d.h"
+#endif
+
+#ifndef PHYSICS_3D_DISABLED
+#include "servers/physics_3d/physics_server_3d.h"
+#endif
+
SceneDebugger::SceneDebugger() {
singleton = this;
@@ -334,7 +342,12 @@ Error SceneDebugger::_msg_hdr_output_toggle_requested(const Array &p_args) {
Error SceneDebugger::_msg_set_debug_collisions(const Array &p_args) {
ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA);
bool enabled = p_args[0];
- SceneTree::get_singleton()->set_debug_collisions_hint(enabled);
+#ifndef PHYSICS_2D_DISABLED
+ PhysicsServer2D::get_singleton()->debug_set_enabled(enabled);
+#endif
+#ifndef PHYSICS_3D_DISABLED
+ PhysicsServer3D::get_singleton()->debug_set_enabled(enabled);
+#endif
return OK;
}
diff --git a/scene/main/node.h b/scene/main/node.h
index be8d39824fa..7b726692b56 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -507,9 +507,6 @@ public:
NOTIFICATION_APPLICATION_PIP_MODE_ENTERED = 2019,
NOTIFICATION_APPLICATION_PIP_MODE_EXITED = 2020,
- // Debug-related notifications.
- NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED = 4000,
-
// Editor specific node notifications.
NOTIFICATION_EDITOR_PRE_SAVE = 9001,
NOTIFICATION_EDITOR_POST_SAVE = 9002,
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 2203c7e0e1a..280a41b4d29 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -967,17 +967,16 @@ void SceneTree::set_quit_on_go_back(bool p_enable) {
#ifdef DEBUG_ENABLED
void SceneTree::set_debug_collisions_hint(bool p_enabled) {
- if (debug_collisions_hint == p_enabled) {
- return;
- }
- debug_collisions_hint = p_enabled;
- if (root) {
- root->propagate_notification(Node::NOTIFICATION_DEBUG_COLLISIONS_HINT_CHANGED);
- }
+#ifndef PHYSICS_2D_DISABLED
+ PhysicsServer2D::get_singleton()->debug_set_enabled(p_enabled);
+#endif
+#ifndef PHYSICS_3D_DISABLED
+ PhysicsServer3D::get_singleton()->debug_set_enabled(p_enabled);
+#endif
}
bool SceneTree::is_debugging_collisions_hint() const {
- return debug_collisions_hint;
+ return PhysicsServer2D::get_singleton()->debug_is_enabled() || PhysicsServer3D::get_singleton()->debug_is_enabled();
}
void SceneTree::set_debug_paths_hint(bool p_enabled) {
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index c2ca23c7c79..62436878363 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -141,7 +141,6 @@ private:
bool quit_on_go_back = true;
#ifdef DEBUG_ENABLED
- bool debug_collisions_hint = false;
bool debug_paths_hint = false;
bool debug_navigation_hint = false;
#endif
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index cd522ce95b5..4efd6a5f91b 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -614,14 +614,16 @@ void Viewport::_notification(int p_what) {
#endif // _3D_DISABLED
add_to_group("_viewports");
-#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
- if (get_tree()->is_debugging_collisions_hint()) {
#ifndef PHYSICS_2D_DISABLED
+ if (PhysicsServer2D::get_singleton()->debug_is_enabled()) {
PhysicsServer2D::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count());
contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create();
RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, current_canvas);
+ set_physics_process_internal(true);
+ }
#endif // PHYSICS_2D_DISABLED
#ifndef PHYSICS_3D_DISABLED
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled()) {
PhysicsServer3D::get_singleton()->space_set_debug_contacts(find_world_3d()->get_space(), get_tree()->get_collision_debug_contact_count());
contact_3d_debug_multimesh = RenderingServer::get_singleton()->multimesh_create();
RenderingServer::get_singleton()->multimesh_allocate_data(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), RSE::MULTIMESH_TRANSFORM_3D, false);
@@ -631,10 +633,9 @@ void Viewport::_notification(int p_what) {
RenderingServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh);
RenderingServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world_3d()->get_scenario());
RenderingServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, RSE::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true);
-#endif // PHYSICS_3D_DISABLED
set_physics_process_internal(true);
}
-#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
+#endif // PHYSICS_3D_DISABLED
_update_texture_filter_changed(false);
_update_texture_repeat_changed(false);
} break;
@@ -720,7 +721,7 @@ void Viewport::_notification(int p_what) {
}
#ifndef PHYSICS_2D_DISABLED
- if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
+ if (PhysicsServer2D::get_singleton()->debug_is_enabled() && contact_2d_debug.is_valid()) {
RenderingServer::get_singleton()->canvas_item_clear(contact_2d_debug);
RenderingServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index
@@ -734,7 +735,7 @@ void Viewport::_notification(int p_what) {
}
#endif // PHYSICS_2D_DISABLED
#ifndef PHYSICS_3D_DISABLED
- if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) {
+ if (PhysicsServer3D::get_singleton()->debug_is_enabled() && contact_3d_debug_multimesh.is_valid()) {
Vector<Vector3> points = PhysicsServer3D::get_singleton()->space_get_contacts(find_world_3d()->get_space());
int point_count = PhysicsServer3D::get_singleton()->space_get_contact_count(find_world_3d()->get_space());
diff --git a/servers/physics_2d/physics_server_2d.cpp b/servers/physics_2d/physics_server_2d.cpp
index ccc0afac196..6387a23359c 100644
--- a/servers/physics_2d/physics_server_2d.cpp
+++ b/servers/physics_2d/physics_server_2d.cpp
@@ -40,6 +40,24 @@ PhysicsServer2D *PhysicsServer2D::get_singleton() {
return singleton;
}
+void PhysicsServer2D::debug_set_enabled(bool p_enabled) {
+#ifdef DEBUG_ENABLED
+ if (debug_enabled == p_enabled) {
+ return;
+ }
+ debug_enabled = p_enabled;
+ emit_signal("_debug_changed");
+#endif
+}
+
+bool PhysicsServer2D::debug_is_enabled() const {
+#ifdef DEBUG_ENABLED
+ return debug_enabled;
+#else
+ return false;
+#endif
+}
+
bool PhysicsServer2D::_body_test_motion(RID p_body, RequiredParam<PhysicsTestMotionParameters2D> p_parameters, const Ref<PhysicsTestMotionResult2D> &p_result) {
EXTRACT_PARAM_OR_FAIL_V(parameters, p_parameters, false);
@@ -323,6 +341,10 @@ void PhysicsServer2D::_bind_methods() {
BIND_ENUM_CONSTANT(PS2DE::INFO_ACTIVE_OBJECTS);
BIND_ENUM_CONSTANT(PS2DE::INFO_COLLISION_PAIRS);
BIND_ENUM_CONSTANT(PS2DE::INFO_ISLAND_COUNT);
+
+#ifdef DEBUG_ENABLED
+ ADD_SIGNAL(MethodInfo("_debug_changed"));
+#endif
}
PhysicsServer2D::PhysicsServer2D() {
diff --git a/servers/physics_2d/physics_server_2d.h b/servers/physics_2d/physics_server_2d.h
index 01bc3867321..9f273cc3e7b 100644
--- a/servers/physics_2d/physics_server_2d.h
+++ b/servers/physics_2d/physics_server_2d.h
@@ -54,9 +54,16 @@ protected:
static void _bind_compatibility_methods();
#endif
+#ifdef DEBUG_ENABLED
+ bool debug_enabled = false;
+#endif
+
public:
static PhysicsServer2D *get_singleton();
+ void debug_set_enabled(bool p_enabled);
+ bool debug_is_enabled() const;
+
virtual RID world_boundary_shape_create() = 0;
virtual RID separation_ray_shape_create() = 0;
virtual RID segment_shape_create() = 0;
diff --git a/servers/physics_3d/physics_server_3d.cpp b/servers/physics_3d/physics_server_3d.cpp
index 9ec09c232f1..85b1a9176be 100644
--- a/servers/physics_3d/physics_server_3d.cpp
+++ b/servers/physics_3d/physics_server_3d.cpp
@@ -40,6 +40,24 @@ PhysicsServer3D *PhysicsServer3D::get_singleton() {
return singleton;
}
+void PhysicsServer3D::debug_set_enabled(bool p_enabled) {
+#ifdef DEBUG_ENABLED
+ if (debug_enabled == p_enabled) {
+ return;
+ }
+ debug_enabled = p_enabled;
+ emit_signal("_debug_changed");
+#endif
+}
+
+bool PhysicsServer3D::debug_is_enabled() const {
+#ifdef DEBUG_ENABLED
+ return debug_enabled;
+#else
+ return false;
+#endif
+}
+
bool PhysicsServer3D::_body_test_motion(RID p_body, RequiredParam<PhysicsTestMotionParameters3D> p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result) {
EXTRACT_PARAM_OR_FAIL_V(parameters, p_parameters, false);
@@ -522,7 +540,10 @@ void PhysicsServer3D::_bind_methods() {
BIND_ENUM_CONSTANT(PS3DE::BODY_AXIS_ANGULAR_X);
BIND_ENUM_CONSTANT(PS3DE::BODY_AXIS_ANGULAR_Y);
BIND_ENUM_CONSTANT(PS3DE::BODY_AXIS_ANGULAR_Z);
+#endif
+#ifdef DEBUG_ENABLED
+ ADD_SIGNAL(MethodInfo("_debug_changed"));
#endif
}
diff --git a/servers/physics_3d/physics_server_3d.h b/servers/physics_3d/physics_server_3d.h
index 42a1b3b224e..f59bf0ab9b3 100644
--- a/servers/physics_3d/physics_server_3d.h
+++ b/servers/physics_3d/physics_server_3d.h
@@ -55,12 +55,19 @@ class PhysicsServer3D : public Object {
virtual bool _body_test_motion(RID p_body, RequiredParam<PhysicsTestMotionParameters3D> p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result = Ref<PhysicsTestMotionResult3D>());
+#ifdef DEBUG_ENABLED
+ bool debug_enabled = false;
+#endif
+
protected:
static void _bind_methods();
public:
static PhysicsServer3D *get_singleton();
+ void debug_set_enabled(bool p_enabled);
+ bool debug_is_enabled() const;
+
RID shape_create(PS3DE::ShapeType p_shape);
virtual RID world_boundary_shape_create() = 0;