Created: October 31 2011

Drops 2D :)

After doing some experiments with the boxing game network speed over bluetooth etc and satisfying myself that it will run ok, I've decided to go ahead and make an app for the app store. Obviously this one will not be done in a week like the last two were, it's quite a bit more work.

I also became extremely distracted with another side-project, a 2D fluid simulation using just the surface of a fluid to simulate it. As the surface moves around the area will change, so the position of the surface points are adjusted to keep the area at the target size. This paper explains some of the ideas quite well: Fluid Animation with Explicit Surface Meshes.

The paper covers a method where the surface is affected by an underlying grid representing the movement of the fluid. I am experimenting with not using any grid at all, but simply surface that preserves its area. This method cannot simulate the incompressible nature of water so it's not really an accurate fluid dynamics thing, but it may just be good enough for use in games. Since there are no particles or grids, the processing time depends only on how many points the surface is made up of, and there is no problem with keeping small details. Drops2D On the down side, apart from the compression issue, fast moving surfaces can be problematic - small drops can tunnel through the surface of a larger drop in one time step. Something similar to Box2D's bullet body setting will be needed. I have a feeling the compression problem could be greatly improved if the time step were extremely small, so that each frame only had a small amount of compression to repair before the next frame occured - as it is now I am trying to handle cases where two drops can go from not touching, to being half-embedded in each other in one time step, but perhaps this is not realistic.

Anyway, the long term goal is to get this interacting with Box2D rigid bodies sometime. I have already used a bunch of code from Box2D which was very helpful to get this far already, in particular the dynamic tree has been awesome. These calculations involve tons of raycasts and it has been performing really well.

Uhm... so the boxing game, yeah. Work has been a bit slow on this front. I resurrected a lot of old code I had and managed to get a proper messaging system up and running, and loaded in 3D models made in blender. I also set up a system so a friend of mine who will be making the audio can upload his sounds to a webserver, and the app will load them from there at runtime. This lets him check out how things will be on the device anytime without me needing to get the files from him and build and distribute a new adhoc ipa.

As for synchronizing the physics, I'll be cheating on that. One device is the 'server' which receives touch inputs from the other device, runs the physics, and sends the entire Box2D world back to the other device every frame hahah... I can do this because the entire world is only 300 bytes or so in size. There is no synchronization of game 'turns' whatsoever, the two devices just send whatever they have available to send at any time.

I went with this method over the typical way I might have done this (which is to send the input only and simulate physics on both devices) mainly for simplicity, since there are no timing issues to think about, and for accuracy - the determinism problem will not matter because only one device is actually doing any physics. Another factor is that I will be writing the gamestate to disk as it is played, to create a replay file. This could also have been done much more economically by only recording the input, but I thought it would be neat to have a replay that could be rewound at will to watch the KO punch highlights or whatever, and the simplest way to do that was just to have the entire world state for any given frame available in the replay file.

Anyway here is the 'arena' so far, the fighters will be the two flat planes in the boxing ring. The game play itself will be entirely 2D but the camera will move around in the 3D scene a little before and after the fight. Boxing2D
Oh yeah, I also added a Box2D gotchas page and an advanced tutorial topic covering the 'fake surface velocity' idea that is quite useful for making conveyor belts. Enjoy!