Header Sep
Java Tips, Tricks & Code
My Rating Score
Login to rate page

October 2004
A case study: Porting Java applications from Nokia - The Pocket Panic experience

[Back]

Following our article "Cross-platform compatibility with Nokia UI Classes" in September 2004 that described the Sony Ericsson support for the Nokia UI API, we asked Pocket Panic about their way of porting the Sony Ericsson Game Developers Challenge 2004 winner Nano Kid. Pocket Panic is a small company from Sweden with games available for Nokia phones but until earlier this year had never developed anything for Sony Ericsson phones. The Sony Ericsson Game Developers Challenge 2004 stimulated them to change this and made them decide to port an existing game, Nano Kid, running on Nokia MIDP 1.0 phones to MIDP 2.0 and the Sony Ericsson K700i.

Pocket Panic ported their Nokia UI API based game to a strict MIDP 2.0 application, and did so with surprisingly small effort. With that step taken, Nano Kid has ensured broad device support and future compatibility.

Background to the porting decision
On the commercial basis of seeing many MIDP 2 phones reach the market, Pocket Panic investigated the technical foundations for porting their successful game to be available on that platform. Previously, with the limitations of MIDP 1, the addition of critical feature code made the MIDlet's JAR size requirements too large. With the support for sprite flipping and object rotation in MIDP 2, the estimated JAR size became small enough for Pocket Panic to decide to start the porting work.

As David Eriksson, Pocket Panic, states: "We just used common sense to do the job. The core of the process was to fix only one thing at a time until completion. The only guidelines and documents used were the MIDP 2 and the Nokia UI API specifications". However, as you study the details in their process, there's a structure and experience to learn from.

The porting steps described at a high level:

  1. Pocket Panic's graphics loader/cache system was replaced by writing a simple loader that could handle the proprietary graphics file format.
  2. The tile-drawing routine was replaced with a TiledLayer.
  3. A Sprite class was used instead of their sprite routine. However, the built in features of the Sprite class, like collision detection or animation, were not used as Pocket Panic already had their own code to do that. 
  4. Nokia's flipping/rotation code sections were replaced by MIDP 2.0 ones. 
  5. The Nokia API-based sound effects engine was removed.  Instead, MIDI songs are played using the MMAPI. 
  6. Detection and adjustment for different screen sizes.
  7. Completed!

It was an obvious advantage to use the Nokia S40 DP2 emulator, as it supports both MIDP 2.0 and Nokia UI API. It meant that the game was actually working throughout most of the process. One feature at a time was converted and tried in an executable game, which made the porting job safe and under control at all times. In the last stage of porting, the Sony Ericsson K700 emulator and a real test device were also used to do the final tests and verifications.

Compared to the original development work, the porting job approximately took another five percent of the effort, which was as a small investment for getting significantly broader device compatibility. Costs were also contained by making as few changes to the game as possible. No new assets (except some MIDI songs) were created, and the game's engine was left untouched. The only features really changed in the MIDP 2 version are the code to draw graphics and to generate sound.

Porting tips
It was not obvious how to port Nokia's transformation codes into MIDP 2.0. Pocket Panic solved it by constructing a matrix containing the MIDP 2.0 codes. Columns correspond to rotations and rows to flips. The following method converts a Nokia transformation code to its corresponding MIDP 2.0 code (Yes, you'll have to figure out the matrix IMAGE_TRANSFORMATIONS yourself.)

 public short convertNokiaUITransformToMIDP2 (int nokiaUITrans) {
 byte y = 0, x = 0;
 if ((nokiaUITrans & NOKIA_FLIP_HORIZ) != 0) {
     y = 2;
     nokiaUITrans ^= NOKIA_FLIP_HORIZ;
 }
 if ((nokiaUITrans & NOKIA_FLIP_VERT) != 0) {
     y++;
     nokiaUITrans ^= NOKIA_FLIP_VERT;
 }
 nokiaUITrans = mod(nokiaUITrans, 360);
 if ((nokiaUITrans & NOKIA_ROT_90) != 0) {
     x = 1;
 } else if ((nokiaUITrans & NOKIA_ROT_180) != 0) {
     x = 2;
 } else if ((nokiaUITrans & NOKIA_ROT_270) != 0) {
     x = 3;
 }
 return IMAGE_TRANSFORMATIONS[y][x];
    }

Generally, an application is easier to port if all device-specific code (such as the calls to the Nokia UI API) is contained in only one class. As an alternative, use a pre-processor to avoid duplicating code.

Pocket Panic has managed to make just one MIDP 2.0 build that runs on both Sony Ericsson and Nokia Series 40 phones. Screen size is detected and the game adapts to that.

Conclusion
As our September article "Cross-platform compatibility with Nokia UI Classes", shows, a Nokia UI API application can actually run on a Sony Ericsson phone with no or a very small effort without porting it to a MIDP 2 application. That might be the best commercial and easiest technical way to go in some cases, weighing the required investment to the expected extras. However, Pocket Panic estimated that the porting from Nokia UI API to a full-blown MIDP 2 application was worth the extra effort to reach the whole growing market of MIDP 2 phones. That estimate turned out to be true as the porting job was even smoother than expected. Also, by winning the Sony Ericsson Game Developers Challenge 2004, Nano Kid in the MIDP 2 version has had a real kick start!

The Lead Programmer and Lead Artist for Nano Kid were speakers at Sony Ericsson's developer seminar at CTIA Wireless IT & Entertainment 2004, and shared their experiences from developing for the Sony Ericsson Game Developers Challenge 2004.

More about the seminar>>


 

My Rating Score
Login to rate page