Liking cljdoc? Tell your friends :D

Contexts

Threeagent provides something called a context that can be used to provide arbitrary data to specific branches of our scene graph. This is somewhat similar to React's Context concept.

Unlike React, in Threeagent there is only one type of context. The context is always a map and can be defined for any branch of the tree by using a map in the first position of a hiccup vector:

[:object
  [{:fruits [:apple :banana]}
   [:object {:id "a"
             :fruit-system {}}]]
  [{:fruits [:banana]}
   [:object {:id "b"
             :fruit-system {}}]]]

When the :fruit-system ISystem/on-entity-created method is called, the :fruits key will be [:apple :banana] for entity a, but it will be [:banana] for entity b.

This can be particularly useful if we want isolate some state between branches of our scene. For example, if we our game has multiple rooms, we might want a separate atom to track room-specific state:

[:object
  (for [i (range num-rooms)]
    [{:room-state (th/atom {})}
     [enemies]
     [props]])]

With this setup, our custom ISystem and IEntityType can use the provided context map to access the :room-state atom without additional logic to isolate state between rooms.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close