Skip to content

Commit

Permalink
fix CI and add component removal test
Browse files Browse the repository at this point in the history
  • Loading branch information
cbournhonesque-sc committed Nov 29, 2023
1 parent ef5d21f commit 9f28762
Show file tree
Hide file tree
Showing 28 changed files with 1,299 additions and 1,212 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Install alsa
run: sudo apt-get install -y libasound2-dev; sudo apt-get install -y libwebkit2gtk-4.0 ;

- name: Clone repo
uses: actions/checkout@v4

Expand All @@ -54,6 +57,9 @@ jobs:
name: Doctest
runs-on: ubuntu-latest
steps:
- name: Install alsa
run: sudo apt-get install -y libasound2-dev; sudo apt-get install -y libwebkit2gtk-4.0 ;

- name: Clone repo
uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
members = ["examples", "macros", "lightyear", "tests"]
members = ["examples", "macros", "lightyear"]
2 changes: 2 additions & 0 deletions lightyear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ rand = "0.8"
ringbuffer = "0.15"
bevy = { version = "0.12", default-features = false }
taplo-cli = "0.8.1"
derive_more = "0.99.17"

[dev-dependencies]
derive_more = { version = "0.99", features = ["add", "mul"] }
mock_instant = { version = "0.3.1" }
tracing-subscriber = "0.3.17"
bitvec = "1.0"
5 changes: 5 additions & 0 deletions lightyear/src/client/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ impl<P: Protocol> Connection<P> {
}
Ok(())
}

#[cfg(test)]
pub fn base(&self) -> &crate::connection::Connection<P> {
&self.base
}
}
255 changes: 255 additions & 0 deletions lightyear/src/client/interpolation/interpolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,258 @@ pub(crate) fn interpolate<C: InterpolatedComponent>(
}
}
}

#[cfg(test)]
mod tests {
// #![allow(unused_imports)]
// #![allow(unused_variables)]
// #![allow(dead_code)]
//
// use std::net::SocketAddr;
// use std::str::FromStr;
// use std::time::{Duration, Instant};
//
// use bevy::log::LogPlugin;
// use bevy::prelude::{
// App, Commands, Entity, EventReader, FixedUpdate, IntoSystemConfigs, PluginGroup, Query, Real,
// Res, ResMut, Startup, Time, With,
// };
// use bevy::time::TimeUpdateStrategy;
// use bevy::winit::WinitPlugin;
// use bevy::{DefaultPlugins, MinimalPlugins};
// use lightyear::client::components::Confirmed;
// use tracing::{debug, info};
// use tracing_subscriber::fmt::format::FmtSpan;
//
// use lightyear::_reexport::*;
// use lightyear::prelude::client::*;
// use lightyear::prelude::*;
// use lightyear_tests::protocol::{protocol, Channel2, Component1, Component2, MyInput, MyProtocol};
// use lightyear_tests::stepper::{BevyStepper, Step};
//
// fn setup() -> (BevyStepper, Entity, Entity, u16) {
// let frame_duration = Duration::from_millis(10);
// let tick_duration = Duration::from_millis(10);
// let shared_config = SharedConfig {
// enable_replication: false,
// tick: TickConfig::new(tick_duration),
// ..Default::default()
// };
// let link_conditioner = LinkConditionerConfig {
// incoming_latency: Duration::from_millis(40),
// incoming_jitter: Duration::from_millis(5),
// incoming_loss: 0.05,
// };
// let sync_config = SyncConfig::default().speedup_factor(1.0);
// let prediction_config = PredictionConfig::default().disable(true);
// let interpolation_delay = Duration::from_millis(100);
// let interpolation_config =
// InterpolationConfig::default().with_delay(InterpolationDelay::Delay(interpolation_delay));
// let mut stepper = BevyStepper::new(
// shared_config,
// sync_config,
// prediction_config,
// interpolation_config,
// link_conditioner,
// frame_duration,
// );
// stepper.client_mut().set_synced();
//
// // Create a confirmed entity
// let confirmed = stepper
// .client_app
// .world
// .spawn((Component1(0.0), ShouldBeInterpolated))
// .id();
//
// // Tick once
// stepper.frame_step();
// assert_eq!(stepper.client().tick(), Tick(1));
// let interpolated = stepper
// .client_app
// .world
// .get::<Confirmed>(confirmed)
// .unwrap()
// .interpolated
// .unwrap();
//
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<Component1>(confirmed)
// .unwrap(),
// &Component1(0.0)
// );
//
// // check that the interpolated entity got spawned
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<Interpolated>(interpolated)
// .unwrap()
// .confirmed_entity,
// confirmed
// );
//
// // check that the component history got created and is empty
// let history = ConfirmedHistory::<Component1>::new();
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<ConfirmedHistory<Component1>>(interpolated)
// .unwrap(),
// &history,
// );
// // check that the confirmed component got replicated
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<Component1>(interpolated)
// .unwrap(),
// &Component1(0.0)
// );
// // check that the interpolate status got updated
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<InterpolateStatus<Component1>>(interpolated)
// .unwrap(),
// &InterpolateStatus::<Component1> {
// start: None,
// end: (Tick(0), Component1(0.0)).into(),
// current: Tick(1) - interpolation_tick_delay,
// }
// );
// (stepper, confirmed, interpolated, interpolation_tick_delay)
// }
//
// // Test interpolation
// #[test]
// fn test_interpolation() -> anyhow::Result<()> {
// let (mut stepper, confirmed, interpolated, interpolation_tick_delay) = setup();
// // reach interpolation start tick
// stepper.frame_step();
// stepper.frame_step();
// // check that the interpolate status got updated (end becomes start)
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<InterpolateStatus<Component1>>(interpolated)
// .unwrap(),
// &InterpolateStatus::<Component1> {
// start: (Tick(0), Component1(0.0)).into(),
// end: None,
// current: Tick(3) - interpolation_tick_delay,
// }
// );
//
// // receive server update
// stepper
// .client_mut()
// .set_latest_received_server_tick(Tick(2));
// stepper
// .client_app
// .world
// .get_entity_mut(confirmed)
// .unwrap()
// .get_mut::<Component1>()
// .unwrap()
// .0 = 2.0;
//
// stepper.frame_step();
// // check that interpolation is working correctly
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<InterpolateStatus<Component1>>(interpolated)
// .unwrap(),
// &InterpolateStatus::<Component1> {
// start: (Tick(0), Component1(0.0)).into(),
// end: (Tick(2), Component1(2.0)).into(),
// current: Tick(4) - interpolation_tick_delay,
// }
// );
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<Component1>(interpolated)
// .unwrap(),
// &Component1(1.0)
// );
// stepper.frame_step();
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<InterpolateStatus<Component1>>(interpolated)
// .unwrap(),
// &InterpolateStatus::<Component1> {
// start: (Tick(2), Component1(2.0)).into(),
// end: None,
// current: Tick(5) - interpolation_tick_delay,
// }
// );
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<Component1>(interpolated)
// .unwrap(),
// &Component1(2.0)
// );
// Ok(())
// }
//
// // We are in the situation: S1 < I
// // where S1 is a confirmed ticks, and I is the interpolated tick
// // and we receive S1 < S2 < I
// // Then we should now start interpolating from S2
// #[test]
// fn test_received_more_recent_start() -> anyhow::Result<()> {
// let (mut stepper, confirmed, interpolated, interpolation_tick_delay) = setup();
//
// // reach interpolation start tick
// stepper.frame_step();
// stepper.frame_step();
// stepper.frame_step();
// stepper.frame_step();
// assert_eq!(stepper.client().tick(), Tick(5));
//
// // receive server update
// stepper
// .client_mut()
// .set_latest_received_server_tick(Tick(1));
// stepper
// .client_app
// .world
// .get_entity_mut(confirmed)
// .unwrap()
// .get_mut::<Component1>()
// .unwrap()
// .0 = 1.0;
//
// stepper.frame_step();
// // check the status uses the more recent server update
// assert_eq!(
// stepper
// .client_app
// .world
// .get::<InterpolateStatus<Component1>>(interpolated)
// .unwrap(),
// &InterpolateStatus::<Component1> {
// start: (Tick(1), Component1(1.0)).into(),
// end: None,
// current: Tick(6) - interpolation_tick_delay,
// }
// );
// Ok(())
// }
}
4 changes: 2 additions & 2 deletions lightyear/src/client/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy::prelude::{
Plugin as PluginType, PostUpdate, PreUpdate,
};

use crate::client::events::{ConnectEvent, DisconnectEvent, EntitySpawnEvent};
use crate::client::events::{ConnectEvent, DisconnectEvent, EntityDespawnEvent, EntitySpawnEvent};
use crate::client::input::InputPlugin;
use crate::client::interpolation::plugin::InterpolationPlugin;
use crate::client::prediction::plugin::{is_in_rollback, PredictionPlugin};
Expand Down Expand Up @@ -89,7 +89,6 @@ impl<P: Protocol> PluginType for ClientPlugin<P> {
))
// RESOURCES //
.insert_resource(client)
.init_resource::<ReplicationData>()
// SYSTEM SETS //
.configure_sets(PreUpdate, MainSet::Receive)
.configure_sets(
Expand All @@ -109,6 +108,7 @@ impl<P: Protocol> PluginType for ClientPlugin<P> {
.add_event::<ConnectEvent>()
.add_event::<DisconnectEvent>()
.add_event::<EntitySpawnEvent>()
.add_event::<EntityDespawnEvent>()
// SYSTEMS //
.add_systems(
PreUpdate,
Expand Down
Loading

0 comments on commit 9f28762

Please sign in to comment.