VirtualClock

View source

ExtendsClock

Provides the app-wide mutable virtual time resource.

VirtualClock extends Clock and is the clock resource exposed by TimePlugin. Access it from a World when application code needs shared virtual time.

The resource preserves the serialized state defined by Clock, so the same virtual-time state can be restored later.

Examples

import { VirtualClock } from '@wimaengine/time'

function readFrameTime(world) {
  const clock = world.getResource(VirtualClock)
  console.log(clock.getDelta(), clock.getElapsed())
}

Constructor


constructor()

Methods


staticserialize(value: Clock): ClockSerial

View source

Converts a clock into the plain state used by the type registry.

The returned object contains the elapsed time and delta in seconds, plus the most recent timestamp in milliseconds.

Parameters

NameDescriptionDefault
value

Clock to serialize.

—

Returns

The ClockSerial state.

staticdeserialize(value: ClockSerial, out?: VirtualClock): Clock

View source

Restores clock state from a serialized value.

When out is supplied, it is updated and returned. Otherwise a new Clock is created. Deserialization restores elapsed, lastTick, and delta exactly; it does not advance the clock or read the current time.

Parameters

NameDescriptionDefault
value

ClockSerial state.

—
out?

VirtualClock to populate.

...

Returns

The restored Clock.