These interfaces define a minimal contract for objects participating in a real-time simulation or game loop.
IUpdatable marks objects that can be advanced over time.IRenderable marks objects that can be drawn with interpolation support for smooth rendering.They are commonly used in game engines, simulations, or ECS-style architectures.
Creation → Update → Destruction
update(dt) is called to advance simulation state.render(alpha) is called to draw the current (or interpolated) state.update(dt: number): void
dt represents the time delta since the last update (usually in seconds).render(alpha: number): void
alpha represents an interpolation factor between the previous and current state (commonly used for smooth rendering between fixed update steps).Implementations typically separate simulation logic from rendering logic:
update(dt) modifies the authoritative state (physics, AI, game logic).render(alpha) uses current and previous state snapshots to interpolate visual output.alpha parameter is especially useful in fixed-timestep systems, where rendering may occur more frequently than simulation updates.This separation helps maintain deterministic simulation while ensuring smooth visuals.
class Player implements IUpdatable, IRenderable {
position = { x: 0, y: 0 };
previousPosition = { x: 0, y: 0 };
velocity = { x: 10, y: 0 };
update(dt: number): void {
this.previousPosition = { ...this.position };
this.position.x += this.velocity.x * dt;
this.position.y += this.velocity.y * dt;
}
render(alpha: number): void {
const x = this.previousPosition.x +
(this.position.x - this.previousPosition.x) * alpha;
const y = this.previousPosition.y +
(this.position.y - this.previousPosition.y) * alpha;
drawCircle(x, y, 10);
}
}
dt) and frame interpolation (alpha)