Tuesday, January 3, 2012

BlastZone 2 Makes its way to iOS!

Once I accomplished all the goals I set out to do for the PC version post release, I decided to start working on the iOS port for the game in November '11.  A year prior, I had already done a lot of work on an alternate render path for OpenGL ES, which is used for graphics programming on mobile devices.  Since the PC version uses the desktop version of OpenGL, this transition doesn't require replacing all the graphics code.  There were other systems I had to rebuild to work on iOS, such as the sound and input systems, but they are much smaller than the rendering system.

** This section gets a bit technical if you're curious **

Most of the OpenGL commands that aren't available for mobile devices I was able to replace with generic code that works on both the mobile and desktop versions of the game.  However, there is one big feature of desktop OpenGL that I didn't want to remove for the mobile version, which is why I built the engine to have two render paths.  The PC version of BlastZone 2 renders most of the graphics using something called a "Display List", which is very fast to draw even on slow computers, which allows me to add more detail to the game without slowdowns.  This method of drawing can only be used in specific circumstances effectively, but BlastZone 2 just happens to be the perfect game for this.  Virtually every model in the game is perfect for this method of drawing, such as airplanes, space ships, and terrain.  The types of models that are bad for this drawing method are more animated ones, such as people and animals.  Instead of Display Lists, OpenGL ES has to fall back to using Vertex Buffer Objects(VBOs) to speed up rendering.  While the speed of this method is respectable, the main reason I assume this was favored is because it can be used for any model type and isn't restrained by favoring specific types of models over others.  However, VBO's are much slower to render than Display Lists, and are roughly half the speed during my tests on the PC version.  Having a slower device that uses a slower rendering method really compounds performance issues, so it was an uphill battle to bring performance up to where I wanted it.  I put a lot of optimization work into the VBO render path for the game and had really tangible results doing so, but it never cought up to the performance of the Display List render path.

** End technical jargon **

When I finally got the game to compile and run on the device, it was a huge moment for me.  While the game was only chugging along at around 5 to 6 frames per second, it was so incredible to see my creation running on such a tiny device that can fit in your pocket.  Up to now I was only used to seeing BlastZone 2 run on a big desktop pc or a laptop.

BlastZone 2 up and running on the iPhone for the first time!

As an engineer, developing for iOS is an interesting and fun problem to solve.  I had to squeeze my existing game into a device that has much less memory and processing power by figuring out a lot of slick optimization techniques, pushing my programming abilities to the limits.  I had to do this while getting the same amount of work done in the end and keeping the game looking almost identical to the PC version.  Fortunately, all iOS devices use a PowerVR graphics chip that supports a very efficient texture compression technique that worked really well crunching down memory requirements without affecting image quality.

The other big goal I was shooting for was crunching the app download down to 20mb so it can be downloaded over a 3G connection and therefore more accessible to my audience.  It was tough, but I managed to do that as well, compressing down the audio and textures without a noticable difference to the player.

All the above helped a lot, but it still wasn't enough to get the performance to a level I wanted.  I had to fall back to reducing geometry complexity as an easy speedup.  I managed to do this in an intelligent way, and with the smaller screen of the iPhone, the game looks almost exactly the same as the PC version.  This brings the graphics fidelity to be very close to some of the best looking games on the platform, which really helps BlastZone 2 stand out on the Apple app store.

Working with iOS gave some great opportunities for adding new control schemes to the game.  The first control scheme I implemented used a virtual d-pad that mimicked how a PC controller or keyboard would play.  From there, I added an accelerometer tilt control option to give an intuitive way to control the ship without having the touch the screen and cover the gameplay. The third control option I implemented was a direct touch control, which moves the ship to your finger, giving the player much more direct and precise positioning not possible on other platforms.

iOS version shaping up really well!
The iOS development had one other good side effect.  I had to put a lot of work into optimizing the performance and memory usage to help the game run acceptably on the iPhone.  Since the game uses a unified code base, I was able to easily bring those optimizations to the PC version, reducing the minimum specs even more without any loss in quality.  I was even able to get the game running at full detail at 60 fps on a netbook which is quite an accomplishment.

Overall, it took about a month and a half to complete the initial port of BlastZone 2 to iOS, which greatly exceeded my expectations.  There were two main reasons for this.  The iOS development environment is very  friendly to C++ development, which integrates seamlessly into the Objective-C based development kit.  Secondly, as I mentioned earlier, iOS uses OpenGL ES to render 3D content, which is very similar to the desktop OpenGL the PC version was written in, but with several functions removed.

Even though the iOS port was done rather quickly, this was at the expense of a few features to get it done in time for the holidays.  The main functionality missing was Apple Game Center integration, which most of the upscale iOS releases do have.  I was able to release an update soon after release to add basic Game Center support and leaderboards since these didn't require much code and I could reuse much of the leaderboard code from the PC version.  At the time of this blog entry writing, I am researching and will begin porting over online multiplayer support very soon.  Online multiplayer support will be a killer feature for BlastZone 2, as its very rare for an iOS side scrolling shooter to have it.  The big advantage I have is that I already wrote all the core logic to get online multiplayer working from the PC version.  The main task now is to integrate it into the Apple Game Center and have Ad-Hoc support at the same time for really low latency play.

BlastZone 2 shortly before the iOS release

Initial reactions and feedback have been very positive and download rates have been great, but I quickly got a list of features people were looking for to improve popularity of the game.  The main control scheme people wanted for an iOS side scrolling shooter is relative touch, which allows the user to move the ship around the screen by the relative touch movement on any part of the screen so this ship doesn't get covered.  Also, people wanted an auto-fire option.  Thankfully, these features were fairly quick to implement.  At the time of this writing, these new input features have been completed along with Achievements support and I'm excited to ship the update out to my audience.

I hope you enjoyed reading about my experiences with the iOS version of BlastZone 2.  Its been a very exciting process and release for me, and the feedback has been incredible!  Downloads and sales have already far surpassed the PC version and I can't wait to ship more updates and features for the game!  As it turns out, BlastZone 2 is very well suited to the iOS platform!

In my next entry, I will detail the future of BlastZone 2 both for the iOS and PC versions along with the other directions the game may take.  See you next time!

No comments:

Post a Comment