Module bones_framework::networking
source · Expand description
Networked multi-player plugin.
Bones uses a Peer-to-Peer, rollback networking model built on GGRS.
Messages are serialized/deserialized to a binary representation using serde
and the postcard
crate.
The major facets of our networking are:
- Matchmaking: How we connect clients to each-other and start an network match.
- Synchronization: How we synchronize a network game between multiple players.
§Matchmaking
There are currently two different matchmaking strategies: online
and lan
. Both of those
modules contain their own matchmaker with docs on how it works. Eventually we will probably have
additional matchmakers for Steam and the browser.
Regardless of the matchmaker, the goal is to find a match and establish a connection to the other
players. Once a match is established, the matchmaker must provide an implementation of
NetworkSocket
that may be used to send GGRS, reliable, and unreliable messages.
Each matchmaker is free to implement this socket with whatever networking transport they wish,
allowing the Steam matchmaker, for example, to use the steam networking library, and the browser
matchmaker to use WebTransport
or WebRTC
.
§Synchronization
Match synchronization, as mentioned above, is accomplished with GGRS, wich is a re-imagining of the GGPO network SDK.
The NetworkSocket
trait, which matchmakers are required to implement for their sockets, is
required to return an implementation of GGRS’s NonBlockingSocket
trait, so that it can send it’s
unreliable messages. The exact method for sending these messages depends on the matchmaker.
The key requirement for rollback networking is:
- The synchronized game loop must be deterministic.
- We must have the ability to snapshot and restore the game state.
- We must be able to run up to 8 game simulation frames in 16ms ( to achieve a 60 FPS frame rate, even in the case where we have to rollback and re-simulate ).
The integration with GGRS is implemented by the GgrsSessionRunner
.
§Input
GgrsSessionRunner
is generic over a couple of input traits, some of which have associated types with other trait bounds. This provides an API for game to define their input collection, control mapping, etc to be used by bones in networking.
§Development & Debugging
Here are some tips for debugging networking features while developing.
§Local Sync Test
It can be cumbersome to start a new networked match every time you need to troubleshoot some part of
the game that may not be rolling back or restoring properly. To help with this, you can run the game
with the --sync-test-check-distance 7
to make the game test rolling back and forward 8 times every
frame as a test when starting a local game.
This allows you to test the rollback without having to connect to a server. If things start popping around the map or having other weird behaviors that they don’t have without the sync-test mode, then you know you have a rollback issue.
ℹ️ Note: Just because you don’t have an issue in sync test mode, doesn’t mean that there is no determinism issues. You still have to test network games with multiple game instances. There are some non-determinism issues that only exhibit themselves when restarting the game.
Re-exports§
pub use crate::networking::random::RngGenerator;
Modules§
- Input traits required by networking. These traits are networking specific, either only used in networking, or extending other traits from
crate::input
for networking. - LAN matchmaking and socket implementation.
- Matchmaking
- Module prelude.
- Serializable data types for network messages used by the game.
- Global, deterministic RNG generation resource.
Structs§
- Resource tracking which players have been disconnected. May not be in world if no disconnects.
- Wraps
ggrs::Message
with includedmatch_id
, used to determine if message received from current match. - The
ggrs::Config
implementation used by Jumpy. SessionRunner
implementation that usesggrs
for network play.- The info required to create a
GgrsSessionRunner
. - Resource containing the
NetworkSocket
implementation while there is a connection to a network game. - A schema-compatible wrapper for ggrs
NetworkStats
struct contains networking stats.
Enums§
- Possible errors returned by network loop.
- Indicates if input from networking is confirmed, predicted, or if player is disconnected.
- The destination for a reliable network message.
- Resource updated each frame exposing syncing/networking information in the current session.
Constants§
- Default frame rate to run at if user provides none
- Muliplier for framerate that will be used when playing an online match.
- Amount of frames GGRS will delay local input.
- Number of frames client may predict beyond confirmed frame before freezing and waiting for inputs from other players. Default value if not specified in
GgrsSessionRunnerInfo
.
Statics§
- Runtime, needed to execute network related calls.
Traits§
- Automatically implemented for
NetworkSocket
+ggrs::NonBlockingSocket<usize>
. - Trait that must be implemented by socket connections establish by matchmakers.
Functions§
- Get the network endpoint used for all communications.