Skip to content

benevolent-games/archimedes

Repository files navigation

🌀 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, consolidate} from "@benev/archimedes"
  1. define components. json-friendly data that entities could have.
    export type MyComponents = {
      health: number
      bleed: number
    }
  2. create entities map. indexed for speedy-fast lookups.
    export const entities = new Entities<MyComponents>()
  3. 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)
        }
      },
    })
  4. manually insert your first entity.
    const wizardId = makeId()
    entities.set(wizardId, {health: 100, bleed: 2})
    
    console.log(entities.get(wizardId)?.health)
      // 100
  5. run your simulation, one tick at a time.
    // simulate one tick
    simulate()
    
    console.log(entities.get(wizardId)?.health)
      // 98


🔮 sim — networkable simulation architecture

coming soon


🌎 net — connect and run multiplayer games

coming soon

About

rollforward netcode for web games

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors