Fork me on GitHub
#clojure-gamedev
<
2021-11-07
>
Joe09:11:49

I'm finding that I'm passing my entire game state as an argument to functions quite a lot, especially as the functionality gets more complex and for any one thing I need to 'know' things from lots of different parts of the game state. In a regular program I'd consider this an anti-pattern to get rid of. Is that also the case here or should I be more relaxed about it in this context?

Joshua Suskalo12:11:27

I think passing the whole state is something to be careful of. That is, much game code needs most of the game state to decide what to do, but it doesn't need to modify it. So if you want to update an entity, pass the entity and the game state and return just the new entity, and the caller will integrate that into the state.

💯 1
Joe12:11:57

That’s interesting, thanks!

Joshua Suskalo12:11:41

The way for an entity to have side effects past itself should be by adding events to some events queue.

👍 1
👀 1
Noah Bogart14:11:38

How is an event queue different that performing the effect directly?