* Save a chunk of data (eg. vehicles, stations, etc.). Each chunk is * prefixed by an ID identifying it, followed by data, and terminator where appropriate * @param ch The chunkhandler that will be used for the operation */
| 2250 | * @param ch The chunkhandler that will be used for the operation |
| 2251 | */ |
| 2252 | static void SlSaveChunk(const ChunkHandler &ch) |
| 2253 | { |
| 2254 | if (ch.type == CH_READONLY) return; |
| 2255 | |
| 2256 | SlWriteUint32(ch.id); |
| 2257 | Debug(sl, 2, "Saving chunk {}", ch.GetName()); |
| 2258 | |
| 2259 | _sl.block_mode = ch.type; |
| 2260 | _sl.expect_table_header = (_sl.block_mode == CH_TABLE || _sl.block_mode == CH_SPARSE_TABLE); |
| 2261 | |
| 2262 | _sl.need_length = (_sl.expect_table_header || _sl.block_mode == CH_RIFF) ? NL_WANTLENGTH : NL_NONE; |
| 2263 | |
| 2264 | switch (_sl.block_mode) { |
| 2265 | case CH_RIFF: |
| 2266 | ch.Save(); |
| 2267 | break; |
| 2268 | case CH_TABLE: |
| 2269 | case CH_ARRAY: |
| 2270 | _sl.last_array_index = 0; |
| 2271 | SlWriteByte(_sl.block_mode); |
| 2272 | ch.Save(); |
| 2273 | SlWriteArrayLength(0); // Terminate arrays |
| 2274 | break; |
| 2275 | case CH_SPARSE_TABLE: |
| 2276 | case CH_SPARSE_ARRAY: |
| 2277 | SlWriteByte(_sl.block_mode); |
| 2278 | ch.Save(); |
| 2279 | SlWriteArrayLength(0); // Terminate arrays |
| 2280 | break; |
| 2281 | default: NOT_REACHED(); |
| 2282 | } |
| 2283 | |
| 2284 | if (_sl.expect_table_header) SlErrorCorrupt("Table chunk without header"); |
| 2285 | } |
| 2286 | |
| 2287 | /** Save all chunks */ |
| 2288 | static void SlSaveChunks() |
no test coverage detected