2007-04-11

Tidying, Optimisation and PALib Bugs

(Written 07/04/2007)

More tidying. I’m splitting the ScrollingText class out into a Font class, TextWriter class, and ScrollingText class, so that I can more easily create new classes like a SineScroller class, etc.

As part of this refactoring process, I found another bug in the PALib. Well, I say bug, but it’s really more of a standards problem. The PALib guys have used the printf() conversion “%c” to mean “change colour” rather than “output a single char”. This confused me for a while because, instead of getting single characters splatted on the screen, I was getting random strings of text.

I came up with this new function as a backwardly-compatible fix:

void PA_OutputChar(u8 screen, u16 x, u16 y, char text) { char output[2]; output[0] = text; output[1] = ‘\0’; PA_OutputText(screen, x, y, output); }

Another thought about using the WiFi system. One of the things I love about recent open-source programs, especially on the Mac, is that they tend to automatically tell you when a new version is available. It should be pretty easy to get the game to fetch an XML file from my web server that contains the latest version of the game; quick check against the internal value will let us know whether or not we’ve got the latest version. I could even make it do other things, like update the scrolling text on the menu screens, list news/other games, etc. I could have a whole section for that. Hmm, maybe I’ll write that after the menu system. It’d need some planning, though - what is it for? What does it do? What use is it? Who will use it?

Had a think about optimisation when working with C++ objects, too - I read something about the amount of work done in calling a function, and now that I’ve done some assembly programming (Z80, m68k, CIL and a lot of reading) it all makes sense. Bearing this in mind, I replaced calls to class properties with local variables in the main font writer loop. Seems to have improved the performance a bit - the flicker in No$GBA (caused by its DMA copier not running at the correct speed) has shifted from the middle of the screen to ¾ of the way to the right, which means the font writer is now running ¼ of a horizontal scan faster.