MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ReadByte

Function ReadByte

src/saveload/oldloader.cpp:86–113  ·  view source on GitHub ↗

* * Reads a byte from the buffer and decompress if needed * */

Source from the content-addressed store, hash-verified

84 *
85 */
86uint8_t ReadByte(LoadgameState &ls)
87{
88 /* Old savegames have a nice compression algorithm (RLE)
89 which means that we have a chunk, which starts with a length
90 byte. If that byte is negative, we have to repeat the next byte
91 that many times ( + 1). Else, we need to read that amount of bytes.
92 Works pretty well if you have many zeros behind each other */
93
94 if (ls.chunk_size == 0) {
95 /* Read new chunk */
96 int8_t new_byte = ReadByteFromFile(ls);
97
98 if (new_byte < 0) {
99 /* Repeat next char for new_byte times */
100 ls.decoding = true;
101 ls.decode_char = ReadByteFromFile(ls);
102 ls.chunk_size = -new_byte + 1;
103 } else {
104 ls.decoding = false;
105 ls.chunk_size = new_byte + 1;
106 }
107 }
108
109 ls.total_read++;
110 ls.chunk_size--;
111
112 return ls.decoding ? ls.decode_char : ReadByteFromFile(ls);
113}
114
115/**
116 *

Callers 7

ReadUint16Function · 0.85
LoadOldVehicleFunction · 0.85
LoadOldCustomStringFunction · 0.85
LoadOldMapPart1Function · 0.85
LoadOldMapPart2Function · 0.85
LoadTTDPatchExtraChunksFunction · 0.85
LoadChunkFunction · 0.85

Calls 1

ReadByteFromFileFunction · 0.85

Tested by

no test coverage detected