nova-net-0.3.0.0: General-purpose reliable UDP with C99 hot path and Haskell protocol logic
Safe HaskellSafe-Inferred
LanguageHaskell2010

NovaNet.Replication.Interpolation

Description

SnapshotBuffer stores timestamped snapshots and interpolates between them at a configurable playback delay, enabling smooth rendering despite network jitter.

Synopsis

Constants

defaultBufferDepth :: Int Source #

Default number of snapshots to buffer before interpolation begins.

defaultPlaybackDelayMs :: Double Source #

Default playback delay in milliseconds behind the latest snapshot.

Interpolatable typeclass

class Interpolatable a where Source #

Types that support linear interpolation between two states.

Methods

lerp :: a -> a -> Double -> a Source #

Linearly interpolate between a and b by factor t in [0, 1].

Instances

Instances details
Interpolatable Double Source # 
Instance details

Defined in NovaNet.Replication.Interpolation

Methods

lerp :: Double -> Double -> Double -> Double Source #

Interpolatable Float Source # 
Instance details

Defined in NovaNet.Replication.Interpolation

Methods

lerp :: Float -> Float -> Double -> Float Source #

(Interpolatable a, Interpolatable b) => Interpolatable (a, b) Source # 
Instance details

Defined in NovaNet.Replication.Interpolation

Methods

lerp :: (a, b) -> (a, b) -> Double -> (a, b) Source #

(Interpolatable a, Interpolatable b, Interpolatable c) => Interpolatable (a, b, c) Source # 
Instance details

Defined in NovaNet.Replication.Interpolation

Methods

lerp :: (a, b, c) -> (a, b, c) -> Double -> (a, b, c) Source #

Snapshot buffer

data SnapshotBuffer a Source #

Ring buffer of timestamped snapshots with interpolation sampling.

newSnapshotBuffer :: SnapshotBuffer a Source #

Create a snapshot buffer with default settings.

newSnapshotBufferWithConfig :: Int -> Double -> SnapshotBuffer a Source #

Create a snapshot buffer with custom settings.

Operations

pushSnapshot :: Double -> a -> SnapshotBuffer a -> SnapshotBuffer a Source #

Push a new snapshot with its server timestamp (milliseconds). Out-of-order snapshots are dropped.

sampleSnapshot :: Interpolatable a => Double -> SnapshotBuffer a -> Maybe a Source #

Sample an interpolated state at renderTime (milliseconds). Returns Nothing if fewer than 2 snapshots are buffered.

snapshotReset :: SnapshotBuffer a -> SnapshotBuffer a Source #

Clear all buffered snapshots.

Queries

snapshotCount :: SnapshotBuffer a -> Int Source #

Number of buffered snapshots.

snapshotIsEmpty :: SnapshotBuffer a -> Bool Source #

Whether the buffer is empty.

snapshotReady :: SnapshotBuffer a -> Bool Source #

Whether enough snapshots are buffered to begin interpolation.

snapshotPlaybackDelayMs :: SnapshotBuffer a -> Double Source #

Get the playback delay in milliseconds.

Configuration

setPlaybackDelayMs :: Double -> SnapshotBuffer a -> SnapshotBuffer a Source #

Set the playback delay in milliseconds.