From 22aa5c96caea50d37500c724fe93766509caf6f0 Mon Sep 17 00:00:00 2001 From: core Date: Sun, 16 Nov 2025 20:37:42 -0500 Subject: [PATCH] chore: further attempts at recursive detach --- crates/unified/src/attachment.rs | 2 +- crates/unified/src/client/ui.rs | 1 + crates/unified/src/server/player.rs | 32 +++++++++++++++++++---------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/crates/unified/src/attachment.rs b/crates/unified/src/attachment.rs index 30e9e6c363a2ca2b6a586b2aa88d6addcd2503f1..333a96f7c218248a3111841a201de165b65a5f37 100644 --- a/crates/unified/src/attachment.rs +++ b/crates/unified/src/attachment.rs @@ -22,7 +22,7 @@ pub struct Joint { pub transform: Transform, } #[derive(Component, Serialize, Deserialize, MapEntities)] -pub struct Peer(#[entities] pub Entity); +pub struct Peer(#[entities] pub Entity, pub bool); #[derive(Component, Serialize, Deserialize, MapEntities)] #[relationship(relationship_target = Joints)] diff --git a/crates/unified/src/client/ui.rs b/crates/unified/src/client/ui.rs index aa95ce5974b1837ebcc525aaae7792435f27c665..4baaa5e145b7d16b687df4fa97b32b36b5dee5dd 100644 --- a/crates/unified/src/client/ui.rs +++ b/crates/unified/src/client/ui.rs @@ -44,6 +44,7 @@ fn setup_ui(mut commands: Commands) { )*/ ], )], + Visibility::Visible )); } diff --git a/crates/unified/src/server/player.rs b/crates/unified/src/server/player.rs index d77cf5391e4b7b78fac6eede411768a444d1ba0a..19e3f35a57ad5c0964790e7da6d4846a14696997 100644 --- a/crates/unified/src/server/player.rs +++ b/crates/unified/src/server/player.rs @@ -31,32 +31,38 @@ fn disconnect_part( recursed_entity: Entity, joints: &Joints, q_joints: Query<&Joints>, - q_peer: Query<(&Peer, &JointOf)>, - + q_peer: Query<(Entity, &Peer, &JointOf)>, + mut processed_peers: &mut Vec, mut commands: Commands, ) { - trace!(?entity, ?joints, "recursive disconnect"); + trace!(?entity, ?joints, ?processed_peers, "recursive disconnect"); // recursive disconnect part for joint in &**joints { - let Ok((other_joint_handle, _)) = q_peer.get(*joint) else { + let Ok((p_e, other_joint_handle, _)) = q_peer.get(*joint) else { continue; }; + if processed_peers.contains(&p_e) { continue }; let other_joint = other_joint_handle.0; commands.entity(*joint).remove::(); + processed_peers.push(p_e); - let Ok((_, other_joint_of)) = q_peer.get(other_joint) else { + let Ok((p_e_2, _, other_joint_of)) = q_peer.get(other_joint) else { continue; }; commands.entity(other_joint).remove::(); + processed_peers.push(p_e_2); let Ok(joints) = q_joints.get(other_joint_of.0) else { continue; }; - /*if other_joint != recursed_entity { - disconnect_part(other_joint, entity, joints, q_joints, q_peer, commands.reborrow()); - } TODO this loops forever? */ + if other_joint != recursed_entity { + disconnect_part(other_joint, entity, joints, q_joints, q_peer, processed_peers, commands.reborrow()); + } + } + for ppeer in &processed_peers { + commands.entity(*ppeer).remove::(); } commands.entity(entity).remove::(); commands.entity(entity).remove::(); @@ -76,7 +82,7 @@ fn dragging( >, snaps: Query<(&SnapOf, &SnapOfJoint)>, joints: Query<(&Joint, &JointOf, &Transform, Option<&Peer>, Entity)>, - peer: Query<(&Peer, &JointOf)>, + peer: Query<(Entity, &Peer, &JointOf)>, q_joints: Query<&Joints>, q_joint: Query<&ImpulseJoint>, clients: Query<&ConnectedNetworkEntity>, @@ -175,18 +181,20 @@ fn dragging( // great, we have a valid peering request let did_disconnect = q_joint.get(source_part.2).is_ok(); + let mut dc_queue = vec![]; disconnect_part( source_part.2, Entity::PLACEHOLDER, source_part.4, q_joints, peer, + &mut dc_queue, commands.reborrow(), ); // create the peering component... - commands.entity(source_joint.4).insert(Peer(target_joint.4)); - commands.entity(target_joint.4).insert(Peer(source_joint.4)); + commands.entity(source_joint.4).insert(Peer(target_joint.4, true)); + commands.entity(target_joint.4).insert(Peer(source_joint.4, true)); // propagate PartInShip... @@ -248,12 +256,14 @@ fn dragging( ); warn!("dragging already attached entities may cause inconsistent behavior!!"); let source_part = parts.get(event.drag_target).unwrap(); + let mut dc_queue = vec![]; disconnect_part( source_part.2, Entity::PLACEHOLDER, source_part.4, q_joints, peer, + &mut dc_queue, commands.reborrow(), ); teleport_to_translation = event.drag_to;