Game Development Reference
In-Depth Information
The bottom line? A single developer has managed to reuse about 80,000 lines of C code,
thus bringing a PC game to Android with a few thousand lines of new code in a couple of
days. Imagine the potential savings in development cost and time. Now compare this to
a team of three developers trying to port the 80,000 lines of raw C to pure Java. It would
probably take them months of head-pounding work with no financial gain (as the code is
open sourced); this simply makes no sense. I hope that at this point you understand why this
chapter is my personal favorite and a must-read for the aspiring Android game developer.
So get the source code for the chapter—and let's get started.
Bringing Doom to a Mobile Device
I was excited about the challenge of bringing the great game of Doom to the mobile
platform. But I had my doubts that this could even be achieved once I looked at the
complexity and the amount of original C code. Listing 5-1 shows a portion of the total
number of lines of C code of the popular Doom engine, PrBoom (dated 2008 and available
from http://prboom.sourceforge.net/ ).
I knew I had two choices for this project:
Port the C code line by line to Java. I even started porting a few files to
Java. Believe me when I say that this is not a good idea. The amount of
time that it would take to do this makes the project unfeasible, especially
considering that the hard work must be done pro bono .
Find a way to pack the game as a dynamic shared object (DSO) and call
it from Java using JNI. This option seems to be simpler and quicker, but
it requires expert knowledge of C and JNI, as well as changes to the
original game to glue together both languages.
Given these two options, the latter is the best approach to the problem, so I decided to build
a DSO and glue it to Java with JNI.
Listing 5-1. Portion of Code for the PrBoom Doom Engine (Approximately 80,000 Lines in Total)
$ wc -l *.c
1585 am_map.c
554 d_client.c
3093 d_deh.c
140 d_items.c
1744 d_main.c
759 d_server.c
48 doomdef.c
108 doomstat.c
85 dstrings.c
668 f_finale.c
202 f_wipe.c
2979 g_game.c
2717 gl_main.c
957 gl_texture.c
767 hu_lib.c
1593 hu_stuff.c
866 mmus2mid.c
467 p_ceilng.c
 
Search WWH ::




Custom Search