Skip to main content

Overview

The @hyperscape/shared package is the core Hyperscape engine, providing:
  • Entity Component System (ECS)
  • Three.js 3D rendering
  • PhysX physics simulation
  • Real-time networking
  • React UI components
  • Game data manifests

Package Location

Rendering

WebGPU with WebGL Fallback

The shared package includes renderer factory utilities for creating renderers with automatic fallback:
Renderer Features:
  • Automatic WebGPU detection and fallback to WebGL
  • Works in WKWebView (Tauri), older Safari, and browsers without WebGPU
  • Configurable shadow maps and post-processing
  • Max anisotropy detection
Environment System:
  • Auto exposure for day/night cycle (mimics eye adaptation)
  • Cascaded shadow maps (WebGPU) or single directional shadows (WebGL)
  • Dynamic ambient lighting based on time of day
  • Fog color transitions

Key Exports

Entity Hierarchy

The entity system follows a clear inheritance pattern:

Systems (Shared)

Located in src/systems/shared/:

Collision System

The movement system includes a unified collision matrix for OSRS-accurate tile blocking:
Key Exports: Usage:

Data Manifests

Game content is defined in TypeScript files in src/data/:
NPC data is loaded from JSON manifests at runtime by DataManager. Add new NPCs in world/assets/manifests/npcs.json.

Skill Unlocks API

The skill unlocks system provides functions for querying what players unlock at each level:
Defence/Defense Normalization: The system automatically handles British/American spelling:
This allows the manifest to use OSRS-accurate British spelling while the codebase uses American spelling consistently.

Entry Points

Server (index.ts)

Exports for server-side usage:

Client (index.client.ts)

Exports for client-side usage:

Dependencies

Recent Changes

Terrain Flattening System (PR #644)

The terrain system now supports flat zones under stations for proper building placement:
  • FlatZone interface — Defines rectangular flat areas with smooth blending
  • Spatial indexing — O(1) flat zone lookup using terrain tiles
  • Manifest-driven — Stations configure flattenGround, flattenPadding, flattenBlendRadius
  • Dynamic registrationregisterFlatZone(), unregisterFlatZone(), getFlatZoneAt()
See Terrain System for details.

Equipment System Fixes (PR #641)

Atomic equip/unequip operations prevent item duplication:
  • Transaction locks prevent race conditions
  • Order of operations — Remove from inventory FIRST (equip), clear equipment FIRST (unequip)
  • Rollback on failure — Restores state if operation fails
  • New helper methodshasSpace(), hasItemAtSlot(), removeItemDirect(), addItemDirect()

Building

Shared must be built before other packages that depend on it. Turbo handles this automatically.

Key Patterns

ECS Architecture

All game logic uses Entity Component System. See ECS Concepts.

Manifest-Driven Data

Game content defined in src/data/. See Manifests.

Type Safety

Strong TypeScript typing throughout—no any types allowed. ESLint enforces this rule.

Dual Entry Points

  • index.ts: Server-side exports (includes Fastify, database utilities)
  • index.client.ts: Client-side exports (browser-compatible)