@@ 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)]
@@ 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<Entity>,
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::<Peer>();
+ 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::<Peer>();
+ 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::<Peer>();
}
commands.entity(entity).remove::<ImpulseJoint>();
commands.entity(entity).remove::<PartInShip>();
@@ 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;