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:- 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
- 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 insrc/systems/shared/:
Collision System
The movement system includes a unified collision matrix for OSRS-accurate tile blocking:
Usage:
Data Manifests
Game content is defined in TypeScript files insrc/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: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 registration —
registerFlatZone(),unregisterFlatZone(),getFlatZoneAt()
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 methods —
hasSpace(),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 insrc/data/. See Manifests.
Type Safety
Strong TypeScript typing throughout—noany 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)