GithubHelp home page GithubHelp logo

msvbg / lightyear Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cbournhonesque/lightyear

0.0 1.0 0.0 30.1 MB

Networking library for the Bevy game engine

Home Page: https://cbournhonesque.github.io/lightyear/book

License: Apache License 2.0

Rust 99.99% Handlebars 0.01%

lightyear's Introduction

Lightyear

crates.io docs.rs codecov

A library for writing server-authoritative multiplayer games with Bevy. Compatibly with wasm via WebTransport.

Try the examples online!

53faada0-1a3d-476a-8e64-30a4c1502859.mp4

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.

Getting started

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.

Features

Ergonomic

Lightyear provides a simple API for sending and receiving messages, and for replicating entities and components:

  • the user needs to define a Protocol that defines all the messages, components, inputs that can be sent over the network; as well as the channels
  • to send messages, the user mostly only needs to interact with the Client<P> and Server<P> structs, which provide methods to send messages and send inputs
  • all messages are accessible via BevyEvents: EventReader<MessageEvent<MyMessage>> or EventReader<EntitySpawnEvent>
  • for replication, the user just needs to add a Replicate component to entities that need to be replicated.

Batteries-included

  • Transport-agnostic: Lightyear uses a very general Transport trait to send raw data on the network. The trait currently has two implementations:
    • UDP sockets
    • WebTransport (using QUIC): available on both native and wasm!
    • WebSocket: available on both native and wasm!
  • Serialization
    • Lightyear uses bitcode for serialization, which supports very compact serialization. It uses bit-packing (a bool will be serialized as a single bit).
  • Message passing
    • Lightyear supports sending packets with different guarantees of ordering and reliability through the use of channels.
    • Packet fragmentation (for messages larger than ~1200 bytes) is supported
  • Input handling
    • Lightyear has special handling for player inputs (mouse presses, keyboards). They are buffered every tick on the Client, and lightyear makes sure that the client input for tick N will be also 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.
    • With the leafwing feature, there is a special integration with the leafwing-input-manager crate, where your leafwing inputs are networked for you!
  • Replication
    • Entities that have the Replicate component 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.
  • Advanced replication
    • Client-side prediction: with just a one-line change, you can enable Prediction so that client inputs are immediately applied on the client, and then corrected by the server.
    • Snapshot interpolation: with just a one-line change, you can enable Snapshot interpolation so that entities are smoothly interpolated even if replicated infrequently.
    • Client-authoritative replication: you can also replicate entities from the client to the server.
    • Pre-spawning predicted entities: you can spawn Predicted entities on the client, and then replicate them to the server. This ensures that the entity is spawned immediately, but will still be controlled by the server.
    • Entity mapping: lightyear also supports replicating components/messages that contain references to other entities. The entities will be mapped from the local World to the remote World.
    • Interest management: lightyear supports replicating only a subset of the World to clients. Interest management is made flexible by the use of Rooms
    • Input Delay: you can add a custom amount of input-delay as a trade-off between having a more responsive game or more mis-predictions
    • Bandwidth Management: you can set a cap to the bandwidth for the connection. Then messages will be sent in decreasing order of priority (that you can set yourself).
  • Configurable
    • Lightyear is highly configurable: you can configure the size of the input buffer, the amount of interpolation-delay, the packet send rate, etc. All the configurations are accessible through the ClientConfig and ServerConfig structs.
  • Observability
    • Lightyear uses the 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.
  • Examples
    • Lightyear has plenty of examples demonstrating all these features, as well as the integration with other bevy crates such as bevy_xpbd_2d

Supported bevy version

Lightyear Bevy
0.10-0.12 0.13
0.1-0.9 0.12

lightyear's People

Contributors

cbournhonesque-sc avatar cbournhonesque avatar dependabot[bot] avatar nul-led avatar blinkdog avatar doonv avatar ant59 avatar nvzqz avatar rbouar avatar zwazel avatar df51d avatar healingdrawing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.