No matching definitions.

ecs/system

src/ecs/system.tur

System value + conflict detection.

Since: E2 (initial); I3 (cap-binding rewrite)

defstruct

System

(defstruct System [])

a runnable bundle (reads-mask, writes-mask, run-fn).

Since: E2

defn

make-system

(make-system [reads-mask : int writes-mask : int run-fn ptr<void>] :)

bundle a top-level defn with its read/write masks.

reads-maskOR of component-id bits the system reads
writes-maskOR of component-id bits the system writes
run-fnptr<void> to a top-level defn (signature `[w : int] : nil`)

A System value.

(def physics
    (make-system
      (bit-or (cid-bit POS-CID) (cid-bit VEL-CID))   ;; reads
      (cid-bit POS-CID)                                ;; writes
      physics-impl))                                  ;; defn ptr

Since: E2

defn

system-reads-mask

(system-reads-mask [s : System] :)

accessor for the System's reads bitmask.

Since: E2

defn

system-writes-mask

(system-writes-mask [s : System] :)

accessor for the System's writes bitmask.

Since: E2

defn

system-run-fn

(system-run-fn [s : System] :)

accessor for the System's run-fn pointer.

Since: E2

defn

system-run!

(system-run! [s : System w : int] :)

invoke the System's run-fn against a world handle.

sSystem value
wworld handle (an :int that the system's run-fn understands)

Since: E2

defn

system-conflicts?

(system-conflicts? [a : System b : System] :)

true if two systems cannot run concurrently.

aSystem value
bSystem value

true if either system's writes-mask overlaps the other's reads-or-writes mask; false if both systems can run in parallel.

(system-conflicts? physics render)  ;; physics writes Pos, render reads Pos -> true

Since: E2

defn

cid-bit

(cid-bit [cid : int] :)

pack a component ID (0..62) into its single-bit mask.

(def POS-CID 0)
  (def VEL-CID 1)
  (def physics-reads (bit-or (cid-bit POS-CID) (cid-bit VEL-CID)))

Since: E2

defmacro

defsystem--mask

(defsystem--mask [comps])

internal helper. Build the bit-or'd cid-bit

defmacro

defsystem--with-write-caps

(defsystem--with-write-caps [body comps])

internal helper. Wrap `body` in a

defmacro

defsystem--with-read-caps

(defsystem--with-read-caps [body comps])

internal helper. Wrap `body` in a

defmacro

defsystem--consume-write-caps

(defsystem--consume-write-caps [comps])

internal helper. Emit `(use-cap!

defmacro

defsystem

(defsystem [name reads-vec writes-vec body])

declare a System and its implementation in one form.

(def Pos-cid 0)
  (def Vel-cid 1)
  (defsystem physics
    [Pos Vel]                  ;; :reads  -- binds Pos-read-cap, Vel-read-cap
    [Pos]                      ;; :writes -- binds Pos-write-cap (linear)
    (println "physics tick"))
  ;; physics-impl and physics both exist at top level.

Since: E2 (initial); I3 (cap-binding rewrite)

defmacro

defsystem-world

(defsystem-world [name world-name reads-vec writes-vec body])

declare a System whose body reaches its world at

namethe System value's name (also prefixes -impl / -fn)
world-namethe world type the body is typed against
reads-vecvector of component names the system reads
writes-vecvector of component names the system writes
bodythe system body; `w` is bound at `world-name`

Nothing at runtime -- expands to three top-level declarations. Required imports at the call site: (import ecs/cap :refer [WriteCap ReadCap make-write-cap make-read-cap use-cap!]) (import ecs/xworld :refer [defworld-box-helpers])

(defworld GameWorld [Pos Vel])
  (defcomponent-accessors GameWorld Pos)
  (defcomponent-cids [Pos Vel])
  (defworld-box-helpers GameWorld)

  (defsystem-world physics GameWorld
    [Pos]                     ;; :reads
    [Pos]                     ;; :writes
    (set-Pos! Pos-write-cap w (slot-new 0) (make-struct Pos 42 0)))

  (system-run! physics (box-GameWorld world))

Since: GEN-V1