Skip to content

Commit

Permalink
fmt + cargo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cBournhonesque committed Mar 3, 2025
1 parent a394bc8 commit 7d9e904
Show file tree
Hide file tree
Showing 41 changed files with 475 additions and 376 deletions.
4 changes: 2 additions & 2 deletions examples/avian_3d_character/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ pub(crate) struct ProtocolPlugin;

impl Plugin for ProtocolPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(LeafwingInputPlugin::<CharacterAction>{
app.add_plugins(LeafwingInputPlugin::<CharacterAction> {
config: InputConfig::<CharacterAction> {
rebroadcast_inputs: true,
..default()
}
},
});

app.register_component::<ColorComponent>(ChannelDirection::ServerToClient)
Expand Down
2 changes: 1 addition & 1 deletion examples/avian_physics/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Plugin for ProtocolPlugin {
config: InputConfig::<PlayerActions> {
rebroadcast_inputs: true,
..default()
}
},
});
app.add_plugins(LeafwingInputPlugin::<AdminActions>::default());
// components
Expand Down
1 change: 0 additions & 1 deletion examples/avian_physics/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub(crate) fn movement(
}
}


// Replicate the pre-predicted entities back to the client
// We have to use `InitialReplicated` instead of `Replicated`, because
// the server has already assumed authority over the entity so the `Replicated` component
Expand Down
7 changes: 3 additions & 4 deletions examples/client_replication/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub(crate) fn init(mut commands: Commands) {
commands.connect_client();
}


/// Listen for events to know when the client is connected;
/// - spawn a text entity to display the client id
/// - spawn a client-owned cursor entity that will be replicated to the server
Expand Down Expand Up @@ -127,7 +126,7 @@ fn spawn_player(
}
}
if keypress.just_pressed(KeyCode::Space) {
commands.spawn((
commands.spawn((
PlayerBundle::new(client_id, Vec2::ZERO),
// add a marker to specify that we will be writing Inputs on this entity
InputMarker::<Inputs>::default(),
Expand All @@ -151,9 +150,9 @@ fn delete_player(
),
>,
) {
for (entity, inputs, ) in players.iter() {
for (entity, inputs) in players.iter() {
if inputs.value.as_ref().is_some_and(|v| v == &Inputs::Delete) {
if let Some(mut entity_mut) = commands.get_entity(entity) {
if let Some(mut entity_mut) = commands.get_entity(entity) {
// we need to use this special function to despawn prediction entity
// the reason is that we actually keep the entity around for a while,
// in case we need to re-store it for rollback
Expand Down
3 changes: 1 addition & 2 deletions examples/client_replication/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ pub enum Inputs {

// Inputs must all implement MapEntities
impl MapEntities for Inputs {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
}
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {}
}

// Protocol
Expand Down
6 changes: 4 additions & 2 deletions examples/client_replication/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ pub(crate) fn init(mut commands: Commands) {

/// Read client inputs and move players
pub(crate) fn movement(
mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>),
mut position_query: Query<
(&mut PlayerPosition, &ActionState<Inputs>),
// if we run in host-server mode, we don't want to apply this system to the local client's entities
// because they are already moved by the client plugin
(Without<Confirmed>, Without<Predicted>),>,
(Without<Confirmed>, Without<Predicted>),
>,
) {
for (position, inputs) in position_query.iter_mut() {
if let Some(input) = &inputs.value {
Expand Down
15 changes: 9 additions & 6 deletions examples/delta_compression/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn buffer_input(
keypress: Res<ButtonInput<KeyCode>>,
) {
query.iter_mut().for_each(|mut action_state| {
let mut input = None;
let mut input = None;
let mut direction = Direction {
up: false,
down: false,
Expand Down Expand Up @@ -85,9 +85,7 @@ pub(crate) fn buffer_input(
/// The client input only gets applied to predicted entities that we own
/// This works because we only predict the user's controlled entity.
/// If we were predicting more entities, we would have to only apply movement to the player owned one.
fn player_movement(
mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>)>,
) {
fn player_movement(mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>)>) {
for (position, input) in position_query.iter_mut() {
if let Some(inputs) = &input.value {
shared::shared_movement_behaviour(position, inputs);
Expand Down Expand Up @@ -129,14 +127,19 @@ pub(crate) fn receive_player_id_insert(mut reader: EventReader<ComponentInsertEv
/// When the predicted copy of the client-owned entity is spawned, do stuff
/// - assign it a different saturation
/// - keep track of it in the Global resource
pub(crate) fn handle_predicted_spawn(mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>, mut commands: Commands) {
pub(crate) fn handle_predicted_spawn(
mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>,
mut commands: Commands,
) {
for (entity, mut color) in predicted.iter_mut() {
let hsva = Hsva {
saturation: 0.4,
..Hsva::from(color.0)
};
color.0 = Color::from(hsva);
commands.entity(entity).insert(InputMarker::<Inputs>::default());
commands
.entity(entity)
.insert(InputMarker::<Inputs>::default());
}
}

Expand Down
3 changes: 1 addition & 2 deletions examples/delta_compression/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ pub enum Inputs {
}

impl MapEntities for Inputs {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
}
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {}
}

// Protocol
Expand Down
4 changes: 1 addition & 3 deletions examples/delta_compression/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ pub(crate) fn handle_disconnections(
}

/// Read client inputs and move players in server therefore giving a basis for other clients
fn movement(
mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>)>,
) {
fn movement(mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>)>) {
for (position, inputs) in position_query.iter_mut() {
if let Some(inputs) = &inputs.value {
shared::shared_movement_behaviour(position, inputs);
Expand Down
22 changes: 14 additions & 8 deletions examples/distributed_authority/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ impl Plugin for ExampleClientPlugin {
buffer_input.in_set(InputSystemSet::WriteClientInputs),
);
app.add_systems(FixedUpdate, player_movement);
app.add_systems(Update, (change_ball_color_on_authority, handle_predicted_spawn));
app.add_systems(
Update,
(change_ball_color_on_authority, handle_predicted_spawn),
);
app.add_systems(OnEnter(NetworkingState::Disconnected), on_disconnect);

app.add_systems(PostUpdate, interpolation_debug_log);
Expand Down Expand Up @@ -67,7 +70,7 @@ pub(crate) fn buffer_input(
keypress: Res<ButtonInput<KeyCode>>,
) {
query.iter_mut().for_each(|mut action_state| {
let mut input = None;
let mut input = None;
let mut direction = Direction {
up: false,
down: false,
Expand Down Expand Up @@ -96,9 +99,7 @@ pub(crate) fn buffer_input(
/// The client input only gets applied to predicted entities that we own
/// This works because we only predict the user's controlled entity.
/// If we were predicting more entities, we would have to only apply movement to the player owned one.
fn player_movement(
mut position_query: Query<(&mut Position, &ActionState<Inputs>)>,
) {
fn player_movement(mut position_query: Query<(&mut Position, &ActionState<Inputs>)>) {
for (position, input) in position_query.iter_mut() {
if let Some(inputs) = &input.value {
shared::shared_movement_behaviour(position, inputs);
Expand Down Expand Up @@ -167,13 +168,18 @@ pub(crate) fn interpolation_debug_log(
/// When the predicted copy of the client-owned entity is spawned, do stuff
/// - assign it a different saturation
/// - keep track of it in the Global resource
pub(crate) fn handle_predicted_spawn(mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>, mut commands: Commands) {
pub(crate) fn handle_predicted_spawn(
mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>,
mut commands: Commands,
) {
for (entity, mut color) in predicted.iter_mut() {
let hsva = Hsva {
saturation: 0.4,
..Hsva::from(color.0)
};
color.0 = Color::from(hsva);
commands.entity(entity).insert(InputMarker::<Inputs>::default());
commands
.entity(entity)
.insert(InputMarker::<Inputs>::default());
}
}
}
3 changes: 1 addition & 2 deletions examples/distributed_authority/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ pub enum Inputs {
}

impl MapEntities for Inputs {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
}
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {}
}

// Protocol
Expand Down
5 changes: 1 addition & 4 deletions examples/distributed_authority/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ pub(crate) fn handle_connections(
}
}


/// Read client inputs and move players in server therefore giving a basis for other clients
fn movement(
mut position_query: Query<(&mut Position, &ActionState<Inputs>)>,
) {
fn movement(mut position_query: Query<(&mut Position, &ActionState<Inputs>)>) {
for (position, inputs) in position_query.iter_mut() {
if let Some(inputs) = &inputs.value {
shared::shared_movement_behaviour(position, inputs);
Expand Down
11 changes: 7 additions & 4 deletions examples/lobby/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ mod game {
}
}


/// The client input only gets applied to predicted entities that we own
/// This works because we only predict the user's controlled entity.
/// If we were predicting more entities, we would have to only apply movement to the player owned one.
Expand All @@ -166,18 +165,22 @@ mod game {
/// When the predicted copy of the client-owned entity is spawned, do stuff
/// - assign it a different saturation
/// - add an InputMarker so that we can control the entity
pub(crate) fn handle_predicted_spawn(mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>, mut commands: Commands) {
pub(crate) fn handle_predicted_spawn(
mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>,
mut commands: Commands,
) {
for (entity, mut color) in predicted.iter_mut() {
let hsva = Hsva {
saturation: 0.4,
..Hsva::from(color.0)
};
color.0 = Color::from(hsva);
commands.entity(entity).insert(InputMarker::<Inputs>::default());
commands
.entity(entity)
.insert(InputMarker::<Inputs>::default());
}
}


/// When the predicted copy of the client-owned entity is spawned, do stuff
/// - assign it a different saturation
/// - keep track of it in the Global resource
Expand Down
3 changes: 1 addition & 2 deletions examples/lobby/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ pub enum Inputs {
}

impl MapEntities for Inputs {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
}
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {}
}

// Protocol
Expand Down
5 changes: 1 addition & 4 deletions examples/lobby/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,13 @@ mod game {
}

/// Read client inputs and move players
pub(crate) fn movement(
mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>)>,
) {
pub(crate) fn movement(mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>)>) {
for (position, inputs) in position_query.iter_mut() {
if let Some(inputs) = &inputs.value {
shared_movement_behaviour(position, inputs);
}
}
}

}

mod lobby {
Expand Down
4 changes: 1 addition & 3 deletions examples/priority/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ pub struct Message1(pub usize);

// Inputs

#[derive(
Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Reflect, Clone, Copy, Actionlike,
)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Reflect, Clone, Copy, Actionlike)]
pub enum Inputs {
Up,
Down,
Expand Down
11 changes: 4 additions & 7 deletions examples/replication_groups/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ fn movement(
}
}


// When the predicted copy of the client-owned entity is spawned, do stuff
// - assign it a different saturation
// - keep track of it in the Global resource
Expand All @@ -98,12 +97,10 @@ pub(crate) fn handle_predicted_spawn(
// so that the position gets updated smoothly every frame
// (updating it only during FixedUpdate might cause visual artifacts, see:
// https://cbournhonesque.github.io/lightyear/book/concepts/advanced_replication/visual_interpolation.html)
commands
.entity(entity)
.insert((
VisualInterpolateStatus::<PlayerPosition>::default(),
InputMarker::<Inputs>::default(),
));
commands.entity(entity).insert((
VisualInterpolateStatus::<PlayerPosition>::default(),
InputMarker::<Inputs>::default(),
));
}
}

Expand Down
6 changes: 2 additions & 4 deletions examples/replication_groups/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ pub enum Direction {
}

impl MapEntities for Direction {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
}
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {}
}

impl Direction {
Expand Down Expand Up @@ -291,8 +290,7 @@ pub enum Inputs {
}

impl MapEntities for Inputs {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
}
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {}
}

// Protocol
Expand Down
6 changes: 4 additions & 2 deletions examples/replication_groups/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ pub(crate) fn handle_connections(

/// Read client inputs and move players
pub(crate) fn movement(
mut position_query: Query<(&mut PlayerPosition, &ActionState<Inputs>),
mut position_query: Query<
(&mut PlayerPosition, &ActionState<Inputs>),
// if we run in host-server mode, we don't want to apply this system to the local client's entities
// because they are already moved by the client plugin
(Without<Confirmed>, Without<Predicted>)>,
(Without<Confirmed>, Without<Predicted>),
>,
) {
for (position, inputs) in position_query.iter_mut() {
if let Some(input) = &inputs.value {
Expand Down
9 changes: 7 additions & 2 deletions examples/simple_box/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,19 @@ pub(crate) fn receive_player_id_insert(mut reader: EventReader<ComponentInsertEv
/// When the predicted copy of the client-owned entity is spawned, do stuff
/// - assign it a different saturation
/// - keep track of it in the Global resource
pub(crate) fn handle_predicted_spawn(mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>, mut commands: Commands) {
pub(crate) fn handle_predicted_spawn(
mut predicted: Query<(Entity, &mut PlayerColor), Added<Predicted>>,
mut commands: Commands,
) {
for (entity, mut color) in predicted.iter_mut() {
let hsva = Hsva {
saturation: 0.4,
..Hsva::from(color.0)
};
color.0 = Color::from(hsva);
commands.entity(entity).insert(InputMarker::<Inputs>::default());
commands
.entity(entity)
.insert(InputMarker::<Inputs>::default());
}
}

Expand Down
3 changes: 1 addition & 2 deletions examples/simple_box/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ pub enum Inputs {
}

impl MapEntities for Inputs {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
}
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {}
}

// Protocol
Expand Down
Loading

0 comments on commit 7d9e904

Please sign in to comment.