1120 |
1120 |
1121 static bool InitMem() |
1121 static bool InitMem() |
1122 { |
1122 { |
1123 _ts.count = 0; |
1123 _ts.count = 0; |
1124 |
1124 |
1125 CleanPool(&_Savegame_pool); |
1125 _Savegame_pool.CleanPool(); |
1126 AddBlockToPool(&_Savegame_pool); |
1126 _Savegame_pool.AddBlockToPool(); |
1127 |
1127 |
1128 /* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */ |
1128 /* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */ |
1129 _sl.bufsize = GetSavegamePoolSize(); |
1129 _sl.bufsize = GetSavegamePoolSize(); |
1130 _sl.buf = GetSavegame(_ts.count); |
1130 _sl.buf = GetSavegame(_ts.count); |
1131 return true; |
1131 return true; |
1132 } |
1132 } |
1133 |
1133 |
1134 static void UnInitMem() |
1134 static void UnInitMem() |
1135 { |
1135 { |
1136 CleanPool(&_Savegame_pool); |
1136 _Savegame_pool.CleanPool(); |
1137 } |
1137 } |
1138 |
1138 |
1139 static void WriteMem(uint size) |
1139 static void WriteMem(uint size) |
1140 { |
1140 { |
1141 _ts.count += size; |
1141 _ts.count += size; |
1142 /* Allocate new block and new buffer-pointer */ |
1142 /* Allocate new block and new buffer-pointer */ |
1143 AddBlockIfNeeded(&_Savegame_pool, _ts.count); |
1143 _Savegame_pool.AddBlockIfNeeded(_ts.count); |
1144 _sl.buf = GetSavegame(_ts.count); |
1144 _sl.buf = GetSavegame(_ts.count); |
1145 } |
1145 } |
1146 |
1146 |
1147 /******************************************** |
1147 /******************************************** |
1148 ********** START OF ZLIB CODE ************** |
1148 ********** START OF ZLIB CODE ************** |
1341 |
1341 |
1342 index--; // correct for the NULL index |
1342 index--; // correct for the NULL index |
1343 |
1343 |
1344 switch (rt) { |
1344 switch (rt) { |
1345 case REF_ORDER: { |
1345 case REF_ORDER: { |
1346 if (!AddBlockIfNeeded(&_Order_pool, index)) |
1346 if (!_Order_pool.AddBlockIfNeeded(index)) |
1347 error("Orders: failed loading savegame: too many orders"); |
1347 error("Orders: failed loading savegame: too many orders"); |
1348 return GetOrder(index); |
1348 return GetOrder(index); |
1349 } |
1349 } |
1350 case REF_VEHICLE: { |
1350 case REF_VEHICLE: { |
1351 if (!AddBlockIfNeeded(&_Vehicle_pool, index)) |
1351 if (!_Vehicle_pool.AddBlockIfNeeded(index)) |
1352 error("Vehicles: failed loading savegame: too many vehicles"); |
1352 error("Vehicles: failed loading savegame: too many vehicles"); |
1353 return GetVehicle(index); |
1353 return GetVehicle(index); |
1354 } |
1354 } |
1355 case REF_STATION: { |
1355 case REF_STATION: { |
1356 if (!AddBlockIfNeeded(&_Station_pool, index)) |
1356 if (!_Station_pool.AddBlockIfNeeded(index)) |
1357 error("Stations: failed loading savegame: too many stations"); |
1357 error("Stations: failed loading savegame: too many stations"); |
1358 return GetStation(index); |
1358 return GetStation(index); |
1359 } |
1359 } |
1360 case REF_TOWN: { |
1360 case REF_TOWN: { |
1361 if (!AddBlockIfNeeded(&_Town_pool, index)) |
1361 if (!_Town_pool.AddBlockIfNeeded(index)) |
1362 error("Towns: failed loading savegame: too many towns"); |
1362 error("Towns: failed loading savegame: too many towns"); |
1363 return GetTown(index); |
1363 return GetTown(index); |
1364 } |
1364 } |
1365 case REF_ROADSTOPS: { |
1365 case REF_ROADSTOPS: { |
1366 if (!AddBlockIfNeeded(&_RoadStop_pool, index)) |
1366 if (!_RoadStop_pool.AddBlockIfNeeded(index)) |
1367 error("RoadStops: failed loading savegame: too many RoadStops"); |
1367 error("RoadStops: failed loading savegame: too many RoadStops"); |
1368 return GetRoadStop(index); |
1368 return GetRoadStop(index); |
1369 } |
1369 } |
1370 case REF_ENGINE_RENEWS: { |
1370 case REF_ENGINE_RENEWS: { |
1371 if (!AddBlockIfNeeded(&_EngineRenew_pool, index)) |
1371 if (!_EngineRenew_pool.AddBlockIfNeeded(index)) |
1372 error("EngineRenews: failed loading savegame: too many EngineRenews"); |
1372 error("EngineRenews: failed loading savegame: too many EngineRenews"); |
1373 return GetEngineRenew(index); |
1373 return GetEngineRenew(index); |
1374 } |
1374 } |
1375 case REF_CARGO_PACKET: { |
1375 case REF_CARGO_PACKET: { |
1376 if (!AddBlockIfNeeded(&_CargoPacket_pool, index)) |
1376 if (!_CargoPacket_pool.AddBlockIfNeeded(index)) |
1377 error("CargoPackets: failed loading savegame: too many Cargo packets"); |
1377 error("CargoPackets: failed loading savegame: too many Cargo packets"); |
1378 return GetCargoPacket(index); |
1378 return GetCargoPacket(index); |
1379 } |
1379 } |
1380 |
1380 |
1381 case REF_VEHICLE_OLD: { |
1381 case REF_VEHICLE_OLD: { |
1384 * and the index was not - 1.. correct for this */ |
1384 * and the index was not - 1.. correct for this */ |
1385 index++; |
1385 index++; |
1386 if (index == INVALID_VEHICLE) |
1386 if (index == INVALID_VEHICLE) |
1387 return NULL; |
1387 return NULL; |
1388 |
1388 |
1389 if (!AddBlockIfNeeded(&_Vehicle_pool, index)) |
1389 if (!_Vehicle_pool.AddBlockIfNeeded(index)) |
1390 error("Vehicles: failed loading savegame: too many vehicles"); |
1390 error("Vehicles: failed loading savegame: too many vehicles"); |
1391 return GetVehicle(index); |
1391 return GetVehicle(index); |
1392 } |
1392 } |
1393 default: NOT_REACHED(); |
1393 default: NOT_REACHED(); |
1394 } |
1394 } |