Changeset - r25596:7bf7822e5659
src/saveload/ai_sl.cpp
Show inline comments
 
@@ -111,15 +111,17 @@ static void Load_AIPL()
 
		}
 
	}
 
}
 

	
 
static void Save_AIPL()
 
{
 
	for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
 
		SlSetArrayIndex(i);
 
		SlAutolength((AutolengthProc *)SaveReal_AIPL, &i);
 
	}
 
}
 

	
 
extern const ChunkHandler _ai_chunk_handlers[] = {
 
	{ 'AIPL', Save_AIPL, Load_AIPL, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler ai_chunk_handlers[] = {
 
	{ 'AIPL', Save_AIPL, Load_AIPL, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _ai_chunk_handlers(ai_chunk_handlers);
src/saveload/airport_sl.cpp
Show inline comments
 
@@ -25,16 +25,18 @@ static void Load_APID()
 
}
 

	
 
static void Save_ATID()
 
{
 
	Save_NewGRFMapping(_airporttile_mngr);
 
}
 

	
 
static void Load_ATID()
 
{
 
	Load_NewGRFMapping(_airporttile_mngr);
 
}
 

	
 
extern const ChunkHandler _airport_chunk_handlers[] = {
 
static const ChunkHandler airport_chunk_handlers[] = {
 
	{ 'ATID', Save_ATID, Load_ATID, nullptr, nullptr, CH_ARRAY },
 
	{ 'APID', Save_APID, Load_APID, nullptr, nullptr, CH_ARRAY | CH_LAST },
 
	{ 'APID', Save_APID, Load_APID, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _airport_chunk_handlers(airport_chunk_handlers);
src/saveload/animated_tile_sl.cpp
Show inline comments
 
@@ -46,15 +46,17 @@ static void Load_ANIT()
 
	}
 

	
 
	uint count = (uint)SlGetFieldLength() / sizeof(_animated_tiles.front());
 
	_animated_tiles.clear();
 
	_animated_tiles.resize(_animated_tiles.size() + count);
 
	SlArray(_animated_tiles.data(), count, SLE_UINT32);
 
}
 

	
 
/**
 
 * "Definition" imported by the saveload code to be able to load and save
 
 * the animated tile table.
 
 */
 
extern const ChunkHandler _animated_tile_chunk_handlers[] = {
 
	{ 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_RIFF | CH_LAST},
 
static const ChunkHandler animated_tile_chunk_handlers[] = {
 
	{ 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_RIFF },
 
};
 

	
 
extern const ChunkHandlerTable _animated_tile_chunk_handlers(animated_tile_chunk_handlers);
src/saveload/autoreplace_sl.cpp
Show inline comments
 
@@ -46,15 +46,17 @@ static void Load_ERNW()
 
			if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
 
		}
 
	}
 
}
 

	
 
static void Ptrs_ERNW()
 
{
 
	for (EngineRenew *er : EngineRenew::Iterate()) {
 
		SlObject(er, _engine_renew_desc);
 
	}
 
}
 

	
 
extern const ChunkHandler _autoreplace_chunk_handlers[] = {
 
	{ 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler autoreplace_chunk_handlers[] = {
 
	{ 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _autoreplace_chunk_handlers(autoreplace_chunk_handlers);
src/saveload/cargomonitor_sl.cpp
Show inline comments
 
@@ -108,16 +108,18 @@ static void LoadPickup()
 
	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);
 
	}
 
}
 

	
 
/** Chunk definition of the cargomonitoring maps. */
 
extern const ChunkHandler _cargomonitor_chunk_handlers[] = {
 
	{ 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_ARRAY},
 
	{ 'CMPU', SavePickup,   LoadPickup,   nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler cargomonitor_chunk_handlers[] = {
 
	{ 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_ARRAY },
 
	{ 'CMPU', SavePickup,   LoadPickup,   nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _cargomonitor_chunk_handlers(cargomonitor_chunk_handlers);
src/saveload/cargopacket_sl.cpp
Show inline comments
 
@@ -117,15 +117,17 @@ static void Save_CAPA()
 
 */
 
static void Load_CAPA()
 
{
 
	int index;
 

	
 
	while ((index = SlIterateArray()) != -1) {
 
		CargoPacket *cp = new (index) CargoPacket();
 
		SlObject(cp, GetCargoPacketDesc());
 
	}
 
}
 

	
 
/** Chunk handlers related to cargo packets. */
 
extern const ChunkHandler _cargopacket_chunk_handlers[] = {
 
	{ 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler cargopacket_chunk_handlers[] = {
 
	{ 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _cargopacket_chunk_handlers(cargopacket_chunk_handlers);
src/saveload/cheat_sl.cpp
Show inline comments
 
@@ -39,15 +39,17 @@ static void Load_CHTS()
 
	Cheat *cht = (Cheat*)&_cheats;
 
	size_t count = SlGetFieldLength() / 2;
 
	/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
 
	if (count > sizeof(_cheats) / sizeof(Cheat)) SlErrorCorrupt("Too many cheat values");
 

	
 
	for (uint i = 0; i < count; i++) {
 
		cht[i].been_used = (SlReadByte() != 0);
 
		cht[i].value     = (SlReadByte() != 0);
 
	}
 
}
 

	
 
/** Chunk handlers related to cheats. */
 
extern const ChunkHandler _cheat_chunk_handlers[] = {
 
	{ 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_RIFF | CH_LAST},
 
static const ChunkHandler cheat_chunk_handlers[] = {
 
	{ 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_RIFF },
 
};
 

	
 
extern const ChunkHandlerTable _cheat_chunk_handlers(cheat_chunk_handlers);
src/saveload/company_sl.cpp
Show inline comments
 
@@ -518,15 +518,17 @@ static void Check_PLYR()
 
		if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
 
	}
 
}
 

	
 
static void Ptrs_PLYR()
 
{
 
	for (Company *c : Company::Iterate()) {
 
		SlObject(c, _company_settings_desc);
 
	}
 
}
 

	
 

	
 
extern const ChunkHandler _company_chunk_handlers[] = {
 
	{ 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY | CH_LAST},
 
static const ChunkHandler company_chunk_handlers[] = {
 
	{ 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers);
src/saveload/depot_sl.cpp
Show inline comments
 
@@ -47,15 +47,17 @@ static void Load_DEPT()
 
		if (IsSavegameVersionBefore(SLV_141)) depot->town = (Town *)(size_t)_town_index;
 
	}
 
}
 

	
 
static void Ptrs_DEPT()
 
{
 
	for (Depot *depot : Depot::Iterate()) {
 
		SlObject(depot, _depot_desc);
 
		if (IsSavegameVersionBefore(SLV_141)) depot->town = Town::Get((size_t)depot->town);
 
	}
 
}
 

	
 
extern const ChunkHandler _depot_chunk_handlers[] = {
 
	{ 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler depot_chunk_handlers[] = {
 
	{ 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _depot_chunk_handlers(depot_chunk_handlers);
src/saveload/economy_sl.cpp
Show inline comments
 
@@ -85,18 +85,20 @@ static void Load_CAPY()
 
		SlObject(cp, _cargopayment_desc);
 
	}
 
}
 

	
 
static void Ptrs_CAPY()
 
{
 
	for (CargoPayment *cp : CargoPayment::Iterate()) {
 
		SlObject(cp, _cargopayment_desc);
 
	}
 
}
 

	
 

	
 
extern const ChunkHandler _economy_chunk_handlers[] = {
 
	{ 'CAPY', Save_CAPY,     Load_CAPY,     Ptrs_CAPY, nullptr, CH_ARRAY},
 
	{ 'PRIC', nullptr,       Load_PRIC,     nullptr,   nullptr, CH_RIFF },
 
	{ 'CAPR', nullptr,       Load_CAPR,     nullptr,   nullptr, CH_RIFF },
 
	{ 'ECMY', Save_ECMY,     Load_ECMY,     nullptr,   nullptr, CH_RIFF | CH_LAST},
 
static const ChunkHandler economy_chunk_handlers[] = {
 
	{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_ARRAY },
 
	{ 'PRIC', nullptr,   Load_PRIC, nullptr,   nullptr, CH_RIFF  },
 
	{ 'CAPR', nullptr,   Load_CAPR, nullptr,   nullptr, CH_RIFF  },
 
	{ 'ECMY', Save_ECMY, Load_ECMY, nullptr,   nullptr, CH_RIFF  },
 
};
 

	
 
extern const ChunkHandlerTable _economy_chunk_handlers(economy_chunk_handlers);
src/saveload/engine_sl.cpp
Show inline comments
 
@@ -184,17 +184,19 @@ static void Save_EIDS()
 
}
 

	
 
static void Load_EIDS()
 
{
 
	_engine_mngr.clear();
 

	
 
	while (SlIterateArray() != -1) {
 
		EngineIDMapping *eid = &_engine_mngr.emplace_back();
 
		SlObject(eid, _engine_id_mapping_desc);
 
	}
 
}
 

	
 
extern const ChunkHandler _engine_chunk_handlers[] = {
 
	{ 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_ARRAY          },
 
	{ 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_ARRAY          },
 
	{ 'ENGS', nullptr,   Load_ENGS, nullptr, nullptr, CH_RIFF | CH_LAST },
 
static const ChunkHandler engine_chunk_handlers[] = {
 
	{ 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_ARRAY },
 
	{ 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_ARRAY },
 
	{ 'ENGS', nullptr,   Load_ENGS, nullptr, nullptr, CH_RIFF  },
 
};
 

	
 
extern const ChunkHandlerTable _engine_chunk_handlers(engine_chunk_handlers);
src/saveload/game_sl.cpp
Show inline comments
 
@@ -164,16 +164,18 @@ static void Load_GSTR()
 
}
 

	
 
static void Save_GSTR()
 
{
 
	if (_current_data == nullptr) return;
 

	
 
	for (uint i = 0; i < _current_data->raw_strings.size(); i++) {
 
		SlSetArrayIndex(i);
 
		SlAutolength((AutolengthProc *)SaveReal_GSTR, &_current_data->raw_strings[i]);
 
	}
 
}
 

	
 
extern const ChunkHandler _game_chunk_handlers[] = {
 
static const ChunkHandler game_chunk_handlers[] = {
 
	{ 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_ARRAY },
 
	{ 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
	{ 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _game_chunk_handlers(game_chunk_handlers);
src/saveload/gamelog_sl.cpp
Show inline comments
 
@@ -159,15 +159,17 @@ static void Save_GLOG()
 
}
 

	
 
static void Load_GLOG()
 
{
 
	Load_GLOG_common(_gamelog_action, _gamelog_actions);
 
}
 

	
 
static void Check_GLOG()
 
{
 
	Load_GLOG_common(_load_check_data.gamelog_action, _load_check_data.gamelog_actions);
 
}
 

	
 
extern const ChunkHandler _gamelog_chunk_handlers[] = {
 
	{ 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_RIFF | CH_LAST }
 
static const ChunkHandler gamelog_chunk_handlers[] = {
 
	{ 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_RIFF }
 
};
 

	
 
extern const ChunkHandlerTable _gamelog_chunk_handlers(gamelog_chunk_handlers);
src/saveload/goal_sl.cpp
Show inline comments
 
@@ -31,15 +31,17 @@ static void Save_GOAL()
 
	}
 
}
 

	
 
static void Load_GOAL()
 
{
 
	int index;
 
	while ((index = SlIterateArray()) != -1) {
 
		Goal *s = new (index) Goal();
 
		SlObject(s, _goals_desc);
 
	}
 
}
 

	
 
extern const ChunkHandler _goal_chunk_handlers[] = {
 
	{ 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler goal_chunk_handlers[] = {
 
	{ 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _goal_chunk_handlers(goal_chunk_handlers);
src/saveload/group_sl.cpp
Show inline comments
 
@@ -46,15 +46,17 @@ static void Load_GRPS()
 
		SlObject(g, _group_desc);
 

	
 
		if (IsSavegameVersionBefore(SLV_189)) g->parent = INVALID_GROUP;
 

	
 
		if (IsSavegameVersionBefore(SLV_GROUP_LIVERIES)) {
 
	                const Company *c = Company::Get(g->owner);
 
	                g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
 
	                g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
 
		}
 
	}
 
}
 

	
 
extern const ChunkHandler _group_chunk_handlers[] = {
 
	{ 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler group_chunk_handlers[] = {
 
	{ 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _group_chunk_handlers(group_chunk_handlers);
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -167,19 +167,21 @@ static void Save_ITBL()
 
static void Load_ITBL()
 
{
 
	for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
		_industry_builder.builddata[it].Reset();
 
	}
 
	int index;
 
	while ((index = SlIterateArray()) != -1) {
 
		if ((uint)index >= NUM_INDUSTRYTYPES) SlErrorCorrupt("Too many industry builder datas");
 
		SlObject(_industry_builder.builddata + index, _industrytype_builder_desc);
 
	}
 
}
 

	
 
extern const ChunkHandler _industry_chunk_handlers[] = {
 
	{ 'INDY', Save_INDY,     Load_INDY,     Ptrs_INDY, nullptr, CH_ARRAY},
 
	{ 'IIDS', Save_IIDS,     Load_IIDS,     nullptr,   nullptr, CH_ARRAY},
 
	{ 'TIDS', Save_TIDS,     Load_TIDS,     nullptr,   nullptr, CH_ARRAY},
 
	{ 'IBLD', LoadSave_IBLD, LoadSave_IBLD, nullptr,   nullptr, CH_RIFF},
 
	{ 'ITBL', Save_ITBL,     Load_ITBL,     nullptr,   nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler industry_chunk_handlers[] = {
 
	{ 'INDY', Save_INDY,     Load_INDY,     Ptrs_INDY, nullptr, CH_ARRAY },
 
	{ 'IIDS', Save_IIDS,     Load_IIDS,     nullptr,   nullptr, CH_ARRAY },
 
	{ 'TIDS', Save_TIDS,     Load_TIDS,     nullptr,   nullptr, CH_ARRAY },
 
	{ 'IBLD', LoadSave_IBLD, LoadSave_IBLD, nullptr,   nullptr, CH_RIFF  },
 
	{ 'ITBL', Save_ITBL,     Load_ITBL,     nullptr,   nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _industry_chunk_handlers(industry_chunk_handlers);
src/saveload/labelmaps_sl.cpp
Show inline comments
 
@@ -112,16 +112,18 @@ static void Save_RAIL()
 
static void Load_RAIL()
 
{
 
	ResetLabelMaps();
 

	
 
	LabelObject lo;
 

	
 
	while (SlIterateArray() != -1) {
 
		SlObject(&lo, _label_object_desc);
 
		_railtype_list.push_back((RailTypeLabel)lo.label);
 
	}
 
}
 

	
 
extern const ChunkHandler _labelmaps_chunk_handlers[] = {
 
	{ 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler labelmaps_chunk_handlers[] = {
 
	{ 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _labelmaps_chunk_handlers(labelmaps_chunk_handlers);
 

	
src/saveload/linkgraph_sl.cpp
Show inline comments
 
@@ -271,17 +271,19 @@ static void Save_LGRS()
 
{
 
	SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
 
}
 

	
 
/**
 
 * Substitute pointers in link graph schedule.
 
 */
 
static void Ptrs_LGRS()
 
{
 
	SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
 
}
 

	
 
extern const ChunkHandler _linkgraph_chunk_handlers[] = {
 
static const ChunkHandler linkgraph_chunk_handlers[] = {
 
	{ 'LGRP', Save_LGRP, Load_LGRP, nullptr,   nullptr, CH_ARRAY },
 
	{ 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr,   nullptr, CH_ARRAY },
 
	{ 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_LAST  }
 
	{ 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_RIFF  }
 
};
 

	
 
extern const ChunkHandlerTable _linkgraph_chunk_handlers(linkgraph_chunk_handlers);
src/saveload/map_sl.cpp
Show inline comments
 
@@ -285,25 +285,27 @@ static void Save_MAP8()
 
{
 
	std::array<uint16, MAP_SL_BUF_SIZE> buf;
 
	TileIndex size = MapSize();
 

	
 
	SlSetLength(size * sizeof(uint16));
 
	for (TileIndex i = 0; i != size;) {
 
		for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m8;
 
		SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
 
	}
 
}
 

	
 

	
 
extern const ChunkHandler _map_chunk_handlers[] = {
 
static const ChunkHandler map_chunk_handlers[] = {
 
	{ 'MAPS', Save_MAPS, Load_MAPS, nullptr, Check_MAPS, CH_RIFF },
 
	{ 'MAPT', Save_MAPT, Load_MAPT, nullptr, nullptr,    CH_RIFF },
 
	{ 'MAPH', Save_MAPH, Load_MAPH, nullptr, nullptr,    CH_RIFF },
 
	{ 'MAPO', Save_MAP1, Load_MAP1, nullptr, nullptr,    CH_RIFF },
 
	{ 'MAP2', Save_MAP2, Load_MAP2, nullptr, nullptr,    CH_RIFF },
 
	{ 'M3LO', Save_MAP3, Load_MAP3, nullptr, nullptr,    CH_RIFF },
 
	{ 'M3HI', Save_MAP4, Load_MAP4, nullptr, nullptr,    CH_RIFF },
 
	{ 'MAP5', Save_MAP5, Load_MAP5, nullptr, nullptr,    CH_RIFF },
 
	{ 'MAPE', Save_MAP6, Load_MAP6, nullptr, nullptr,    CH_RIFF },
 
	{ 'MAP7', Save_MAP7, Load_MAP7, nullptr, nullptr,    CH_RIFF },
 
	{ 'MAP8', Save_MAP8, Load_MAP8, nullptr, nullptr,    CH_RIFF | CH_LAST },
 
	{ 'MAP8', Save_MAP8, Load_MAP8, nullptr, nullptr,    CH_RIFF },
 
};
 

	
 
extern const ChunkHandlerTable _map_chunk_handlers(map_chunk_handlers);
src/saveload/misc_sl.cpp
Show inline comments
 
@@ -136,16 +136,18 @@ static const SaveLoad _view_desc[] = {
 
	SLEG_CONDVAR(_saved_scrollpos_x,    SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
 
	SLEG_CONDVAR(_saved_scrollpos_x,    SLE_INT32,                  SLV_6, SL_MAX_VERSION),
 
	SLEG_CONDVAR(_saved_scrollpos_y,    SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
 
	SLEG_CONDVAR(_saved_scrollpos_y,    SLE_INT32,                  SLV_6, SL_MAX_VERSION),
 
	    SLEG_VAR(_saved_scrollpos_zoom, SLE_UINT8),
 
};
 

	
 
static void SaveLoad_VIEW()
 
{
 
	SlGlobList(_view_desc);
 
}
 

	
 
extern const ChunkHandler _misc_chunk_handlers[] = {
 
	{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, nullptr, Check_DATE, CH_RIFF},
 
	{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, nullptr, nullptr,    CH_RIFF | CH_LAST},
 
static const ChunkHandler misc_chunk_handlers[] = {
 
	{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, nullptr, Check_DATE, CH_RIFF },
 
	{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, nullptr, nullptr,    CH_RIFF },
 
};
 

	
 
extern const ChunkHandlerTable _misc_chunk_handlers(misc_chunk_handlers);
src/saveload/newgrf_sl.cpp
Show inline comments
 
@@ -102,15 +102,17 @@ static void Load_NGRF()
 
		ResetGRFConfig(false);
 
	} else {
 
		/* Append static NewGRF configuration */
 
		AppendStaticGRFConfigs(&_grfconfig);
 
	}
 
}
 

	
 
static void Check_NGRF()
 
{
 
	Load_NGRF_common(_load_check_data.grfconfig);
 
}
 

	
 
extern const ChunkHandler _newgrf_chunk_handlers[] = {
 
	{ 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_ARRAY | CH_LAST }
 
static const ChunkHandler newgrf_chunk_handlers[] = {
 
	{ 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_ARRAY }
 
};
 

	
 
extern const ChunkHandlerTable _newgrf_chunk_handlers(newgrf_chunk_handlers);
src/saveload/object_sl.cpp
Show inline comments
 
@@ -57,16 +57,18 @@ static void Ptrs_OBJS()
 
}
 

	
 
static void Save_OBID()
 
{
 
	Save_NewGRFMapping(_object_mngr);
 
}
 

	
 
static void Load_OBID()
 
{
 
	Load_NewGRFMapping(_object_mngr);
 
}
 

	
 
extern const ChunkHandler _object_chunk_handlers[] = {
 
static const ChunkHandler object_chunk_handlers[] = {
 
	{ 'OBID', Save_OBID, Load_OBID, nullptr,   nullptr, CH_ARRAY },
 
	{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_ARRAY | CH_LAST},
 
	{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _object_chunk_handlers(object_chunk_handlers);
src/saveload/order_sl.cpp
Show inline comments
 
@@ -277,17 +277,19 @@ void Load_BKOR()
 
		OrderBackup *ob = new (index) OrderBackup();
 
		SlObject(ob, GetOrderBackupDescription());
 
	}
 
}
 

	
 
static void Ptrs_BKOR()
 
{
 
	for (OrderBackup *ob : OrderBackup::Iterate()) {
 
		SlObject(ob, GetOrderBackupDescription());
 
	}
 
}
 

	
 
extern const ChunkHandler _order_chunk_handlers[] = {
 
	{ 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, nullptr, CH_ARRAY},
 
	{ 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, nullptr, CH_ARRAY},
 
	{ 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler order_chunk_handlers[] = {
 
	{ 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, nullptr, CH_ARRAY },
 
	{ 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, nullptr, CH_ARRAY },
 
	{ 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _order_chunk_handlers(order_chunk_handlers);
src/saveload/saveload.cpp
Show inline comments
 
@@ -205,119 +205,125 @@ struct SaveLoadParams {
 
	ReadBuffer *reader;                  ///< Savegame reading buffer.
 
	LoadFilter *lf;                      ///< Filter to read the savegame from.
 

	
 
	StringID error_str;                  ///< the translatable error message to show
 
	char *extra_msg;                     ///< the error message
 

	
 
	uint16 game_speed;                   ///< The game speed when saving started.
 
	bool saveinprogress;                 ///< Whether there is currently a save in progress.
 
};
 

	
 
static SaveLoadParams _sl; ///< Parameters used for/at saveload.
 

	
 
/* these define the chunks */
 
extern const ChunkHandler _gamelog_chunk_handlers[];
 
extern const ChunkHandler _map_chunk_handlers[];
 
extern const ChunkHandler _misc_chunk_handlers[];
 
extern const ChunkHandler _name_chunk_handlers[];
 
extern const ChunkHandler _cheat_chunk_handlers[] ;
 
extern const ChunkHandler _setting_chunk_handlers[];
 
extern const ChunkHandler _company_chunk_handlers[];
 
extern const ChunkHandler _engine_chunk_handlers[];
 
extern const ChunkHandler _veh_chunk_handlers[];
 
extern const ChunkHandler _waypoint_chunk_handlers[];
 
extern const ChunkHandler _depot_chunk_handlers[];
 
extern const ChunkHandler _order_chunk_handlers[];
 
extern const ChunkHandler _town_chunk_handlers[];
 
extern const ChunkHandler _sign_chunk_handlers[];
 
extern const ChunkHandler _station_chunk_handlers[];
 
extern const ChunkHandler _industry_chunk_handlers[];
 
extern const ChunkHandler _economy_chunk_handlers[];
 
extern const ChunkHandler _subsidy_chunk_handlers[];
 
extern const ChunkHandler _cargomonitor_chunk_handlers[];
 
extern const ChunkHandler _goal_chunk_handlers[];
 
extern const ChunkHandler _story_page_chunk_handlers[];
 
extern const ChunkHandler _ai_chunk_handlers[];
 
extern const ChunkHandler _game_chunk_handlers[];
 
extern const ChunkHandler _animated_tile_chunk_handlers[];
 
extern const ChunkHandler _newgrf_chunk_handlers[];
 
extern const ChunkHandler _group_chunk_handlers[];
 
extern const ChunkHandler _cargopacket_chunk_handlers[];
 
extern const ChunkHandler _autoreplace_chunk_handlers[];
 
extern const ChunkHandler _labelmaps_chunk_handlers[];
 
extern const ChunkHandler _linkgraph_chunk_handlers[];
 
extern const ChunkHandler _airport_chunk_handlers[];
 
extern const ChunkHandler _object_chunk_handlers[];
 
extern const ChunkHandler _persistent_storage_chunk_handlers[];
 

	
 
/** Array of all chunks in a savegame, \c nullptr terminated. */
 
static const ChunkHandler * const _chunk_handlers[] = {
 
	_gamelog_chunk_handlers,
 
	_map_chunk_handlers,
 
	_misc_chunk_handlers,
 
	_name_chunk_handlers,
 
	_cheat_chunk_handlers,
 
	_setting_chunk_handlers,
 
	_veh_chunk_handlers,
 
	_waypoint_chunk_handlers,
 
	_depot_chunk_handlers,
 
	_order_chunk_handlers,
 
	_industry_chunk_handlers,
 
	_economy_chunk_handlers,
 
	_subsidy_chunk_handlers,
 
	_cargomonitor_chunk_handlers,
 
	_goal_chunk_handlers,
 
	_story_page_chunk_handlers,
 
	_engine_chunk_handlers,
 
	_town_chunk_handlers,
 
	_sign_chunk_handlers,
 
	_station_chunk_handlers,
 
	_company_chunk_handlers,
 
	_ai_chunk_handlers,
 
	_game_chunk_handlers,
 
	_animated_tile_chunk_handlers,
 
	_newgrf_chunk_handlers,
 
	_group_chunk_handlers,
 
	_cargopacket_chunk_handlers,
 
	_autoreplace_chunk_handlers,
 
	_labelmaps_chunk_handlers,
 
	_linkgraph_chunk_handlers,
 
	_airport_chunk_handlers,
 
	_object_chunk_handlers,
 
	_persistent_storage_chunk_handlers,
 
	nullptr,
 
};
 

	
 
/**
 
 * Iterate over all chunk handlers.
 
 * @param ch the chunk handler iterator
 
 */
 
#define FOR_ALL_CHUNK_HANDLERS(ch) \
 
	for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != nullptr; chsc++) \
 
		for (const ChunkHandler *ch = *chsc; ch != nullptr; ch = (ch->flags & CH_LAST) ? nullptr : ch + 1)
 
static const std::vector<ChunkHandler> &ChunkHandlers()
 
{
 
	/* These define the chunks */
 
	extern const ChunkHandlerTable _gamelog_chunk_handlers;
 
	extern const ChunkHandlerTable _map_chunk_handlers;
 
	extern const ChunkHandlerTable _misc_chunk_handlers;
 
	extern const ChunkHandlerTable _name_chunk_handlers;
 
	extern const ChunkHandlerTable _cheat_chunk_handlers;
 
	extern const ChunkHandlerTable _setting_chunk_handlers;
 
	extern const ChunkHandlerTable _company_chunk_handlers;
 
	extern const ChunkHandlerTable _engine_chunk_handlers;
 
	extern const ChunkHandlerTable _veh_chunk_handlers;
 
	extern const ChunkHandlerTable _waypoint_chunk_handlers;
 
	extern const ChunkHandlerTable _depot_chunk_handlers;
 
	extern const ChunkHandlerTable _order_chunk_handlers;
 
	extern const ChunkHandlerTable _town_chunk_handlers;
 
	extern const ChunkHandlerTable _sign_chunk_handlers;
 
	extern const ChunkHandlerTable _station_chunk_handlers;
 
	extern const ChunkHandlerTable _industry_chunk_handlers;
 
	extern const ChunkHandlerTable _economy_chunk_handlers;
 
	extern const ChunkHandlerTable _subsidy_chunk_handlers;
 
	extern const ChunkHandlerTable _cargomonitor_chunk_handlers;
 
	extern const ChunkHandlerTable _goal_chunk_handlers;
 
	extern const ChunkHandlerTable _story_page_chunk_handlers;
 
	extern const ChunkHandlerTable _ai_chunk_handlers;
 
	extern const ChunkHandlerTable _game_chunk_handlers;
 
	extern const ChunkHandlerTable _animated_tile_chunk_handlers;
 
	extern const ChunkHandlerTable _newgrf_chunk_handlers;
 
	extern const ChunkHandlerTable _group_chunk_handlers;
 
	extern const ChunkHandlerTable _cargopacket_chunk_handlers;
 
	extern const ChunkHandlerTable _autoreplace_chunk_handlers;
 
	extern const ChunkHandlerTable _labelmaps_chunk_handlers;
 
	extern const ChunkHandlerTable _linkgraph_chunk_handlers;
 
	extern const ChunkHandlerTable _airport_chunk_handlers;
 
	extern const ChunkHandlerTable _object_chunk_handlers;
 
	extern const ChunkHandlerTable _persistent_storage_chunk_handlers;
 

	
 
	/** List of all chunks in a savegame. */
 
	static const ChunkHandlerTable _chunk_handler_tables[] = {
 
		_gamelog_chunk_handlers,
 
		_map_chunk_handlers,
 
		_misc_chunk_handlers,
 
		_name_chunk_handlers,
 
		_cheat_chunk_handlers,
 
		_setting_chunk_handlers,
 
		_veh_chunk_handlers,
 
		_waypoint_chunk_handlers,
 
		_depot_chunk_handlers,
 
		_order_chunk_handlers,
 
		_industry_chunk_handlers,
 
		_economy_chunk_handlers,
 
		_subsidy_chunk_handlers,
 
		_cargomonitor_chunk_handlers,
 
		_goal_chunk_handlers,
 
		_story_page_chunk_handlers,
 
		_engine_chunk_handlers,
 
		_town_chunk_handlers,
 
		_sign_chunk_handlers,
 
		_station_chunk_handlers,
 
		_company_chunk_handlers,
 
		_ai_chunk_handlers,
 
		_game_chunk_handlers,
 
		_animated_tile_chunk_handlers,
 
		_newgrf_chunk_handlers,
 
		_group_chunk_handlers,
 
		_cargopacket_chunk_handlers,
 
		_autoreplace_chunk_handlers,
 
		_labelmaps_chunk_handlers,
 
		_linkgraph_chunk_handlers,
 
		_airport_chunk_handlers,
 
		_object_chunk_handlers,
 
		_persistent_storage_chunk_handlers,
 
	};
 

	
 
	static std::vector<ChunkHandler> _chunk_handlers;
 

	
 
	if (_chunk_handlers.empty()) {
 
		for (auto &chunk_handler_table : _chunk_handler_tables) {
 
			for (auto &chunk_handler : chunk_handler_table) {
 
				_chunk_handlers.push_back(chunk_handler);
 
			}
 
		}
 
	}
 

	
 
	return _chunk_handlers;
 
}
 

	
 
/** 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_ALL_CHUNK_HANDLERS(ch) {
 
		if (ch->ptrs_proc != nullptr) {
 
			DEBUG(sl, 3, "Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
 
			ch->ptrs_proc();
 
	for (auto &ch : ChunkHandlers()) {
 
		if (ch.ptrs_proc != nullptr) {
 
			DEBUG(sl, 3, "Nulling pointers for %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
 
			ch.ptrs_proc();
 
		}
 
	}
 

	
 
	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
 
@@ -1645,207 +1651,207 @@ void SlAutolength(AutolengthProc *proc, 
 
	offs = _sl.dumper->GetSize() + _sl.obj_len;
 

	
 
	/* And write the stuff */
 
	proc(arg);
 

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

	
 
/**
 
 * 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)
 
static void SlLoadChunk(const ChunkHandler &ch)
 
{
 
	byte m = SlReadByte();
 
	size_t len;
 
	size_t endoffs;
 

	
 
	_sl.block_mode = m;
 
	_sl.obj_len = 0;
 

	
 
	switch (m) {
 
		case CH_ARRAY:
 
			_sl.array_index = 0;
 
			ch->load_proc();
 
			ch.load_proc();
 
			if (_next_offs != 0) SlErrorCorrupt("Invalid array length");
 
			break;
 
		case CH_SPARSE_ARRAY:
 
			ch->load_proc();
 
			ch.load_proc();
 
			if (_next_offs != 0) SlErrorCorrupt("Invalid array length");
 
			break;
 
		default:
 
			if ((m & 0xF) == CH_RIFF) {
 
				/* Read length */
 
				len = (SlReadByte() << 16) | ((m >> 4) << 24);
 
				len += SlReadUint16();
 
				_sl.obj_len = len;
 
				endoffs = _sl.reader->GetSize() + len;
 
				ch->load_proc();
 
				ch.load_proc();
 
				if (_sl.reader->GetSize() != endoffs) SlErrorCorrupt("Invalid chunk size");
 
			} else {
 
				SlErrorCorrupt("Invalid chunk type");
 
			}
 
			break;
 
	}
 
}
 

	
 
/**
 
 * Load a chunk of data for checking savegames.
 
 * If the chunkhandler is nullptr, the chunk is skipped.
 
 * @param ch The chunkhandler that will be used for the operation
 
 */
 
static void SlLoadCheckChunk(const ChunkHandler *ch)
 
static void SlLoadCheckChunk(const ChunkHandler &ch)
 
{
 
	byte m = SlReadByte();
 
	size_t len;
 
	size_t endoffs;
 

	
 
	_sl.block_mode = m;
 
	_sl.obj_len = 0;
 

	
 
	switch (m) {
 
		case CH_ARRAY:
 
			_sl.array_index = 0;
 
			if (ch->load_check_proc) {
 
				ch->load_check_proc();
 
			if (ch.load_check_proc) {
 
				ch.load_check_proc();
 
			} else {
 
				SlSkipArray();
 
			}
 
			break;
 
		case CH_SPARSE_ARRAY:
 
			if (ch->load_check_proc) {
 
				ch->load_check_proc();
 
			if (ch.load_check_proc) {
 
				ch.load_check_proc();
 
			} else {
 
				SlSkipArray();
 
			}
 
			break;
 
		default:
 
			if ((m & 0xF) == CH_RIFF) {
 
				/* Read length */
 
				len = (SlReadByte() << 16) | ((m >> 4) << 24);
 
				len += SlReadUint16();
 
				_sl.obj_len = len;
 
				endoffs = _sl.reader->GetSize() + len;
 
				if (ch->load_check_proc) {
 
					ch->load_check_proc();
 
				if (ch.load_check_proc) {
 
					ch.load_check_proc();
 
				} else {
 
					SlSkipBytes(len);
 
				}
 
				if (_sl.reader->GetSize() != endoffs) SlErrorCorrupt("Invalid chunk size");
 
			} else {
 
				SlErrorCorrupt("Invalid chunk type");
 
			}
 
			break;
 
	}
 
}
 

	
 
/**
 
 * Save a chunk of data (eg. vehicles, stations, etc.). Each chunk is
 
 * prefixed by an ID identifying it, followed by data, and terminator where appropriate
 
 * @param ch The chunkhandler that will be used for the operation
 
 */
 
static void SlSaveChunk(const ChunkHandler *ch)
 
static void SlSaveChunk(const ChunkHandler &ch)
 
{
 
	ChunkSaveLoadProc *proc = ch->save_proc;
 
	ChunkSaveLoadProc *proc = ch.save_proc;
 

	
 
	/* Don't save any chunk information if there is no save handler. */
 
	if (proc == nullptr) return;
 

	
 
	SlWriteUint32(ch->id);
 
	DEBUG(sl, 2, "Saving chunk %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
 

	
 
	_sl.block_mode = ch->flags & CH_TYPE_MASK;
 
	switch (ch->flags & CH_TYPE_MASK) {
 
	SlWriteUint32(ch.id);
 
	DEBUG(sl, 2, "Saving chunk %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
 

	
 
	_sl.block_mode = ch.type;
 
	switch (ch.type) {
 
		case CH_RIFF:
 
			_sl.need_length = NL_WANTLENGTH;
 
			proc();
 
			break;
 
		case CH_ARRAY:
 
			_sl.last_array_index = 0;
 
			SlWriteByte(CH_ARRAY);
 
			proc();
 
			SlWriteArrayLength(0); // Terminate arrays
 
			break;
 
		case CH_SPARSE_ARRAY:
 
			SlWriteByte(CH_SPARSE_ARRAY);
 
			proc();
 
			SlWriteArrayLength(0); // Terminate arrays
 
			break;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/** Save all chunks */
 
static void SlSaveChunks()
 
{
 
	FOR_ALL_CHUNK_HANDLERS(ch) {
 
	for (auto &ch : ChunkHandlers()) {
 
		SlSaveChunk(ch);
 
	}
 

	
 
	/* Terminator */
 
	SlWriteUint32(0);
 
}
 

	
 
/**
 
 * Find the ChunkHandler that will be used for processing the found
 
 * chunk in the savegame or in memory
 
 * @param id the chunk in question
 
 * @return returns the appropriate chunkhandler
 
 */
 
static const ChunkHandler *SlFindChunkHandler(uint32 id)
 
{
 
	FOR_ALL_CHUNK_HANDLERS(ch) if (ch->id == id) return ch;
 
	for (auto &ch : ChunkHandlers()) if (ch.id == id) return &ch;
 
	return nullptr;
 
}
 

	
 
/** Load all chunks */
 
static void SlLoadChunks()
 
{
 
	uint32 id;
 
	const ChunkHandler *ch;
 

	
 
	for (id = SlReadUint32(); id != 0; id = SlReadUint32()) {
 
		DEBUG(sl, 2, "Loading chunk %c%c%c%c", id >> 24, id >> 16, id >> 8, id);
 

	
 
		ch = SlFindChunkHandler(id);
 
		if (ch == nullptr) SlErrorCorrupt("Unknown chunk type");
 
		SlLoadChunk(ch);
 
		SlLoadChunk(*ch);
 
	}
 
}
 

	
 
/** Load all chunks for savegame checking */
 
static void SlLoadCheckChunks()
 
{
 
	uint32 id;
 
	const ChunkHandler *ch;
 

	
 
	for (id = SlReadUint32(); id != 0; id = SlReadUint32()) {
 
		DEBUG(sl, 2, "Loading chunk %c%c%c%c", id >> 24, id >> 16, id >> 8, id);
 

	
 
		ch = SlFindChunkHandler(id);
 
		if (ch == nullptr) SlErrorCorrupt("Unknown chunk type");
 
		SlLoadCheckChunk(ch);
 
		SlLoadCheckChunk(*ch);
 
	}
 
}
 

	
 
/** Fix all pointers (convert index -> pointer) */
 
static void SlFixPointers()
 
{
 
	_sl.action = SLA_PTRS;
 

	
 
	FOR_ALL_CHUNK_HANDLERS(ch) {
 
		if (ch->ptrs_proc != nullptr) {
 
			DEBUG(sl, 3, "Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
 
			ch->ptrs_proc();
 
	for (auto &ch : ChunkHandlers()) {
 
		if (ch.ptrs_proc != nullptr) {
 
			DEBUG(sl, 3, "Fixing pointers for %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
 
			ch.ptrs_proc();
 
		}
 
	}
 

	
 
	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.
 

	
src/saveload/saveload.h
Show inline comments
 
@@ -5,24 +5,25 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file saveload.h Functions/types related to saving and loading games. */
 

	
 
#ifndef SAVELOAD_H
 
#define SAVELOAD_H
 

	
 
#include "../fileio_type.h"
 
#include "../strings_type.h"
 
#include "../core/span_type.hpp"
 
#include <string>
 
#include <vector>
 

	
 
/** SaveLoad versions
 
 * Previous savegame versions, the trunk revision where they were
 
 * introduced and the released version that had that particular
 
 * savegame version.
 
 * Up to savegame version 18 there is a minor version as well.
 
 *
 
 * Older entries keep their original numbering.
 
 *
 
 * Newer entries should use a descriptive labels, numeric version
 
 * and PR can be added to comment.
 
 *
 
@@ -369,59 +370,60 @@ void SetSaveLoadError(StringID str);
 
const char *GetSaveLoadErrorString();
 
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
 
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,
 
	CH_SPARSE_ARRAY = 2,
 
};
 

	
 
/** 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.
 
	uint32 flags;                       ///< Flags of the chunk. @see ChunkType
 
	ChunkType type;                     ///< Type of the chunk. @see ChunkType
 
};
 

	
 
/** A table of ChunkHandler entries. */
 
using ChunkHandlerTable = span<const ChunkHandler>;
 

	
 
/** Type of reference (#SLE_REF, #SLE_CONDREF). */
 
enum SLRefType {
 
	REF_ORDER          =  0, ///< Load/save a reference to an order.
 
	REF_VEHICLE        =  1, ///< Load/save a reference to a vehicle.
 
	REF_STATION        =  2, ///< Load/save a reference to a station.
 
	REF_TOWN           =  3, ///< Load/save a reference to a town.
 
	REF_VEHICLE_OLD    =  4, ///< Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
 
	REF_ROADSTOPS      =  5, ///< Load/save a reference to a bus/truck stop.
 
	REF_ENGINE_RENEWS  =  6, ///< Load/save a reference to an engine renewal (autoreplace).
 
	REF_CARGO_PACKET   =  7, ///< Load/save a reference to a cargo packet.
 
	REF_ORDERLIST      =  8, ///< Load/save a reference to an orderlist.
 
	REF_STORAGE        =  9, ///< Load/save a reference to a persistent storage.
 
	REF_LINK_GRAPH     = 10, ///< Load/save a reference to a link graph.
 
	REF_LINK_GRAPH_JOB = 11, ///< Load/save a reference to a link graph job.
 
};
 

	
 
/** Flags of a chunk. */
 
enum ChunkType {
 
	CH_RIFF         =  0,
 
	CH_ARRAY        =  1,
 
	CH_SPARSE_ARRAY =  2,
 
	CH_TYPE_MASK    =  3,
 
	CH_LAST         =  8, ///< Last chunk in this array.
 
};
 

	
 
/**
 
 * VarTypes is the general bitmasked magic type that tells us
 
 * certain characteristics about the variable it refers to. For example
 
 * SLE_FILE_* gives the size(type) as it would be in the savegame and
 
 * SLE_VAR_* the size(type) as it is in memory during runtime. These are
 
 * the first 8 bits (0-3 SLE_FILE, 4-7 SLE_VAR).
 
 * Bits 8-15 are reserved for various flags as explained below
 
 */
 
enum VarTypes {
 
	/* 4 bits allocated a maximum of 16 types for NumberType */
 
	SLE_FILE_I8       = 0,
 
	SLE_FILE_U8       = 1,
src/saveload/signs_sl.cpp
Show inline comments
 
@@ -53,15 +53,17 @@ static void Load_SIGN()
 
		if (IsSavegameVersionBefore(SLV_6, 1) || (IsSavegameVersionBefore(SLV_83) && si->owner == INVALID_OWNER)) {
 
			si->owner = OWNER_NONE;
 
		}
 

	
 
		/* Signs placed in scenario editor shall now be OWNER_DEITY */
 
		if (IsSavegameVersionBefore(SLV_171) && si->owner == OWNER_NONE && _file_to_saveload.abstract_ftype == FT_SCENARIO) {
 
			si->owner = OWNER_DEITY;
 
		}
 
	}
 
}
 

	
 
/** Chunk handlers related to signs. */
 
extern const ChunkHandler _sign_chunk_handlers[] = {
 
	{ 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler sign_chunk_handlers[] = {
 
	{ 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _sign_chunk_handlers(sign_chunk_handlers);
src/saveload/station_sl.cpp
Show inline comments
 
@@ -604,17 +604,19 @@ static void Load_ROADSTOP()
 

	
 
		SlObject(rs, _roadstop_desc);
 
	}
 
}
 

	
 
static void Ptrs_ROADSTOP()
 
{
 
	for (RoadStop *rs : RoadStop::Iterate()) {
 
		SlObject(rs, _roadstop_desc);
 
	}
 
}
 

	
 
extern const ChunkHandler _station_chunk_handlers[] = {
 
static const ChunkHandler station_chunk_handlers[] = {
 
	{ 'STNS', nullptr,       Load_STNS,     Ptrs_STNS,     nullptr, CH_ARRAY },
 
	{ 'STNN', Save_STNN,     Load_STNN,     Ptrs_STNN,     nullptr, CH_ARRAY },
 
	{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_ARRAY | CH_LAST},
 
	{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _station_chunk_handlers(station_chunk_handlers);
src/saveload/storage_sl.cpp
Show inline comments
 
@@ -35,15 +35,17 @@ static void Load_PSAC()
 
/** Save persistent storage data. */
 
static void Save_PSAC()
 
{
 
	/* Write the industries */
 
	for (PersistentStorage *ps : PersistentStorage::Iterate()) {
 
		ps->ClearChanges();
 
		SlSetArrayIndex(ps->index);
 
		SlObject(ps, _storage_desc);
 
	}
 
}
 

	
 
/** Chunk handler for persistent storages. */
 
extern const ChunkHandler _persistent_storage_chunk_handlers[] = {
 
	{ 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler persistent_storage_chunk_handlers[] = {
 
	{ 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _persistent_storage_chunk_handlers(persistent_storage_chunk_handlers);
src/saveload/story_sl.cpp
Show inline comments
 
@@ -86,16 +86,18 @@ static void Load_STORY_PAGE()
 
		StoryPage *s = new (index) StoryPage();
 
		SlObject(s, _story_pages_desc);
 
		if (s->sort_value > max_sort_value) {
 
			max_sort_value = s->sort_value;
 
		}
 
	}
 
	/* Update the next sort value, so that the next
 
	 * created page is shown after all existing pages.
 
	 */
 
	_story_page_next_sort_value = max_sort_value + 1;
 
}
 

	
 
extern const ChunkHandler _story_page_chunk_handlers[] = {
 
	{ 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_ARRAY},
 
	{ 'STPA', Save_STORY_PAGE,         Load_STORY_PAGE,         nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler story_page_chunk_handlers[] = {
 
	{ 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_ARRAY },
 
	{ 'STPA', Save_STORY_PAGE,         Load_STORY_PAGE,         nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _story_page_chunk_handlers(story_page_chunk_handlers);
src/saveload/strings_sl.cpp
Show inline comments
 
@@ -122,15 +122,17 @@ static void Load_NAME()
 

	
 
	while ((index = SlIterateArray()) != -1) {
 
		if (index >= NUM_OLD_STRINGS) SlErrorCorrupt("Invalid old name index");
 
		if (SlGetFieldLength() > (uint)LEN_OLD_STRINGS) SlErrorCorrupt("Invalid old name length");
 

	
 
		SlArray(&_old_name_array[LEN_OLD_STRINGS * index], SlGetFieldLength(), SLE_UINT8);
 
		/* Make sure the old name is null terminated */
 
		_old_name_array[LEN_OLD_STRINGS * index + LEN_OLD_STRINGS - 1] = '\0';
 
	}
 
}
 

	
 
/** Chunk handlers related to strings. */
 
extern const ChunkHandler _name_chunk_handlers[] = {
 
	{ 'NAME', nullptr, Load_NAME, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler name_chunk_handlers[] = {
 
	{ 'NAME', nullptr, Load_NAME, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _name_chunk_handlers(name_chunk_handlers);
src/saveload/subsidy_sl.cpp
Show inline comments
 
@@ -34,15 +34,17 @@ static void Save_SUBS()
 
	}
 
}
 

	
 
static void Load_SUBS()
 
{
 
	int index;
 
	while ((index = SlIterateArray()) != -1) {
 
		Subsidy *s = new (index) Subsidy();
 
		SlObject(s, _subsidies_desc);
 
	}
 
}
 

	
 
extern const ChunkHandler _subsidy_chunk_handlers[] = {
 
	{ 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler subsidy_chunk_handlers[] = {
 
	{ 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _subsidy_chunk_handlers(subsidy_chunk_handlers);
src/saveload/town_sl.cpp
Show inline comments
 
@@ -287,16 +287,18 @@ static void Load_TOWN()
 
/** Fix pointers when loading town data. */
 
static void Ptrs_TOWN()
 
{
 
	/* Don't run when savegame version lower than 161. */
 
	if (IsSavegameVersionBefore(SLV_161)) return;
 

	
 
	for (Town *t : Town::Iterate()) {
 
		SlObject(t, _town_desc);
 
	}
 
}
 

	
 
/** Chunk handler for towns. */
 
extern const ChunkHandler _town_chunk_handlers[] = {
 
static const ChunkHandler town_chunk_handlers[] = {
 
	{ 'HIDS', Save_HIDS, Load_HIDS, nullptr,   nullptr, CH_ARRAY },
 
	{ 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_ARRAY | CH_LAST},
 
	{ 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _town_chunk_handlers(town_chunk_handlers);
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -922,15 +922,17 @@ void Load_VEHS()
 
		/* Advanced vehicle lists got added */
 
		if (IsSavegameVersionBefore(SLV_60)) v->group_id = DEFAULT_GROUP;
 
	}
 
}
 

	
 
static void Ptrs_VEHS()
 
{
 
	for (Vehicle *v : Vehicle::Iterate()) {
 
		SlObject(v, GetVehicleDescription(v->type));
 
	}
 
}
 

	
 
extern const ChunkHandler _veh_chunk_handlers[] = {
 
	{ 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_ARRAY | CH_LAST},
 
static const ChunkHandler veh_chunk_handlers[] = {
 
	{ 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _veh_chunk_handlers(veh_chunk_handlers);
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -215,15 +215,17 @@ static void Ptrs_WAYP()
 
				 * possibly corrupt ones) will not be queried in the nullptr Ptrs proc run. */
 
				_old_waypoints.clear();
 
				SlErrorCorrupt("Referencing invalid Town");
 
			}
 
			wp.town = Town::Get(wp.town_index);
 
		}
 
		if (IsSavegameVersionBefore(SLV_84)) {
 
			wp.name = CopyFromOldName(wp.string_id);
 
		}
 
	}
 
}
 

	
 
extern const ChunkHandler _waypoint_chunk_handlers[] = {
 
	{ 'CHKP', nullptr, Load_WAYP, Ptrs_WAYP, nullptr, CH_ARRAY | CH_LAST},
 
static const ChunkHandler waypoint_chunk_handlers[] = {
 
	{ 'CHKP', nullptr, Load_WAYP, Ptrs_WAYP, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _waypoint_chunk_handlers(waypoint_chunk_handlers);
src/settings.cpp
Show inline comments
 
@@ -2076,28 +2076,30 @@ static void Load_PATS()
 
}
 

	
 
static void Check_PATS()
 
{
 
	LoadSettings(_settings, &_load_check_data.settings);
 
}
 

	
 
static void Save_PATS()
 
{
 
	SaveSettings(_settings, &_settings_game);
 
}
 

	
 
extern const ChunkHandler _setting_chunk_handlers[] = {
 
	{ 'OPTS', nullptr,      Load_OPTS, nullptr, nullptr,       CH_RIFF},
 
	{ 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF | CH_LAST},
 
static const ChunkHandler setting_chunk_handlers[] = {
 
	{ 'OPTS', nullptr,   Load_OPTS, nullptr, nullptr,    CH_RIFF },
 
	{ 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF },
 
};
 

	
 
extern const ChunkHandlerTable _setting_chunk_handlers(setting_chunk_handlers);
 

	
 
static bool IsSignedVarMemType(VarType vt)
 
{
 
	switch (GetVarMemType(vt)) {
 
		case SLE_VAR_I8:
 
		case SLE_VAR_I16:
 
		case SLE_VAR_I32:
 
		case SLE_VAR_I64:
 
			return true;
 
	}
 
	return false;
 
}
0 comments (0 inline, 0 general)