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

lmorchard/bitECS

 
 

Repository files navigation

👾 bitECS 👾 npm Minzipped npm 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

🚀 Unparalleled performance benchmarks

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

💿 Install

npm i bitecs

📘 Documentation

🏁 Getting Started
📑 API
FAQ

🕹 Example

import {
  createWorld,
  Types,
  defineComponent,
  defineQuery,
  addEntity,
  addComponent,
  defineSystem,
  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 = defineSystem((world) => {
  const ents = movementQuery(world)
  for (let i = 0; i < ents.length; i++) {
    const eid = ents[i]
    Position.x[eid] += Velocity.x[eid]
    Position.y[eid] += Velocity.y[eid]
    Position.z[eid] += Velocity.z[eid]
  }
})

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

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)

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

🔌 Powering

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.9%
  • TypeScript 0.1%