Monthly Archives: August 2010

Blackberry Programming: Increasing Video Speed Through Prerendering

A Problem of Efficiency

As I finishing up the full version of Galactic Blast (screenshots on this soon, its a fully fleshed out game inspired by the demo, to be released on App World) – I ran into an issue in a strange area. The animation was smooth throughout the game, except oddly enough, on the instructions screen.

The instructions screen in Galactic Blast includes some text describing the storyline, some text describing the keyboard controls, bitmaps showing each of the enemies and power ups with description text, and some credits at the end. Since there’s much more than can fit on a single screen, the user can scroll up and down – nothing fancy, just your basic instructions screen. However, the scrolling was anything but smooth. As I debugged more, I found out that redrawing all the bitmaps and text at each scroll was simply taking too long – all the function and helper calls involved in rendering everything was just too much for the processor.

The Solution

As I thought more about it, I realized that it would be much better to simply render one item instead of 20-30 items each time. And since instructions are static in nature (they don’t change or animate), it was a prime candidate for prerendering all the text and bitmaps to a single, big bitmap. However, I wanted the program to prerender the items automatically at runtime – I didn’t want to have to create the bitmap manually (which would be a huge pain anytime I needed to edit something – like adding a new line of text in). The code below achieves this by creating a bitmap in memory and rendering all the desired text/images to it at the start of the program, and then simply displays (and scrolls) this bitmap on the instructions screen.

The Code

I’ve removed the specific text, bitmaps, and positioning from the code to make things a little clearer:


// _instructionsBM is the large bitmap we will be rendering all our text 
// and images to.  This is the bitmap we will actually
// display on the instructions screen, thereby increasing efficiency
// since we're only redrawing one bitmap each time the 
// player scrolls instead of a bunch of bitmaps.
private static Bitmap _instructionsBM;

   public static void prerenderInstructions() {
      Graphics tempGraphics;
      String objectiveString;
      Bitmap tempBitmap;
      Object castArray[][];     
      
      // Populate a string with the objective of the game
      objectiveString = "Text describing the objective of the game  ";
      
      // Populate an array with the enemy bitmaps, their names,
      // and how many points they are
      castArray = new Object[2][];
      castArray[0] = new Object[] { enemyBitmap1, "Enemy 1", "50 Points" };
      castArray[1] = new Object[] { enemyBitmap2, "Enemy 2", "75 Points" };
   
 

        // Initialize the bitmap, and then give it an alpha channel for
        // transparency, allowing the background to show through 
        // behind the text and bitmaps
       _instructionsBM = new Bitmap(Bitmap.ROWWISE_16BIT_COLOR, WIDTH, HEIGHT);
       _instructionsBM.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP); 

        // Start with a blank, completely transparent image
      _instructionsBM.setARGB(new int[_instructionsBM.getWidth()*_instructionsBM.getHeight()], 0,               
                                             _instructionsBM.getWidth(), 0, 0, 
                                             _instructionsBM.getWidth(), _instructionsBM.getHeight());

      // The Graphics object acts a surface that drawing operations 
      // can be performed on.  By calling the Graphics constructor
      // with the bitmap as an argument, all drawing operations
      // will be performed upon the bitmap itself.
      tempGraphics = new Graphics(_instructionsBM);

      // All operations to follow will be fully opaque (so pixels not 
      //acted upon will stay transparent, while any text/images drawn
      // will be solid.
      tempGraphics.setGlobalAlpha(255);
            
      // Draw the text onto the bitmap
      tempGraphics.setColor(Color.YELLOW);
      tempGraphics.drawText(objectiveString, 5, 5);    
      
      // Draw enemy bitmaps onto the bitmap
      for (int lcv = 0 ; lcv < castArray.length ; lcv++) {
         tempBitmap = (Bitmap) castArray[lcv][0];
         tempGraphics.drawBitmap(Utils.getDimension(5, 50+lcv*50, 
                                                tempBitmap.getWidth(), tempBitmap.getHeight(), tempBitmap, 0, 0);
         tempGraphics.drawText((String) castArray[lcv][1], 100, 50+lcv*50);  
         tempGraphics.drawText((String) castArray[lcv][1], 200, 50+lcv*50);  
      }
   }

Shredz64 – New Disk Images and Firmware Posted

For those who want to download the NTSC or PAL version of Shredz64, I updated the disk images available online to include the latest track selection.

Additionally, the link on the blog to the PSX64 firmware now points to version 1.1, the latest update which incorporates the macro and speed fixes. For archival purposes, I’ve left 1.0 and 1.0a in the download directory as well.

Also, hopefully another new track soon, maybe even this weekend!

Shredz64 – Core Track Set Update

Just a quick update – I’ve made the following updates:

  1. Replaced the Zak Mckracken remix with the Bombo theme as one of the 10 tracks included in Shredz64
  2. Since there are now a couple versions of Shredz64 out there (the original had the Stairway Intro as a track, others had the Zak remix, and the new ones will have Bombo) – I’ve made ALL tracks available for download off the Synthetic Dreams website, found here. That way, you can grab any songs you’d like, regardless of what version you have.

This balances out the difficulty range of the included tracks a bit better. All disks shipped out from here on will contain the Bombo theme.

Shredz64 – New Track Available

First off, lots more sales of boards this week, thanks to everyone for their interest and support!

Also, there is a new download track available on the Synthetic Dreams website – Bombo by Ben Daglish. We’ve gotten a lot of feedback from people that the game difficulty is quite high, so I was sure to make this track at an easy difficulty level. It’s a great tune – you can take a listen here.

Shredz64 and PSX64 Updates

Due to quite a bit of interest and positive support, I’ve tried to kick my butt back in gear and start producing more PSX64 boards, as well as update Shredz64 a bit. We’ve been popping up in a few expos and meetups, including TNMOC’s Vintage Computer Festival 2010 at Bletchley Park, VCF East, SC3 Arcade Party, and most recently at the Commodore Computer Club.

It means a lot that people are still very interested in this work, so I’ve started by making the following updates:

  1. Updated the PSX64 firmware to fix a bug in macro recording, tighten up the analog joystick response, and increase sensitivity for precision game play when a non-Guitar controller is plugged in.
  2. Updated the Shredz64 webpage with a downloadable bonus track, the Stairway to Heaven Intro, by Nantco Bakker. This track appeared on very early versions of Shredz64, but was replaced with Edwin’s Dream. Now both tracks can be enjoyed.
  3. Since shipping varies wildly, and I tend to make boards as the need arises, I replaced the Paypal button on the order page with a link to the contact page. If you’re interested in ordering a PSX64, simply contact me with your shipping address, and I’ll quote you out the total price.

Thanks for your support everyone!