Awesome
:warning: v0.4 coming soon! Read the docs here
<h1 align="center"> ā¤ ā¤ ā¤ <br /> bitECS </h1> <p align="center"> <a href="https://www.npmjs.com/package/bitecs"> <img src="https://img.shields.io/npm/v/bitecs.svg" alt="Version" /> </a> <a href="https://www.npmjs.com/package/bitecs"> <img src="https://badgen.net/bundlephobia/minzip/bitecs" alt="Minzipped" /> </a> <a href="https://www.npmjs.com/package/bitecs"> <img src="https://img.shields.io/npm/dt/bitecs.svg" alt="Downloads" /> </a> <a href="https://github.com/NateTheGreatt/bitECS/blob/master/LICENSE"> <img src="https://badgen.net/npm/license/bitecs" alt="License" /> </a> </p> <p align="center"> Functional, minimal, <a href="https://www.dataorienteddesign.com/dodbook/">data-oriented</a>, ultra-high performance <a href="https://en.wikipedia.org/wiki/Entity_component_system">ECS</a> library written using JavaScript TypedArrays. </p> </center>āØ 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
<a href="https://github.com/etherealengine/etherealengine/"><img src="https://user-images.githubusercontent.com/5104160/275346499-878a74b0-11eb-463d-a70e-6cb7055683eb.png" width="420"/></a>
<a href="https://github.com/thirdroom/thirdroom"><img src="https://github.com/thirdroom/thirdroom/raw/main/docs/assets/logo.png" width="420"/></a>
<a href="https://github.com/mozilla/hubs"><img src="https://github.com/NateTheGreatt/bitECS/blob/master/mozilla-hubs.png" width="420"/></a>