https://github.com/natethegreatt/bitecs
Flexible, minimal, data-oriented ECS library for Typescript
https://github.com/natethegreatt/bitecs
ecs entitycomponentsystem functional game game-development game-engine gamedev high-performance particles
Last synced: 3 days ago
JSON representation
Flexible, minimal, data-oriented ECS library for Typescript
- Host: GitHub
- URL: https://github.com/natethegreatt/bitecs
- Owner: NateTheGreatt
- License: mpl-2.0
- Created: 2020-04-02T21:53:05.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-08-25T15:09:23.000Z (5 months ago)
- Last Synced: 2025-10-29T22:46:10.472Z (3 months ago)
- Topics: ecs, entitycomponentsystem, functional, game, game-development, game-engine, gamedev, high-performance, particles
- Language: TypeScript
- Homepage:
- Size: 3.99 MB
- Stars: 1,177
- Watchers: 23
- Forks: 99
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
โค โค โค
bitECS
Flexible, minimal, data-oriented ECS library for Typescript.
## โจ Features
`bitECS` is a minimal, less opinionated, and powerful Entity Component System (ECS) library. It provides a lean API that enables developers to build their architecture to their liking, offering flexibility while maintaining efficiency where needed. Features include:
| | |
|---|---|
| ๐ฎ Simple, declarative API | ๐ Lightweight (`~5kb` minzipped) |
| ๐ Powerful querying | ๐ฆ Zero dependencies |
| ๐ Relational entity modeling | ๐งต Thread-friendly |
| ๐พ Serialization included | ๐ Made with love |
## ๐ฟ Install
```
npm i bitecs
```
## ๐ Documentation
| |
| ---------------- |
| ๐ [Introduction](/docs/Intro.md) |
| ๐พ [Serialization](/docs/Serialization.md) |
| ๐งต [Multithreading](/docs/Multithreading.md) |
| ๐ [API Docs](/docs/API.md) |
## ๐น Example
```typescript
import {
createWorld,
query,
addEntity,
removeEntity,
addComponent,
} from 'bitecs'
// Put components wherever you want
const Health = [] as number[]
const world = createWorld({
components: {
// They can be any shape you want
// SoA:
Position: { x: [], y: [] },
Velocity: { x: new Float32Array(1e5), y: new Float32Array(1e5) },
// AoS:
Player: [] as { level: number; experience: number; name: string }[]
},
time: {
delta: 0,
elapsed: 0,
then: performance.now()
}
})
const { Position, Velocity, Player } = world.components
const eid = addEntity(world)
addComponent(world, eid, Position)
addComponent(world, eid, Velocity)
addComponent(world, eid, Player)
addComponent(world, eid, Health)
// SoA access pattern
Position.x[eid] = 0
Position.y[eid] = 0
Velocity.x[eid] = 1.23
Velocity.y[eid] = 1.23
Health[eid] = 100
// AoS access pattern
Player[eid] = { level: 1, experience: 0, name: "Hero" }
const movementSystem = (world) => {
const { Position, Velocity } = world.components
for (const eid of query(world, [Position, Velocity])) {
Position.x[eid] += Velocity.x[eid] * world.time.delta
Position.y[eid] += Velocity.y[eid] * world.time.delta
}
}
const experienceSystem = (world) => {
const { Player } = world.components
for (const eid of query(world, [Player])) {
Player[eid].experience += world.time.delta / 1000
if (Player[eid].experience >= 100) {
Player[eid].level++
Player[eid].experience = 0
}
}
}
const healthSystem = (world) => {
for (const eid of query(world, [Health])) {
if (Health[eid] <= 0) removeEntity(world, eid)
}
}
const timeSystem = (world) => {
const { time } = world
const now = performance.now()
const delta = now - time.then
time.delta = delta
time.elapsed += delta
time.then = now
}
const update = (world) => {
timeSystem(world)
movementSystem(world)
experienceSystem(world)
healthSystem(world)
}
// Node environment
setInterval(() => {
update(world)
}, 1000/60)
// Browser environment
requestAnimationFrame(function animate() {
update(world)
requestAnimationFrame(animate)
})
```
## ๐ Used by
- [Enchantment Engine](https://github.com/EnchantmentEngine/EnchantmentEngine)
- [Third Room](https://github.com/thirdroom/thirdroom)
- [Hubs](https://github.com/Hubs-Foundation/hubs)
## ๐ Star History
[](https://star-history.com/#NateTheGreatt/bitECS&Date)