Crates.io | lightyear_examples_common |
lib.rs | lightyear_examples_common |
version | |
source | src |
created_at | 2024-05-16 14:21:29.196025 |
updated_at | 2025-01-28 01:41:30.526768 |
description | Common harness for the lightyear examples |
homepage | |
repository | https://github.com/cBournhonesque/lightyear |
max_upload_size | |
id | 1242104 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This folder contains various examples that showcase various lightyear
features.
The top level Cargo.toml
workspace defines the deps that examples can use and pick features from.
simple_setup
: minimal example that just shows how to create the lightyear client and server pluginssimple_box
: example that showcases how to send inputs from client to server, and how to add client-prediction and interpolationclient_replication
: example that shows how to replicate entities from the client to the server. (i.e. the client has authority)delta_compression
: example that shows how a component can be replicated with delta-compression enabled. Whenever the component value
changes, only the difference is sent over the network, instead of the full component value.interest_management
: example that shows how to use interest management to only replicate a subset of entities
to each player, via the VisibilityManager
and the RoomManager
replication_groups
: example that shows how to replicate entities that refer to other entities
(e.g. they have a component containing an Entity
id). You need to use ReplicationGroup
to ensure that the
those entities are replicated in the same messagepriority
: example that shows how to manage bandwidth by enabling priority accumulation. Messages will be sent in
order of their priority.avian_physics
: example that shows how to replicate a physics simulation using xpbd.
We also use the leafwing
feature for a better way to manage inputs.avian_3d_character
: example that shows clients controlling server-authoritative 3D objects simulated using avian.spaceships
: more advanced version of avian_physics
with player movement based on forces, fully server authoritative, predicted bullet spawning.fps
: example that shows how to spawn player-objects directly on the Predicted timeline, and how to use lag compensation to compute collisions between predicted and interpolated entities.auth
: an example that shows how a client can get a ConnectToken
to connect to a serverlobby
: an example that shows how the network topology can be changed at runtime.
Every client can potentially act as a host for the game (instead of the dedicated server).cargo run server
cargo run client -c 1
cargo run client -c 2
cargo run
or cargo run separate
cargo run --no-default-features --features=server
cargo run host-server
You can control the behaviour of the example by changing the list of features. By default, all features are enabled (client, server, gui).
For example you can run the server in headless mode (without gui) by running cargo run --no-default-features --features=server
.
You can modify the file assets/settings.ron
to modify some networking settings.
NOTE: I am using trunk to build and serve the wasm example.
To test the example in wasm, you can run the following commands: RUSTFLAGS='--cfg getrandom_backend="wasm_js"' trunk server --features=client
You will need a valid SSL certificate to test the example in wasm using webtransport. You will need to run the following commands:
cd "$(git rev-parse --show-toplevel)" && sh examples/certificates/generate.sh
(to generate the temporary SSL
certificates, they are only valid for 2 weeks)
cargo run -- server
to start the server. The server will print out the certificate digest (something
like 1fd28860bd2010067cee636a64bcbb492142295b297fd8c480e604b70ce4d644
)
You then have to replace the certificate digest in the assets/settings.ron
file with the one that the server printed
out.
then start the client wasm test with RUSTFLAGS='--cfg getrandom_backend="wasm_js"' trunk server --features=client
The common crate provides the initial UI setup along with a connect/disconnect button, and manages the bevygap stuff if needed.
# building the game server container
docker build -t examples -f examples/Dockerfile.server --progress=plain --build-arg examples="simple_box spaceships" .
# and to run, specify the example name as an env:
docker run --rm -it -e EXAMPLE_NAME=simple_box examples
# or with a key and an extra SANs for self-signed cert:
docker run --rm -it -e EXAMPLE_NAME=simple_box -e LIGHTYEAR_PRIVATE_KEY="1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1" -e SELF_SIGNED_SANS="example.com,10.1.2.3" examples