Re: A85: Compress levels


[Next][Index][Thread]

Re: A85: Compress levels




At 01:38 AM 3/20/98 GMT, you wrote:
>>If you have a lot of horizontal coherence, then I would use an algorithm
>>similar to the PCX format used on the PC.  SQRXZ 82 will have level
>>compression using this method (I have gotten compression as good as 80%
>>with it).
>>
>
>how does it work?

Let's say you have a level like this:

0 = space
1 = block
2 = enemy
3 = main character
4 = exit

11111111111111111111111111
10000100000000000000000001
10000100111111111111111101
10000100000000100000000001
10000111111000100111111111
10000002001100110000000001
10001111100110010000000001
10011000110011010000000001
13111000111020010002220041
11111111111111111111111111


This grid is 26x10 (260 bytes expanded).  To compress using the PCX format,
I will assume that every number including and beyond 129 decimal is a
signal to the decompression routine that a series of cells (2 continuous
cells = 129, 3 cont. cells = 130, ...) is to be decompressed into the
buffer where the level is to be played from (255 = end of level
compression).  The sample level (above) compressed would look like this:

.db 154, 1, 131, 0, 1, 146, 0, 129, 1, 131, 0, 1, 129, 0, 143, 1, 0, 129, 1
.db 131, 0, 1, 135, 0, 1, 137, 0, 129, 1, 131, 0, 133, 1, 130, 0, 1, 129, 0
.db 137, 1, 133, 0, 2, 129, 0, 129, 1, 129, 0, 129, 1, 136, 0, 129, 1
.db 130, 0, 132, 1, 129, 0, 129, 1, 129, 0, 1, 136, 0, 129, 1, 129, 0
.db 129, 1, 130, 0, 129, 1, 129, 0, 129, 1, 0, 1, 136, 0, 129, 1, 3, 130, 1
.db 130, 0, 130, 1, 0, 2, 129, 0, 1, 130, 0, 130, 2, 129, 0, 4, 154, 1, 255

This level is compressed down to 110 bytes.  This gives about 58%
compression.  Notice that the level has little coherence in general and
will therefore give about 50-60% compression.  The following sample shows a
really bad example of horizontal coherence:

10101010101010101010101010
10101010101010101010101010
10101010101010101010101010
10101010101010101010101010
10101010101010101010101010
10101010101010101010101010
10101010101010101010101010
10101010101010101010101010
10101010101010101010101010
10101010101010101010101010

This is the worst possible situation because the resulting compressed level
increases a byte (if you use the end of level indicator of 255) and has 0%
compression.  The following board optimizes the level for maximum
compression and also makes it look a little nicer in most cases:

11111111111111111111111111
10000100000000000000000001
10000100111111111111111101
10000100000000100000000001
10000111110000100111111111
10000020001000100000000001
10001111100100010000000001
10010000010011010000000001
13100000001020010000222041
11111111111111111111111111

Hope that helps.


                 Thomas J. Hruska -- thruska@tir.com
Shining Light Productions -- "Meeting the needs of fellow programmers"
         http://www.geocities.com/SiliconValley/Heights/8504
                    http://shinelight.home.ml.org


References: