Wednesday, November 26, 2014

Using the OpenAL library in Xcode for iOS.

The last two days I have been porting The Little Plane That Could to iOS. It was already running on OculusRift(Windows), Linux, Android and Mac OSX. When porting it, I struggled with the poor OpenAL implementation that comes with the iOS SDK.

I knew that there was a very low limit of 32 sound sources for iOS. I figured that this limit only applied to sound sources that were in 'AL_PLAYING' state. And sure enough: you can create much more than 32 sources, without getting errors back from the OpenAL implementation.

In my game, I have 48 planes flying around, each with engine sounds. If we forget about gun sounds and explosion sounds for a while, these 48 engine sounds already exceed what the iOS implementation of OpenAL can handle. So this is why I adopted a method of only playing the four closest engine sounds. If an engine sound was further away, I would pause the playing of this sound. This worked well on all platforms, except iOS.

The problem I experienced was the following: alGetError() would start returning a non-sensical value of -1. And the sounds would no longer get started. The return value of -1 for alGetError() violates the OpenAL specification standard though. If you study the header files of the SDK, you see that the only acceptable return values are 0 (AL_NO_ERROR) or:

 * Invalid Name paramater passed to AL call.
#define AL_INVALID_NAME                           0xA001
 * Invalid parameter passed to AL call.
#define AL_INVALID_ENUM                           0xA002
 * Invalid enum parameter value.
#define AL_INVALID_VALUE                          0xA003
 * Illegal call.
#define AL_INVALID_OPERATION                      0xA004
 * No mojo.
#define AL_OUT_OF_MEMORY                          0xA005

After struggling to find the cause of the problem for half a day, I finally solved this issue. It turns out that the 32 source limit applies to BOTH playing and paused sources. Only sources that have not started playing yet (AL_INITIAL) or have been stopped (AL_STOPPED) do not count against the limit. So the fix was relatively easy: sources that are not nearby should not be paused. They should be stopped instead. This does not take away the fact that the alGetError return value is not according to spec. Apple should fix this.

Wednesday, November 19, 2014

What has Bram been up to?

So, it's been quiet for too long on this blog. It is about time to report on what I have been up to. Why not start with a small snippet of video?

Since July 2013 I have been mulling over the next step for my crane sim game. And as the holy grail, I have put forward an ambitious development target: deformable terrain. Frankly, I have not yet seen a single game getting this right. I most likely will not achieve completely realistic, sandbox-style, unlimited deformable terrain either. But I will surely try. The video above show a bulldozer at work in my terrain simulator.

Currently I have achieved the following:

  • Proper 3D terrain, not those crummy height-fields. So you can have overhangs.
  • Universally deformable terrain: you can dig anywhere and not just at designated spots.
  • Tunnelling! Yes - you can dig your own tunnel.
  • Soil mixing. You can dig up grey coloured dirt in the west, and deposit it on a brown coloured sediment in the east.
  • Near infinite size. I bound the height and depth (Z) of the plane. But in the long/lat (X/Y) directions, you can drive near infinitely far. And deform the terrain at any place. Distances are only limited by MAX_INT and the size of your disk, because any modifications you do to the terrain are stored to disk.
  • Procedural definition of the virgin grounds. I only store disturbances of the virgin ground. So you can dig a hole, then drive 8 hrs going in any direction, and drive 8 hrs back to the original location. Your hole in the ground will still be there! (This is a big thing!)
  • Tracing back your steps, BTW, is easy. Because while driving, depressions are made in the soil which are permanent. They will still be there, even after 100s of hrs of play. Everything persists.
I think this technology is pretty unique and not found in any other game. The basic tech is all implemented, and nearly good enough. What is not there at all, is game-play. Wonderful game technology is one thing. Making a interesting, fun to play game is another. There are some routes I could take w.r.t. the game-play:
  • Make it into an arcade style game with a lot of KATCHING! noises, and bright graphics every time you dig up a gem from the earth.
  • Do it like the original Little Crane game: break up the gameplay in a number of puzzle-like levels with simple goals. Digging for treasure, unearthing a temple, burying an item, digging a tunnel, building a dam and such, could all be simple objectives in such a game.
  • Make a full blown gold-mining simulator. Process earth by moving it into a trommel.
  • Make a full blown gold-mining simulator plus economic sim: borrow money from bank, buy claims, buy diesel, etc.
  • Make a full blown gold-mining simulator MMO. Buy and sell claims online. Bid for scarce resources (land) against other players.
The smaller the scope, the higher chance of succeeding of course, so I should avoid the latter ones.

Things I am doing at this moment include added more vehicles, like dump truck and excavator to the simulation. I also have to trace a bug where soil simulation goes hay wire at negative world coordinates. As my world is procedurally defined, I could cheat and spawn all action at large positive coordinates, but that feels wrong.