Lugaru for PSVita

This is a port I did to bring the classic 2005 PC game Lugaru to the Playstation Vita as homebrew. I wanted to do it both because it's a fun project, but also as an exercise in optimization.

The original Lugaru does all processing on a single thread, and it only uses the obsolete fixed-function OpenGL APIs. As a consequence of this, the game can't take advantage of hardware acceleration, hardware instancing, etc.

For context, the PS Vita's processor is a 32-bit ARM Cortex-A clocked at 333mhz with only 3 usable cores, and games are typically only able to use around half of the 512mb total RAM on the system.

My goal was to get the performance to a point where the entire main story can be played from start to finish at 60 FPS on the stock clock speeds (i.e. with no overclocking). Achieving 60 FPS is import because Lugaru is a fast-based action game, so slowdowns can ruin the gameplay experience.

Not only did I accomplish that goal, but the game is so fast now that it can sustain 60 FPS even if you underclock the system!

Refactoring old code

Getting to 60 FPS required a lot of different things, and it would be tedious to write about them all. In short, the highest-impact change was implementing a consumer-producer system for distributing workloads across all available cores, and then meticulously refactoring a lot of existing systems in Lugaru to make use of it.

While I don't have before-and-after screenshots, I do have an after:

Additionally, I slapped together an asset processor for textures using waf. This was needed to downscale textures, transcode them into compressed formats, and generate mipmaps. Without this, the original textures from the LugaruOSS project would take up too much memory.

Future work

The game is in a beta state, meaning it still has some bugs and occasional crashes. If I decide to dedicate more time to this some day, those are issues I'd like to fix.

Additionally, there is still a lot of room for additional optimizations. If someone ever wants to port this game to more consoles that are weaker than the Vita, then this fork would be a good place to start.

I would be interested in seeing how well the Nintendo 3DS can run this game, since that console has half the cores, a lower clock speed, and a quarter of the RAM. A 60 FPS port there would likely require more work to redesign the rendering system to make use of hardware acceleration, at least for hardware instancing if not also vertex shaders for the animations. That would be a lot of work, but would be cool to see.

Video

Here's a video of the game recorded on a real PS Vita using this.

Download