@javelin/ecs
A TypeScript Entity-Component System (ECS) for Node and web browsers.
Docs
Visit https://javelin.games for documentation, examples, and external resources.
Features
Fast
Entities are organized by their component makeup into Archetypes for quick lookups and iteration. In a small app (10 component types, 10 archetypes, 10 queries), Javelin can iterate ~2.5 million entities per 16ms on a 2GHz Intel i5 processor.
Ergonomic
Define your game's data model using simple syntax.
const Transform = {
x: float64,
y: float64,
}
const Inventory = {
bags: arrayOf(arrayOf(uint32)),
}
const world = createWorld()
const entity = world.spawn(
component(Transform),
component(Inventory),
)
Intuitive
Query game state using simple syntax.
const qryBodies = createQuery(Transform, Velocity)
const sysPhysics = () =>
qryBodies((e, [t, v]) => {
t.x += v.x
t.y += v.y
})
Powerful
Best practices are built-in with tools like Topics for inter-system messaging:
const sysMovement = () =>
qryInput((e, [input]) => {
if (input.jump) {
topPhysics.push(impulse(e, 0, 10))
}
})
const sysPhysics = () => {
for (const message of topPhysics) {
}
}
and Effects for handling async code, third-party dependencies, and events:
const sysRender = () => {
const scene = useScene()
const model = useLoadGLTF("llama.gltf")
useMonitor(
qryPlayers,
e => scene.insert(e, model, world.get(e, Transform)),
e => scene.destroy(e),
)
}