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, makeExecute} 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. readonly entities. recommended to use this in your systems.
    export const entitiesReadonly = entities.readonly
  4. 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)
        }
      },
    ]
  5. manually insert your first entity.
    const wizardId = makeId()
    entities.set(wizardId, {health: 100, bleed: 2})
    
    console.log(entities.get(wizardId)?.health)
      // 100
  6. 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

About

rollforward netcode for web games

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors