Page 1 of 1

Tilemap Compression

Posted: Sun Dec 22, 2019 1:02 am
by themrcul
Hello gentlemen,
Up until now I have been compressing my tilesets and sprite tilesets but not my tilemap (plane mappings).

Lately I have been thinking about how much ROM space my plane mappings will be if I leave them uncompressed, and realised that I need to implement some sort of compression otherwise whatever project I attempt will simply not fit in ROM.

Rather than invent the wheel I did some cursory research into what people did back in the day, and it appears that, at least for the Sonic games, Enigma compression was used for tilemaps.
Being an RLE style compression specifically optimised for how tilemap data is usually stored (possibly many repeated runs of the same palette, priority and flip bits, adjacent tiles quite possibly being an incremented address in VRAM in relation to each other, etc), it compresses tilemap data efficiently and, best of all, has random access possibility which is necessary for sending columns and/or rows to VRAM for efficient scrolling while using a minimal use of CPU and RAM to do so.

All that being said, has anyone implemented this sort of compression in their games yet? Has anyone located or written their own version of Enigma that they would be willing to share??
I thought about using the standard LZ4W compressor/decompressor but that does not do random access, and I would need to implement zones of areas in the tilemap and possibly decompress several areas of the tilemap into RAM in order to send the correct columns/rows to VRAM which could get very complicated very quickly! So a random access RLE style compression format specifically tailored to tilemap data is of course ideal!

Re: Tilemap Compression

Posted: Sun Dec 22, 2019 2:20 am
by Miquel
I haven’t studied 16bit Sonic games in detail, but I’m pretty confident they use a several level metatile as main compression system. In that case I don’t think is possible to compress the metatiles themselves, but I don’t know about the (top) map.

Be sure to understand what I'm talking about because most games back then used metatiles and build/compress algorithms based on metatiles.

Aplib is my favorite compression utility, it’s simple, good compression factor but takes too much time to do it on demand, but you can use it several frames ahead is perfect, also (only) the compression algorithm is not public. You can see an example on the SGDK.

Enigma allows random access? I didn’t know that. Is a big point. In that case for sure use it if you need to decompress columns with the benefit of global compression. In case you game goes forward and backward, be sure you compression algorithm allows it.