I’ve been learning about concurrency and Actors, and just got a test program working.
http://www.hexara.com/pond.html
http://www.hexara.com/Images/LotsOfThreads.JPG
On this program, there are 576 threads (one for each of the squares) running independently. Each with the following basic structure:
While(true)
{
move();
Thread.sleep(sleepAmt);
}
I made the sleep amounts different for the different threads. Instead of a game loop, there is a timer() that triggers a redraw every 25 msec, taking a “snapshot” of the current state.
I’m using an array that matches the display, one element per pixel, for collision detection. I’ve never done collision detection this way before, by locking and consulting elements that correspond to the pixels. (These squares are 8x8 pixels, so there are 64 “drips” in the “pond” that are locked and inspected with each move.) But it seems to make a certain philosophical sense. Space itself is the medium by which we determine what is close and what we can occupy or not.
This structure can also be thought of as a sort of “message passing” medium for the “Actors”. When they probe a position, they can find out whether and what other Actor is there, and response behavior can be defined for the situation. For example, in the case of collision, compute a bounce. Or maybe reds can eat oranges or blob together with greens. (One could certainly animate sprites in this context.)
I’m used to reading about things like QuadTrees or Bins. In those cases, one is consults and checks against lists of other objects. Here, one is consulting the space itself. Is this sort of collision detection done in games? (I’m okay with recreating wheels, as a learning experience.) Examples?
I’m also intrigued about the possibilities for designing games or controls over hundreds of independently threaded objects, and am wondering if there are other games to look at as models. I don’t know. It just seemed kind of cool and I wanted to show it off and see what others thought.