Thanks for the answers.
I realized the macro wasn't a good idea and I will keep using atoms to
manage state, just found the reset! function =)

Islon

On May 17, 10:28 am, Michael Gardner <gardne...@gmail.com> wrote:
> On May 15, 2010, at 4:56 PM, islon wrote:
>
> > I'm working in a simple single-thread console-based rpg game in
> > clojure (a port from my own scala version)
> > and didn't want to use any concurrency structure because the game is
> > single threaded.
> > I was thinking about a macro like
>
> > (defmacro set!! [s val]
> >  `(def ~s ~val))
>
> > so I can set my game state without using transactions, agents, etc.
> > Any comments about it?
>
> I wrote a Pong clone in Clojure just to stretch my mind a bit. Here's what I 
> do:
>
> The entire game world is a single struct-map (may become a record at some 
> point), stored in a global ref. When my world-update timer fires, I deref the 
> world and then pass it to my world-updater functions. These updaters return 
> the new world state, which I then set via ref-set.
>
> This is almost as simple as the usual global vars approach, and allowed me to 
> trivially split the world-drawing code into another thread that runs on a 
> different schedule. It also permits stuff like printing out or saving the 
> entire world state very easily.
>
> Actually, were it not for Swing, I wouldn't even be using mutable structures 
> at all-- I'd be passing the world state from update to update using 
> tail-recursion.
>
> You might also be interested in these links:
>
> http://nakkaya.com/2009/12/19/cloning-pong-part-1/(I originally based my Pong 
> game on this 
> code)http://jng.imagine27.com/articles/2009-09-12-122605_pong_in_clojure.html(cloning
>  Pong is apparently pretty 
> popular!)http://briancarper.net/blog/making-an-rpg-in-clojure-part-one-of-many(site
>  down at the moment)http://prog21.dadgum.com/23.html(not Clojure, but 
> interesting for functional games in general)
>
> --
> 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 
> athttp://groups.google.com/group/clojure?hl=en

-- 
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