From 301ee568734bd15235fa7cc5a360badb87a9d67c Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 26 Dec 2023 16:26:48 +0100 Subject: [PATCH] Fix collide to work correctly (#94) * try a fix for disable collision joint * Update godot-cpp * fix iterator issue for shape_collide * do contacts for release build too if debug --- box2d | 2 +- godot-cpp | 2 +- src/bodies/box2d_body_2d.cpp | 6 +----- src/box2d-wrapper/box2d_wrapper.cpp | 3 ++- src/joints/box2d_joint_2d.cpp | 1 - src/spaces/box2d_space_2d.cpp | 4 ---- 6 files changed, 5 insertions(+), 13 deletions(-) diff --git a/box2d b/box2d index 774779b..b31e89d 160000 --- a/box2d +++ b/box2d @@ -1 +1 @@ -Subproject commit 774779bb291755f6cb26df87a859e676c4c41ee5 +Subproject commit b31e89d5d923b485d72bf58899304a8863e5caa0 diff --git a/godot-cpp b/godot-cpp index 54136ee..78ffea5 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit 54136ee8357c5140a3775c54f08db5f7deda2058 +Subproject commit 78ffea5b136f3178c31cddb28f6b963ceaa89420 diff --git a/src/bodies/box2d_body_2d.cpp b/src/bodies/box2d_body_2d.cpp index 38fa8a9..662a11d 100644 --- a/src/bodies/box2d_body_2d.cpp +++ b/src/bodies/box2d_body_2d.cpp @@ -488,13 +488,9 @@ void Box2DBody2D::_init_collider(box2d::FixtureHandle collider_handle) const { // Send contact infos for dynamic bodies if (mode >= PhysicsServer2D::BODY_MODE_KINEMATIC) { -#ifdef DEBUG_ENABLED - // Always send contacts in case debug contacts is enabled - bool send_contacts = true; -#else // Only send contacts if contact monitor is enabled bool send_contacts = can_report_contacts(); -#endif + // TODO set contacts callback only if needed //box2d::collider_set_contact_force_events_enabled(space_handle, collider_handle, send_contacts); } } diff --git a/src/box2d-wrapper/box2d_wrapper.cpp b/src/box2d-wrapper/box2d_wrapper.cpp index 5bdda3e..f2dedb9 100644 --- a/src/box2d-wrapper/box2d_wrapper.cpp +++ b/src/box2d-wrapper/box2d_wrapper.cpp @@ -796,6 +796,7 @@ bool box2d::is_handle_valid(b2Joint *handle) { void box2d::joint_set_disable_collision(b2Joint *joint_handle, bool disable_collision) { + joint_handle->SetCollideConnected(!disable_collision); } void box2d::joint_change_revolute_params(b2World *world_handle, @@ -979,7 +980,7 @@ ShapeCollideResult box2d::shape_collide(const b2Vec2 motion1, transformA, b2Vec2_zero, motion1, - shape_info2.handle.handles[i], + shape_info2.handle.handles[j], transformB, b2Vec2_zero, motion2); diff --git a/src/joints/box2d_joint_2d.cpp b/src/joints/box2d_joint_2d.cpp index 7c464e8..69a94ee 100644 --- a/src/joints/box2d_joint_2d.cpp +++ b/src/joints/box2d_joint_2d.cpp @@ -11,7 +11,6 @@ void Box2DJoint2D::copy_settings_from(Box2DJoint2D *p_joint) { set_max_force(p_joint->get_max_force()); set_bias(p_joint->get_bias()); set_max_bias(p_joint->get_max_bias()); - disable_collisions_between_bodies(p_joint->is_disabled_collisions_between_bodies()); } void Box2DJoint2D::disable_collisions_between_bodies(const bool p_disabled) { diff --git a/src/spaces/box2d_space_2d.cpp b/src/spaces/box2d_space_2d.cpp index 0a30e51..5b6cfed 100644 --- a/src/spaces/box2d_space_2d.cpp +++ b/src/spaces/box2d_space_2d.cpp @@ -398,11 +398,9 @@ bool Box2DSpace2D::contact_force_event_callback(b2World *world_handle, const box bool send_contacts = false; -#ifdef DEBUG_ENABLED if (space->is_debugging_contacts()) { send_contacts = true; } -#endif uint32_t shape1 = 0; Box2DCollisionObject2D *pObject1 = nullptr; @@ -440,13 +438,11 @@ bool Box2DSpace2D::contact_point_callback(b2World *world_handle, const box2d::Co bool keep_sending_contacts = false; -#ifdef DEBUG_ENABLED if (space->is_debugging_contacts()) { keep_sending_contacts = true; space->add_debug_contact(pos1); space->add_debug_contact(pos2); } -#endif // body and shape 1 uint32_t shape1 = 0; Box2DCollisionObject2D *pObject1 = nullptr;