├── book
├── .gitignore
├── src
│ ├── guides
│ │ └── title.md
│ ├── appendix
│ │ └── title.md
│ ├── concepts
│ │ ├── bevy_integration
│ │ │ ├── title.md
│ │ │ ├── events.md
│ │ │ ├── server.md
│ │ │ ├── client
│ │ │ │ ├── title.md
│ │ │ │ └── time_sync.md
│ │ │ └── shared_plugin.md
│ │ ├── advanced_replication
│ │ │ ├── title.md
│ │ │ ├── component_sync_mode.md
│ │ │ └── inputs.md
│ │ ├── replication
│ │ │ └── title.md
│ │ ├── reliability
│ │ │ ├── title.md
│ │ │ └── channels.md
│ │ ├── transport
│ │ │ ├── title.md
│ │ │ ├── serialization.md
│ │ │ └── packet.md
│ │ ├── connection
│ │ │ └── multi_connection.md
│ │ └── title.md
│ ├── tutorial
│ │ └── title.md
│ └── introduction.md
├── theme
│ └── head.hbs
├── book.toml
├── CONTRIBUTING.md
└── mermaid-init.js
├── .dockerignore
├── benches
├── criterion
│ ├── src
│ │ ├── measurements
│ │ │ └── mod.rs
│ │ ├── lib.rs
│ │ └── replication_profiling.rs
│ ├── benches
│ │ ├── bandwidth
│ │ │ └── main.rs
│ │ └── timing
│ │ │ └── main.rs
│ ├── bench.sh
│ ├── justfile
│ └── Cargo.toml
├── divan
│ ├── src
│ │ ├── lib.rs
│ │ └── message.rs
│ ├── bench.sh
│ └── Cargo.toml
└── compiletime
│ ├── run.sh
│ └── Cargo.toml
├── certificates
├── digest.txt
├── key.pem
├── generate.sh
└── cert.pem
├── lightyear_tests
├── src
│ ├── multi_server
│ │ └── mod.rs
│ ├── client_server
│ │ ├── input
│ │ │ └── mod.rs
│ │ ├── avian
│ │ │ └── mod.rs
│ │ ├── mod.rs
│ │ └── connection.rs
│ ├── host_server
│ │ ├── input
│ │ │ └── mod.rs
│ │ └── mod.rs
│ ├── lib.rs
│ └── bin
│ │ └── replicate.rs
└── justfile
├── lightyear_replication
└── src
│ ├── visibility
│ ├── mod.rs
│ └── error.rs
│ ├── send
│ └── mod.rs
│ ├── impls
│ ├── avian3d.rs
│ └── avian2d.rs
│ ├── error.rs
│ └── registry
│ └── mod.rs
├── lightyear_deterministic_replication
├── src
│ ├── messages.rs
│ ├── plugin.rs
│ └── lib.rs
└── Cargo.toml
├── lightyear_core
├── src
│ ├── network.rs
│ ├── test.rs
│ ├── plugin.rs
│ ├── prediction.rs
│ ├── interpolation.rs
│ └── lib.rs
└── Cargo.toml
├── lightyear_prediction
├── src
│ └── deterministic.rs
└── Cargo.toml
├── .gitignore
├── lightyear_avian
└── src
│ ├── lag_compensation
│ └── mod.rs
│ └── lib.rs
├── examples
├── simple_box
│ ├── src
│ │ ├── lib.rs
│ │ ├── renderer.rs
│ │ └── shared.rs
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ └── Cargo.toml
├── bevy_enhanced_inputs
│ ├── src
│ │ ├── lib.rs
│ │ └── protocol.rs
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── Cargo.toml
│ └── README.md
├── auth
│ ├── index.html
│ ├── src
│ │ └── shared.rs
│ ├── .cargo
│ │ └── config.toml
│ └── Cargo.toml
├── fps
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── lobby
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── src
│ │ ├── shared.rs
│ │ └── renderer.rs
│ └── Cargo.toml
├── priority
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── src
│ │ ├── shared.rs
│ │ └── main.rs
│ └── Cargo.toml
├── avian_physics
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ └── Cargo.toml
├── projectiles
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ └── Cargo.toml
├── avian_3d_character
│ ├── index.html
│ └── Cargo.toml
├── client_replication
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── src
│ │ └── renderer.rs
│ └── Cargo.toml
├── delta_compression
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── src
│ │ ├── shared.rs
│ │ └── renderer.rs
│ └── Cargo.toml
├── network_visibility
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── src
│ │ ├── shared.rs
│ │ └── renderer.rs
│ ├── Cargo.toml
│ └── README.md
├── replication_groups
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── renderer.rs
├── distributed_authority
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── Cargo.toml
│ └── src
│ │ └── renderer.rs
├── deterministic_replication
│ ├── index.html
│ ├── .cargo
│ │ └── config.toml
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ └── server.rs
├── simple_setup
│ ├── .cargo
│ │ └── config.toml
│ ├── Cargo.toml
│ ├── src
│ │ ├── shared.rs
│ │ └── client.rs
│ └── README.md
├── common
│ ├── src
│ │ └── shared.rs
│ └── www
│ │ └── index.html
└── launcher
│ ├── README.md
│ └── Cargo.toml
├── lightyear_ui
├── src
│ └── lib.rs
└── Cargo.toml
├── lightyear_connection
├── src
│ ├── direction.rs
│ ├── client_of.rs
│ ├── identity.rs
│ └── shared.rs
└── Cargo.toml
├── demos
└── spaceships
│ ├── index.html
│ ├── .cargo
│ └── config.toml
│ └── Cargo.toml
├── lightyear_utils
├── src
│ ├── captures.rs
│ ├── lib.rs
│ └── collections.rs
└── Cargo.toml
├── lightyear_transport
├── src
│ ├── channel
│ │ ├── receivers
│ │ │ └── error.rs
│ │ ├── mod.rs
│ │ ├── stats.rs
│ │ └── README.md
│ ├── packet
│ │ ├── error.rs
│ │ ├── packet_type.rs
│ │ └── mod.rs
│ ├── error.rs
│ ├── lib.rs
│ ├── client.rs
│ └── server.rs
└── Cargo.toml
├── .github
├── dependabot.yml
├── FUNDING.yml
├── workflows
│ └── website.yaml
└── actions
│ └── install-linux-deps
│ └── action.yml
├── lightyear_sync
├── src
│ ├── server.rs
│ ├── ping
│ │ ├── mod.rs
│ │ └── store.rs
│ ├── timeline
│ │ └── mod.rs
│ └── plugin.rs
└── Cargo.toml
├── .cargo
├── config_ci.toml
└── config.toml
├── lightyear_netcode
└── src
│ └── bytes.rs
├── lightyear_metrics
├── src
│ └── lib.rs
└── Cargo.toml
├── lightyear_inputs_bei
├── src
│ └── lib.rs
└── Cargo.toml
├── lightyear_aeronet
└── Cargo.toml
├── lightyear_link
└── Cargo.toml
├── lightyear_crossbeam
└── Cargo.toml
├── lightyear_udp
└── Cargo.toml
├── lightyear_raw_connection
├── Cargo.toml
└── src
│ └── lib.rs
├── lightyear_inputs_native
├── Cargo.toml
└── src
│ └── plugin.rs
├── lightyear_frame_interpolation
└── Cargo.toml
├── lightyear_interpolation
├── src
│ ├── despawn.rs
│ └── lib.rs
├── CHANGELOG.md
└── Cargo.toml
├── LICENSE-MIT
├── lightyear_serde
└── Cargo.toml
├── lightyear_webtransport
├── src
│ └── lib.rs
└── Cargo.toml
├── lightyear_inputs_leafwing
└── Cargo.toml
├── lightyear_websocket
├── src
│ └── lib.rs
└── Cargo.toml
├── .pre-commit-config.yaml
├── lightyear_steam
└── Cargo.toml
├── lightyear
└── src
│ └── web.rs
├── lightyear_messages
├── Cargo.toml
└── src
│ └── client.rs
├── lightyear_inputs
├── src
│ └── lib.rs
└── Cargo.toml
├── lightyear_avian2d
└── Cargo.toml
├── lightyear_avian3d
└── Cargo.toml
└── CHANGELOG.md
/book/.gitignore:
--------------------------------------------------------------------------------
1 | booka
2 |
--------------------------------------------------------------------------------
/book/src/guides/title.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | target/
2 | .git/
3 |
--------------------------------------------------------------------------------
/book/src/appendix/title.md:
--------------------------------------------------------------------------------
1 | # Appendix
2 |
--------------------------------------------------------------------------------
/book/src/concepts/bevy_integration/title.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/book/src/concepts/advanced_replication/title.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/book/src/concepts/bevy_integration/events.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/book/src/concepts/bevy_integration/server.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/book/src/concepts/bevy_integration/client/title.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/book/src/concepts/bevy_integration/shared_plugin.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/book/src/concepts/bevy_integration/client/time_sync.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/book/src/concepts/replication/title.md:
--------------------------------------------------------------------------------
1 | # Replication
2 |
--------------------------------------------------------------------------------
/book/src/concepts/advanced_replication/component_sync_mode.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/benches/criterion/src/measurements/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod bandwidth;
2 |
--------------------------------------------------------------------------------
/certificates/digest.txt:
--------------------------------------------------------------------------------
1 | 2E6DF3B559DEB469CD238CA56A903310502DE781427D758BBA0E3B2801556704
--------------------------------------------------------------------------------
/lightyear_tests/src/multi_server/mod.rs:
--------------------------------------------------------------------------------
1 | #[cfg(feature = "steam")]
2 | mod steam;
3 |
--------------------------------------------------------------------------------
/lightyear_tests/src/client_server/input/mod.rs:
--------------------------------------------------------------------------------
1 | mod bei;
2 | mod leafwing;
3 | mod native;
4 |
--------------------------------------------------------------------------------
/lightyear_tests/src/host_server/input/mod.rs:
--------------------------------------------------------------------------------
1 | mod bei;
2 | mod leafwing;
3 | mod native;
4 |
--------------------------------------------------------------------------------
/lightyear_tests/src/host_server/mod.rs:
--------------------------------------------------------------------------------
1 | mod base;
2 |
3 | mod messages;
4 |
5 | mod input;
6 |
--------------------------------------------------------------------------------
/lightyear_replication/src/visibility/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod immediate;
2 |
3 | pub mod error;
4 | pub mod room;
5 |
--------------------------------------------------------------------------------
/lightyear_tests/src/client_server/avian/mod.rs:
--------------------------------------------------------------------------------
1 | mod position_replication;
2 | mod transform_replication;
3 |
--------------------------------------------------------------------------------
/lightyear_deterministic_replication/src/messages.rs:
--------------------------------------------------------------------------------
1 | // pub enum ConnectionEvent {
2 | // Connected(PeerId)
3 | // Disconnected
4 | // }
5 |
--------------------------------------------------------------------------------
/lightyear_core/src/network.rs:
--------------------------------------------------------------------------------
1 | // TODO: use newtype instead of u16
2 | /// ID used to serialize IDs over the network efficiently
3 | pub type NetId = u16;
4 |
--------------------------------------------------------------------------------
/benches/criterion/benches/bandwidth/main.rs:
--------------------------------------------------------------------------------
1 | use criterion::criterion_main;
2 |
3 | mod replication;
4 |
5 | criterion_main!(replication::replication_bandwidth);
6 |
--------------------------------------------------------------------------------
/lightyear_replication/src/send/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod archetypes;
2 |
3 | pub(crate) mod buffer;
4 |
5 | pub mod components;
6 |
7 | pub mod plugin;
8 |
9 | pub mod sender;
10 |
--------------------------------------------------------------------------------
/lightyear_prediction/src/deterministic.rs:
--------------------------------------------------------------------------------
1 | //! Prediction primitives when we run in deterministic replication mode (only inputs are replicated)
2 |
3 | struct DeterministicPredicted;
4 |
--------------------------------------------------------------------------------
/book/theme/head.hbs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /Cargo.lock
3 | /.idea
4 | /examples/**/dist/
5 | .DS_Store
6 | /examples/target/
7 | /examples/Cargo.lock
8 | .aider*
9 | **/CL1
10 | **/CL2
11 | **/SL
12 | **/HL
13 | .vscode
14 |
--------------------------------------------------------------------------------
/benches/criterion/benches/timing/main.rs:
--------------------------------------------------------------------------------
1 | use criterion::criterion_main;
2 |
3 | mod message;
4 |
5 | mod replication;
6 |
7 | criterion_main!(message::message_benches, replication::replication_benches,);
8 |
--------------------------------------------------------------------------------
/lightyear_avian/src/lag_compensation/mod.rs:
--------------------------------------------------------------------------------
1 | //! Provides helpers to perform lag compensation so that client-predicted entities
2 | //! can interact with interpolated entities.
3 |
4 | pub mod history;
5 | pub mod query;
6 |
--------------------------------------------------------------------------------
/lightyear_core/src/test.rs:
--------------------------------------------------------------------------------
1 | use bevy_ecs::component::Component;
2 |
3 | #[derive(Component, Default)]
4 | pub struct TestHelper {
5 | /// If True, we will drop the packets at the IO layer
6 | pub block_send: bool,
7 | }
8 |
--------------------------------------------------------------------------------
/lightyear_replication/src/visibility/error.rs:
--------------------------------------------------------------------------------
1 | use bevy_ecs::entity::Entity;
2 |
3 | #[derive(thiserror::Error, Debug)]
4 | pub enum NetworkVisibilityError {
5 | #[error("room {0:?} was not found")]
6 | RoomNotFound(Entity),
7 | }
8 |
--------------------------------------------------------------------------------
/examples/simple_box/src/lib.rs:
--------------------------------------------------------------------------------
1 | pub mod protocol;
2 |
3 | #[cfg(feature = "client")]
4 | pub mod client;
5 |
6 | #[cfg(feature = "server")]
7 | pub mod server;
8 |
9 | #[cfg(feature = "gui")]
10 | pub mod renderer;
11 |
12 | pub mod shared;
13 |
--------------------------------------------------------------------------------
/lightyear_ui/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! # Lightyear UI
2 | #![no_std]
3 |
4 | extern crate alloc;
5 | #[cfg(feature = "std")]
6 | extern crate std;
7 |
8 | pub mod debug;
9 |
10 | pub mod prelude {
11 | pub use crate::debug::DebugUIPlugin;
12 | }
13 |
--------------------------------------------------------------------------------
/examples/bevy_enhanced_inputs/src/lib.rs:
--------------------------------------------------------------------------------
1 | pub mod protocol;
2 |
3 | #[cfg(feature = "client")]
4 | pub mod client;
5 |
6 | #[cfg(feature = "server")]
7 | pub mod server;
8 |
9 | #[cfg(feature = "gui")]
10 | pub mod renderer;
11 |
12 | pub mod shared;
13 |
--------------------------------------------------------------------------------
/lightyear_connection/src/direction.rs:
--------------------------------------------------------------------------------
1 | #[derive(Clone, Copy, PartialEq, Debug)]
2 | /// [`NetworkDirection`] specifies in which direction the packets can be sent
3 | pub enum NetworkDirection {
4 | ClientToServer,
5 | ServerToClient,
6 | Bidirectional,
7 | }
8 |
--------------------------------------------------------------------------------
/certificates/key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg0nCfP5pPE6Xiafwq
3 | RH8hi4vtRxBsDwhMkKHE9gLcs2+hRANCAAR/6+ya3qAD8UWQKosenUO8XZckDFg4
4 | sRvmav9xL1EbKKBdLAijzMpptUg8Jdlfz4Sk0UFA8HhZ2rzv7SWyuw6C
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/lightyear_tests/src/client_server/mod.rs:
--------------------------------------------------------------------------------
1 | mod base;
2 |
3 | mod authority;
4 | mod avian;
5 | mod connection;
6 | mod delta;
7 | mod hierarchy;
8 | mod input;
9 | mod messages;
10 | mod prediction;
11 | mod replication;
12 | mod replication_advanced;
13 | mod visibility;
14 |
--------------------------------------------------------------------------------
/examples/auth/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/fps/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/demos/spaceships/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/lobby/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/priority/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/benches/divan/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! This crate contains benchmarking tests for the Lightyear project, using Divan.
2 | //! It includes modules for profiling and protocol-specific benchmarks.
3 | #![allow(clippy::all)]
4 | #![allow(unused_imports)]
5 | #![allow(unused_variables)]
6 | #![allow(dead_code)]
7 |
--------------------------------------------------------------------------------
/examples/avian_physics/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/projectiles/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/simple_box/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/avian_3d_character/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/client_replication/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/delta_compression/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/network_visibility/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/replication_groups/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/bevy_enhanced_inputs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/distributed_authority/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/benches/compiletime/run.sh:
--------------------------------------------------------------------------------
1 | # Rebuild the compiletime crate without rebuilding the dependencies
2 | # Measure the time it takes to compile the crate
3 | rm -rf "target/debug/.fingerprint/compiletime*" && rm -rf "target/debug/incremental/compiletime*" && rm -rf "target/debug/compiletime*" && cargo build -p compiletime
--------------------------------------------------------------------------------
/examples/deterministic_replication/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bevy game
7 |
8 |
9 |
--------------------------------------------------------------------------------
/lightyear_utils/src/captures.rs:
--------------------------------------------------------------------------------
1 | //! Captures trick to allow for better impl Iterator + 'a
2 | //! See ``
3 | //! and ``
4 |
5 | pub trait Captures {}
6 | impl Captures for T {}
7 |
--------------------------------------------------------------------------------
/lightyear_transport/src/channel/receivers/error.rs:
--------------------------------------------------------------------------------
1 | //! Errors for receiving packets
2 |
3 | pub type Result = core::result::Result;
4 | #[derive(thiserror::Error, Debug)]
5 | pub enum ChannelReceiveError {
6 | #[error("A message was received without a message ID")]
7 | MissingMessageId,
8 | }
9 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: cargo
4 | directory: /
5 | schedule:
6 | interval: weekly
7 | labels:
8 | - "dependencies"
9 | - package-ecosystem: github-actions
10 | directory: /
11 | schedule:
12 | interval: weekly
13 | labels:
14 | - "github actions"
--------------------------------------------------------------------------------
/benches/criterion/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! This crate contains benchmarking tests for the Lightyear project, using Criterion.
2 | //! It includes modules for profiling and protocol-specific benchmarks.
3 | #![allow(clippy::all)]
4 | #![allow(unused_imports)]
5 | #![allow(unused_variables)]
6 | #![allow(dead_code)]
7 | pub mod measurements;
8 | pub mod profiler;
9 |
--------------------------------------------------------------------------------
/lightyear_sync/src/server.rs:
--------------------------------------------------------------------------------
1 | use bevy_app::{App, Plugin};
2 |
3 | use crate::plugin::TimelineSyncPlugin;
4 |
5 | pub struct ServerPlugin;
6 |
7 | impl Plugin for ServerPlugin {
8 | fn build(&self, app: &mut App) {
9 | if !app.is_plugin_added::() {
10 | app.add_plugins(TimelineSyncPlugin);
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.cargo/config_ci.toml:
--------------------------------------------------------------------------------
1 | # This config is used for the CI workflow.
2 |
3 | # Enable a small amount of optimization in the dev profile.
4 | [profile.dev]
5 | opt-level = 1
6 |
7 | # Enable a large amount of optimization in the dev profile for dependencies.
8 | [profile.dev.package."*"]
9 | opt-level = 3
10 |
11 | [target.x86_64-pc-windows-msvc]
12 | linker = "rust-lld.exe"
13 |
--------------------------------------------------------------------------------
/book/book.toml:
--------------------------------------------------------------------------------
1 | [book]
2 | authors = ["Charles Bournhonesque"]
3 | language = "en"
4 | multilingual = false
5 | src = "src"
6 | title = "Lightyear book"
7 |
8 | [preprocessor]
9 |
10 | [preprocessor.mermaid]
11 | command = "mdbook-mermaid"
12 |
13 | [output]
14 |
15 | #[output.linkcheck]
16 |
17 | [output.html]
18 | additional-js = ["mermaid.min.js", "mermaid-init.js"]
19 | site-url = "/book/"
20 |
--------------------------------------------------------------------------------
/lightyear_netcode/src/bytes.rs:
--------------------------------------------------------------------------------
1 | use lightyear_serde::reader::ReadInteger;
2 | use lightyear_serde::writer::WriteInteger;
3 |
4 | pub trait Bytes: Sized {
5 | const SIZE: usize = core::mem::size_of::();
6 | type Error;
7 | fn write_to(&self, writer: &mut impl WriteInteger) -> Result<(), Self::Error>;
8 | fn read_from(reader: &mut impl ReadInteger) -> Result;
9 | }
10 |
--------------------------------------------------------------------------------
/examples/auth/src/shared.rs:
--------------------------------------------------------------------------------
1 | //! This module contains the shared code between the client and the server for the auth example.
2 | use core::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
3 |
4 | // Define a shared port for the authentication backend
5 | pub const AUTH_BACKEND_PORT: u16 = 4000;
6 |
7 | pub const AUTH_BACKEND_ADDRESS: SocketAddr =
8 | SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, AUTH_BACKEND_PORT));
9 |
--------------------------------------------------------------------------------
/lightyear_deterministic_replication/src/plugin.rs:
--------------------------------------------------------------------------------
1 | use crate::Deterministic;
2 | use bevy_app::{App, Plugin};
3 | use lightyear_prediction::rollback::DeterministicPredicted;
4 |
5 | pub struct DeterministicReplicationPlugin;
6 |
7 | impl Plugin for DeterministicReplicationPlugin {
8 | fn build(&self, app: &mut App) {
9 | app.register_required_components::();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/lightyear_sync/src/ping/mod.rs:
--------------------------------------------------------------------------------
1 | //! Module to handle sending ping/pong messages and compute connection statistics (rtt, jitter, etc.)
2 |
3 | pub mod manager;
4 |
5 | pub mod message;
6 |
7 | pub mod diagnostics;
8 | pub mod estimator;
9 | pub mod plugin;
10 | pub mod store;
11 |
12 | /// Default channel to send pings. This is a Sequenced Unreliable channel, because
13 | /// there is no point in getting older pings.
14 | pub struct PingChannel;
15 |
--------------------------------------------------------------------------------
/lightyear_utils/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! Contains a set of useful utilities
2 |
3 | #![no_std]
4 |
5 | extern crate alloc;
6 | extern crate core;
7 | #[cfg(feature = "std")]
8 | extern crate std;
9 |
10 | pub mod free_list;
11 |
12 | pub mod ready_buffer;
13 |
14 | pub mod sequence_buffer;
15 |
16 | pub mod captures;
17 | pub mod collections;
18 |
19 | pub mod ecs;
20 | pub mod registry;
21 | pub mod wrapping_id;
22 |
23 | #[cfg(feature = "metrics")]
24 | pub mod metrics;
25 |
--------------------------------------------------------------------------------
/lightyear_sync/src/timeline/mod.rs:
--------------------------------------------------------------------------------
1 | use bevy_ecs::component::Component;
2 |
3 | pub mod input;
4 | pub mod remote;
5 | pub mod sync;
6 |
7 | /// Marker component to identity the timeline that will update the bevy app.
8 | ///
9 | /// [`Time`](bevy_time::Time) will be updated according to the driving timeline's relative_speed.
10 | #[derive(Component, Default)]
11 | pub struct DrivingTimeline {
12 | pub marker: core::marker::PhantomData,
13 | }
14 |
--------------------------------------------------------------------------------
/benches/compiletime/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "compiletime"
3 | version.workspace = true
4 | authors.workspace = true
5 | publish.workspace = true
6 | edition.workspace = true
7 | rust-version.workspace = true
8 | license.workspace = true
9 |
10 | [dependencies]
11 | lightyear = { workspace = true, features = ["replication"] }
12 | bevy.workspace = true
13 | serde.workspace = true
14 |
15 | [lints]
16 | workspace = true
17 |
18 | [[bin]]
19 | name = "compiletime"
20 | doc = false
21 |
--------------------------------------------------------------------------------
/benches/divan/bench.sh:
--------------------------------------------------------------------------------
1 | # Run the benchmark and generate a flamegraph.
2 | # The env variables are needed to have debug symbols even in release mode.
3 | CARGO_PROFILE_RELEASE_DEBUG=true RUSTFLAGS='-C force-frame-pointers=y' cargo bench --bench=replication --profile=release -- send_float_insert/1 --nocapture --profile-time=10
4 |
5 | # Run the flamegraph separately
6 | CARGO_PROFILE_RELEASE_DEBUG=true RUSTFLAGS='-C force-frame-pointers=y' cargo flamegraph --root --bin=replication_profiling --profile=release
--------------------------------------------------------------------------------
/lightyear_metrics/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! # Lightyear UI
2 | #![no_std]
3 |
4 | extern crate alloc;
5 | #[cfg(feature = "std")]
6 | extern crate std;
7 |
8 | pub mod plugin;
9 | pub mod registry;
10 |
11 | pub use metrics;
12 | pub use metrics_util;
13 |
14 | pub mod prelude {
15 | pub use crate::plugin::{ClearBucketsSystem, MetricsPlugin};
16 | #[cfg(feature = "std")]
17 | pub use crate::registry::GLOBAL_RECORDER;
18 |
19 | pub use crate::registry::{MetricsRegistry, SearchResult};
20 | }
21 |
--------------------------------------------------------------------------------
/benches/criterion/bench.sh:
--------------------------------------------------------------------------------
1 | # Run the benchmark and generate a flamegraph.
2 | # The env variables are needed to have debug symbols even in release mode.
3 | CARGO_PROFILE_RELEASE_DEBUG=true RUSTFLAGS='-C force-frame-pointers=y' cargo bench --bench=replication --profile=release -- send_float_insert/1 --nocapture --profile-time=10
4 |
5 | # Run the flamegraph separately
6 | CARGO_PROFILE_RELEASE_DEBUG=true RUSTFLAGS='-C force-frame-pointers=y' cargo flamegraph --root --bin=replication_profiling --profile=release
7 |
8 | #
--------------------------------------------------------------------------------
/certificates/generate.sh:
--------------------------------------------------------------------------------
1 | # Generates a self-signed certificate valid for 14 days, to use for webtransport
2 | # run this from the root folder
3 | OUT=certificates
4 | openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -keyout $OUT/key.pem -out $OUT/cert.pem -days 14 -nodes -subj "/CN=localhost"
5 |
6 | FINGERPRINT=$(openssl x509 -in "$OUT/cert.pem" -noout -sha256 -fingerprint | sed 's/^.*=//' | sed 's/://g')
7 | printf '%s' "$FINGERPRINT" > $OUT/digest.txt
8 |
9 | echo "Wrote new fingerprint $FINGERPRINT to $OUT/digest.txt"
--------------------------------------------------------------------------------
/examples/auth/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/fps/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/demos/spaceships/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/lobby/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/priority/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/lightyear_utils/src/collections.rs:
--------------------------------------------------------------------------------
1 | #[allow(unused)]
2 | // these are wrappers around HashMap and HashSet that use the EntityHasher
3 | pub use bevy_ecs::entity::{hash_map::EntityHashMap, hash_set::EntityHashSet};
4 |
5 | use bevy_platform::hash::FixedHasher;
6 |
7 | // bevy's HashMap is `hashbrown::HashMap` which causes issues with type inference
8 | // Adding this type alias to help with inference
9 | pub type HashMap = hashbrown::HashMap;
10 | pub type HashSet = hashbrown::HashSet;
11 |
--------------------------------------------------------------------------------
/book/src/tutorial/title.md:
--------------------------------------------------------------------------------
1 | # Tutorial
2 |
3 | This section will teach you how to quickly setup networking in your bevy game using lightyear.
4 |
5 | You can find many examples in the [examples](https://github.com/cBournhonesque/lightyear/tree/main/examples) folder.
6 |
7 | In this tutorial, we will reproduce the [simple box example](https://github.com/cBournhonesque/lightyear/tree/main/examples/simple_box) that showcases
8 | how to:
9 | - setup a basic client/server app
10 | - replicate an entity from server to clients
11 | - add prediction and interpolation
--------------------------------------------------------------------------------
/examples/avian_physics/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/projectiles/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/simple_box/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/simple_setup/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/client_replication/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/delta_compression/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/network_visibility/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/replication_groups/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/lightyear_core/src/plugin.rs:
--------------------------------------------------------------------------------
1 | use crate::timeline::TimelinePlugin;
2 | use bevy_app::{App, Plugin};
3 | use bevy_time::TimePlugin;
4 | use core::time::Duration;
5 |
6 | pub struct CorePlugins {
7 | pub tick_duration: Duration,
8 | }
9 |
10 | impl Plugin for CorePlugins {
11 | fn build(&self, app: &mut App) {
12 | if !app.is_plugin_added::() {
13 | app.add_plugins(TimePlugin);
14 | }
15 | app.add_plugins(TimelinePlugin {
16 | tick_duration: self.tick_duration,
17 | });
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lightyear_tests/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![allow(unused_must_use)]
2 | /*! # Lightyear IO
3 |
4 | Low-level IO primitives for the lightyear networking library.
5 | This crate provides abstractions for sending and receiving raw bytes over the network.
6 | */
7 | #![cfg_attr(not(feature = "std"), no_std)]
8 |
9 | extern crate alloc;
10 | extern crate core;
11 |
12 | #[cfg(test)]
13 | #[cfg(feature = "test_utils")]
14 | mod client_server;
15 | pub mod protocol;
16 | pub mod stepper;
17 |
18 | #[cfg(test)]
19 | mod host_server;
20 |
21 | #[cfg(test)]
22 | mod multi_server;
23 |
--------------------------------------------------------------------------------
/examples/bevy_enhanced_inputs/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/distributed_authority/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/examples/deterministic_replication/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [build]
2 | # it is a good idea to specify your target here, to avoid losing incremental compilation when compiling to wasm
3 | # target = "aarch64-apple-darwin"
4 | rustflags = ["--cfg", "web_sys_unstable_apis"]
5 |
6 | [target.wasm32-unknown-unknown]
7 | runner = "wasm-server-runner"
8 |
9 | # Enable max optimizations for dependencies, but not for our code:
10 | [profile.dev.package."*"]
11 | opt-level = 3
12 |
13 | # Enable only a small amount of optimization in debug mode
14 | [profile.dev]
15 | opt-level = 1
16 |
--------------------------------------------------------------------------------
/lightyear_transport/src/packet/error.rs:
--------------------------------------------------------------------------------
1 | //! Errors for building packets
2 |
3 | use crate::channel::receivers::error::ChannelReceiveError;
4 | use lightyear_serde::SerializationError;
5 |
6 | pub type Result = core::result::Result;
7 | #[derive(thiserror::Error, Debug)]
8 | pub enum PacketError {
9 | #[error("serialization error: {0}")]
10 | Serialization(#[from] SerializationError),
11 | #[error("channel was not found")]
12 | ChannelNotFound,
13 | #[error("receiver channel error: {0}")]
14 | ChannelReceiveError(#[from] ChannelReceiveError),
15 | }
16 |
--------------------------------------------------------------------------------
/book/src/concepts/reliability/title.md:
--------------------------------------------------------------------------------
1 | # Reliability
2 |
3 | In this layer we add some mechanisms to be able to send and receive messages reliably or in a given order.
4 |
5 | It is similar to the [reliable](https://github.com/networkprotocol/reliable) layer created by Glenn Fiedler on top of his netcode.io code.
6 |
7 | This layer introduces:
8 | - reliability: make sure a packets is received by the remote peer
9 | - ordering: make sure packets are received in the same order they were sent
10 | - channels: allow to send packets on different channels, which can have different reliability and ordering guarantees
11 |
12 |
--------------------------------------------------------------------------------
/lightyear_inputs_bei/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! # Lightyear Inputs BEI
2 | //!
3 | //! This crate provides an integration between `lightyear` and `bevy-enhanced-input`.
4 | #![no_std]
5 |
6 | extern crate alloc;
7 | extern crate core;
8 | #[cfg(feature = "std")]
9 | extern crate std;
10 |
11 | pub mod input_message;
12 |
13 | mod marker;
14 | mod plugin;
15 | mod setup;
16 |
17 | pub mod prelude {
18 | pub use crate::input_message::BEIBuffer;
19 | pub use crate::marker::InputMarker;
20 | pub use crate::plugin::InputPlugin;
21 | pub use crate::setup::InputRegistryExt;
22 | pub use bevy_enhanced_input::prelude::*;
23 | }
24 |
--------------------------------------------------------------------------------
/certificates/cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIBfTCCASOgAwIBAgIUTp0sb9+yFqebXU5Dwq/5o1LCocowCgYIKoZIzj0EAwIw
3 | FDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI1MTAxMzIyMjU1N1oXDTI1MTAyNzIy
4 | MjU1N1owFDESMBAGA1UEAwwJbG9jYWxob3N0MFkwEwYHKoZIzj0CAQYIKoZIzj0D
5 | AQcDQgAEf+vsmt6gA/FFkCqLHp1DvF2XJAxYOLEb5mr/cS9RGyigXSwIo8zKabVI
6 | PCXZX8+EpNFBQPB4Wdq87+0lsrsOgqNTMFEwHQYDVR0OBBYEFP9hzrrzQYvAvzAh
7 | GDdfyUGlbg6IMB8GA1UdIwQYMBaAFP9hzrrzQYvAvzAhGDdfyUGlbg6IMA8GA1Ud
8 | EwEB/wQFMAMBAf8wCgYIKoZIzj0EAwIDSAAwRQIgN+92ZlxxntlpwOEB9B6pvdvm
9 | HPR7tI1qPN83CZnWjaICIQDrISGOPTLXPJfbsUpcABO48k114AVDasILxT7G1ilb
10 | cw==
11 | -----END CERTIFICATE-----
12 |
--------------------------------------------------------------------------------
/lightyear_transport/src/channel/mod.rs:
--------------------------------------------------------------------------------
1 | /*! Channels are used to add reliability/ordering on top of the transport layer
2 | */
3 |
4 | pub use crate::channel::registry::ChannelKind;
5 |
6 | pub mod builder;
7 | pub mod receivers;
8 | pub mod senders;
9 |
10 | pub mod registry;
11 | #[cfg(feature = "trace")]
12 | pub mod stats;
13 |
14 | /// A Channel is used to specify some properties of how the bytes are sent over the network.
15 | ///
16 | /// The properties can be specified using the [`ChannelSettings`](crate::prelude::ChannelSettings).
17 | pub trait Channel: Send + Sync + 'static {}
18 | impl Channel for T {}
19 |
--------------------------------------------------------------------------------
/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [alias]
2 | # we need to run all tests with a single thread otherwise the `mock_instant::global::Instant` gets
3 | # overwritten in parallel tests
4 | t = "test -- --test-threads=1"
5 | clip = "clippy --workspace --features=lightyear_core/not_mock --exclude=compiletime --exclude=avian_3d_character --exclude=launcher --exclude=delta_compression --exclude=distributed_authority --no-deps -- -D warnings -A clippy::needless_lifetimes"
6 |
7 | [unstable]
8 | profile-rustflags = true
9 |
10 | [profile.profiling]
11 | inherits = "release"
12 | # only works in nightly
13 | #rustflags = [
14 | # "-C",
15 | # "force-frame-pointers=yes",
16 | # "-C",
17 | # "symbol-mangling-version=v0",
18 | #]
19 | debug = true
20 |
--------------------------------------------------------------------------------
/lightyear_tests/src/client_server/connection.rs:
--------------------------------------------------------------------------------
1 | //! Check various replication scenarios between 2 peers only
2 |
3 | use crate::stepper::*;
4 | use bevy::prelude::{Entity, With};
5 | use lightyear_connection::client_of::ClientOf;
6 | use test_log::test;
7 |
8 | #[test]
9 | fn test_disconnection() {
10 | let mut stepper = ClientServerStepper::from_config(StepperConfig::single());
11 |
12 | stepper.disconnect_client();
13 |
14 | // check that the client is not present in the server world
15 | assert!(
16 | stepper
17 | .server_app
18 | .world_mut()
19 | .query_filtered::>()
20 | .single(stepper.server_app.world())
21 | .is_err()
22 | );
23 | }
24 |
--------------------------------------------------------------------------------
/lightyear_replication/src/impls/avian3d.rs:
--------------------------------------------------------------------------------
1 | use crate::delta::Diffable;
2 | use avian3d::prelude::{Position, Rotation};
3 |
4 | impl Diffable for Position {
5 | fn base_value() -> Self {
6 | Position::default()
7 | }
8 |
9 | fn diff(&self, new: &Self) -> Self {
10 | Position::from(new.0 - self.0)
11 | }
12 |
13 | fn apply_diff(&mut self, delta: &Self) {
14 | self.0 += **delta;
15 | }
16 | }
17 |
18 | impl Diffable for Rotation {
19 | fn base_value() -> Self {
20 | Rotation::default()
21 | }
22 |
23 | fn diff(&self, new: &Self) -> Self {
24 | Rotation(new.0 * *self.inverse())
25 | }
26 |
27 | fn apply_diff(&mut self, delta: &Self) {
28 | self.0 *= delta.0;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/book/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | To contribute to the book, you wil need `mdbook`, `mdbook-mermaid`, and `mdbook-linkcheck` installed.
4 | These can be installed through `cargo install` or through your package manager:
5 |
6 | ```sh
7 | cargo install mdbook mdbook-mermaid mdbook-linkcheck
8 | ```
9 |
10 | They are also available as packages in Nix:
11 |
12 | ```sh
13 | nix-shell -p mdbook mdbook-mermaid mdbook-linkcheck
14 | ```
15 |
16 | You will need to install `mdbook-mermaid`'s CSS/JS into the book's `book` directory:
17 |
18 | ```sh
19 | mdbook-mermaid install book
20 | ```
21 |
22 | You can now serve the book locally:
23 |
24 | ```sh
25 | mdbook serve book
26 | ```
27 |
28 | For more information, please consult the [mdBook documentation](https://rust-lang.github.io/mdBook/).
--------------------------------------------------------------------------------
/lightyear_sync/src/plugin.rs:
--------------------------------------------------------------------------------
1 | use crate::ping::plugin::PingPlugin;
2 | use bevy_app::{App, Plugin, PostUpdate};
3 | use bevy_ecs::schedule::SystemSet;
4 |
5 | #[deprecated(note = "Use SyncSystems instead")]
6 | pub type SyncSet = SyncSystems;
7 |
8 | #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone, Copy)]
9 | pub enum SyncSystems {
10 | /// Sync SyncedTimelines to the Remote timelines using networking information (RTT/jitter) from the PingManager
11 | Sync,
12 | }
13 |
14 | pub struct TimelineSyncPlugin;
15 |
16 | impl Plugin for TimelineSyncPlugin {
17 | fn build(&self, app: &mut App) {
18 | if !app.is_plugin_added::() {
19 | app.add_plugins(PingPlugin);
20 | }
21 | app.configure_sets(PostUpdate, SyncSystems::Sync);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lightyear_replication/src/impls/avian2d.rs:
--------------------------------------------------------------------------------
1 | use crate::delta::Diffable;
2 | use avian2d::prelude::{Position, Rotation};
3 |
4 | impl Diffable for Position {
5 | fn base_value() -> Self {
6 | Position::default()
7 | }
8 |
9 | fn diff(&self, new: &Self) -> Position {
10 | Position(new.0 - self.0)
11 | }
12 |
13 | fn apply_diff(&mut self, delta: &Position) {
14 | self.0 += **delta;
15 | }
16 | }
17 |
18 | impl Diffable for Rotation {
19 | fn base_value() -> Self {
20 | Rotation::default()
21 | }
22 |
23 | fn diff(&self, new: &Self) -> Rotation {
24 | Rotation::radians(self.angle_between(*new))
25 | }
26 |
27 | fn apply_diff(&mut self, delta: &Rotation) {
28 | *self = self.add_angle_fast(delta.as_radians());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/book/src/concepts/transport/title.md:
--------------------------------------------------------------------------------
1 | # Transport
2 |
3 | The `Transport` trait is the trait that is used to send and receive raw data on the network.
4 |
5 | It is very general:
6 |
7 | ```rust,noplayground
8 | pub trait PacketSender: Send + Sync {
9 | /// Send data on the socket to the remote address
10 | fn send(&mut self, payload: &[u8], address: &SocketAddr) -> Result<()>;
11 | }
12 | pub trait PacketReceiver: Send + Sync {
13 | /// Receive a packet from the socket. Returns the data read and the origin.
14 | ///
15 | /// Returns Ok(None) if no data is available
16 | fn recv(&mut self) -> Result