Time

C++ can update these internal values via the embed SAPI / extension.

Namespace:

namespace Lenga\Engine\Core;

class Time

Methods

time

public static function time()

C++ can update these internal values via the embed SAPI / extension.

unscaledTime

public static function unscaledTime()

Returns the real time elapsed since application start, unaffected by pause.

deltaTime

public static function deltaTime()

Returns the time elapsed since the last frame.

unscaledDeltaTime

public static function unscaledDeltaTime()

Returns the real frame delta time, unaffected by pause.

fixedDeltaTime

public static function fixedDeltaTime()

Returns the fixed delta time value.

fixedStepCount

public static function fixedStepCount()

isPaused

public static function isPaused()

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Time;

class MovementController extends Behaviour
{
    public float $speed = 5.0;

    public function update(): void
    {
        // Frame-rate-independent movement
        $moveDistance = $this->speed * Time::deltaTime();
        $this->transform->translate($moveDistance, 0, 0);

        // Get time since game started
        $elapsedTime = Time::time();
        Debug::log('Time elapsed: ' . $elapsedTime);
    }

    public function fixedUpdate(): void
    {
        // Physics updates use fixed delta time
        $fixedDelta = Time::fixedDeltaTime();
        // Apply physics calculations with consistent timestep
    }
}