On Aug 30, 7:14 am, CuppoJava <patrickli_2...@hotmail.com> wrote:
> Hi Elliot,
> I've written a small game using Clojure and LWJGL, and I've run into
> the exact same issue (balancing between mutability and immutability)
> when I was working on it. The three approaches I tried were:

First of all, thanks for your input; I'm still trying to figure out
what model is best for my game. Comments inline.

> The world is 1 ref containing the state of the game. Everything else
> is immutable.

I've thought about this (via zippers), but it seems to me that it
wouldn't be very good for either parallelism or message passing.

> Sprites are maps of refs of their properties. So practically
> everything is mutable.

Keeping a ref for each attribute seems excessive to me.

> And finally, sprites are refs of their states. Their states themselves
> are immutable.

This seems sensible to me.

I'm wondering if it might make sense to use agents to get an implicit
sort of message passing behavior between objects.

> I found the last option to be both the fastest and also the most
> straight-forward to program. The rule of thumb I used was: "Do I care
> about the identity of this object? or do I care only about the value?"
> If Identity is important, (ie. you need to know WHICH sprite this is)
> then I used a ref. If I cared only about the value (ie. what's the
> sprites state? I could care less about WHICH state object it is.) then
> it should be an immutable structure.
>
> Caveat: The only issue I've run into with this scheme is when the
> states of a sprite depend upon the identity of another sprite. (eg.
> This sprite needs to know WHICH weapon he's wielding.) So in this
> case, the state will contain a reference to a ref, which is something
> that's been written as not a very good thing to do.

So if I made a tree holding actors where actors are agents wrapping
maps, then I can imagine that I might want to give an agent a
reference to another agent (to allow them to pass messages back and
forth).

(def root (agent
           {:name :root
            :children [(agent
                        {:name :child})]}))

Are you saying that this is not a suggested way of doing things?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to