123 /* Old savegames have a nice compression algorithm (RLE) |
123 /* Old savegames have a nice compression algorithm (RLE) |
124 which means that we have a chunk, which starts with a length |
124 which means that we have a chunk, which starts with a length |
125 byte. If that byte is negative, we have to repeat the next byte |
125 byte. If that byte is negative, we have to repeat the next byte |
126 that many times (+1). Else, we need to read that amount of bytes. |
126 that many times (+1). Else, we need to read that amount of bytes. |
127 Works pretty good if you have many zero's behind eachother */ |
127 Works pretty good if you have many zero's behind eachother */ |
128 int8 new_byte; |
128 |
129 |
129 if (ls->chunk_size == 0) { |
130 /* Check if we are reading a chunk */ |
130 /* Read new chunk */ |
131 if (ls->chunk_size != 0) { |
131 int8 new_byte = ReadByteFromFile(ls); |
132 ls->total_read++; |
132 |
133 ls->chunk_size--; |
133 if (new_byte < 0) { |
134 |
134 /* Repeat next char for new_byte times */ |
135 /* If we are decoding, return the decode_char */ |
135 ls->decoding = true; |
136 if (ls->decoding) |
136 ls->decode_char = ReadByteFromFile(ls); |
137 return ls->decode_char; |
137 ls->chunk_size = -new_byte + 1; |
138 |
138 } else { |
139 /* Else return byte from file */ |
139 ls->decoding = false; |
140 return ReadByteFromFile(ls); |
140 ls->chunk_size = new_byte + 1; |
141 } |
141 } |
142 |
142 } |
143 /* Read new chunk */ |
143 |
144 new_byte = ReadByteFromFile(ls); |
144 ls->total_read++; |
145 |
145 ls->chunk_size--; |
146 if (new_byte < 0) { |
146 |
147 /* Repeat next char for new_byte times */ |
147 return ls->decoding ? ls->decode_char : ReadByteFromFile(ls); |
148 ls->decoding = true; |
|
149 ls->decode_char = ReadByteFromFile(ls); |
|
150 ls->chunk_size = -new_byte + 1; |
|
151 } else { |
|
152 ls->decoding = false; |
|
153 ls->chunk_size = new_byte + 1; |
|
154 } |
|
155 |
|
156 /* Call this function again to return a byte */ |
|
157 return ReadByte(ls); |
|
158 } |
148 } |
159 |
149 |
160 /** |
150 /** |
161 * |
151 * |
162 * Loads a chunk from the old savegame |
152 * Loads a chunk from the old savegame |