Quantum 3 3.0.1

Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Quantum.FrameTimer Struct Reference

Built-in timer struct for game logic. More...

Public Member Functions

readonly int ElapsedFrames (FrameBase frame)
 How many frames or ticks since the timer was started. More...
 
readonly FP ElapsedSeconds (FrameBase frame)
 How long since the timer has started in seconds. More...
 
override int GetHashCode ()
 Overrides the hash code generation of this type. More...
 
readonly bool HasStoppedThisFrame (FrameBase frame)
 Has the timer expired during this frame. More...
 
readonly bool IsRunning (FrameBase frame)
 Is the timer set and still running. More...
 
readonly int RemainingFrames (FrameBase frame)
 How many frames are remaining until the timer expires. More...
 
readonly FP RemainingSeconds (FrameBase frame)
 How much time is remaining until the timer expires in seconds. More...
 
void Restart (FrameBase frame)
 Restarts the timer. More...
 

Static Public Member Functions

static FrameTimer FromFrames (FrameBase frame, int durationInFrames)
 Create a new timer from a delay in frames. More...
 
static FrameTimer FromSeconds (FrameBase frame, FP durationInSeconds)
 Create a new timer from a delay in seconds. More...
 
static void Serialize (void *ptr, IDeterministicFrameSerializer serializer)
 Serializes a FrameTimer into a FrameSerializer to write or read from a frame snapshot. More...
 

Public Attributes

readonly bool IsSet => TargetFrame >= StartFrame && StartFrame > 0
 If the timer is has been set. A valid timer has a StartFrame greater than 0 and the target frame TargetFrame greater than or equal to the StartFrame. More...
 
int StartFrame
 The frame number at which the timer has started. More...
 
int TargetFrame
 The frame number at which the timer will run out. More...
 

Static Public Attributes

static FrameTimer None = default
 Empty timer. More...
 
const int SIZE = sizeof(int) * 2
 The size of the component (or struct/type) in-memory inside the Frame data-buffers or stack (when passed as value parameter). Not related to the snapshot payload this occupies, which is bit-packed and compressed. More...
 

Detailed Description

Built-in timer struct for game logic.

Member Function Documentation

◆ IsRunning()

readonly bool Quantum.FrameTimer.IsRunning ( FrameBase  frame)

Is the timer set and still running.

Parameters
frameThe current Frame instance.
Returns
true if the timer is valid and the current frame > number is smaller than TargetFrame. false otherwise.

◆ HasStoppedThisFrame()

readonly bool Quantum.FrameTimer.HasStoppedThisFrame ( FrameBase  frame)

Has the timer expired during this frame.

Parameters
frameThe current Frame instance.
Returns
true if the timer is not expired and the current frame number is equal to TargetFrame. false otherwise.

Useful for one time operations that happen only at timer expiry.

◆ RemainingFrames()

readonly int Quantum.FrameTimer.RemainingFrames ( FrameBase  frame)
inline

How many frames are remaining until the timer expires.

Parameters
frameThe current Frame instance.
Returns
TargetFrame - current Frame number. Never returns a negative value.

◆ RemainingSeconds()

readonly FP Quantum.FrameTimer.RemainingSeconds ( FrameBase  frame)
inline

How much time is remaining until the timer expires in seconds.

Parameters
frameThe current Frame instance.
Returns
Multiplies the remaining frame count by the frame delta time.

◆ ElapsedFrames()

readonly int Quantum.FrameTimer.ElapsedFrames ( FrameBase  frame)
inline

How many frames or ticks since the timer was started.

Parameters
frameThe current Frame instance.
Returns
Returns current frame number - the start frame number. Never returns a negative value.

◆ ElapsedSeconds()

readonly FP Quantum.FrameTimer.ElapsedSeconds ( FrameBase  frame)
inline

How long since the timer has started in seconds.

Parameters
frameThe current Frame instance.
Returns
Returns the timer since the timer start. Never returns a negative value.

◆ Restart()

void Quantum.FrameTimer.Restart ( FrameBase  frame)
inline

Restarts the timer.

Parameters
frameThe current Frame instance.

◆ FromSeconds()

static FrameTimer Quantum.FrameTimer.FromSeconds ( FrameBase  frame,
FP  durationInSeconds 
)
inlinestatic

Create a new timer from a delay in seconds.

Parameters
frame
durationInSeconds
Returns
A new FrameTimer instance with the specified duration.

◆ FromFrames()

static FrameTimer Quantum.FrameTimer.FromFrames ( FrameBase  frame,
int  durationInFrames 
)
inlinestatic

Create a new timer from a delay in frames.

Parameters
frameThe current Frame instance.
durationInFramesThe number of frames to wait before the timer expires.
Returns
A new FrameTimer instance with the specified duration.

◆ Serialize()

static void Quantum.FrameTimer.Serialize ( void *  ptr,
IDeterministicFrameSerializer  serializer 
)
inlinestatic

Serializes a FrameTimer into a FrameSerializer to write or read from a frame snapshot.

Parameters
ptrThe pointer to the FrameTimer.
serializerThe FrameSerializer instance into which the struct will be serialized.

◆ GetHashCode()

override int Quantum.FrameTimer.GetHashCode ( )
inline

Overrides the hash code generation of this type.

Returns
A hash code of the current state of this instance.

Member Data Documentation

◆ SIZE

const int Quantum.FrameTimer.SIZE = sizeof(int) * 2
static

The size of the component (or struct/type) in-memory inside the Frame data-buffers or stack (when passed as value parameter). Not related to the snapshot payload this occupies, which is bit-packed and compressed.

◆ None

FrameTimer Quantum.FrameTimer.None = default
static

Empty timer.

◆ TargetFrame

int Quantum.FrameTimer.TargetFrame

The frame number at which the timer will run out.

◆ StartFrame

int Quantum.FrameTimer.StartFrame

The frame number at which the timer has started.

◆ IsSet

readonly bool Quantum.FrameTimer.IsSet => TargetFrame >= StartFrame && StartFrame > 0

If the timer is has been set. A valid timer has a StartFrame greater than 0 and the target frame TargetFrame greater than or equal to the StartFrame.