2009-11-04

Skin Loading

One of the most neglected areas of Woopsi is the skinning system. It is an unrewarding set of classes to spend much time on, really. To create a skinnable class, a subclass must be made that can use a skin struct as part of its draw() routine. It’s basically a case of duplicating vast swathes of (potentially bug-infested) code for nothing but a frivolous aesthetic effect.

More frustratingly, creating a skin struct is laborious and tedious. First the skin must be created; then it must be chopped into individual bitmaps; then the bitmaps must be converted to C sourcecode; then the sourcecode must be included in the Woopsi project; then the properties of the struct must be populated with values extracted from the bitmaps; then the skinned objects must be instantiated and given pointers to the skin struct. This is far too much work.

As a way of improving the situation, I’ve added a SkinIO class. This can be given a path and told to load the skin from it. It uses the new BitmapIO class to automatically load the individual BMPs that make up a skin and work out their properties, returning a pre-populated skin struct. Much, much easier to work with. It doesn’t currently support all features of the skin struct, such as offsets, etc, but I’m going to add a config file parser that can load that data from a text file.

Creating the skin loader was, of course, immensely annoying, as is creating any code that uses libfat. None of the DS emulators supports FAT emulation in any meaningful way (I’m ignoring complex commandline gymnastics that require a Linux installation), so testing FAT-enabled code becomes an endless cycle of the following steps:

  • 10 Remove flash cart from DS
  • 20 Remove mini-SD card from flash cart
  • 30 Insert mini-SD card into SD adaptor card
  • 40 Insert SD adaptor card into card reader
  • 50 Compile DS program
  • 60 Drag ROM to SD card
  • 70 Eject SD card
  • 80 Remove SD card from reader
  • 90 Remove mini-SD card from adaptor
  • 100 Insert mini-SD card into flash cart
  • 110 Insert flash cart into DS
  • 120 Switch on DS
  • 130 Select ROM menu
  • 140 Run ROM
  • 150 Watch as the ROM crashes with no useful error message
  • 160 GOTO 10

I ran into a bug that made no sense. I couldn’t even rely on the SDL version, as it worked perfectly in that. Skip forwards an hour, and it turns out that I’d forgotten to call fatInitDefault().

In other changes, the skin classes have been moved to the “bonus” folder and are no longer part of the main Woopsi library. I’ve added a skin example and removed the skin code from the Woopsi demo. Also, I’ve moved the fatInitDefault() stub method that is used in SDL mode from the top of all classes that use libfat into the nds.h file.