| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
NovaNet.Replication.Interpolation
Description
SnapshotBuffer stores timestamped snapshots and interpolates
between them at a configurable playback delay, enabling smooth
rendering despite network jitter.
Synopsis
- defaultBufferDepth :: Int
- defaultPlaybackDelayMs :: Double
- class Interpolatable a where
- data SnapshotBuffer a
- newSnapshotBuffer :: SnapshotBuffer a
- newSnapshotBufferWithConfig :: Int -> Double -> SnapshotBuffer a
- pushSnapshot :: Double -> a -> SnapshotBuffer a -> SnapshotBuffer a
- sampleSnapshot :: Interpolatable a => Double -> SnapshotBuffer a -> Maybe a
- snapshotReset :: SnapshotBuffer a -> SnapshotBuffer a
- snapshotCount :: SnapshotBuffer a -> Int
- snapshotIsEmpty :: SnapshotBuffer a -> Bool
- snapshotReady :: SnapshotBuffer a -> Bool
- snapshotPlaybackDelayMs :: SnapshotBuffer a -> Double
- setPlaybackDelayMs :: Double -> SnapshotBuffer a -> SnapshotBuffer a
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
| Interpolatable Double Source # | |
| Interpolatable Float Source # | |
| (Interpolatable a, Interpolatable b) => Interpolatable (a, b) Source # | |
Defined in NovaNet.Replication.Interpolation | |
| (Interpolatable a, Interpolatable b, Interpolatable c) => Interpolatable (a, b, c) Source # | |
Defined in NovaNet.Replication.Interpolation | |
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.