Pure functional programming and game state


Is there a common technique to handle state (in general) in a functional programming language? There are solutions in every (functional) programming language to handle global state, but I want to avoid this as far as I could.

All state in a pure functional manner are function parameters. So I need to put the whole game state (a gigantic hashmap with the world, players, positions, score, assets, enemies, …)) as a parameter to all functions which wants to manipulate the world on a given input or trigger. The function itself picks the relevant information from the gamestate blob, do something with it, manipulate the gamestate and return the gamestate. But this looks like a poor mans solution for the problem. If I put the whole gamestate into all functions, there is no benefit for me in contrast to global variables or the imperative approach.

I could put just the relevant information into the functions and return the actions which will be taken for the given input. And one single function apply all the actions to the gamestate. But most functions need a lot of “relevant” information. move() need the object position, the velocity, the map for collision, position of all enemys, current health, … So this approach does not seem to work either.

So my question is how do I handle the massive amount of state in a functional programming language — especially for game development?

EDIT: There are some game frameworks for building games in Clojure. There approach to solve this problem partially is to thread all objects in the game as “entities” and put it in a huge bag. A gigant main function is holding the screen and the entities and handle events ( :o n-key-down, :o n-init, …) for this entities and run the main display loop. But this is not the clean solution I am searching for.

What's the equivalent of UIBezierPath in Cocos2d-x?


I’m beginner in Cocos2d-x , and i want to implement this tutorial with Cocos2d-x v.3 cpp, but the problem i dont know if there’s UIBezierPath in cocos2d-x.

Could you help me to draw the Bezier Arrow please?

3D Background for a Verticle Shooter: Making it loop?


I know how to scroll a background using spritebatches + 2D background images, but how would I do it with a 3D model?

Quotient splits in direct product


I have a quotient, say
$$Pert(mathcal{A} oplus mathcal{B}) / ker(phi) cong Im(phi) = Pert(mathcal{A}) times Pert(mathcal{B}),$$
and I know that
$$Pert(mathcal{A} oplus mathcal{B}) cong ker(phi) times Im(phi),$$
but I can’t see why this holds.

This holds for some groups, but $Pert$ is a semigroup.

I have proven it in a different way, which gave the result, but I need to prove it this way as well. Can you help me?

Phenomenon regarding square of any integer…


There is a phenomenon regarding squares of integers which i observed today.

$n^2 = sum_1^n^-^1 + sum_1^n $

I am a computer science graduate and i never heard about this phenomenon till date.
Is it already found by someone in history? Why this phenomenon occurs?

$ int frac{1}{(x-a)(x+b)} dx $


Could you please explain how to integrate this integral:

$$ int frac{1}{(x-a)(x+b)} dx $$

“New” tag in clan info next to name. How long does it last?


How long does the “new” tag last next to players names that have joined your clan?

How do you find out how many coins you have collected?


I keep collecting coins which are unlocking loads of upgrades all the time. But how to you find how many coins you have collected in total? Knowing this will give me an idea how much more stuff there is to collect.

What is the point of stars at the end of races?


In the top left corner of the post-race menu, there is a prompt to press + to add (or remove) one star out of six. What do these stars do?

How do I reuse a fluorescent light fixture?


I am reusing a fluorescent fixture with two black wires and one white. Do both black wires go to the black (hot) wire?

Question and Answer is proudly powered by WordPress.
Theme "The Fundamentals of Graphic Design" by Arjuna
Icons by FamFamFam