"do not disturb my circles!"
— archimedes, c. 212 bc
npm install @benev/archimedes- 🧩 #ecs, entities, components, systems.
- 🔮 #sim, code like it's single-player, archimedes makes it multiplayer.
- 🌎 #net, whole-world rollforward, everything is clientside predicted for insta-feels.
import {Entities, Change, makeId, consolidate} from "@benev/archimedes"- define components. json-friendly data that entities could have.
export type MyComponents = { health: number bleed: number }
- create entities map. indexed for speedy-fast lookups.
export const entities = new Entities<MyComponents>()
- consolidate system fns, with context.
const context = { entities: entities.readonly, change: new Change<MyComponents>(delta => applyDeltas(entities, delta)), } export const simulate = consolidate(context, { bleeding: ({entities, change}) => () => { for (const [id, components] of entities.select("health", "bleed")) { if (components.bleed > 0) { const health = components.health - components.bleed change.merge(id, {health}) } } }, death: ({entities, change}) => () => { for (const [id, components] of entities.select("health")) { if (components.health <= 0) change.delete(id) } }, })
- manually insert your first entity.
const wizardId = makeId() entities.set(wizardId, {health: 100, bleed: 2}) console.log(entities.get(wizardId)?.health) // 100
- run your simulation, one tick at a time.
// simulate one tick simulate() console.log(entities.get(wizardId)?.health) // 98
coming soon
coming soon
