Merge branch 'cpp-11' into save_ext

# Conflicts:
#	src/saveload/saveload.h
This commit is contained in:
Jonathan G Rennison
2019-02-13 18:51:53 +00:00
108 changed files with 795 additions and 350 deletions

View File

@@ -55,6 +55,7 @@
#include "../order_backup.h"
#include "../error.h"
#include "../disaster_vehicle.h"
#include "../ship.h"
#include "saveload_internal.h"
@@ -203,10 +204,8 @@ static void UpdateCurrencies()
*/
static void UpdateVoidTiles()
{
uint i;
for (i = 0; i < MapMaxY(); ++i) MakeVoid(i * MapSizeX() + MapMaxX());
for (i = 0; i < MapSizeX(); ++i) MakeVoid(MapSizeX() * MapMaxY() + i);
for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, MapMaxY()));
for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(MapMaxX(), y));
}
static inline RailType UpdateRailType(RailType rt, RailType min)
@@ -3045,6 +3044,42 @@ bool AfterLoadGame()
}
}
if (IsSavegameVersionBefore(SLV_SHIPS_STOP_IN_LOCKS)) {
/* Move ships from lock slope to upper or lower position. */
Ship *s;
FOR_ALL_SHIPS(s) {
/* Suitable tile? */
if (!IsTileType(s->tile, MP_WATER) || !IsLock(s->tile) || GetLockPart(s->tile) != LOCK_PART_MIDDLE) continue;
/* We don't need to adjust position when at the tile centre */
int x = s->x_pos & 0xF;
int y = s->y_pos & 0xF;
if (x == 8 && y == 8) continue;
/* Test if ship is on the second half of the tile */
bool second_half;
DiagDirection shipdiagdir = DirToDiagDir(s->direction);
switch (shipdiagdir) {
default: NOT_REACHED();
case DIAGDIR_NE: second_half = x < 8; break;
case DIAGDIR_NW: second_half = y < 8; break;
case DIAGDIR_SW: second_half = x > 8; break;
case DIAGDIR_SE: second_half = y > 8; break;
}
DiagDirection slopediagdir = GetInclinedSlopeDirection(GetTileSlope(s->tile));
/* Heading up slope == passed half way */
if ((shipdiagdir == slopediagdir) == second_half) {
/* On top half of lock */
s->z_pos = GetTileMaxZ(s->tile) * (int)TILE_HEIGHT;
} else {
/* On lower half of lock */
s->z_pos = GetTileZ(s->tile) * (int)TILE_HEIGHT;
}
}
}
/* Station acceptance is some kind of cache */
if (IsSavegameVersionBefore(SLV_127)) {
Station *st;

View File

@@ -29,6 +29,21 @@ static const SaveLoad _cargomonitor_pair_desc[] = {
SLE_END()
};
static CargoMonitorID FixupCargoMonitor(CargoMonitorID number)
{
/* Between SLV_EXTEND_CARGOTYPES and SLV_FIX_CARGO_MONITOR, the
* CargoMonitorID structure had insufficient packing for more
* than 32 cargo types. Here we have to shuffle bits to account
* for the change.
* Company moved from bits 24-31 to 25-28.
* Cargo type increased from bits 19-23 to 19-24.
*/
SB(number, 25, 4, GB(number, 24, 4));
SB(number, 29, 3, 0);
ClrBit(number, 24);
return number;
}
/** Save the #_cargo_deliveries monitoring map. */
static void SaveDelivery()
{
@@ -52,12 +67,15 @@ static void SaveDelivery()
static void LoadDelivery()
{
TempStorage storage;
bool fix = IsSavegameVersionBefore(SLV_FIX_CARGO_MONITOR);
ClearCargoDeliveryMonitoring();
for (;;) {
if (SlIterateArray() < 0) break;
SlObject(&storage, _cargomonitor_pair_desc);
if (fix) storage.number = FixupCargoMonitor(storage.number);
std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
_cargo_deliveries.insert(p);
}
@@ -87,12 +105,15 @@ static void SavePickup()
static void LoadPickup()
{
TempStorage storage;
bool fix = IsSavegameVersionBefore(SLV_FIX_CARGO_MONITOR);
ClearCargoPickupMonitoring();
for (;;) {
if (SlIterateArray() < 0) break;
SlObject(&storage, _cargomonitor_pair_desc);
if (fix) storage.number = FixupCargoMonitor(storage.number);
std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
_cargo_pickups.insert(p);
}

View File

@@ -395,18 +395,21 @@ void NORETURN SlErrorCorrupt(const char *msg, bool already_malloced)
}
/**
* As SlErrorCorruptFmt, except that it takes a format string and additional parameters
* Issue an SlErrorCorrupt with a format string.
* @param format format string
* @param ... arguments to format string
* @note This function does never return as it throws an exception to
* break out of all the saveload code.
*/
void NORETURN CDECL SlErrorCorruptFmt(const char *msg, ...)
void NORETURN CDECL SlErrorCorruptFmt(const char *format, ...)
{
va_list va;
va_start(va, msg);
char *str = str_vfmt(msg, va);
va_start(va, format);
char *str = str_vfmt(format, va);
va_end(va);
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, str, true);
}
typedef void (*AsyncSaveFinishProc)(); ///< Callback for when the savegame loading is finished.
static AsyncSaveFinishProc _async_save_finish = NULL; ///< Callback to call when the savegame loading is finished.
static ThreadObject *_save_thread; ///< The thread we're using to compress and write a savegame

View File

@@ -292,6 +292,8 @@ enum SaveLoadVersion : uint16 {
SLV_SHIP_ROTATION, ///< 204 PR#7065 Add extra rotation stages for ships.
SLV_GROUP_LIVERIES, ///< 205 PR#7108 Livery storage change and group liveries.
SLV_SHIPS_STOP_IN_LOCKS, ///< 206 PR#7150 Ship/lock movement changes.
SLV_FIX_CARGO_MONITOR, ///< 207 PR#7175 Cargo monitor data packing fix to support 64 cargotypes.
SL_MAX_VERSION, ///< Highest possible saveload version
};
@@ -1001,7 +1003,7 @@ bool SlObjectMember(void *object, const SaveLoad *sld);
void NORETURN SlError(StringID string, const char *extra_msg = NULL, bool already_malloced = false);
void NORETURN SlErrorCorrupt(const char *msg, bool already_malloced = false);
void NORETURN CDECL SlErrorFmt(StringID string, const char *msg, ...) WARN_FORMAT(2, 3);
void NORETURN CDECL SlErrorCorruptFmt(const char *msg, ...) WARN_FORMAT(1, 2);
void NORETURN CDECL SlErrorCorruptFmt(const char *format, ...) WARN_FORMAT(1, 2);
bool SaveloadCrashWithMissingNewGRFs();