std/ecs/store

std/ecs/src/store.trb

trait Store

trait Store<Component>

What a package asks of a world: a column of one component type the package owns.

A package declares its own components and bounds its systems by this trait, so a program admits the package by holding a group of columns that carries it. That is the whole of the open component set, and it needs no erasure.

Examples

type Health with Equals, Show {
  points: Int
}

type Vitals {
  var health: Column<Health> = Column()
}

extend Vitals with Store<Health> {
  fn column(): Column<Health> {
    health
  }

  var fn attach(entity: Entity, value: Health) {
    health.put entity, value
  }

  var fn detach(entity: Entity) {
    health.remove entity
  }
}

var vitals = Vitals()
vitals.attach Entity(0), Health(3)
assert(vitals.column().get(Entity(0)) == Some(Health(3)))

fn column

fn column(): Column<Component>

The column of this component type.

fn attach

var fn attach(entity: Entity, value: Component)

Gives entity the component, replacing the one it has.

fn detach

var fn detach(entity: Entity)

Takes the component off entity; an entity without one changes nothing.

type ComponentKey

type ComponentKey with Equals, Hash, Show

The name a scene file, an inspector and a schedule know a component type by.

A package writes it by hand until the compiler can fold it from the type (componentKey<Component>(), ECS.md gap 6), and writes the package's qualified name in front, so two packages cannot hand out one key.

Examples

const key = ComponentKey "acme/game/Position"
assert(key == ComponentKey("acme/game/Position"))
assert(key.name == "acme/game/Position")

field name

name: String

The key itself.