Skip to content

Commit

Permalink
Order lightyear plugins w.r.t avian plugins (#602)
Browse files Browse the repository at this point in the history
* order lightyear plugins w.r.t avian plugins

* fix
  • Loading branch information
cBournhonesque authored Aug 19, 2024
1 parent ef6263f commit 6ea2c2e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
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

0 comments on commit 6ea2c2e

Please sign in to comment.