Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hecs

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hecs

An experimental ECS written in Javascript.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

HECS

HECS Entity Component System

An experimental ECS written in Javascript.

Goals

  • Performance
    • As little memory allocation and garbage collection as possible
    • Fast iterators
  • Predictability
    • Systems run in the order they are registered
    • Events are processed in the game loop with the rest of the system's logic

Roadmap

  • Custom Schedulers
    • Specify dependencies between systems
    • Enable systems to run in parallel
  • Parallelism
    • Using transferable objects in WebWorkers
    • Using SharedArrayBuffer
  • WASM Integration
    • Rust API that can be used to write high performance systems in WASM

Getting Started

npm install -S hecs
import { World, System, EntityId, Read, Write } from "hecs";

const world = new World();

class Position {
  constructor(x) {
    this.x = x;
  }
}

class Velocity {
  constructor(v) {
    this.v = v;
  }
}

world.registerComponent(Position);
world.registerComponent(Velocity);

class VelocitySystem extends System {
  setup() {
    return {
      entities: this.world.createQuery(Write(Position), Read(Velocity))
    };
  }

  update() {
    for (const [position, velocity] of this.ctx.entities) {
      position.x += velocity.v;
    }
  }
}

class LoggingSystem extends System {
  setup() {
    return {
      entities: this.world.createQuery(EntityId, Read(Position))
    };
  }

  update() {
    for (const [entityId, position] of this.ctx.entities) {
      console.log(`Entity ${entityId} has position: ${position.x}`);
    }
  }
}

world.registerSystem(new VelocitySystem());
world.registerSystem(new LoggingSystem());

const entity1 = world.createEntity();
world.addComponent(entity1, new Position(0));
world.addComponent(entity1, new Velocity(1));

const entity2 = world.createEntity();
world.addComponent(entity2, new Position(10));
world.addComponent(entity2, new Velocity(0.5));

function update() {
  world.update();
  requestAnimationFrame(update);
}

requestAnimationFrame(update);

Credits

  • API heavily inspired by Specs

FAQs

Package last updated on 23 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc