Things are improving slowly

In the Currently Working On page, I explained how I’m in the process of replacing the old Asphyre graphics framework with a new one built on the SDL library. I knew that using it would slim down the code base and speed things up, but the glimpse I just got of the scope of the improvement still shocked me.
The routine that loaded the system graphic into memory used to be a real beast. It was 370 lines of code, first loading the graphic itself, then doing a ton of processing on it, cutting parts of the image out, assembling some animations from them, and loading each one into the game’s image list separately. It had to be done this way because Asphyre’s image list requires you to enter an image element size up front for each image. This works well for sprite sheets, where everything’s the same size, but the system graphic sheet is a collection of many different images with many different sizes.

Turns out SDL doesn’t do that. When it comes time to draw something to the screen, it’ll let you copy a rectangle of any size off of the original image. This means that all that image-processing can be thrown out. All I have to do now is load the full-size image into memory and define the size and location for each of the drawing rectangles.

The new version’s only 51 lines of code. More than half of that is setting up drawing rectangles. With no more image processing to do, this routine (which accounted for a good percentage of the map’s setup time) now runs a few hundred times faster. I’ve got a similar revision to make to the chipset loader. When that’s done, the base load time for the Map Viewer will probably be in miliseconds, instead of seconds.

2 Responses to “Things are improving slowly”

  1. T says:

    One thing you’ll want to watch out when using SDL for an RPGMaker clone, is that you’re going to have issues with scaling graphics, rotating, etc. There are libraries for it, but it’s not tremendously fast… at all.

    A wise thing to do may be to investigate Open GL and use it within SDL for rotations, etc. It might not work perfectly on every computer, but it’s an idea and the only real thing I’ve found that would be capable of getting everything you want out of it.

    Best of luck!

  2. Thanks. I’m aware of the issues–already butting my head against some of them in fact–and I’m planning on doing a lot of the work in OpenGL. And apparently the next SDL release is going to have better encapsulated support for OpenGL, which will make things a lot easier.