ecs/world
defworld + defcomponent macros and entity bookkeeping.
Since: E0 (defstruct emission); E2 (accessor emission via
defcomponent
(defcomponent [T])
register a type as a component (E2d-P4).
Since: E0 (documentation marker); E2d-P4 (emits the Component instance)
defcomponent-accessors
(defcomponent-accessors [world-name comp-name])
emit `get-<Comp>` / `set-<Comp>!` /
Since: E2 (initial); I4 (cap gating); E2d-P6 (StorageOps routing)
defworld
(defworld [name comps])
declare a closed world type carrying typed storages.
Since: E0 (1..4 components); E1 (5 components); E2d-P5 ((Storage T)
defcomponent-cids
(defcomponent-cids [comps])
emit `(def <Comp>-cid N)` for each component
Since: GEN-V0
defcomponent-class
(defcomponent-class [comp-name])
declare a `Has<Comp>` typeclass with one
Since: E2 (depends on gap A + gap E + gap G; SEGV-safe under gap H
defcomponent-class-instance
(defcomponent-class-instance [world-name comp-name])
bind a (world, component) pair into
Since: E2 (instance binding); I2 (cap minting)
defworld-classes
(defworld-classes [name comps])
`defworld`, plus the `Has<Comp>` class and the
| name | the world type name | |
| comps | vector of component type names |
(defworld-classes GameWorld [Pos Vel])
;; emits:
;; (defworld GameWorld [Pos Vel])
;; (defcomponent-class Pos)
;; (defcomponent-class-instance GameWorld Pos)
;; (defcomponent-class Vel)
;; (defcomponent-class-instance GameWorld Vel)
This is a SEPARATE macro rather than a change to `defworld` on
purpose. The instance expansion emits cap-mint helpers that name
`ecs/cap` symbols at the call site, so folding it into `defworld`
would require every existing call site to import
`WriteCap`/`ReadCap`/`make-write-cap`/`make-read-cap` -- a breaking
change to a macro whose users overwhelmingly do not touch the
typeclass surface at all. Use `defworld` when you just want the world
struct; use this when you also want `Has<Comp>` dispatch.
Callers must import both `ecs/cap` (the four cap symbols above) and
this module. Redeclaring a component's class is harmless, so two
worlds may share a component -- each `defworld-classes` re-emits
`(defcomponent-class C)` and only the instances differ.
Since: ECB step 3 (docs/upcoming/v1/ecs-component-set-bounds-plan.md)
world-alloc-entity!
(world-alloc-entity! [gens : int] :)
allocate the next entity slot.
Since: E0
world-despawn!
(world-despawn! [gens : int e : Entity] :)
bump the generation of an entity slot.
Since: E0
Internal definitions
world-fields-- expand a component vector into the flatdefcomponent-cids--from-- internal helper. Walks a componentdefworld-classes--from-- internal helper. Walks a component vector