1.0.5 • Published 11 months ago

@bitshim/engine v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@bitshim/engine

npm version codecov

A lightweight, high-performance core for browser-based game engines, providing Web Worker–based ticking and flexible loop management.


Why use this?

  • 🚀 High-performance: Web Worker–driven simulation tick loop
  • 🧠 Smart focus handling: Automatically throttles or pauses when hidden/unfocused
  • Multiple loops: Easily manage physics, simulation, rendering, etc.

Table of Contents


Installation

# npm
npm install @bitshim/engine

# yarn
yarn add @bitshim/engine

# bun
bun add @bitshim/engine

Quick Start

import { createEngine } from '@bitshim/engine';

function handleSimulationTick() {
  console.log('Running simulation step');
}

function handleRenderTick() {
  console.log('Rendering scene frame');
}

const engine = createEngine({
  loops: [
    {
      name: 'simulation',
      interval: 1000 / 60,
      callback: handleSimulationTick,
    },
    {
      name: 'rendering',
      interval: 1000 / 60,
      callback: handleRenderTick,
      reduceWhenUnfocused: true,
      pauseWhenHidden: true,
      unfocusedInterval: 1000 / 30,
    },
  ],
});

Other Loops

You can add more loops for background tasks, physics, or analytics:

function handlePhysicsTick() {
  console.log('Executing physics update');
}

engine.loopManager.registerLoop({
  name: 'physics',
  interval: 1000 / 20, // 20 FPS physics
  callback: handlePhysicsTick,
});

API Reference

createEngine(options)

Creates and initializes the core game engine.

ParameterTypeDescription
loopsLoopConfig[]Array of loop configurations (required; must not be empty)
hznumberWeb Worker tick rate in Hz (default: 60)
autoStartbooleanWhether to start automatically on creation (default: true)

Returns an object with:

  • start() – Starts the Worker with the specified tick rate
  • stop() – Terminates the Worker
  • worker – Underlying Worker instance
  • loopManager – Manager for controlling individual loops

License

MIT © Bit Shim — commercial use allowed

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago