Reputation: 915
I'm toying in my free time with a sandbox/world simulation/powdertoy type of game using clojure and quil. The idea here is that each coordinate/unit in the world can have one identity (sand/water/air/plant) with certain properties (light/heath etc). In each iteration each coordinate gets updated only taking in account the coordinate next to it (recieves heat from a warmer coordinate/ water falls down when there is air underneat it)
Updating the world can get offcourse very computing intensive the bigger the world gets. But speed is not my highest priority (say for example 5-10 iterations/ second is good enough).
I was wondering if it would be feasible to update each unit in the world in parralel using the concurrency principles used in Rich's ants colony demo where each ant has its own thread. (so each unit in the world get its own thread). I have a really hard time to wrap my head arround all the things that are happening in the ant colony demo. Would there be a problem when for example 2 sand units try to move to the same air unit at the same time? Can there exist that many threads? (eg 500 000 coordinates -> 500 000 threads). Or would it be best forget about all of this and just update all coordinates sequently.I was also thinking about introducing kind of static flag for each coordinate. So I only have to update the coordinates where there could be a change. (using a vector of changable coordinates in the next iteration)
Greetings and thanks for reading. :)
Upvotes: 3
Views: 739
Reputation: 10085
You should check out Clojure Ants - a Literate Programming Version, which explains Rich's code really well.
Upvotes: 2