I am working on a game in Clojurescript. Inside the game loop all the game's state is being tracked in a hashmap.
(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.