Crates.io | lightyear |
lib.rs | lightyear |
version | 0.17.1 |
source | src |
created_at | 2023-02-04 19:00:07.28414 |
updated_at | 2024-08-30 17:14:50.097955 |
description | Server-client networking library for the Bevy game engine |
homepage | |
repository | https://github.com/cBournhonesque/lightyear |
max_upload_size | |
id | 776568 |
size | 1,924,730 |
A library for writing server-authoritative multiplayer games with Bevy. Compatible with wasm via WebTransport.
https://github.com/cBournhonesque/lightyear/assets/8112632/7b57d48a-d8b0-4cdd-a16f-f991a394c852
Demo using one server with 2 clients. The entity is predicted (slightly ahead of server) on the controlling client and interpolated (slightly behind server) on the other client. The server only sends updates to clients 10 times per second but the clients still see smooth updates.
You can first check out the examples.
To quickly get started, you can follow this tutorial, which re-creates the simple_box example.
You can also find more information in this WIP book.
Lightyear provides a simple API for sending and receiving messages, and for replicating entities and components:
Messages
, Components
, Inputs
that can be sent over
the network; as well as the Channels
to be used:// messages
app.add_message::<Message1>(ChannelDirection::Bidirectional);
// inputs
app.add_plugins(InputPlugin::<Inputs>::default());
// components
app.register_component::<PlayerId>(ChannelDirection::ServerToClient)
.add_prediction(ComponentSyncMode::Once)
.add_interpolation(ComponentSyncMode::Once);
// channels
app.add_channel::<Channel1>(ChannelSettings {
mode: ChannelMode::OrderedReliable(ReliableSettings::default()),
..default()
});
to enable replication, the user just needs to add a Replicate
bundle to entities that need to be replicated.
all network-related events are accessible via bevy Events
: EventReader<MessageEvent<MyMessage>>
or EventReader<EntitySpawnEvent>
I provide a certain number of bevy Resources
to interact with the library (InputManager
, ConnectionManager
, TickManager
,
etc.)
bincode
as a default serializer, but you can provide your own serialization functionClient
, and lightyear makes sure that the client input for tick N
will
be processed on tick N
on the server.
Inputs are protected against packet-loss: each packet will contain the client inputs for the last few frames.leafwing
feature, there is a special integration with
the leafwing-input-manager
crate, where
your leafwing
inputs are networked for you!Replicate
bundle will be automatically replicated to clients. Only the components that
change will be sent over the network. This functionality is similar to what bevy_replicon provides.Rooms
ClientConfig
and ServerConfig
structs.tracing
and metrics
libraries to emit spans and logs around most events (
sending/receiving messages, etc.). The metrics can be exported to Prometheus for analysis.bevy_xpbd_2d
Lightyear | Bevy |
---|---|
0.16-0.17 | 0.14 |
0.10-0.15 | 0.13 |
0.1-0.9 | 0.12 |