@benev/archimedes
v0.1.0-7
Published
game ecs with auto networking
Maintainers
Readme

🌀 archimedes, netlogic for multiplayer web games
"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.
🧩 ecs — entities, components, systems
import {Entities, Change, makeId, makeExecute} 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>() - readonly entities. recommended to use this in your systems.
export const entitiesReadonly = entities.readonly - define systems. select entities by components. changes are formalized.
const systems = (change: Change<MyComponents>) => [ function bleeding() { for (const [id, components] of entitiesReadonly.select("health", "bleed")) { if (components.bleed > 0) { const health = components.health - components.bleed change.merge(id, {health}) } } }, function death() { for (const [id, components] of entitiesReadonly.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 - create an execute fn. run one tick at a time.
const execute = makeExecute(entities, systems) // simulate one tick execute() console.log(entities.get(wizardId)?.health) // 98
🔮 sim — networkable simulation architecture
coming soon
🌎 net — connect and run multiplayer games
coming soon
