Time
This module contains functions for retrieving time-related information, such as the time since the program started, the time since the last frame, and the Unix time.
To use this module, include the following line in your project file:
require engine.time_core // or require engine.core
Note
All functions for delta time, if called from on_update() return how much real time passed from start of the previous frame to start of the current frame, times the scale for functions that don’t have unscaled in their name.
But if these functions are called from during physics simulation (from on_fixed_update() or collision callbacks), they return time between physics steps, which is always fixed delta time, and since time scale does not affect physics time step, both normal and unscaled functions will return unscaled delta time.
Functions
- get_clock(): clock
- Returns:
clock - the value that represents the time in seconds since 00:00 hours, Jan 1, 1970 UTC (i.e., the current unix time)
Usage example:
let unixTime = get_clock() // note that the returned value is not an integer
let seconds = int64(unixTime)
- get_current_frame(): uint64
- Returns:
uint64 - the current frame number since the start of the program
- get_delta_time(): float
- Returns:
float - the time in seconds since the last frame to the current frame. For physics (inside on_fixed_update() or collision callbacks) this is the time between physics steps, which is always unscaled fixed delta time. This applies for all delta time functions.
- get_delta_time_msec(): int
- Returns:
int - the time in milliseconds since the last frame to the current frame
- get_delta_time_scale(): float
- Returns:
float - the time scaling factor
- get_delta_time_usec(): int
- Returns:
int - the time in microseconds since the last on_update call
- get_sync_time(): float
- Returns:
float - the time in seconds synced between client & server
- get_time(): float
- Returns:
float - the time in seconds since the start of the program to the current frame
- get_time(ref: int64): float
- Arguments:
ref : int64 - the reference time, get it with
ref_time_ticks()
- Returns:
float - the time in seconds since the reference time
Usage example:
let refTime = ref_time_ticks()
// do something
let elapsedTimeSec = get_time(refTime)
- get_time_msec(): int64
- Returns:
int64 - the time in milliseconds since the start of the program to the current frame
- get_time_msec(ref: int64): int
retrieves the time in milliseconds since the reference time
Usage example:
let refTime = ref_time_ticks()
// do something
let elapsedTimeMsec = get_time_msec(refTime)
- Arguments:
ref : int64 - the reference time, get it with
ref_time_ticks()
- Returns:
int - the time in milliseconds since the specified tick
- get_time_nsec(ref: int64): int64
Retrieves the time in nanoseconds since the reference time.
- Usage example::
let refTime = ref_time_ticks() // do something let elapsedTimeNsec = get_time_nsec(refTime)
- Arguments:
ref : int64 - the reference time, get it with
ref_time_ticks()
- Returns:
int64 - the time in nanoseconds since the specified tick
- get_time_usec(): int64
- Returns:
int64 - the time in microseconds since the start of the program
- get_time_usec(ref: int64): int
Retrieves the time in microseconds since the reference time.
- Usage example::
let refTime = ref_time_ticks() // do something let elapsedTimeUsec = get_time_usec(refTime)
- Arguments:
ref : int64 - the reference time, get it with
ref_time_ticks()
- Returns:
int - the time in microseconds since the specified tick
- get_unscaled_delta_time(): float
- Returns:
float - the time in seconds since the last frame to the current frame, ignoring time scaling
- get_unscaled_delta_time_msec(): int
- Returns:
int - the time in milliseconds since the last frame to the current frame, ignoring time scaling
- get_unscaled_delta_time_usec(): int
- Returns:
int - the time in microseconds since the last on_update call, ignoring time scaling
- get_unscaled_time(): float
- Returns:
float - the time in seconds since the start of the program to the current frame, ignoring time scaling
- get_unscaled_time_msec(): int64
- Returns:
int64 - the time in milliseconds since the start of the program to the current frame, ignoring time scaling
- get_unscaled_time_usec(): int64
- Returns:
int64 - the time in microseconds since the start of the program, ignoring time scaling
- ref_time_ticks(): int64
- Returns:
int64 - the current reference timer tick value
- set_delta_time_scale(scale: float): float
Change the time scaling factor. The value is clamped to the range [0.0, 1000.0] and the new time scaling factor is returned. Note that time scale does not affect physics time step. If you need physics step to also scale, you’ll have to change it separately with set_physics_fps().
- Arguments:
scale : float - the factor to scale the time by
- Returns:
float - the new time scaling factor