Skip to main content

Overview

Hyperscape uses an Entity Component System (ECS) architecture for all game logic. This pattern separates data from behavior, making the codebase modular and extensible.

Core Concepts

Entities

Entities are game objects with 3D representation, networking, physics, and component-based architecture:
Examples: Players, Mobs, Items, Resources, NPCs, Headstones

Components

Components are registered data containers. Hyperscape uses a component factory system:

Systems

Systems contain all game logic. They query entities by component and process them each tick.

Why ECS?

Composition Over Inheritance

Instead of deep class hierarchies, entities gain capabilities by adding components:

Performance

Systems process entities in batches, enabling efficient updates for many game objects. Recent Optimizations:
  • Raycast Proxy: Invisible capsule meshes for instant entity click detection (~700-1800ms improvement over VRM SkinnedMesh raycast)
  • Event-Driven Health: Client health bars use events instead of polling (eliminates race conditions)
  • React Optimizations: useMemo and useCallback in InventoryPanel for render efficiency
  • Map-Based Tracking: O(1) lookups for eat delay and attack cooldown management
  • Model Normalization: Scale normalization runs once at load time, before caching

Flexibility

Add new features by creating new components and systems without modifying existing code.

Data Flow

Working with ECS

Adding Components

Getting Components

Entity Lifecycle

Network Synchronization

Key Files

Design Principles

  1. Entities are data containers—no logic in entity classes
  2. Systems own all behavior—logic lives in systems
  3. Components are plain objects—no methods, just data
  4. Use existing systems—don’t create new ones without good reason