I am working on a game in Clojurescript. Inside the game loop all the
game's state is being tracked in a hashmap.
The gameloop is somewhat inspired by this article:
https://swannodette.github.io/2013/08/02/100000-processes
(go (loop [refresh (timeout rate) s state]
(let [[v c] (alts! [refresh ui-channel])]
(condp = c
refresh (let [new-state (update-state s)]
(render! new-state)
(recur (timeout rate) new-state))
ui-channel (let [new-state (process-ui s v)]
(recur refresh new-state))))))
I'm not at all sure if this strategy is sensible performance-wise but I'm
trying to make a clear distinction between a functional part in which the
game's state is being update by the update-state function, and a user
interface part where a lot of side effects occur, brought together by
channels, as the above snippet hopefully makes clear.
I have noticed that by doing this, I tend to make many function calls from
the update-state function with the complete game state as a parameter,
whether it is to update the location of a single game entity, or to decide
whether a mouse click hit a player, etc.
Now my question is: is it considered bad (memory-wise and performance-wise)
if you pass around the complete game state all the time? It is not a huge
object (location, speed, orientation, color of about 25 entities). Or is it
better to select just these pieces of data that are needed, pass them
around, and then update the game state? I guess in other words, does it
matter where and when the destructuring is being done?
Hope this question makes any sense, let me know if more specific examples
are needed.
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/clojurescript/b80e1c12-cf6a-4b8f-ab1f-910e6a5ef13b%40googlegroups.com.