File diff r25773:457e167f3c9e → r25774:14ee6e7f4ecc
src/saveload/saveload.cpp
Show inline comments
 
@@ -305,28 +305,26 @@ static const std::vector<ChunkHandlerRef
 

	
 
/** Null all pointers (convert index -> nullptr) */
 
static void SlNullPointers()
 
{
 
	_sl.action = SLA_NULL;
 

	
 
	/* 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);
 
}
 

	
 
/**
 
 * Error handler. Sets everything up to show an error message and to clean
 
 * up the mess of a partial savegame load.
 
 * @param string The translatable error message to show.
 
 * @param extra_msg An extra error message coming from one of the APIs.
 
 * @note This function does never return as it throws an exception to
 
 *       break out of all the saveload code.
 
@@ -2105,63 +2103,40 @@ void SlAutolength(AutolengthProc *proc, 
 
	/* Setup length */
 
	_sl.need_length = NL_WANTLENGTH;
 
	SlSetLength(_sl.obj_len);
 

	
 
	offs = _sl.dumper->GetSize() + _sl.obj_len;
 

	
 
	/* 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
 
 */
 
static void SlLoadChunk(const ChunkHandler &ch)
 
{
 
	byte m = SlReadByte();
 
	size_t len;
 
	size_t endoffs;
 
@@ -2343,28 +2318,26 @@ static void SlLoadCheckChunks()
 
		ch = SlFindChunkHandler(id);
 
		if (ch == nullptr) SlErrorCorrupt("Unknown chunk type");
 
		SlLoadCheckChunk(*ch);
 
	}
 
}
 

	
 
/** 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);
 
}
 

	
 

	
 
/** Yes, simply reading from a file. */
 
struct FileReader : LoadFilter {
 
	FILE *file; ///< The file to read from.
 
	long begin; ///< The begin of the file.
 

	
 
	/**