Photon Quantum 3.0.0

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

Built in timer used for timing game logic. More...

Public Member Functions

override int GetHashCode ()
 Overrides the hash code generation of this type. More...
 
bool IsExpired (FrameBase frame)
 If the timer is valid and has expired. More...
 
bool IsExpiredOrNotValid (FrameBase frame)
 If the timer is not valid or has expired. More...
 
bool IsExpiredThisFrame (FrameBase frame)
 If the timer expired during this frame. More...
 
bool IsRunning (FrameBase frame)
 If the timer is not expired. More...
 
int? RemainingFrames (FrameBase frame)
 How many frames are remaining until the timer expires. More...
 
FPRemainingTime (FrameBase frame)
 How much time is remaining until the timer expires. More...
 
void Restart (FrameBase frame)
 Restarts the timer. More...
 
int? TimeInFramesSinceStart (FrameBase frame)
 How long since the timer has started in frames. More...
 
FPTimeInSecondsSinceStart (FrameBase frame)
 How long since the timer has started in seconds. More...
 

Static Public Member Functions

static FrameTimer FromFrames (FrameBase frame, int frames)
 Create a new timer from a delay in frames. More...
 
static FrameTimer FromSeconds (FrameBase frame, FP delayInSeconds)
 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

bool IsValid => Value >= StartFrame && StartFrame > 0
 If the timer is valid. A valid timer has a StartFrame greater than 0 and the target frame Value greater than or equal to the StartFrame. More...
 
int StartFrame
 The frame number at which the timer has started. More...
 
int? TargetFrame => IsValid ? Value : default
 The target frame of the timer, if the timer is valid. More...
 
int Value
 The frame number at which the timer will expire. 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 used for timing game logic.

Member Function Documentation

◆ IsExpired()

bool Quantum.FrameTimer.IsExpired ( FrameBase  frame)

If the timer is valid and has expired.

Parameters
frameThe current Frame instance.
Returns
true if the timer is valid and the current frame number is greater than or equal to the target frame Value. false othewise.

◆ IsExpiredThisFrame()

bool Quantum.FrameTimer.IsExpiredThisFrame ( FrameBase  frame)

If the timer expired during this frame.

Parameters
frameThe current Frame instance.
Returns
true if the timer is expired and the current frame number is equal to the target frame number Value. false othewise.

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

◆ IsRunning()

bool Quantum.FrameTimer.IsRunning ( FrameBase  frame)

If the timer is not expired.

Parameters
frameThe current Frame instance.
Returns
true if the timer is not expired. false otherwise.

◆ IsExpiredOrNotValid()

bool Quantum.FrameTimer.IsExpiredOrNotValid ( FrameBase  frame)

If the timer is not valid or has expired.

Parameters
frameThe current Frame instance.
Returns
true if the timer is expired or is not valid. false otherwise.

◆ RemainingFrames()

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

How many frames are remaining until the timer expires.

Parameters
frameThe current Frame instance.
Returns
If the timer is valid, the number of frames remaining until the timer expires. Otherwise, returns null.

◆ RemainingTime()

FP? Quantum.FrameTimer.RemainingTime ( FrameBase  frame)
inline

How much time is remaining until the timer expires.

Parameters
frameThe current Frame instance.
Returns
If the timer is valid, the remaining time in seconds until the timer expires, assuming that the frame FrameBase.DeltaTime will remain constant. Otherwise, returns null.

◆ TimeInFramesSinceStart()

int? Quantum.FrameTimer.TimeInFramesSinceStart ( FrameBase  frame)
inline

How long since the timer has started in frames.

Parameters
frameThe current Frame instance.
Returns
If the current frame is greater than or equal to the start frame, returns the difference between those values. Otherwise, returns null.

◆ TimeInSecondsSinceStart()

FP? Quantum.FrameTimer.TimeInSecondsSinceStart ( FrameBase  frame)
inline

How long since the timer has started in seconds.

Parameters
frameThe current Frame instance.
Returns
If the timer is valid, the time in seconds since the timer has started, assuming that the frame FrameBase.DeltaTime has remained constant. Otherwise, returns null.

◆ 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  delayInSeconds 
)
inlinestatic

Create a new timer from a delay in seconds.

Parameters
frame
delayInSeconds
Returns

◆ FromFrames()

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

Create a new timer from a delay in frames.

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

◆ 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.

◆ Value

int Quantum.FrameTimer.Value

The frame number at which the timer will expire.

◆ StartFrame

int Quantum.FrameTimer.StartFrame

The frame number at which the timer has started.

◆ IsValid

bool Quantum.FrameTimer.IsValid => Value >= StartFrame && StartFrame > 0

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

◆ TargetFrame

int? Quantum.FrameTimer.TargetFrame => IsValid ? Value : default

The target frame of the timer, if the timer is valid.

Returns
If the timer is valid, the target frame Value. Otherwise, returns null.