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

bitecs

Package Overview
Dependencies
Maintainers
1
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitecs

Tiny, data-driven, high performance ECS library written in Javascript

  • 0.2.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
923
increased by7.08%
Maintainers
1
Weekly downloads
 
Created
Source

👾 bitECS 👾

Functional, tiny, data-oriented, high performance ECS library written using JavaScript TypedArrays.

Features

  • Functional
  • <3kb gzipped
  • Zero dependencies
  • Node or Browser
  • Killer performance

Install

npm i bitecs

Example

import { 
  createWorld,
  registerComponent,
  registerComponents,
  defineComponent,
  defineQuery,
  enterQuery,
  exitQuery,
  defineSystem,
  addComponent,
  removeComponent,
  addEntity,
  removeEntity,
  pipe,
  Types,
} from 'bitecs'

// create a world
const world = createWorld()

// define component data stores
const { f32 } = Types
const Vector2 = { x: f32, y: f32 }
const Position = defineComponent(Vector2)
const Velocity = defineComponent(Vector2)
const Health = defineComponent(f32)
const Alive = defineComponent() // "tag" component

// register components on world
registerComponents(world, [Position, Velocity, Health]) // in groups
registerComponent(world, Alive) // or individually

// define a query using components
const movementQuery = defineQuery([Position, Velocity])

// enter-query hook, called when an entity's components matches the query
enterQuery(world, movementQuery, eid => {})

// exit-query hook, called when an entity's components no longer matches the query
exitQuery(world, movementQuery, eid => {})

// define a system using the query
const movementSystem = defineSystem(movementQuery, ents => {
  for (let i = 0; i < ents.length; i++) {
    const eid = ents[i];
    Position.x[eid] += Velocity.x[eid]
    Position.y[eid] += Velocity.y[eid]
  }
})

// add an entity to the world
const eid = addEntity(world)

// add components to the new entity in the world
addComponent(world, Position, eid)
addComponent(world, Velocity, eid)

// there are no component getters or setters
// data is accessed directly by entity ID
Velocity.x[eid] = 1
Velocity.y[eid] = 2

const pipeline = pipe(
  movementSystem,
  movementSystem,
  movementSystem,
)

movementSystem(world) // executes movement system on world
pipeline(world) // executes a pipeline of systems on world

Full documentation and feature rich examples can be found here.

FAQs

Package last updated on 15 Apr 2021

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