Changeset - r25774:14ee6e7f4ecc
[Not reviewed]
src/saveload/autoreplace_sl.cpp
Show inline comments
 
@@ -23,16 +23,13 @@ static const SaveLoad _engine_renew_desc
 
	    SLE_REF(EngineRenew, next,     REF_ENGINE_RENEWS),
 
	SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
 
	SLE_CONDVAR(EngineRenew, replace_when_old, SLE_BOOL, SLV_175, SL_MAX_VERSION),
 
};
 

	
 
struct ERNWChunkHandler : ChunkHandler {
 
	ERNWChunkHandler() : ChunkHandler('ERNW', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	ERNWChunkHandler() : ChunkHandler('ERNW', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_engine_renew_desc);
 

	
 
		for (EngineRenew *er : EngineRenew::Iterate()) {
src/saveload/company_sl.cpp
Show inline comments
 
@@ -495,17 +495,13 @@ static const SaveLoad _company_desc[] = 
 
	SLEG_STRUCT("cur_economy", SlCompanyEconomy),
 
	SLEG_STRUCTLIST("old_economy", SlCompanyOldEconomy),
 
	SLEG_CONDSTRUCTLIST("liveries", SlCompanyLiveries,                               SLV_34, SL_MAX_VERSION),
 
};
 

	
 
struct PLYRChunkHandler : ChunkHandler {
 
	PLYRChunkHandler() : ChunkHandler('PLYR', CH_TABLE)
 
	{
 
		this->load_check = true;
 
		this->fix_pointers = true;
 
	}
 
	PLYRChunkHandler() : ChunkHandler('PLYR', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_company_desc);
 

	
 
		for (Company *c : Company::Iterate()) {
src/saveload/depot_sl.cpp
Show inline comments
 
@@ -27,16 +27,13 @@ static const SaveLoad _depot_desc[] = {
 
	 SLE_CONDVAR(Depot, town_cn,    SLE_UINT16,               SLV_141, SL_MAX_VERSION),
 
	SLE_CONDSSTR(Depot, name,       SLE_STR,                  SLV_141, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Depot, build_date, SLE_INT32,                SLV_142, SL_MAX_VERSION),
 
};
 

	
 
struct DEPTChunkHandler : ChunkHandler {
 
	DEPTChunkHandler() : ChunkHandler('DEPT', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	DEPTChunkHandler() : ChunkHandler('DEPT', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_depot_desc);
 

	
 
		for (Depot *depot : Depot::Iterate()) {
src/saveload/economy_sl.cpp
Show inline comments
 
@@ -86,16 +86,13 @@ static const SaveLoad _cargopayment_desc
 
	    SLE_VAR(CargoPayment, route_profit,    SLE_INT64),
 
	    SLE_VAR(CargoPayment, visual_profit,   SLE_INT64),
 
	SLE_CONDVAR(CargoPayment, visual_transfer, SLE_INT64, SLV_181, SL_MAX_VERSION),
 
};
 

	
 
struct CAPYChunkHandler : ChunkHandler {
 
	CAPYChunkHandler() : ChunkHandler('CAPY', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	CAPYChunkHandler() : ChunkHandler('CAPY', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_cargopayment_desc);
 

	
 
		for (CargoPayment *cp : CargoPayment::Iterate()) {
src/saveload/gamelog_sl.cpp
Show inline comments
 
@@ -345,16 +345,13 @@ static const SaveLoad _gamelog_desc[] = 
 
	SLE_CONDVAR(LoggedAction, at,            SLE_UINT8,   SLV_RIFF_TO_ARRAY, SL_MAX_VERSION),
 
	SLE_VAR(LoggedAction, tick,              SLE_UINT16),
 
	SLEG_STRUCTLIST("action", SlGamelogAction),
 
};
 

	
 
struct GLOGChunkHandler : ChunkHandler {
 
	GLOGChunkHandler() : ChunkHandler('GLOG', CH_TABLE)
 
	{
 
		this->load_check = true;
 
	}
 
	GLOGChunkHandler() : ChunkHandler('GLOG', CH_TABLE) {}
 

	
 
	void LoadCommon(LoggedAction *&gamelog_action, uint &gamelog_actions) const
 
	{
 
		assert(gamelog_action == nullptr);
 
		assert(gamelog_actions == 0);
 

	
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -72,16 +72,13 @@ static const SaveLoad _industry_desc[] =
 

	
 
	SLE_CONDVAR(Industry, random,                     SLE_UINT16,                SLV_82, SL_MAX_VERSION),
 
	SLE_CONDSSTR(Industry, text,     SLE_STR | SLF_ALLOW_CONTROL,     SLV_INDUSTRY_TEXT, SL_MAX_VERSION),
 
};
 

	
 
struct INDYChunkHandler : ChunkHandler {
 
	INDYChunkHandler() : ChunkHandler('INDY', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	INDYChunkHandler() : ChunkHandler('INDY', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_industry_desc);
 

	
 
		/* Write the industries */
src/saveload/linkgraph_sl.cpp
Show inline comments
 
@@ -298,16 +298,13 @@ struct LGRJChunkHandler : ChunkHandler {
 
};
 

	
 
/**
 
 * Link graph schedule.
 
 */
 
struct LGRSChunkHandler : ChunkHandler {
 
	LGRSChunkHandler() : ChunkHandler('LGRS', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	LGRSChunkHandler() : ChunkHandler('LGRS', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(GetLinkGraphScheduleDesc());
 

	
 
		SlSetArrayIndex(0);
src/saveload/map_sl.cpp
Show inline comments
 
@@ -25,16 +25,13 @@ static uint32 _map_dim_y;
 
static const SaveLoad _map_desc[] = {
 
	SLEG_CONDVAR("dim_x", _map_dim_x, SLE_UINT32, SLV_6, SL_MAX_VERSION),
 
	SLEG_CONDVAR("dim_y", _map_dim_y, SLE_UINT32, SLV_6, SL_MAX_VERSION),
 
};
 

	
 
struct MAPSChunkHandler : ChunkHandler {
 
	MAPSChunkHandler() : ChunkHandler('MAPS', CH_TABLE)
 
	{
 
		this->load_check = true;
 
	}
 
	MAPSChunkHandler() : ChunkHandler('MAPS', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_map_desc);
 

	
 
		_map_dim_x = MapSizeX();
src/saveload/misc_sl.cpp
Show inline comments
 
@@ -93,16 +93,13 @@ static const SaveLoad _date_check_desc[]
 
	SLEG_CONDVAR("date", _load_check_data.current_date,  SLE_INT32,                  SLV_31, SL_MAX_VERSION),
 
};
 

	
 
/* Save load date related variables as well as persistent tick counters
 
 * XXX: currently some unrelated stuff is just put here */
 
struct DATEChunkHandler : ChunkHandler {
 
	DATEChunkHandler() : ChunkHandler('DATE', CH_TABLE)
 
	{
 
		this->load_check = true;
 
	}
 
	DATEChunkHandler() : ChunkHandler('DATE', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_date_desc);
 

	
 
		SlSetArrayIndex(0);
src/saveload/newgrf_sl.cpp
Show inline comments
 
@@ -71,16 +71,13 @@ static const SaveLoad _grfconfig_desc[] 
 
	    SLE_VAR(GRFConfig, num_params,       SLE_UINT8),
 
	SLE_CONDVAR(GRFConfig, palette,          SLE_UINT8,  SLV_101, SL_MAX_VERSION),
 
};
 

	
 

	
 
struct NGRFChunkHandler : ChunkHandler {
 
	NGRFChunkHandler() : ChunkHandler('NGRF', CH_TABLE)
 
	{
 
		this->load_check = true;
 
	}
 
	NGRFChunkHandler() : ChunkHandler('NGRF', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_grfconfig_desc);
 

	
 
		int index = 0;
src/saveload/object_sl.cpp
Show inline comments
 
@@ -27,16 +27,13 @@ static const SaveLoad _object_desc[] = {
 
	SLE_CONDVAR(Object, colour,                     SLE_UINT8,                  SLV_148, SL_MAX_VERSION),
 
	SLE_CONDVAR(Object, view,                       SLE_UINT8,                  SLV_155, SL_MAX_VERSION),
 
	SLE_CONDVAR(Object, type,                       SLE_UINT16,                 SLV_186, SL_MAX_VERSION),
 
};
 

	
 
struct OBJSChunkHandler : ChunkHandler {
 
	OBJSChunkHandler() : ChunkHandler('OBJS', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	OBJSChunkHandler() : ChunkHandler('OBJS', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_object_desc);
 

	
 
		/* Write the objects */
src/saveload/order_sl.cpp
Show inline comments
 
@@ -116,16 +116,13 @@ SaveLoadTable GetOrderDescription()
 
	};
 

	
 
	return _order_desc;
 
}
 

	
 
struct ORDRChunkHandler : ChunkHandler {
 
	ORDRChunkHandler() : ChunkHandler('ORDR', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	ORDRChunkHandler() : ChunkHandler('ORDR', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		const SaveLoadTable slt = GetOrderDescription();
 
		SlTableHeader(slt);
 

	
 
@@ -212,16 +209,13 @@ SaveLoadTable GetOrderListDescription()
 
	};
 

	
 
	return _orderlist_desc;
 
}
 

	
 
struct ORDLChunkHandler : ChunkHandler {
 
	ORDLChunkHandler() : ChunkHandler('ORDL', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	ORDLChunkHandler() : ChunkHandler('ORDL', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		const SaveLoadTable slt = GetOrderListDescription();
 
		SlTableHeader(slt);
 

	
 
@@ -274,16 +268,13 @@ SaveLoadTable GetOrderBackupDescription(
 
	};
 

	
 
	return _order_backup_desc;
 
}
 

	
 
struct BKORChunkHandler : ChunkHandler {
 
	BKORChunkHandler() : ChunkHandler('BKOR', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	BKORChunkHandler() : ChunkHandler('BKOR', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		const SaveLoadTable slt = GetOrderBackupDescription();
 
		SlTableHeader(slt);
 

	
src/saveload/saveload.cpp
Show inline comments
 
@@ -311,16 +311,14 @@ static void SlNullPointers()
 
	/* We don't want any savegame conversion code to run
 
	 * during NULLing; especially those that try to get
 
	 * pointers from other pools. */
 
	_sl_version = SAVEGAME_VERSION;
 

	
 
	for (const ChunkHandler &ch : ChunkHandlers()) {
 
		if (ch.fix_pointers) {
 
			Debug(sl, 3, "Nulling pointers for {:c}{:c}{:c}{:c}", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
 
			ch.FixPointers();
 
		}
 
		Debug(sl, 3, "Nulling pointers for {:c}{:c}{:c}{:c}", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
 
		ch.FixPointers();
 
	}
 

	
 
	assert(_sl.action == SLA_NULL);
 
}
 

	
 
/**
 
@@ -2111,51 +2109,28 @@ void SlAutolength(AutolengthProc *proc, 
 
	/* And write the stuff */
 
	proc(arg);
 

	
 
	if (offs != _sl.dumper->GetSize()) SlErrorCorrupt("Invalid chunk size");
 
}
 

	
 
void ChunkHandler::Save() const
 
{
 
	assert(this->save_proc != nullptr);
 
	this->save_proc();
 
}
 

	
 
void ChunkHandler::Load() const
 
{
 
	assert(this->load_proc != nullptr);
 
	this->load_proc();
 
}
 

	
 
void ChunkHandler::FixPointers() const
 
{
 
	assert(this->ptrs_proc != nullptr);
 
	this->ptrs_proc();
 
}
 

	
 
void ChunkHandler::LoadCheck(size_t len) const
 
{
 
	if (this->load_check) {
 
		assert(this->load_check_proc != nullptr);
 
		this->load_check_proc();
 
	} else {
 
		switch (_sl.block_mode) {
 
			case CH_TABLE:
 
			case CH_SPARSE_TABLE:
 
				SlTableHeader({});
 
				FALLTHROUGH;
 
			case CH_ARRAY:
 
			case CH_SPARSE_ARRAY:
 
				SlSkipArray();
 
				break;
 
			case CH_RIFF:
 
				SlSkipBytes(len);
 
				break;
 
			default:
 
				NOT_REACHED();
 
		}
 
	switch (_sl.block_mode) {
 
		case CH_TABLE:
 
		case CH_SPARSE_TABLE:
 
			SlTableHeader({});
 
			FALLTHROUGH;
 
		case CH_ARRAY:
 
		case CH_SPARSE_ARRAY:
 
			SlSkipArray();
 
			break;
 
		case CH_RIFF:
 
			SlSkipBytes(len);
 
			break;
 
		default:
 
			NOT_REACHED();
 
	}
 
}
 

	
 
/**
 
 * Load a chunk of data (eg vehicles, stations, etc.)
 
 * @param ch The chunkhandler that will be used for the operation
 
@@ -2349,16 +2324,14 @@ static void SlLoadCheckChunks()
 
/** Fix all pointers (convert index -> pointer) */
 
static void SlFixPointers()
 
{
 
	_sl.action = SLA_PTRS;
 

	
 
	for (const ChunkHandler &ch : ChunkHandlers()) {
 
		if (ch.fix_pointers) {
 
			Debug(sl, 3, "Fixing pointers for {:c}{:c}{:c}{:c}", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
 
			ch.FixPointers();
 
		}
 
		Debug(sl, 3, "Fixing pointers for {:c}{:c}{:c}{:c}", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
 
		ch.FixPointers();
 
	}
 

	
 
	assert(_sl.action == SLA_PTRS);
 
}
 

	
 

	
src/saveload/saveload.h
Show inline comments
 
@@ -381,13 +381,12 @@ void WaitTillSaved();
 
void ProcessAsyncSaveFinish();
 
void DoExitSave();
 

	
 
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded);
 
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader);
 

	
 
typedef void ChunkSaveLoadProc();
 
typedef void AutolengthProc(void *arg);
 

	
 
/** Type of a chunk. */
 
enum ChunkType {
 
	CH_RIFF = 0,
 
	CH_ARRAY = 1,
 
@@ -399,51 +398,37 @@ enum ChunkType {
 
	CH_READONLY, ///< Chunk is never saved.
 
};
 

	
 
/** Handlers and description of chunk. */
 
struct ChunkHandler {
 
	uint32 id;                          ///< Unique ID (4 letters).
 
	ChunkSaveLoadProc *save_proc;       ///< Save procedure of the chunk.
 
	ChunkSaveLoadProc *load_proc;       ///< Load procedure of the chunk.
 
	ChunkSaveLoadProc *ptrs_proc;       ///< Manipulate pointers in the chunk.
 
	ChunkSaveLoadProc *load_check_proc; ///< Load procedure for game preview.
 
	ChunkType type;                     ///< Type of the chunk. @see ChunkType
 

	
 
	bool fix_pointers = false;
 
	bool load_check = false;
 

	
 
	ChunkHandler(uint32 id, ChunkType type) : id(id), type(type) {}
 

	
 
	ChunkHandler(uint32 id, ChunkSaveLoadProc *save_proc, ChunkSaveLoadProc *load_proc, ChunkSaveLoadProc *ptrs_proc, ChunkSaveLoadProc *load_check_proc, ChunkType type)
 
		: id(id), save_proc(save_proc), load_proc(load_proc), ptrs_proc(ptrs_proc), load_check_proc(load_check_proc), type(type)
 
	{
 
		this->fix_pointers = ptrs_proc != nullptr;
 
		this->load_check = load_check_proc != nullptr;
 
	}
 

	
 
	virtual ~ChunkHandler() {}
 

	
 
	/**
 
	 * Save the chunk.
 
	 * Must be overridden, unless Chunk type is CH_READONLY.
 
	 */
 
	virtual void Save() const;
 
	virtual void Save() const { NOT_REACHED(); }
 

	
 
	/**
 
	 * Load the chunk.
 
	 * Must be overridden.
 
	 */
 
	virtual void Load() const;
 
	virtual void Load() const = 0;
 

	
 
	/**
 
	 * Fix the pointers.
 
	 * Pointers are saved using the index of the pointed object.
 
	 * On load, pointers are filled with indices and need to be fixed to point to the real object.
 
	 * Must be overridden if the chunk saves any pointer.
 
	 */
 
	virtual void FixPointers() const;
 
	virtual void FixPointers() const {}
 

	
 
	/**
 
	 * Load the chunk for game preview.
 
	 * Default implementation just skips the data.
 
	 * @param len Number of bytes to skip.
 
	 */
src/saveload/settings_sl.cpp
Show inline comments
 
@@ -154,16 +154,13 @@ struct OPTSChunkHandler : ChunkHandler {
 
		LoadSettings(_gameopt_settings, &_settings_game, _gameopt_sl_compat);
 
		HandleOldDiffCustom(true);
 
	}
 
};
 

	
 
struct PATSChunkHandler : ChunkHandler {
 
	PATSChunkHandler() : ChunkHandler('PATS', CH_TABLE)
 
	{
 
		this->load_check = true;
 
	}
 
	PATSChunkHandler() : ChunkHandler('PATS', CH_TABLE) {}
 

	
 
	void Load() const override
 
	{
 
		/* Copy over default setting since some might not get loaded in
 
		 * a networking environment. This ensures for example that the local
 
		 * currency setting stays when joining a network-server */
src/saveload/station_sl.cpp
Show inline comments
 
@@ -482,16 +482,13 @@ static const SaveLoad _old_station_desc[
 

	
 
	SLEG_STRUCTLIST("goods", SlStationGoods),
 
	SLEG_CONDSTRUCTLIST("speclist", SlStationSpecList,                           SLV_27, SL_MAX_VERSION),
 
};
 

	
 
struct STNSChunkHandler : ChunkHandler {
 
	STNSChunkHandler() : ChunkHandler('STNS', CH_READONLY)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	STNSChunkHandler() : ChunkHandler('STNS', CH_READONLY) {}
 

	
 
	void Load() const override
 
	{
 
		const std::vector<SaveLoad> slt = SlCompatTableHeader(_old_station_desc, _old_station_sl_compat);
 

	
 
		_cargo_source_xy = 0;
 
@@ -656,16 +653,13 @@ static const SaveLoad _station_desc[] = 
 
	SLEG_STRUCT("normal", SlStationNormal),
 
	SLEG_STRUCT("waypoint", SlStationWaypoint),
 
	SLEG_CONDSTRUCTLIST("speclist", SlStationSpecList, SLV_27, SL_MAX_VERSION),
 
};
 

	
 
struct STNNChunkHandler : ChunkHandler {
 
	STNNChunkHandler() : ChunkHandler('STNN', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	STNNChunkHandler() : ChunkHandler('STNN', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_station_desc);
 

	
 
		/* Write the stations */
 
@@ -702,16 +696,13 @@ struct STNNChunkHandler : ChunkHandler {
 
			SlObject(bst, _station_desc);
 
		}
 
	}
 
};
 

	
 
struct ROADChunkHandler : ChunkHandler {
 
	ROADChunkHandler() : ChunkHandler('ROAD', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	ROADChunkHandler() : ChunkHandler('ROAD', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_roadstop_desc);
 

	
 
		for (RoadStop *rs : RoadStop::Iterate()) {
src/saveload/town_sl.cpp
Show inline comments
 
@@ -284,16 +284,13 @@ struct HIDSChunkHandler : ChunkHandler {
 
	{
 
		Load_NewGRFMapping(_house_mngr);
 
	}
 
};
 

	
 
struct CITYChunkHandler : ChunkHandler {
 
	CITYChunkHandler() : ChunkHandler('CITY', CH_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	CITYChunkHandler() : ChunkHandler('CITY', CH_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_town_desc);
 

	
 
		for (Town *t : Town::Iterate()) {
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -992,16 +992,13 @@ const static SaveLoad _vehicle_desc[] = 
 
	SLEG_STRUCT("aircraft", SlVehicleAircraft),
 
	SLEG_STRUCT("effect", SlVehicleEffect),
 
	SLEG_STRUCT("disaster", SlVehicleDisaster),
 
};
 

	
 
struct VEHSChunkHandler : ChunkHandler {
 
	VEHSChunkHandler() : ChunkHandler('VEHS', CH_SPARSE_TABLE)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	VEHSChunkHandler() : ChunkHandler('VEHS', CH_SPARSE_TABLE) {}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_vehicle_desc);
 

	
 
		/* Write the vehicles */
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -180,16 +180,13 @@ static const SaveLoad _old_waypoint_desc
 
	SLE_CONDVAR(OldWaypoint, localidx,   SLE_UINT8,                   SLV_3, SL_MAX_VERSION),
 
	SLE_CONDVAR(OldWaypoint, grfid,      SLE_UINT32,                 SLV_17, SL_MAX_VERSION),
 
	SLE_CONDVAR(OldWaypoint, owner,      SLE_UINT8,                 SLV_101, SL_MAX_VERSION),
 
};
 

	
 
struct CHKPChunkHandler : ChunkHandler {
 
	CHKPChunkHandler() : ChunkHandler('CHKP', CH_READONLY)
 
	{
 
		this->fix_pointers = true;
 
	}
 
	CHKPChunkHandler() : ChunkHandler('CHKP', CH_READONLY) {}
 

	
 
	void Load() const override
 
	{
 
		/* Precaution for when loading failed and it didn't get cleared */
 
		ResetOldWaypoints();
 

	
0 comments (0 inline, 0 general)