Built-in timer struct for game logic that counts FrameBase.GameTick instead of the frame number. Pausing or slowing down the game time (see FrameBase.GameTimeScale) pauses or slows down this timer.
More...
|
| static readonly GameTimer | None = default |
| | Empty timer. More...
|
| |
| const int | SIZE = FP.SIZE * 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...
|
| |
Built-in timer struct for game logic that counts FrameBase.GameTick instead of the frame number. Pausing or slowing down the game time (see FrameBase.GameTimeScale) pauses or slows down this timer.
◆ DurationNormalized()
| readonly FP Quantum.GameTimer.DurationNormalized |
( |
FrameBase |
frame | ) |
|
|
inline |
The progress of the timer between 0 (just started) and 1 (expired), e.g. to display a cooldown.
- Parameters
-
| frame | The current Frame instance. |
- Returns
- The elapsed ticks divided by the Duration, clamped to [0, 1]. 1 for a set timer with a duration of 0, 0 if the timer is not set.
◆ IsRunning()
| readonly bool Quantum.GameTimer.IsRunning |
( |
FrameBase |
frame | ) |
|
Is the timer set and still running.
- Parameters
-
| frame | The current Frame instance. |
- Returns
true if the timer is valid and the current game tick is smaller than TargetTick. false otherwise.
◆ HasStoppedThisTick()
| readonly bool Quantum.GameTimer.HasStoppedThisTick |
( |
FrameBase |
frame | ) |
|
Has the timer expired during this frame.
- Parameters
-
| frame | The current Frame instance. |
- Returns
true if the timer is valid and the game tick reached or passed TargetTick during this frame. false otherwise.
Useful for one time operations that happen only at timer expiry. Only true once per expiry, also while the game tick is paused or slowed down. Never true while paused: a timer with a duration of 0 started while paused stops in the first frame the game tick advances again.
◆ RemainingTicks()
| readonly FP Quantum.GameTimer.RemainingTicks |
( |
FrameBase |
frame | ) |
|
|
inline |
How many game ticks are remaining until the timer expires.
- Parameters
-
| frame | The current Frame instance. |
- Returns
- TargetTick - current game tick. Never returns a negative value.
◆ RemainingSeconds()
| readonly FP Quantum.GameTimer.RemainingSeconds |
( |
FrameBase |
frame | ) |
|
|
inline |
How much game time is remaining until the timer expires in seconds.
- Parameters
-
| frame | The current Frame instance. |
- Returns
- Divides the remaining ticks by the simulation rate (FrameBase.UpdateRate). Never returns a negative value.
To get the real seconds until expiry divide by FrameBase.GameTimeScale (if it is above 0), which is only exact if the time scale does not change until the timer expires. While paused the timer does not expire.
◆ ElapsedTicks()
| readonly FP Quantum.GameTimer.ElapsedTicks |
( |
FrameBase |
frame | ) |
|
|
inline |
How many game ticks since the timer was started.
- Parameters
-
| frame | The current Frame instance. |
- Returns
- Returns current game tick - the start tick. Never returns a negative value.
◆ ElapsedSeconds()
| readonly FP Quantum.GameTimer.ElapsedSeconds |
( |
FrameBase |
frame | ) |
|
|
inline |
How much game time since the timer has started in seconds.
- Parameters
-
| frame | The current Frame instance. |
- Returns
- Divides the elapsed ticks by the simulation rate (FrameBase.UpdateRate). Never returns a negative value.
To get the real seconds since the start divide by FrameBase.GameTimeScale (if it is above 0), which is only exact if the time scale has not changed since the timer started.
◆ OvershootTicks()
| readonly FP Quantum.GameTimer.OvershootTicks |
( |
FrameBase |
frame | ) |
|
|
inline |
How many game ticks the game tick has passed TargetTick by, e.g. to place a spawn at the exact expiry point.
- Parameters
-
| frame | The current Frame instance. |
- Returns
- Current game tick - TargetTick. 0 while the timer is running or not set.
◆ OvershootSeconds()
| readonly FP Quantum.GameTimer.OvershootSeconds |
( |
FrameBase |
frame | ) |
|
|
inline |
How much game time the game tick has passed TargetTick by in seconds.
- Parameters
-
| frame | The current Frame instance. |
- Returns
- Divides the overshoot ticks by the simulation rate (FrameBase.UpdateRate). 0 while the timer is running or not set.
◆ Restart()
| void Quantum.GameTimer.Restart |
( |
FrameBase |
frame, |
|
|
bool |
keepOvershoot = false |
|
) |
| |
|
inline |
Restarts the timer with the same Duration.
- Parameters
-
| frame | The current Frame instance. |
| keepOvershoot | If true and the target is reached, the timer restarts at its previous TargetTick instead of the current game tick, keeping the ticks the game tick has already passed the target by. Use it for repeating timers (e.g. restarted when HasStoppedThisTick(FrameBase)) so the interval does not drift when the game tick does not land exactly on the target (e.g. while slowed down). A timer that is still running restarts at the current game tick in both modes. If the game tick passed more than one interval this frame (e.g. time scale above 1 and a short interval), the new target is already reached: HasStoppedThisTick(FrameBase) only reports it during this frame, so restart in a loop (while (timer.HasStoppedThisTick(f)) { timer.Restart(f, true); }) to handle every interval. Restarting only once leaves the target behind the game tick and the timer never stops again. |
A timer with a duration of 0 (or the 1 raw unit nudge) restarts to stop in the next frame the game tick advances, in both modes. Restarting it to the current game tick would stop it again during this frame (an endless restart loop) or never again.
◆ FromSeconds()
Create a new timer from a delay in seconds of game time.
The seconds are converted with the simulation rate (FrameBase.UpdateRate) instead of FrameBase.DeltaTime, so whole seconds are exact whole ticks at any rate (e.g. 1 second at 60 Hz is exactly 60 ticks, 1/60 cannot be stored exactly by FP).
- Parameters
-
| frame | The current Frame instance. |
| durationInSeconds | The game time in seconds to wait before the timer expires. |
- Returns
- A new GameTimer instance with the specified duration.
To expire after real seconds multiply them by FrameBase.GameTimeScale, which is only exact if the time scale does not change until the timer expires. While paused the timer does not expire.
◆ FromTicks()
Create a new timer from a delay in game ticks.
- Parameters
-
| frame | The current Frame instance. |
| durationInTicks | The game ticks to wait before the timer expires. |
- Returns
- A new GameTimer instance with the specified duration.
A duration of 0 started while paused (or before the first frame) gets a duration of 1 raw unit instead, so HasStoppedThisTick(FrameBase) reports it in the first frame the game tick advances again. Without it the target would be the game tick the next advance starts from, which is outside the range a stop is reported for.
◆ Serialize()
Serializes a GameTimer into a FrameSerializer to write or read from a frame snapshot.
- Parameters
-
| ptr | The pointer to the GameTimer. |
| serializer | The FrameSerializer instance into which the struct will be serialized. |
◆ GetHashCode()
| readonly override int Quantum.GameTimer.GetHashCode |
( |
| ) |
|
|
inline |
Overrides the hash code generation of this type.
- Returns
- A hash code of the current state of this instance.
◆ SIZE
| const int Quantum.GameTimer.SIZE = FP.SIZE * 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
| readonly GameTimer Quantum.GameTimer.None = default |
|
static |
◆ TargetTick
| FP Quantum.GameTimer.TargetTick |
The game tick at which the timer will run out.
◆ StartTick
| FP Quantum.GameTimer.StartTick |
The game tick at which the timer has started.
◆ IsSet
If the timer is has been set. A valid timer has a TargetTick greater than 0 and the target tick TargetTick greater than or equal to the StartTick.
◆ Duration