Table of Contents

Interface INetcodeSession<TInput>

Namespace
Backdash
Assembly
Backdash.dll

Context for a multiplayer game session.

public interface INetcodeSession<TInput> : INetcodeSessionInfo, IDisposable where TInput : unmanaged

Type Parameters

TInput

Game input type

Inherited Members

Properties

NumberOfPlayers

Returns the number of player in the current session

int NumberOfPlayers { get; }

Property Value

int

NumberOfSpectators

Returns the number of spectators in the current session

int NumberOfSpectators { get; }

Property Value

int

Random

Deterministic random value generator. This must be called after SynchronizeInputs()

IDeterministicRandom Random { get; }

Property Value

IDeterministicRandom

Methods

AddLocalInput(PlayerHandle, in TInput)

Used add local inputs and notify the netcode that they should be transmitted to remote players. This must be called once every frame for all player of type Local.

ResultCode AddLocalInput(PlayerHandle player, in TInput localInput)

Parameters

player PlayerHandle

Player owner of the inputs

localInput TInput

The input value

Returns

ResultCode

AddPlayer(Player)

Add the player into current session. Usually an instance of LocalPlayer, RemotePlayer or Spectator

ResultCode AddPlayer(Player player)

Parameters

player Player

Returns

ResultCode

Ok if success.

AddPlayers(IReadOnlyList<Player>)

Add a list of into current session. Usually instances of LocalPlayer, RemotePlayer or Spectator

IReadOnlyList<ResultCode> AddPlayers(IReadOnlyList<Player> players)

Parameters

players IReadOnlyList<Player>

Returns

IReadOnlyList<ResultCode>

A equivalent ResultCode list.

AdvanceFrame()

Should be called at the end of each frame of your application and also in AdvanceFrame().

void AdvanceFrame()

BeginFrame()

Should be called at the start of each frame of your application

void BeginFrame()

DisconnectPlayer(in PlayerHandle)

Disconnects a remote player from a game.

void DisconnectPlayer(in PlayerHandle player)

Parameters

player PlayerHandle

GetInput(in PlayerHandle)

Returns the value of a synchronized input for the requested player. This must be called after SynchronizeInputs()

ref readonly SynchronizedInput<TInput> GetInput(in PlayerHandle player)

Parameters

player PlayerHandle

Returns

SynchronizedInput<TInput>

GetInput(int)

Returns the value of a synchronized input for the requested player index. This must be called after SynchronizeInputs()

ref readonly SynchronizedInput<TInput> GetInput(int index)

Parameters

index int

Returns

SynchronizedInput<TInput>

GetInputs(Span<SynchronizedInput<TInput>>)

Copy the value of all synchronized inputs into the buffer. This must be called after SynchronizeInputs()

void GetInputs(Span<SynchronizedInput<TInput>> buffer)

Parameters

buffer Span<SynchronizedInput<TInput>>

GetInputs(Span<TInput>)

Copy the value of all synchronized inputs into the buffer. This must be called after SynchronizeInputs()

void GetInputs(Span<TInput> buffer)

Parameters

buffer Span<TInput>

GetNetworkStatus(in PlayerHandle, ref PeerNetworkStats)

Gets statistics and information about a player into info. Returns false if the request player is not connected or synchronized.

bool GetNetworkStatus(in PlayerHandle player, ref PeerNetworkStats info)

Parameters

player PlayerHandle
info PeerNetworkStats

Returns

bool

GetPlayerStatus(in PlayerHandle)

Returns connection status of a player.

PlayerConnectionStatus GetPlayerStatus(in PlayerHandle player)

Parameters

player PlayerHandle

Returns

PlayerConnectionStatus

GetPlayers()

Returns a list of all input players in the session.

IReadOnlyCollection<PlayerHandle> GetPlayers()

Returns

IReadOnlyCollection<PlayerHandle>

GetSpectators()

Returns a list of all spectators in the session.

IReadOnlyCollection<PlayerHandle> GetSpectators()

Returns

IReadOnlyCollection<PlayerHandle>

SetFrameDelay(PlayerHandle, int)

Change the amount of delay frames for local input.

void SetFrameDelay(PlayerHandle player, int delayInFrames)

Parameters

player PlayerHandle
delayInFrames int

SetHandler(INetcodeSessionHandler)

Set the handler for the current session. The client must call this before Start(CancellationToken).

void SetHandler(INetcodeSessionHandler handler)

Parameters

handler INetcodeSessionHandler

Start(CancellationToken)

Starts the background work for the session (Socket receiver, input queue, peer synchronization, etc.)

void Start(CancellationToken stoppingToken = default)

Parameters

stoppingToken CancellationToken

SynchronizeInputs()

Synchronizes the inputs of the local and remote players into a local buffer You should call this before every frame of execution, including those frames which happen during rollback.

ResultCode SynchronizeInputs()

Returns

ResultCode

WaitToStop(CancellationToken)

Waits the session background work to finish.

Task WaitToStop(CancellationToken stoppingToken = default)

Parameters

stoppingToken CancellationToken

Returns

Task