Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order lightyear plugins w.r.t avian plugins #602

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lightyear/src/shared/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ impl Plugin for SharedPlugin {
.register_type::<LinkConditionerConfig>()
.register_type::<CompressionConfig>();

// PLUGINS
#[cfg(feature = "avian2d")]
app.add_plugins(crate::utils::avian2d::Avian2dPlugin);
#[cfg(feature = "avian3d")]
app.add_plugins(crate::utils::avian3d::Avian3dPlugin);

// RESOURCES
// the SharedPlugin is called after the ClientConfig is inserted
let input_send_interval =
Expand Down
2 changes: 1 addition & 1 deletion lightyear/src/shared/replication/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type EntityHashMap<K, V> = hashbrown::HashMap<K, V, EntityHash>;
type EntityHashSet<K> = hashbrown::HashSet<K, EntityHash>;

#[derive(Debug)]
pub(crate) struct ReplicationReceiver {
pub struct ReplicationReceiver {
/// Map between local and remote entities. (used mostly on client because it's when we receive entity updates)
pub remote_entity_map: RemoteEntityMap,

Expand Down
29 changes: 29 additions & 0 deletions lightyear/src/utils/avian2d.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
//! Implement lightyear traits for some common bevy types
use crate::prelude::client::{InterpolationSet, PredictionSet};
use crate::shared::replication::delta::Diffable;
use crate::shared::sets::{ClientMarker, InternalReplicationSet, ServerMarker};
use avian2d::math::Scalar;
use avian2d::prelude::*;
use bevy::prelude::{App, FixedPostUpdate, IntoSystemSetConfigs, Plugin};
use tracing::trace;

pub(crate) struct Avian2dPlugin;

impl Plugin for Avian2dPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
FixedPostUpdate,
(
PhysicsSet::Prepare,
PhysicsSet::StepSimulation,
PhysicsSet::Sync,
)
.before((
PredictionSet::UpdateHistory,
PredictionSet::IncrementRollbackTick,
InterpolationSet::UpdateVisualInterpolationState,
))
// run physics after setting the PreSpawned hash to avoid any physics interaction affecting the hash
// TODO: maybe use observers so that we don't have any ordering requirements?
.after((
InternalReplicationSet::<ClientMarker>::SetPreSpawnedHash,
InternalReplicationSet::<ServerMarker>::SetPreSpawnedHash,
)),
);
}
}

pub mod position {
use super::*;

Expand Down
29 changes: 29 additions & 0 deletions lightyear/src/utils/avian3d.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
//! Implement lightyear traits for some common bevy types
use crate::prelude::client::{InterpolationSet, PredictionSet};
use crate::shared::replication::delta::Diffable;
use crate::shared::sets::{ClientMarker, InternalReplicationSet, ServerMarker};
use avian3d::math::Scalar;
use avian3d::prelude::*;
use bevy::app::{App, FixedPostUpdate, Plugin};
use bevy::prelude::IntoSystemSetConfigs;
use tracing::trace;

pub(crate) struct Avian3dPlugin;
impl Plugin for Avian3dPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
FixedPostUpdate,
(
avian2d::prelude::PhysicsSet::Prepare,
avian2d::prelude::PhysicsSet::StepSimulation,
avian2d::prelude::PhysicsSet::Sync,
)
.before((
PredictionSet::UpdateHistory,
PredictionSet::IncrementRollbackTick,
InterpolationSet::UpdateVisualInterpolationState,
))
// run physics after setting the PreSpawned hash to avoid any physics interaction affecting the hash
// TODO: maybe use observers so that we don't have any ordering requirements?
.after((
InternalReplicationSet::<ClientMarker>::SetPreSpawnedHash,
InternalReplicationSet::<ServerMarker>::SetPreSpawnedHash,
)),
);
}
}

pub mod position {
use super::*;

Expand Down
Loading