Atom Engine

IUpdatable and IRenderable Interfaces

Purpose

These interfaces define a minimal contract for objects participating in a real-time simulation or game loop.

They are commonly used in game engines, simulations, or ECS-style architectures.

Lifecycle

Creation → Update → Destruction

  1. Creation: Objects are instantiated and registered with the update/render system.
  2. Update: Each frame or tick, update(dt) is called to advance simulation state.
  3. Render: Each frame, render(alpha) is called to draw the current (or interpolated) state.
  4. Destruction: Objects are removed from systems and no longer updated or rendered.

Public API

IUpdatable

IRenderable

Internal Behavior

Implementations typically separate simulation logic from rendering logic:

This separation helps maintain deterministic simulation while ensuring smooth visuals.

Example

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);
    }
}