I think you're reaching for mutability a little too soon. You could aim to
be more functional, then leave the mutation up to atoms or megarefs.

For example:

    (def empty-system
      {:entities {}, :components {}})

    (let [i (java.lang.concurrent.atomic.AtomicInteger. 1)
      (defn new-id [] (.getAndIncrement i)))

    (defn add-entity [system ent-id]
      (assoc system :entities ent-id {})))

    (defn remove-entity [system ent-id]
      (dissoc system :entities ent-id))

    (defn component-name [component]
       (-> component meta ::name))

    (defn set-component [system ent-id component]
      (let [comp-name (component-name component)]
        (-> system
            (assoc-in [:entities ent-id comp-name] component)
            (assoc-in [:components comp-name ent-id] component))))

    (defn remove-component [system ent-id comp-name]
      (-> system
          (update-in [:entities ent-id] dissoc comp-name)
          (update-in [:components comp-name] dissoc ent-id)))


This would give you a way of adding and removing entities and components,
and an way of looking up components by entity, and a way of looking up all
entities that adhere to a particular component.

- James


On 8 June 2014 13:33, Atamert Ölçgen <mu...@muhuk.com> wrote:

> clecs is an entity-component-system written in clojure.
>
> It is not production ready but it is complete in the sense you can use it
> for your hobby projects.
>
> It is available in clojars.
>
> The repo is here: https://github.com/muhuk/clecs
>
> I have written a rant about it[1] but I won't crosspost it here entirely,
> just this bit:
>
> ...if you can take a look and at least tell me about your first
>> impressions it would be great. I have two main questions:
>>
>>
>>    - Do you think having a game development library that is completely
>>    agnostic about rendering, sound & inputs, i.e. doesn't provide any of
>>    these, make sense?
>>
>>
>>    - Do you think the API looks right? Is it idiomatic Clojure from a
>>    library user's perspective?
>>
>>
>
> [1]:
> http://blog.muhuk.com/2014/06/08/entity_component_system_in_clojure.html
>
>
> --
> Kind Regards,
> Atamert Ölçgen
>
> -+-
> --+
> +++
>
> www.muhuk.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to