Skip to content

Functional, minimal, data-oriented, ultra-high performance ECS library written in JavaScript

License

Notifications You must be signed in to change notification settings

NateTheGreatt/bitECS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โค โค โค
bitECS

Version Minzipped Downloads License

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

โœจ Features

๐Ÿ”ฎ Simple, declarative API ๐Ÿ”ฅ Blazing fast iteration
๐Ÿ” Powerful & performant queries ๐Ÿ’พ Serialization included
๐Ÿƒ Zero dependencies ๐ŸŒ Node or browser
๐Ÿค ~5kb minzipped ๐Ÿท TypeScript support
โค Made with love ๐Ÿ”บ glMatrix support

๐Ÿ“ˆ Benchmarks

noctjs/ecs-benchmark ddmills/js-ecs-benchmarks

๐Ÿ’ฟ Install

npm i bitecs

๐Ÿ“˜ Documentation

๐Ÿ Getting Started
๐Ÿ“‘ API
โ” FAQ
๐Ÿ› Tutorial

๐Ÿ•น Example

import {
  createWorld,
  Types,
  defineComponent,
  defineQuery,
  addEntity,
  addComponent,
  pipe,
} from 'bitecs'

const Vector3 = { x: Types.f32, y: Types.f32, z: Types.f32 }
const Position = defineComponent(Vector3)
const Velocity = defineComponent(Vector3)

const movementQuery = defineQuery([Position, Velocity])

const movementSystem = (world) => {
  const { time: { delta } } = world
  const ents = movementQuery(world)
  for (let i = 0; i < ents.length; i++) {
    const eid = ents[i]
    Position.x[eid] += Velocity.x[eid] * delta
    Position.y[eid] += Velocity.y[eid] * delta
    Position.z[eid] += Velocity.z[eid] * delta
  }
  return world
}

const timeSystem = world => {
  const { time } = world
  const now = performance.now()
  const delta = now - time.then
  time.delta = delta
  time.elapsed += delta
  time.then = now
  return world
}

const pipeline = pipe(movementSystem, timeSystem)

const world = createWorld()
world.time = { delta: 0, elapsed: 0, then: performance.now() }

const eid = addEntity(world)
addComponent(world, Position, eid)
addComponent(world, Velocity, eid)
Velocity.x[eid] = 1.23
Velocity.y[eid] = 1.23

setInterval(() => {
  pipeline(world)
}, 16)

๐Ÿ”Œ Powering