RoomDefinition: tickRate property
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe tickRate property of a room definition gives the room ticks: it runs onTick() that many times a second and sends what changed once per tick.
Value
An integer from 1 to 120, the ticks per second. Without one, the room has no ticks.
Exceptions
defineRoom() throws a RangeError for a tickRate that isn’t an integer from 1 to 120. It throws an Error for a definition without one that has onTick(), a stepper, a history, or a bot behaviour with a tick hook. The types reject those too.
Description
Give a room a tickRate when it simulates: something changes every moment whether or not players act, as in physics, movement that clients predict or interpolate, or a timer counted in ticks.
Leave it out when the room only changes because a player did something, as in a board, card or turn-based game, a chat or a shared editor. A room without ticks sends what its code changed as soon as that code yields, so a move reaches the other players one round trip after the player made it, and it costs nothing while nothing happens. Its room.tick stays 0 and room.tickRate is 0.
Ticks run with a fixed timestep, 1 / tickRate seconds, which onTick and the stepper get as dt. After a stall a room runs at most 4 ticks to catch up and drops the rest. Ticks stop while the room is hibernated.
Examples
A racing room at 30 ticks a second
// race.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";
const Race = entity("race", { lap: "u8", elapsed: "f64" });
export default defineRoom({
schema: defineSchema({ state: Race }),
tickRate: 30,
onTick(room, dt) {
room.state.elapsed += dt;
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
tickRate | 0.1 | 0.1 | 0.1 | 0.1 |