Liking cljdoc? Tell your friends :D

clecs.backend.atom-world

Reference implementation of clecs API.

AtomWorld stores it's data in-memory. It is backed by an clojure.core/atom internally.

Currently systems run sequentially.

Reference implementation of clecs API.

`AtomWorld` stores it's data in-memory. It is backed by an
`clojure.core/atom` internally.

Currently systems run sequentially.
raw docstring

clecs.query

Primitives for query criteria.

query method of [[clecs.world.queryable/IQueryableWorld]] is used to find entities based on their components.

Examples:

;; Return a seq containing entity id's that
;; has FooComponent:
(query queryable-world (all FooComponent))

;; Same as the previous one:
(query queryable-world (any FooComponent))

;; Entities with both FooComponent and BarComponent
(query queryable-world
       (all FooComponent BarComponent))

;; Entities with either FooComponent or BarComponent
(query queryable-world
       (any FooComponent BarComponent))

;; Entities with FooComponent and either
;; BazComponent or BatComponent
(query queryable-world
       (all FooComponent (any BazComponent
                              BatComponent)))

;; Entities with either FooComponent and
;; BarComponent or BazComponent and BatComponent
(query queryable-world
       (any (all FooComponent BarComponent)
            (all BazComponent BatComponent)))

You can nest primitive calls infinitely. However it is considered bad design to query too many components at once.

See also [[clecs.world.queryable/IQueryableWorld]].

Primitives for query criteria.

`query` method of [[clecs.world.queryable/IQueryableWorld]]
is used to find entities based on their components.

#### Examples:

    ;; Return a seq containing entity id's that
    ;; has FooComponent:
    (query queryable-world (all FooComponent))

    ;; Same as the previous one:
    (query queryable-world (any FooComponent))

    ;; Entities with both FooComponent and BarComponent
    (query queryable-world
           (all FooComponent BarComponent))

    ;; Entities with either FooComponent or BarComponent
    (query queryable-world
           (any FooComponent BarComponent))

    ;; Entities with FooComponent and either
    ;; BazComponent or BatComponent
    (query queryable-world
           (all FooComponent (any BazComponent
                                  BatComponent)))

    ;; Entities with either FooComponent and
    ;; BarComponent or BazComponent and BatComponent
    (query queryable-world
           (any (all FooComponent BarComponent)
                (all BazComponent BatComponent)))

You can nest primitive calls infinitely. However
it is considered bad design to query too many
components at once.

See also [[clecs.world.queryable/IQueryableWorld]].
raw docstring

clecs.test.mock

Mock worlds that delegate their operations to functions.

Because protocol method can't be mocked using with-redefs etc. systems and world backends are difficult to unit test. Paying one level of indirection, protocols can be mocked using functions defined in this module.

Examples:

(def foo-system [w dt]
  (doseq [eid (world/query w (all :FooComponent
                                  (any :BarComponent
                                       :BazComponent)))]
    (world/remove-component w eid :FooComponent)))

(fact "foo-system does stuff."
      (let [w (mock/mock-editable-world)
            q (all :FooComponent
                   (any :BarComponent
                        :BazComponent))]
        (foo-system w anything) => anything
        (provided (mock/query w q) => [..e1.. ..e2..]
                  (mock/remove-component w ..e1.. :FooComponent) => nil
                  (mock/remove-component w ..e2.. :FooComponent) => nil)))
Mock worlds that delegate their operations to functions.

Because protocol method can't be mocked using `with-redefs`
etc. systems and world backends are difficult to unit test.
Paying one level of indirection, protocols can be mocked
using functions defined in this module.

#### Examples:

    (def foo-system [w dt]
      (doseq [eid (world/query w (all :FooComponent
                                      (any :BarComponent
                                           :BazComponent)))]
        (world/remove-component w eid :FooComponent)))

    (fact "foo-system does stuff."
          (let [w (mock/mock-editable-world)
                q (all :FooComponent
                       (any :BarComponent
                            :BazComponent))]
            (foo-system w anything) => anything
            (provided (mock/query w q) => [..e1.. ..e2..]
                      (mock/remove-component w ..e1.. :FooComponent) => nil
                      (mock/remove-component w ..e2.. :FooComponent) => nil)))
raw docstring

clecs.world

Protocols that define clecs API.

Definitions

World : Worlds are top level containers. Entities, components are stored in worlds and systems are run within the context of worlds.

Entity : Objects in the world. Entities are merely identifiers, they do not store any information. This is an important difference from object oriented data structures, where all information related to an object is stored with the object.

Clecs refers to entities as `entity-id` or
`eid`. An entity-id can be an integer or a
UUID or any other type depending on the
world implementation.

Component : Components encode a single aspect about an entity. Entities can have any number of components and components can be added or removed from an entity during its lifetime. Therefore there is not necessarily a static set components for a set of entities. This is another difference from the object oriented approach which enforces a static template of aspects for each type of entity.

System : Systems are either maps (new style) or (old style) callables that define operations over the world. Each system should ideally deal with a unique aspect of the application.

Systems may primarily deal with a single
component but it is not a requirement.

Query : There are two kinds of queries in clecs:

1. Queries for entities associated with certain
   components.
1. Queries of a certain entity for its individual
   components.

Queries can be only be run by systems.
Protocols that define clecs API.

#### Definitions

World
:   Worlds are top level containers. Entities,
    components are stored in worlds and systems
    are run within the context of worlds.

Entity
:   Objects in the world. Entities are merely
    identifiers, they do not store any information.
    This is an important difference from object
    oriented data structures, where all information
    related to an object is stored with the object.

    Clecs refers to entities as `entity-id` or
    `eid`. An entity-id can be an integer or a
    UUID or any other type depending on the
    world implementation.

Component
:   Components encode a single aspect about an
    entity. Entities can have any number of
    components and components can be added or
    removed from an entity during its lifetime.
    Therefore there is not necessarily a static
    set components for a set of entities. This
    is another difference from the object oriented
    approach which enforces a static template of
    aspects for each type of entity.

System
:   Systems are either maps (new style) or (old style)
    callables that define operations
    over the world. Each system should ideally
    deal with a unique aspect of the application.

    Systems may primarily deal with a single
    component but it is not a requirement.

Query
:   There are two kinds of queries in clecs:

    1. Queries for entities associated with certain
       components.
    1. Queries of a certain entity for its individual
       components.

    Queries can be only be run by systems.
raw docstring

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

× close