Changeset - r25774:14ee6e7f4ecc
[Not reviewed]
src/saveload/autoreplace_sl.cpp
Show inline comments
 
@@ -26,10 +26,7 @@ static const SaveLoad _engine_renew_desc
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/company_sl.cpp
Show inline comments
 
@@ -498,11 +498,7 @@ static const SaveLoad _company_desc[] = 
 
};
 

	
 
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
 
	{
src/saveload/depot_sl.cpp
Show inline comments
 
@@ -30,10 +30,7 @@ static const SaveLoad _depot_desc[] = {
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/economy_sl.cpp
Show inline comments
 
@@ -89,10 +89,7 @@ static const SaveLoad _cargopayment_desc
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/gamelog_sl.cpp
Show inline comments
 
@@ -348,10 +348,7 @@ static const SaveLoad _gamelog_desc[] = 
 
};
 

	
 
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
 
	{
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -75,10 +75,7 @@ static const SaveLoad _industry_desc[] =
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/linkgraph_sl.cpp
Show inline comments
 
@@ -301,10 +301,7 @@ 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
 
	{
src/saveload/map_sl.cpp
Show inline comments
 
@@ -28,10 +28,7 @@ static const SaveLoad _map_desc[] = {
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/misc_sl.cpp
Show inline comments
 
@@ -96,10 +96,7 @@ static const SaveLoad _date_check_desc[]
 
/* 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
 
	{
src/saveload/newgrf_sl.cpp
Show inline comments
 
@@ -74,10 +74,7 @@ static const SaveLoad _grfconfig_desc[] 
 

	
 

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

	
 
	void Save() const override
 
	{
src/saveload/object_sl.cpp
Show inline comments
 
@@ -30,10 +30,7 @@ static const SaveLoad _object_desc[] = {
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/order_sl.cpp
Show inline comments
 
@@ -119,10 +119,7 @@ SaveLoadTable GetOrderDescription()
 
}
 

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

	
 
	void Save() const override
 
	{
 
@@ -215,10 +212,7 @@ SaveLoadTable GetOrderListDescription()
 
}
 

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

	
 
	void Save() const override
 
	{
 
@@ -277,10 +271,7 @@ SaveLoadTable GetOrderBackupDescription(
 
}
 

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

	
 
	void Save() const override
 
	{
src/saveload/saveload.cpp
Show inline comments
 
@@ -314,10 +314,8 @@ static void SlNullPointers()
 
	_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);
 
@@ -2114,45 +2112,22 @@ void SlAutolength(AutolengthProc *proc, 
 
	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();
 
	}
 
}
 

	
 
@@ -2352,10 +2327,8 @@ 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
 
@@ -384,7 +384,6 @@ 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. */
 
@@ -402,37 +401,23 @@ enum ChunkType {
 
/** 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.
 
@@ -440,7 +425,7 @@ struct ChunkHandler {
 
	 * 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.
src/saveload/settings_sl.cpp
Show inline comments
 
@@ -157,10 +157,7 @@ struct OPTSChunkHandler : ChunkHandler {
 
};
 

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

	
 
	void Load() const override
 
	{
src/saveload/station_sl.cpp
Show inline comments
 
@@ -485,10 +485,7 @@ static const SaveLoad _old_station_desc[
 
};
 

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

	
 
	void Load() const override
 
	{
 
@@ -659,10 +656,7 @@ static const SaveLoad _station_desc[] = 
 
};
 

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

	
 
	void Save() const override
 
	{
 
@@ -705,10 +699,7 @@ struct STNNChunkHandler : ChunkHandler {
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/town_sl.cpp
Show inline comments
 
@@ -287,10 +287,7 @@ struct HIDSChunkHandler : ChunkHandler {
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -995,10 +995,7 @@ const static SaveLoad _vehicle_desc[] = 
 
};
 

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

	
 
	void Save() const override
 
	{
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -183,10 +183,7 @@ static const SaveLoad _old_waypoint_desc
 
};
 

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

	
 
	void Load() const override
 
	{
0 comments (0 inline, 0 general)