Photon Quantum 3.0.0

Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
Photon.Deterministic.DeterministicFrameRingBuffer Class Reference

The frame ring buffer is a utility collection class that stores a fixed number of latest frames in a ring buffer, usually in a certain time interval. A use-case for example are instant replays which allow to create a new simulation in the past time of the main simulation. More...

Inherits IDisposable.

Public Member Functions

 DeterministicFrameRingBuffer (int capacity)
 Create the frame ring buffer with a fixed capacity. More...
 
void Clear ()
 Clear all frames in the ring buffer. More...
 
DeterministicFrame Find (int frameNumber, DeterministicFrameSnapshotBufferFindMode findMode=DeterministicFrameSnapshotBufferFindMode.Equal)
 Find a frame that matches the desired frame number. More...
 
DeterministicFrame PeekBack (int offset=0)
 Return the frame at the head of the ring buffer. More...
 
void PushBack (DeterministicFrame frame, Func< DeterministicFrame > createFrame)
 Add a frame to the collection, the frame object is copied. If the collection is full the oldest frame will be overwritten. More...
 
void PushBack (DeterministicFrame frame, IDeterministicGame game, IDisposable context)
 Add a frame to the collection, the frame object is copied. If the collection is full the oldest frame will be overwritten. More...
 

Static Public Member Functions

static Int32 GetSize (Int32 window, Int32 samplingRate)
 Calculate the required size based for the ring buffer on the time window and sampling rate. More...
 
static bool TryGetCommonSamplingPattern (Int32 windowA, Int32 samplingA, Int32 windowB, Int32 samplingB, out Int32 commonWindow, out Int32 commonSampling)
 This method checks if there is a common sampling pattern between two windows of frames by comparing their sampling rates and window sizes. If a common pattern is found, it returns true and provides the common window size and sampling rate through the output parameters. Otherwise, it returns false and sets the output parameters to 0. More...
 

Public Attributes

DeterministicFrame[] Data => _data
 Returns the internal data array. More...
 

Properties

int Capacity [get]
 Returns the capacity of the ring buffer. More...
 
int Count [get]
 Returns the current count of frames in the ring buffer. More...
 
DeterministicFrame this[int index] [get]
 Access a frame by index. The index is relative to the head of the ring buffer, so index 0 is always the older frame stored. More...
 

Detailed Description

The frame ring buffer is a utility collection class that stores a fixed number of latest frames in a ring buffer, usually in a certain time interval. A use-case for example are instant replays which allow to create a new simulation in the past time of the main simulation.

Constructor & Destructor Documentation

◆ DeterministicFrameRingBuffer()

Photon.Deterministic.DeterministicFrameRingBuffer.DeterministicFrameRingBuffer ( int  capacity)
inline

Create the frame ring buffer with a fixed capacity.

Parameters
capacityRing buffer size
Exceptions
ArgumentExceptionIs raised when the capacity is smaller than 1

Member Function Documentation

◆ Clear()

void Photon.Deterministic.DeterministicFrameRingBuffer.Clear ( )
inline

Clear all frames in the ring buffer.

◆ Find()

DeterministicFrame Photon.Deterministic.DeterministicFrameRingBuffer.Find ( int  frameNumber,
DeterministicFrameSnapshotBufferFindMode  findMode = DeterministicFrameSnapshotBufferFindMode.Equal 
)
inline

Find a frame that matches the desired frame number.

Parameters
frameNumberThe desired frame number
findModeThe find mode
Returns
The best frame relative to the desired frame number or null

◆ PushBack() [1/2]

void Photon.Deterministic.DeterministicFrameRingBuffer.PushBack ( DeterministicFrame  frame,
IDeterministicGame  game,
IDisposable  context 
)
inline

Add a frame to the collection, the frame object is copied. If the collection is full the oldest frame will be overwritten.

Parameters
frameThe frame to save
gameGame object
contextContext object

◆ PushBack() [2/2]

void Photon.Deterministic.DeterministicFrameRingBuffer.PushBack ( DeterministicFrame  frame,
Func< DeterministicFrame createFrame 
)
inline

Add a frame to the collection, the frame object is copied. If the collection is full the oldest frame will be overwritten.

Parameters
frameThe frame to save
createFrameA callback to create a copy of the frame

◆ PeekBack()

DeterministicFrame Photon.Deterministic.DeterministicFrameRingBuffer.PeekBack ( int  offset = 0)
inline

Return the frame at the head of the ring buffer.

Parameters
offsetThe offset relative to the head
Returns
Frame object at the position
Exceptions
InvalidOperationExceptionIs raised when the collection is empty
IndexOutOfRangeExceptionIs raised when the offset is invalid or out of bounds

◆ TryGetCommonSamplingPattern()

static bool Photon.Deterministic.DeterministicFrameRingBuffer.TryGetCommonSamplingPattern ( Int32  windowA,
Int32  samplingA,
Int32  windowB,
Int32  samplingB,
out Int32  commonWindow,
out Int32  commonSampling 
)
inlinestatic

This method checks if there is a common sampling pattern between two windows of frames by comparing their sampling rates and window sizes. If a common pattern is found, it returns true and provides the common window size and sampling rate through the output parameters. Otherwise, it returns false and sets the output parameters to 0.

Parameters
windowATime window a in ticks
samplingASampling interval a
windowBTime window b in ticks
samplingBSampling interval b
commonWindowCommon time window
commonSamplingCommon sample rate
Returns
true if a common pattern was found

◆ GetSize()

static Int32 Photon.Deterministic.DeterministicFrameRingBuffer.GetSize ( Int32  window,
Int32  samplingRate 
)
inlinestatic

Calculate the required size based for the ring buffer on the time window and sampling rate.

Parameters
windowTime window in ticks
samplingRateSampling interval
Returns

Member Data Documentation

◆ Data

DeterministicFrame [] Photon.Deterministic.DeterministicFrameRingBuffer.Data => _data

Returns the internal data array.

Property Documentation

◆ Capacity

int Photon.Deterministic.DeterministicFrameRingBuffer.Capacity
get

Returns the capacity of the ring buffer.

◆ Count

int Photon.Deterministic.DeterministicFrameRingBuffer.Count
get

Returns the current count of frames in the ring buffer.

◆ this[int index]

DeterministicFrame Photon.Deterministic.DeterministicFrameRingBuffer.this[int index]
get

Access a frame by index. The index is relative to the head of the ring buffer, so index 0 is always the older frame stored.

Parameters
indexIndex of the current saves frames.
Returns
Frame object
Exceptions
ArgumentOutOfRangeExceptionIs raised when the desired index value is less than 0 or out of bounds Count