Remove unused packet variant, move peer UUID to start of packet

This commit is contained in:
Michael Bradley 2025-10-25 22:22:11 -04:00
parent fee5fb3c95
commit fe967d70b9
Signed by: MichaelBradley
SSH key fingerprint: SHA256:BKO2eI2LPsCbQS3n3i5SdwZTAIV3F1lHezR07qP+Ob0
5 changed files with 18 additions and 66 deletions

View file

@ -40,7 +40,7 @@ where
}
}
fn spawner<T: NetworkDecodable + Component>(
fn incoming_network_entity<T: NetworkDecodable + Component>(
mut inbound: MessageReader<InboundPacket>,
mut commands: Commands,
) {
@ -59,7 +59,7 @@ fn new_peer<T: NetworkEncodable + Component>(
) -> Result {
let peer = peers.get(add.entity)?;
for component in components {
outbound.write(Packet::create(component.encode(), peer.id));
outbound.write(Packet::create(peer.id, component.encode()));
}
Ok(())
}
@ -72,13 +72,13 @@ fn new_entity<T: NetworkEncodable + Component>(
) {
if let Ok(component) = components.get(add.entity) {
for peer in peers {
outbound.write(Packet::create(component.encode(), peer.id));
outbound.write(Packet::create(peer.id, component.encode()));
}
}
}
pub fn distribution_plugin<T: Networked>(app: &mut App) {
app.add_systems(FixedUpdate, spawner::<T>)
app.add_systems(FixedUpdate, incoming_network_entity::<T>)
.add_observer(new_peer::<T>)
.add_observer(new_entity::<T>);
}