SetNet.Lockstep 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SetNet.Lockstep --version 1.1.0
                    
NuGet\Install-Package SetNet.Lockstep -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SetNet.Lockstep" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.Lockstep" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.Lockstep" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SetNet.Lockstep --version 1.1.0
                    
#r "nuget: SetNet.Lockstep, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SetNet.Lockstep@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SetNet.Lockstep&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.Lockstep&version=1.1.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>

SetNet.Lockstep

Deterministic lockstep engine for SetNet.

Two ways to network a game: replicate state (server streams positions — see SetNet.StateSync), or replicate inputs (every client runs the same simulation from the same inputs). The second is lockstep, and it's how most RTS games work: sending "player 2 ordered these 40 units to move" is tiny compared to streaming 40 unit positions every tick.

Here, the server collects each participant's input for a turn and — once all inputs are in (or the turn times out) — broadcasts the complete input set. Every client then advances its simulation by one turn, identically.

Install

dotnet add package SetNet
dotnet add package SetNet.Lockstep

Setup

LockstepRuntime.Enable();     // once at startup, both ends, before creating client/server

Server

server.UseLockstep(new LockstepOptions { TurnTimeoutMs = 200 });

The server auto-enrolls every connected peer as a participant, runs the turn clock, and relays inputs opaquely (it never deserializes them, so it stays serializer-agnostic).

Client (typed)

// choose your per-turn input type — (de)serialized via the registered serializer:
var ls = client.UseLockstep<PlayerCommand>();

ls.TurnReady += (turn, inputs) =>       // inputs: playerId -> PlayerCommand
{
    foreach (var (playerId, cmd) in inputs)
        Simulation.Apply(playerId, cmd);
    Simulation.Step();                  // advance exactly one deterministic tick
};

// each turn, submit your command:
ls.SubmitInput(new PlayerCommand { Move = dir, Fire = firing });

TurnReady hands you a IReadOnlyDictionary<string, PlayerCommand>fully typed, no raw bytes. Use client.UseLockstep<byte[]>() if you want to manage serialization yourself.

Determinism is on you

Lockstep only guarantees every client receives the same inputs in the same order. Whether they compute the same result depends on your simulation:

  • Prefer fixed-point or integer math; be careful with float (order-of-operations and platform differences can diverge).
  • Don't branch on non-replicated state (wall-clock time, Random without a shared seed, iteration order of unordered collections).
  • Step the simulation only in TurnReady, never in a render/Update loop.

A divergence (desync) means one client computed a different world — usually fatal for lockstep, so test with a periodic state checksum.

Options

Option Default Meaning
TurnTimeoutMs 200 Max wait for every participant's input before finalizing a turn anyway (drops laggards)

How it works

  • The server holds a turn number T. Clients submit an input tagged for their current turn.
  • A turn finalizes when all participants have submitted for it (fast path) or after TurnTimeoutMs (safety net). The finalized input set is broadcast; T advances.
  • Clients run a turn or two behind real time (the input delay), which is the standard lockstep trade-off for perfect consistency.
  • Reserved wire types 65514 / 65515.

Notes

  • Best for turn-based and RTS-style games; for fast action shooters prefer state replication + prediction.
  • A dropped/slow player is dropped from a turn after the timeout — handle "missing input" gracefully (e.g. repeat last command).

Documentation & source

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 94 8/5/2026
1.1.0 118 7/2/2026