Skip to content

Commit

Permalink
de_net: Separate (non)reliable datagram counters (DigitalExtinction#604)
Browse files Browse the repository at this point in the history
This will simplify reliable datagram deduplication because it could be
assumed that there is only a small number of holes before the highest
received ID.
  • Loading branch information
Indy2222 authored Jul 6, 2023
1 parent 479d87c commit 843ba5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions crates/net/src/tasks/usender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ pub(super) async fn run(
) {
info!("Starting package sender on port {port}...");

let mut counter = PackageId::zero();
let mut counter_reliable = PackageId::zero();
let mut counter_unreliable = PackageId::zero();

loop {
let Ok(package) = packages.recv().await else {
break;
};

let header = DatagramHeader::new_package(package.reliable(), package.peers(), counter);
counter = counter.incremented();
let counter = if package.reliable() {
&mut counter_reliable
} else {
&mut counter_unreliable
};

let header = DatagramHeader::new_package(package.reliable(), package.peers(), *counter);
*counter = counter.incremented();

if let DatagramHeader::Package(package_header) = header {
if package_header.reliable() {
Expand Down
3 changes: 2 additions & 1 deletion docs/src/multiplayer/connector/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ by the mask `0b1000_0000`).

Each user package has an ID, encoded within the last three bytes of the
datagram header. These IDs increment until they reach the maximum value that
can be encoded within three bytes, after which the counter resets to 0.
can be encoded within three bytes, after which the counter resets to 0. The ID
sequence for reliable and unreliable packages are independent.

Packages can be transmitted in either reliable or non-reliable mode.
Reliability is signaled by the second highest bit of the flags byte
Expand Down

0 comments on commit 843ba5d

Please sign in to comment.