1

How to handle any change of state of a character with functional programming?

If I'm using functional programming the character should be stateless, in my understanding. With that said, I should instantiate a new character every time a position, for example, is changed. Is this correct? This doesn't sound very efficient, but I might be wrong. I'm tinkering before start implementing and wanted to be sure this is the right way.

Thanks.

liggiorgio
  • 4,636
  • 6
  • 25
  • 37
renno
  • 115
  • 6
  • Game development rarely uses purely functional styles. About the closest we get is highly data-oriented design, like ECS systems operating on buffers of data like a giant map call. May I ask why you're looking at functional style as a key goal for your character update logic? – DMGregory Mar 02 '19 at 04:40
  • I've used ECS and I loved it. I'm looking at functional style, because I've used in other projects and I liked it a lot. – renno Mar 02 '19 at 12:44
  • Here’s a link to a series of short articles about implementing pac-man in a purely functional way: https://prog21.dadgum.com/23.html It doesn’t come down one way or the other on whether this is a good idea or not. – Ryan1729 Mar 02 '19 at 17:59

1 Answers1

1

What your looking for is FRP game development.

Some Video Introductions:

It is 100% possible and preferable to make the core game logic in a purely functional way, the industry as a whole is simply behind, stuck in one paradigm of thinking.

Its possible to do it in Unity as well.

To answer the question a new game state will be updated/created every time something moves, as carmack says in his talk, it's not a problem. The drastic reduction in cognitive overhead that comes from a purely functional, highly maintainable, flexible architecture far out ways the performance hit, if it exists at all.