Skip to content

Latest commit

ย 

History

143 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

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

๐Ÿ›๏ธ game ecs and netcode

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages