Changeset - r25585:53810459092f
[Not reviewed]
master
0 40 1
Patric Stout - 3 years ago 2021-05-31 20:26:44
truebrain@openttd.org
Codechange: C++-ify lists for SaveLoad (#9323)

Basically, this changes "SaveLoad *" to either:
1) "SaveLoadTable" if a list of SaveLoads was meant
2) "SaveLoad &" if a single entry was meant

As added bonus, this removes SL_END / SLE_END / SLEG_END. This
also adds core/span.hpp, a "std::span"-lite.
41 files changed with 213 insertions and 223 deletions:
0 comments (0 inline, 0 general)
src/cargopacket.h
Show inline comments
 
@@ -14,12 +14,13 @@
 
#include "economy_type.h"
 
#include "station_type.h"
 
#include "order_type.h"
 
#include "cargo_type.h"
 
#include "vehicle_type.h"
 
#include "core/multimap.hpp"
 
#include "saveload/saveload.h"
 
#include <list>
 

	
 
/** Unique identifier for a single cargo packet. */
 
typedef uint32 CargoPacketID;
 
struct CargoPacket;
 

	
 
@@ -29,13 +30,13 @@ typedef Pool<CargoPacket, CargoPacketID,
 
extern CargoPacketPool _cargopacket_pool;
 

	
 
struct GoodsEntry; // forward-declare for Stage() and RerouteStalePackets()
 

	
 
template <class Tinst, class Tcont> class CargoList;
 
class StationCargoList; // forward-declare, so we can use it in VehicleCargoList.
 
extern const struct SaveLoad *GetCargoPacketDesc();
 
extern SaveLoadTable GetCargoPacketDesc();
 

	
 
typedef uint32 TileOrStationID;
 

	
 
/**
 
 * Container for cargo from the same location and time.
 
 */
 
@@ -55,13 +56,13 @@ private:
 

	
 
	/** The CargoList caches, thus needs to know about it. */
 
	template <class Tinst, class Tcont> friend class CargoList;
 
	friend class VehicleCargoList;
 
	friend class StationCargoList;
 
	/** We want this to be saved, right? */
 
	friend const struct SaveLoad *GetCargoPacketDesc();
 
	friend SaveLoadTable GetCargoPacketDesc();
 
public:
 
	/** Maximum number of items in a single cargo packet. */
 
	static const uint16 MAX_COUNT = UINT16_MAX;
 

	
 
	CargoPacket();
 
	CargoPacket(StationID source, TileIndex source_xy, uint16 count, SourceType source_type, SourceID source_id);
 
@@ -302,13 +303,13 @@ protected:
 
public:
 
	/** The station cargo list needs to control the unloading. */
 
	friend class StationCargoList;
 
	/** The super class ought to know what it's doing. */
 
	friend class CargoList<VehicleCargoList, CargoPacketList>;
 
	/** The vehicles have a cargo list (and we want that saved). */
 
	friend const struct SaveLoad *GetVehicleDescription(VehicleType vt);
 
	friend SaveLoadTable GetVehicleDescription(VehicleType vt);
 

	
 
	friend class CargoShift;
 
	friend class CargoTransfer;
 
	friend class CargoDelivery;
 
	template<class Tsource>
 
	friend class CargoRemoval;
 
@@ -453,13 +454,13 @@ protected:
 
	uint reserved_count; ///< Amount of cargo being reserved for loading.
 

	
 
public:
 
	/** The super class ought to know what it's doing. */
 
	friend class CargoList<StationCargoList, StationCargoPacketMap>;
 
	/** The stations, via GoodsEntry, have a CargoList. */
 
	friend const struct SaveLoad *GetGoodsDesc();
 
	friend SaveLoadTable GetGoodsDesc();
 

	
 
	friend class CargoLoad;
 
	friend class CargoTransfer;
 
	template<class Tsource>
 
	friend class CargoRemoval;
 
	friend class CargoReservation;
src/core/span_type.hpp
Show inline comments
 
new file 100644
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * 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 span_type.hpp Minimized implementation of C++20 std::span. */
 

	
 
#ifndef CORE_SPAN_TYPE_HPP
 
#define CORE_SPAN_TYPE_HPP
 

	
 
/* This is a partial copy/paste from https://github.com/gsl-lite/gsl-lite/blob/master/include/gsl/gsl-lite.hpp */
 

	
 
/* Template to check if a template variable defines size() and data(). */
 
template <class, class = void>
 
struct has_size_and_data : std::false_type{};
 
template <class C>
 
struct has_size_and_data
 
<
 
	C, std::void_t<
 
		decltype(std::size(std::declval<C>())),
 
		decltype(std::data(std::declval<C>()))>
 
> : std::true_type{};
 

	
 
/* Template to check if two elements are compatible. */
 
template <class, class, class = void>
 
struct is_compatible_element : std::false_type {};
 
template <class C, class E>
 
struct is_compatible_element
 
<
 
	C, E, std::void_t<
 
		decltype(std::data(std::declval<C>())),
 
		typename std::remove_pointer<decltype(std::data( std::declval<C&>()))>::type(*)[]>
 
> : std::is_convertible<typename std::remove_pointer<decltype(std::data(std::declval<C&>()))>::type(*)[], E(*)[]>{};
 

	
 
/* Template to check if a container is compatible. gsl-lite also includes is_array and is_std_array, but as we don't use them, they are omitted. */
 
template <class C, class E>
 
struct is_compatible_container : std::bool_constant
 
<
 
	has_size_and_data<C>::value
 
	&& is_compatible_element<C,E>::value
 
>{};
 

	
 
/**
 
 * A trimmed down version of what std::span will be in C++20.
 
 *
 
 * It is fully forwards compatible, so if this codebase switches to C++20,
 
 * all "span" instances can be replaced by "std::span" without loss of
 
 * functionality.
 
 *
 
 * Currently it only supports basic functionality:
 
 * - size() and friends
 
 * - begin() and friends
 
 *
 
 * It is meant to simplify function parameters, where we only want to walk
 
 * a continuous list.
 
 */
 
template<class T>
 
class span {
 
public:
 
	typedef T element_type;
 
	typedef typename std::remove_cv< T >::type value_type;
 

	
 
	typedef T &reference;
 
	typedef T *pointer;
 
	typedef const T &const_reference;
 
	typedef const T *const_pointer;
 

	
 
	typedef pointer iterator;
 
	typedef const_pointer const_iterator;
 

	
 
	typedef size_t size_type;
 
	typedef std::ptrdiff_t difference_type;
 

	
 
	constexpr span(pointer data_in, size_t size_in) : first(data_in), last(data_in + size_in) {}
 

	
 
	template<class Container, typename std::enable_if<(is_compatible_container<Container, element_type>::value), int>::type = 0>
 
	constexpr span(Container &list) noexcept : first(std::data(list)), last(std::data(list) + std::size(list)) {}
 
	template<class Container, typename std::enable_if<(std::is_const<element_type>::value && is_compatible_container<Container, element_type>::value), int>::type = 0>
 
	constexpr span(const Container &list) noexcept : first(std::data(list)), last(std::data(list) + std::size(list)) {}
 

	
 
	constexpr size_t size() const noexcept { return static_cast<size_t>( last - first ); }
 
	constexpr std::ptrdiff_t ssize() const noexcept { return static_cast<std::ptrdiff_t>( last - first ); }
 
	constexpr bool empty() const noexcept { return size() == 0; }
 

	
 
	constexpr iterator begin() const noexcept { return iterator(first); }
 
	constexpr iterator end() const noexcept { return iterator(last); }
 

	
 
	constexpr const_iterator cbegin() const noexcept { return const_iterator(first); }
 
	constexpr const_iterator cend() const noexcept { return const_iterator(last); }
 

	
 
private:
 
	pointer first;
 
	pointer last;
 
};
 

	
 
#endif /* CORE_SPAN_TYPE_HPP */
src/linkgraph/linkgraph.h
Show inline comments
 
@@ -13,16 +13,16 @@
 
#include "../core/pool_type.hpp"
 
#include "../core/smallmap_type.hpp"
 
#include "../core/smallmatrix_type.hpp"
 
#include "../station_base.h"
 
#include "../cargotype.h"
 
#include "../date_func.h"
 
#include "../saveload/saveload.h"
 
#include "linkgraph_type.h"
 
#include <utility>
 

	
 
struct SaveLoad;
 
class LinkGraph;
 

	
 
/**
 
 * Type of the pool for link graph components. Each station can be in at up to
 
 * 32 link graphs. So we allow for plenty of them to be created.
 
 */
 
@@ -522,14 +522,14 @@ public:
 
	NodeID AddNode(const Station *st);
 
	void RemoveNode(NodeID id);
 

	
 
protected:
 
	friend class LinkGraph::ConstNode;
 
	friend class LinkGraph::Node;
 
	friend const SaveLoad *GetLinkGraphDesc();
 
	friend const SaveLoad *GetLinkGraphJobDesc();
 
	friend SaveLoadTable GetLinkGraphDesc();
 
	friend SaveLoadTable GetLinkGraphJobDesc();
 
	friend void SaveLoad_LinkGraph(LinkGraph &lg);
 

	
 
	CargoID cargo;         ///< Cargo of this component's link graph.
 
	Date last_compression; ///< Last time the capacities and supplies were compressed.
 
	NodeVector nodes;      ///< Nodes in the component.
 
	EdgeMatrix edges;      ///< Edges in the component.
src/linkgraph/linkgraphjob.h
Show inline comments
 
@@ -49,13 +49,13 @@ private:
 
		void Init(uint supply);
 
	};
 

	
 
	typedef std::vector<NodeAnnotation> NodeAnnotationVector;
 
	typedef SmallMatrix<EdgeAnnotation> EdgeAnnotationMatrix;
 

	
 
	friend const SaveLoad *GetLinkGraphJobDesc();
 
	friend SaveLoadTable GetLinkGraphJobDesc();
 
	friend class LinkGraphSchedule;
 

	
 
protected:
 
	const LinkGraph link_graph;       ///< Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
 
	const LinkGraphSettings settings; ///< Copy of _settings_game.linkgraph at spawn time.
 
	std::thread thread;               ///< Thread the job is running in or a default-constructed thread if it's running in the main thread.
src/linkgraph/linkgraphschedule.h
Show inline comments
 
@@ -36,13 +36,13 @@ public:
 
class LinkGraphSchedule {
 
private:
 
	LinkGraphSchedule();
 
	~LinkGraphSchedule();
 
	typedef std::list<LinkGraph *> GraphList;
 
	typedef std::list<LinkGraphJob *> JobList;
 
	friend const SaveLoad *GetLinkGraphScheduleDesc();
 
	friend SaveLoadTable GetLinkGraphScheduleDesc();
 

	
 
protected:
 
	ComponentHandler *handlers[6]; ///< Handlers to be run for each job.
 
	GraphList schedule;            ///< Queue for new jobs.
 
	JobList running;               ///< Currently running jobs.
 

	
src/order_backup.h
Show inline comments
 
@@ -12,12 +12,13 @@
 

	
 
#include "core/pool_type.hpp"
 
#include "group_type.h"
 
#include "tile_type.h"
 
#include "vehicle_type.h"
 
#include "base_consist.h"
 
#include "saveload/saveload.h"
 

	
 
/** Unique identifier for an order backup. */
 
typedef uint8 OrderBackupID;
 
struct OrderBackup;
 

	
 
/** The pool type for order backups. */
 
@@ -31,13 +32,13 @@ static const uint32 MAKE_ORDER_BACKUP_FL
 
/**
 
 * Data for backing up an order of a vehicle so it can be
 
 * restored after a vehicle is rebuilt in the same depot.
 
 */
 
struct OrderBackup : OrderBackupPool::PoolItem<&_order_backup_pool>, BaseConsist {
 
private:
 
	friend const struct SaveLoad *GetOrderBackupDescription(); ///< Saving and loading of order backups.
 
	friend SaveLoadTable GetOrderBackupDescription(); ///< Saving and loading of order backups.
 
	friend void Load_BKOR();   ///< Creating empty orders upon savegame loading.
 
	uint32 user;               ///< The user that requested the backup.
 
	TileIndex tile;            ///< Tile of the depot where the order was changed.
 
	GroupID group;             ///< The group the vehicle was part of.
 

	
 
	const Vehicle *clone;      ///< Vehicle this vehicle was a clone of.
src/order_base.h
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "core/bitmath_func.hpp"
 
#include "cargo_type.h"
 
#include "depot_type.h"
 
#include "station_type.h"
 
#include "vehicle_type.h"
 
#include "date_type.h"
 
#include "saveload/saveload.h"
 

	
 
typedef Pool<Order, OrderID, 256, 0xFF0000> OrderPool;
 
typedef Pool<OrderList, OrderListID, 128, 64000> OrderListPool;
 
extern OrderPool _order_pool;
 
extern OrderListPool _orderlist_pool;
 

	
 
@@ -28,15 +29,15 @@ extern OrderListPool _orderlist_pool;
 
 * - Load_ORDR, all the global orders
 
 * - Vehicle -> current_order
 
 * - REF_ORDER (all REFs are currently limited to 16 bits!!)
 
 */
 
struct Order : OrderPool::PoolItem<&_order_pool> {
 
private:
 
	friend const struct SaveLoad *GetVehicleDescription(VehicleType vt); ///< Saving and loading the current order of vehicles.
 
	friend SaveLoadTable GetVehicleDescription(VehicleType vt); ///< Saving and loading the current order of vehicles.
 
	friend void Load_VEHS();                                             ///< Loading of ancient vehicles.
 
	friend const struct SaveLoad *GetOrderDescription();                 ///< Saving and loading of orders.
 
	friend SaveLoadTable GetOrderDescription();                 ///< Saving and loading of orders.
 

	
 
	uint8 type;           ///< The type of order + non-stop flags
 
	uint8 flags;          ///< Load/unload types, depot order/action types.
 
	DestinationID dest;   ///< The destination of the order.
 

	
 
	CargoID refit_cargo;  ///< Refit CargoID
 
@@ -247,13 +248,13 @@ void DeleteOrder(Vehicle *v, VehicleOrde
 
 * Shared order list linking together the linked list of orders and the list
 
 *  of vehicles sharing this order list.
 
 */
 
struct OrderList : OrderListPool::PoolItem<&_orderlist_pool> {
 
private:
 
	friend void AfterLoadVehicles(bool part_of_load); ///< For instantiating the shared vehicle chain
 
	friend const struct SaveLoad *GetOrderListDescription(); ///< Saving and loading of order lists.
 
	friend SaveLoadTable GetOrderListDescription(); ///< Saving and loading of order lists.
 

	
 
	StationID GetBestLoadableNext(const Vehicle *v, const Order *o1, const Order *o2) const;
 

	
 
	Order *first;                     ///< First order of the order list.
 
	VehicleOrderID num_orders;        ///< NOSAVE: How many orders there are in the list.
 
	VehicleOrderID num_manual_orders; ///< NOSAVE: How many manually added orders are there in the list.
src/saveload/ai_sl.cpp
Show inline comments
 
@@ -27,13 +27,12 @@ static bool        _ai_saveload_is_rando
 

	
 
static const SaveLoad _ai_company[] = {
 
	   SLEG_SSTR(_ai_saveload_name,         SLE_STR),
 
	   SLEG_SSTR(_ai_saveload_settings,     SLE_STR),
 
	SLEG_CONDVAR(_ai_saveload_version,   SLE_UINT32, SLV_108, SL_MAX_VERSION),
 
	SLEG_CONDVAR(_ai_saveload_is_random,   SLE_BOOL, SLV_136, SL_MAX_VERSION),
 
	     SLE_END()
 
};
 

	
 
static void SaveReal_AIPL(int *index_ptr)
 
{
 
	CompanyID index = (CompanyID)*index_ptr;
 
	AIConfig *config = AIConfig::GetConfig(index);
src/saveload/autoreplace_sl.cpp
Show inline comments
 
@@ -18,13 +18,12 @@ static const SaveLoad _engine_renew_desc
 
	    SLE_VAR(EngineRenew, from,     SLE_UINT16),
 
	    SLE_VAR(EngineRenew, to,       SLE_UINT16),
 

	
 
	    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),
 
	SLE_END()
 
};
 

	
 
static void Save_ERNW()
 
{
 
	for (EngineRenew *er : EngineRenew::Iterate()) {
 
		SlSetArrayIndex(er->index);
src/saveload/cargomonitor_sl.cpp
Show inline comments
 
@@ -21,13 +21,12 @@ struct TempStorage {
 
};
 

	
 
/** Description of the #TempStorage structure for the purpose of load and save. */
 
static const SaveLoad _cargomonitor_pair_desc[] = {
 
	SLE_VAR(TempStorage, number, SLE_UINT32),
 
	SLE_VAR(TempStorage, amount, SLE_UINT32),
 
	SLE_END()
 
};
 

	
 
static CargoMonitorID FixupCargoMonitor(CargoMonitorID number)
 
{
 
	/* Between SLV_EXTEND_CARGOTYPES and SLV_FIX_CARGO_MONITOR, the
 
	 * CargoMonitorID structure had insufficient packing for more
src/saveload/cargopacket_sl.cpp
Show inline comments
 
@@ -80,13 +80,13 @@
 

	
 
/**
 
 * Wrapper function to get the CargoPacket's internal structure while
 
 * some of the variables itself are private.
 
 * @return the saveload description for CargoPackets.
 
 */
 
const SaveLoad *GetCargoPacketDesc()
 
SaveLoadTable GetCargoPacketDesc()
 
{
 
	static const SaveLoad _cargopacket_desc[] = {
 
		     SLE_VAR(CargoPacket, source,          SLE_UINT16),
 
		     SLE_VAR(CargoPacket, source_xy,       SLE_UINT32),
 
		     SLE_VAR(CargoPacket, loaded_at_xy,    SLE_UINT32),
 
		     SLE_VAR(CargoPacket, count,           SLE_UINT16),
 
@@ -94,14 +94,12 @@ const SaveLoad *GetCargoPacketDesc()
 
		     SLE_VAR(CargoPacket, feeder_share,    SLE_INT64),
 
		 SLE_CONDVAR(CargoPacket, source_type,     SLE_UINT8,  SLV_125, SL_MAX_VERSION),
 
		 SLE_CONDVAR(CargoPacket, source_id,       SLE_UINT16, SLV_125, SL_MAX_VERSION),
 

	
 
		/* Used to be paid_for, but that got changed. */
 
		SLE_CONDNULL(1, SL_MIN_VERSION, SLV_121),
 

	
 
		SLE_END()
 
	};
 
	return _cargopacket_desc;
 
}
 

	
 
/**
 
 * Save the cargo packets.
src/saveload/company_sl.cpp
Show inline comments
 
@@ -290,14 +290,12 @@ static const SaveLoad _company_desc[] = 
 
	SLE_CONDNULL(1, SLV_107, SLV_112), ///< is_noai
 
	SLE_CONDNULL(1, SLV_4, SLV_100),
 

	
 
	SLE_CONDVAR(CompanyProperties, terraform_limit,       SLE_UINT32,                SLV_156, SL_MAX_VERSION),
 
	SLE_CONDVAR(CompanyProperties, clear_limit,           SLE_UINT32,                SLV_156, SL_MAX_VERSION),
 
	SLE_CONDVAR(CompanyProperties, tree_limit,            SLE_UINT32,                SLV_175, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _company_settings_desc[] = {
 
	/* Engine renewal settings */
 
	SLE_CONDNULL(512, SLV_16, SLV_19),
 
	SLE_CONDREF(Company, engine_renew_list,            REF_ENGINE_RENEWS,   SLV_19, SL_MAX_VERSION),
 
@@ -311,14 +309,12 @@ static const SaveLoad _company_settings_
 
	SLE_CONDVAR(Company, settings.vehicle.servint_trains,    SLE_UINT16,     SLV_120, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, settings.vehicle.servint_roadveh,   SLE_UINT16,     SLV_120, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, settings.vehicle.servint_aircraft,  SLE_UINT16,     SLV_120, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, settings.vehicle.servint_ships,     SLE_UINT16,     SLV_120, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(63, SLV_2, SLV_144), // old reserved space
 

	
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _company_settings_skip_desc[] = {
 
	/* Engine renewal settings */
 
	SLE_CONDNULL(512, SLV_16, SLV_19),
 
	SLE_CONDNULL(2, SLV_19, SLV_69),                 // engine_renew_list
 
@@ -333,14 +329,12 @@ static const SaveLoad _company_settings_
 
	SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION),    // settings.vehicle.servint_trains
 
	SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION),    // settings.vehicle.servint_roadveh
 
	SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION),    // settings.vehicle.servint_aircraft
 
	SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION),    // settings.vehicle.servint_ships
 

	
 
	SLE_CONDNULL(63, SLV_2, SLV_144), // old reserved space
 

	
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _company_economy_desc[] = {
 
	/* these were changed to 64-bit in savegame format 2 */
 
	SLE_CONDVAR(CompanyEconomyEntry, income,              SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
 
	SLE_CONDVAR(CompanyEconomyEntry, income,              SLE_INT64,                  SLV_2, SL_MAX_VERSION),
 
@@ -350,14 +344,12 @@ static const SaveLoad _company_economy_d
 
	SLE_CONDVAR(CompanyEconomyEntry, company_value,       SLE_INT64,                  SLV_2, SL_MAX_VERSION),
 

	
 
	SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32,       SL_MIN_VERSION, SLV_170),
 
	SLE_CONDARR(CompanyEconomyEntry, delivered_cargo,     SLE_UINT32, 32,           SLV_170, SLV_EXTEND_CARGOTYPES),
 
	SLE_CONDARR(CompanyEconomyEntry, delivered_cargo,     SLE_UINT32, NUM_CARGO,    SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
 
	    SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
 

	
 
	SLE_END()
 
};
 

	
 
/* We do need to read this single value, as the bigger it gets, the more data is stored */
 
struct CompanyOldAI {
 
	uint8 num_build_rec;
 
};
 
@@ -387,29 +379,26 @@ static const SaveLoad _company_ai_desc[]
 

	
 
	SLE_CONDNULL(18, SL_MIN_VERSION, SLV_107),
 
	SLE_CONDNULL(20, SL_MIN_VERSION, SLV_107),
 
	SLE_CONDNULL(32, SL_MIN_VERSION, SLV_107),
 

	
 
	SLE_CONDNULL(64, SLV_2, SLV_107),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _company_ai_build_rec_desc[] = {
 
	SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
 
	SLE_CONDNULL(4, SLV_6, SLV_107),
 
	SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
 
	SLE_CONDNULL(4, SLV_6, SLV_107),
 
	SLE_CONDNULL(8, SL_MIN_VERSION, SLV_107),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _company_livery_desc[] = {
 
	SLE_CONDVAR(Livery, in_use,  SLE_UINT8, SLV_34, SL_MAX_VERSION),
 
	SLE_CONDVAR(Livery, colour1, SLE_UINT8, SLV_34, SL_MAX_VERSION),
 
	SLE_CONDVAR(Livery, colour2, SLE_UINT8, SLV_34, SL_MAX_VERSION),
 
	SLE_END()
 
};
 

	
 
static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
 
{
 
	int i;
 

	
src/saveload/depot_sl.cpp
Show inline comments
 
@@ -22,13 +22,12 @@ static const SaveLoad _depot_desc[] = {
 
	 SLE_CONDVAR(Depot, xy,         SLE_UINT32,                 SLV_6, SL_MAX_VERSION),
 
	SLEG_CONDVAR(_town_index,       SLE_UINT16,                 SL_MIN_VERSION, SLV_141),
 
	 SLE_CONDREF(Depot, town,       REF_TOWN,                 SLV_141, SL_MAX_VERSION),
 
	 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),
 
	 SLE_END()
 
};
 

	
 
static void Save_DEPT()
 
{
 
	for (Depot *depot : Depot::Iterate()) {
 
		SlSetArrayIndex(depot->index);
src/saveload/economy_sl.cpp
Show inline comments
 
@@ -43,13 +43,12 @@ static const SaveLoad _economy_desc[] = 
 
	SLE_CONDVAR(Economy, inflation_payment,             SLE_UINT64,                SLV_126, SL_MAX_VERSION),
 
	    SLE_VAR(Economy, fluct,                         SLE_INT16),
 
	    SLE_VAR(Economy, interest_rate,                 SLE_UINT8),
 
	    SLE_VAR(Economy, infl_amount,                   SLE_UINT8),
 
	    SLE_VAR(Economy, infl_amount_pr,                SLE_UINT8),
 
	SLE_CONDVAR(Economy, industry_daily_change_counter, SLE_UINT32,                SLV_102, SL_MAX_VERSION),
 
	    SLE_END()
 
};
 

	
 
/** Economy variables */
 
static void Save_ECMY()
 
{
 
	SlObject(&_economy, _economy_desc);
 
@@ -64,13 +63,12 @@ static void Load_ECMY()
 

	
 
static const SaveLoad _cargopayment_desc[] = {
 
	    SLE_REF(CargoPayment, front,           REF_VEHICLE),
 
	    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),
 
	    SLE_END()
 
};
 

	
 
static void Save_CAPY()
 
{
 
	for (CargoPayment *cp : CargoPayment::Iterate()) {
 
		SlSetArrayIndex(cp->index);
src/saveload/engine_sl.cpp
Show inline comments
 
@@ -39,14 +39,12 @@ static const SaveLoad _engine_desc[] = {
 
	 SLE_CONDVAR(Engine, company_avail,       SLE_FILE_U8  | SLE_VAR_U16,  SL_MIN_VERSION, SLV_104),
 
	 SLE_CONDVAR(Engine, company_avail,       SLE_UINT16,                SLV_104, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Engine, company_hidden,      SLE_UINT16,                SLV_193, SL_MAX_VERSION),
 
	SLE_CONDSSTR(Engine, name,                SLE_STR,                    SLV_84, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(16,                                                       SLV_2, SLV_144), // old reserved space
 

	
 
	SLE_END()
 
};
 

	
 
static std::vector<Engine*> _temp_engine;
 

	
 
/**
 
 * Allocate an Engine structure, but not using the pools.
 
@@ -170,13 +168,12 @@ static void Load_ENGS()
 
/** Save and load the mapping between the engine id in the pool, and the grf file it came from. */
 
static const SaveLoad _engine_id_mapping_desc[] = {
 
	SLE_VAR(EngineIDMapping, grfid,         SLE_UINT32),
 
	SLE_VAR(EngineIDMapping, internal_id,   SLE_UINT16),
 
	SLE_VAR(EngineIDMapping, type,          SLE_UINT8),
 
	SLE_VAR(EngineIDMapping, substitute_id, SLE_UINT8),
 
	SLE_END()
 
};
 

	
 
static void Save_EIDS()
 
{
 
	uint index = 0;
 
	for (EngineIDMapping &eid : _engine_mngr) {
src/saveload/game_sl.cpp
Show inline comments
 
@@ -27,13 +27,12 @@ static bool        _game_saveload_is_ran
 

	
 
static const SaveLoad _game_script[] = {
 
	   SLEG_SSTR(_game_saveload_name,         SLE_STR),
 
	   SLEG_SSTR(_game_saveload_settings,     SLE_STR),
 
	    SLEG_VAR(_game_saveload_version,   SLE_UINT32),
 
	    SLEG_VAR(_game_saveload_is_random,   SLE_BOOL),
 
	     SLE_END()
 
};
 

	
 
static void SaveReal_GSDT(int *index_ptr)
 
{
 
	GameConfig *config = GameConfig::GetConfig();
 

	
 
@@ -114,18 +113,16 @@ extern GameStrings *_current_data;
 
static std::string _game_saveload_string;
 
static uint _game_saveload_strings;
 

	
 
static const SaveLoad _game_language_header[] = {
 
	SLEG_SSTR(_game_saveload_string, SLE_STR),
 
	 SLEG_VAR(_game_saveload_strings, SLE_UINT32),
 
	  SLE_END()
 
};
 

	
 
static const SaveLoad _game_language_string[] = {
 
	SLEG_SSTR(_game_saveload_string, SLE_STR | SLF_ALLOW_CONTROL),
 
	  SLE_END()
 
};
 

	
 
static void SaveReal_GSTR(const LanguageStrings *ls)
 
{
 
	_game_saveload_string  = ls->language.c_str();
 
	_game_saveload_strings = (uint)ls->lines.size();
src/saveload/gamelog_sl.cpp
Show inline comments
 
@@ -14,82 +14,71 @@
 
#include "saveload.h"
 

	
 
#include "../safeguards.h"
 

	
 
static const SaveLoad _glog_action_desc[] = {
 
	SLE_VAR(LoggedAction, tick,              SLE_UINT16),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_mode_desc[] = {
 
	SLE_VAR(LoggedChange, mode.mode,         SLE_UINT8),
 
	SLE_VAR(LoggedChange, mode.landscape,    SLE_UINT8),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_revision_desc[] = {
 
	SLE_ARR(LoggedChange, revision.text,     SLE_UINT8,  GAMELOG_REVISION_LENGTH),
 
	SLE_VAR(LoggedChange, revision.newgrf,   SLE_UINT32),
 
	SLE_VAR(LoggedChange, revision.slver,    SLE_UINT16),
 
	SLE_VAR(LoggedChange, revision.modified, SLE_UINT8),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_oldver_desc[] = {
 
	SLE_VAR(LoggedChange, oldver.type,       SLE_UINT32),
 
	SLE_VAR(LoggedChange, oldver.version,    SLE_UINT32),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_setting_desc[] = {
 
	SLE_STR(LoggedChange, setting.name,      SLE_STR,    128),
 
	SLE_VAR(LoggedChange, setting.oldval,    SLE_INT32),
 
	SLE_VAR(LoggedChange, setting.newval,    SLE_INT32),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_grfadd_desc[] = {
 
	SLE_VAR(LoggedChange, grfadd.grfid,      SLE_UINT32    ),
 
	SLE_ARR(LoggedChange, grfadd.md5sum,     SLE_UINT8,  16),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_grfrem_desc[] = {
 
	SLE_VAR(LoggedChange, grfrem.grfid,      SLE_UINT32),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_grfcompat_desc[] = {
 
	SLE_VAR(LoggedChange, grfcompat.grfid,   SLE_UINT32    ),
 
	SLE_ARR(LoggedChange, grfcompat.md5sum,  SLE_UINT8,  16),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_grfparam_desc[] = {
 
	SLE_VAR(LoggedChange, grfparam.grfid,    SLE_UINT32),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_grfmove_desc[] = {
 
	SLE_VAR(LoggedChange, grfmove.grfid,     SLE_UINT32),
 
	SLE_VAR(LoggedChange, grfmove.offset,    SLE_INT32),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_grfbug_desc[] = {
 
	SLE_VAR(LoggedChange, grfbug.data,       SLE_UINT64),
 
	SLE_VAR(LoggedChange, grfbug.grfid,      SLE_UINT32),
 
	SLE_VAR(LoggedChange, grfbug.bug,        SLE_UINT8),
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _glog_emergency_desc[] = {
 
	SLE_END()
 
	SLE_CONDNULL(0, SL_MIN_VERSION, SL_MIN_VERSION), // Just an empty list, to keep the rest of the code easier.
 
};
 

	
 
static const SaveLoad * const _glog_desc[] = {
 
static const SaveLoadTable _glog_desc[] = {
 
	_glog_mode_desc,
 
	_glog_revision_desc,
 
	_glog_oldver_desc,
 
	_glog_setting_desc,
 
	_glog_grfadd_desc,
 
	_glog_grfrem_desc,
src/saveload/goal_sl.cpp
Show inline comments
 
@@ -18,13 +18,12 @@ static const SaveLoad _goals_desc[] = {
 
	    SLE_VAR(Goal, company,   SLE_FILE_U16 | SLE_VAR_U8),
 
	    SLE_VAR(Goal, type,      SLE_FILE_U16 | SLE_VAR_U8),
 
	    SLE_VAR(Goal, dst,       SLE_UINT32),
 
	    SLE_STR(Goal, text,      SLE_STR | SLF_ALLOW_CONTROL, 0),
 
	SLE_CONDSTR(Goal, progress,  SLE_STR | SLF_ALLOW_CONTROL, 0, SLV_182, SL_MAX_VERSION),
 
	SLE_CONDVAR(Goal, completed, SLE_BOOL, SLV_182, SL_MAX_VERSION),
 
	    SLE_END()
 
};
 

	
 
static void Save_GOAL()
 
{
 
	for (Goal *s : Goal::Iterate()) {
 
		SlSetArrayIndex(s->index);
src/saveload/group_sl.cpp
Show inline comments
 
@@ -23,13 +23,12 @@ static const SaveLoad _group_desc[] = {
 
	     SLE_VAR(Group, vehicle_type,       SLE_UINT8),
 
	     SLE_VAR(Group, flags,              SLE_UINT8),
 
	 SLE_CONDVAR(Group, livery.in_use,      SLE_UINT8,                     SLV_GROUP_LIVERIES, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Group, livery.colour1,     SLE_UINT8,                     SLV_GROUP_LIVERIES, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Group, livery.colour2,     SLE_UINT8,                     SLV_GROUP_LIVERIES, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Group, parent,             SLE_UINT16,                    SLV_189, SL_MAX_VERSION),
 
	     SLE_END()
 
};
 

	
 
static void Save_GRPS()
 
{
 
	for (Group *g : Group::Iterate()) {
 
		SlSetArrayIndex(g->index);
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -72,14 +72,12 @@ static const SaveLoad _industry_desc[] =
 

	
 
	SLE_CONDNULL(1, SLV_82, SLV_197), // random_triggers
 
	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),
 

	
 
	SLE_CONDNULL(32, SLV_2, SLV_144), // old reserved space
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_INDY()
 
{
 
	/* Write the industries */
 
	for (Industry *ind : Industry::Iterate()) {
 
@@ -136,13 +134,12 @@ static void Ptrs_INDY()
 
	}
 
}
 

	
 
/** Description of the data to save and load in #IndustryBuildData. */
 
static const SaveLoad _industry_builder_desc[] = {
 
	SLEG_VAR(_industry_builder.wanted_inds, SLE_UINT32),
 
	SLEG_END()
 
};
 

	
 
/** Load/save industry builder. */
 
static void LoadSave_IBLD()
 
{
 
	SlGlobList(_industry_builder_desc);
 
@@ -152,13 +149,12 @@ static void LoadSave_IBLD()
 
static const SaveLoad _industrytype_builder_desc[] = {
 
	SLE_VAR(IndustryTypeBuildData, probability,  SLE_UINT32),
 
	SLE_VAR(IndustryTypeBuildData, min_number,   SLE_UINT8),
 
	SLE_VAR(IndustryTypeBuildData, target_count, SLE_UINT16),
 
	SLE_VAR(IndustryTypeBuildData, max_wait,     SLE_UINT16),
 
	SLE_VAR(IndustryTypeBuildData, wait_count,   SLE_UINT16),
 
	SLE_END()
 
};
 

	
 
/** Save industry-type build data. */
 
static void Save_ITBL()
 
{
 
	for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
src/saveload/labelmaps_sl.cpp
Show inline comments
 
@@ -92,13 +92,12 @@ void ResetLabelMaps()
 
struct LabelObject {
 
	uint32 label;
 
};
 

	
 
static const SaveLoad _label_object_desc[] = {
 
	SLE_VAR(LabelObject, label, SLE_UINT32),
 
	SLE_END(),
 
};
 

	
 
static void Save_RAIL()
 
{
 
	LabelObject lo;
 

	
src/saveload/linkgraph_sl.cpp
Show inline comments
 
@@ -23,19 +23,18 @@ typedef LinkGraph::BaseEdge Edge;
 
static uint16 _num_nodes;
 

	
 
/**
 
 * Get a SaveLoad array for a link graph.
 
 * @return SaveLoad array for link graph.
 
 */
 
const SaveLoad *GetLinkGraphDesc()
 
SaveLoadTable GetLinkGraphDesc()
 
{
 
	static const SaveLoad link_graph_desc[] = {
 
		 SLE_VAR(LinkGraph, last_compression, SLE_INT32),
 
		SLEG_VAR(_num_nodes,                  SLE_UINT16),
 
		 SLE_VAR(LinkGraph, cargo,            SLE_UINT8),
 
		 SLE_END()
 
	};
 
	return link_graph_desc;
 
}
 

	
 
/**
 
 * Get a SaveLoad array for a link graph job. The settings struct is derived from
 
@@ -43,21 +42,20 @@ const SaveLoad *GetLinkGraphDesc()
 
 * is called the first time.
 
 * It's necessary to keep a copy of the settings for each link graph job so that you can
 
 * change the settings while in-game and still not mess with current link graph runs.
 
 * Of course the settings have to be saved and loaded, too, to avoid desyncs.
 
 * @return Array of SaveLoad structs.
 
 */
 
const SaveLoad *GetLinkGraphJobDesc()
 
SaveLoadTable GetLinkGraphJobDesc()
 
{
 
	static std::vector<SaveLoad> saveloads;
 
	static const char *prefix = "linkgraph.";
 

	
 
	static const SaveLoad job_desc[] = {
 
		SLE_VAR(LinkGraphJob, join_date,        SLE_INT32),
 
		SLE_VAR(LinkGraphJob, link_graph.index, SLE_UINT16),
 
		SLE_END()
 
	};
 

	
 
	/* The member offset arithmetic below is only valid if the types in question
 
	 * are standard layout types. Otherwise, it would be undefined behaviour. */
 
	static_assert(std::is_standard_layout<LinkGraphSettings>::value, "LinkGraphSettings needs to be a standard layout type");
 

	
 
@@ -71,31 +69,29 @@ const SaveLoad *GetLinkGraphJobDesc()
 
		GetSettingSaveLoadByPrefix(prefix, saveloads);
 

	
 
		for (auto &sl : saveloads) {
 
			sl.address_proc = proc;
 
		}
 

	
 
		int i = 0;
 
		do {
 
			saveloads.push_back(job_desc[i++]);
 
		} while (saveloads.back().cmd != SL_END);
 
		for (auto &sld : job_desc) {
 
			saveloads.push_back(sld);
 
		}
 
	}
 

	
 
	return &saveloads[0];
 
	return saveloads;
 
}
 

	
 
/**
 
 * Get a SaveLoad array for the link graph schedule.
 
 * @return SaveLoad array for the link graph schedule.
 
 */
 
const SaveLoad *GetLinkGraphScheduleDesc()
 
SaveLoadTable GetLinkGraphScheduleDesc()
 
{
 
	static const SaveLoad schedule_desc[] = {
 
		SLE_LST(LinkGraphSchedule, schedule, REF_LINK_GRAPH),
 
		SLE_LST(LinkGraphSchedule, running,  REF_LINK_GRAPH_JOB),
 
		SLE_END()
 
	};
 
	return schedule_desc;
 
}
 

	
 
/* Edges and nodes are saved in the correct order, so we don't need to save their IDs. */
 

	
 
@@ -105,26 +101,24 @@ const SaveLoad *GetLinkGraphScheduleDesc
 
static const SaveLoad _node_desc[] = {
 
	SLE_CONDVAR(Node, xy,          SLE_UINT32, SLV_191, SL_MAX_VERSION),
 
	    SLE_VAR(Node, supply,      SLE_UINT32),
 
	    SLE_VAR(Node, demand,      SLE_UINT32),
 
	    SLE_VAR(Node, station,     SLE_UINT16),
 
	    SLE_VAR(Node, last_update, SLE_INT32),
 
	    SLE_END()
 
};
 

	
 
/**
 
 * SaveLoad desc for a link graph edge.
 
 */
 
static const SaveLoad _edge_desc[] = {
 
	SLE_CONDNULL(4, SL_MIN_VERSION, SLV_191), // distance
 
	     SLE_VAR(Edge, capacity,                 SLE_UINT32),
 
	     SLE_VAR(Edge, usage,                    SLE_UINT32),
 
	     SLE_VAR(Edge, last_unrestricted_update, SLE_INT32),
 
	 SLE_CONDVAR(Edge, last_restricted_update,   SLE_INT32, SLV_187, SL_MAX_VERSION),
 
	     SLE_VAR(Edge, next_edge,                SLE_UINT16),
 
	     SLE_END()
 
};
 

	
 
/**
 
 * Save/load a link graph.
 
 * @param lg Link graph to be saved or loaded.
 
 */
src/saveload/map_sl.cpp
Show inline comments
 
@@ -17,16 +17,15 @@
 

	
 
#include "../safeguards.h"
 

	
 
static uint32 _map_dim_x;
 
static uint32 _map_dim_y;
 

	
 
static const SaveLoadGlobVarList _map_dimensions[] = {
 
static const SaveLoad _map_dimensions[] = {
 
	SLEG_CONDVAR(_map_dim_x, SLE_UINT32, SLV_6, SL_MAX_VERSION),
 
	SLEG_CONDVAR(_map_dim_y, SLE_UINT32, SLV_6, SL_MAX_VERSION),
 
	    SLEG_END()
 
};
 

	
 
static void Save_MAPS()
 
{
 
	_map_dim_x = MapSizeX();
 
	_map_dim_y = MapSizeY();
src/saveload/misc_sl.cpp
Show inline comments
 
@@ -65,13 +65,13 @@ void ResetViewportAfterLoadGame()
 
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
 
	MarkWholeScreenDirty();
 
}
 

	
 
byte _age_cargo_skip_counter; ///< Skip aging of cargo? Used before savegame version 162.
 

	
 
static const SaveLoadGlobVarList _date_desc[] = {
 
static const SaveLoad _date_desc[] = {
 
	SLEG_CONDVAR(_date,                   SLE_FILE_U16 | SLE_VAR_I32,  SL_MIN_VERSION,  SLV_31),
 
	SLEG_CONDVAR(_date,                   SLE_INT32,                  SLV_31, SL_MAX_VERSION),
 
	    SLEG_VAR(_date_fract,             SLE_UINT16),
 
	    SLEG_VAR(_tick_counter,           SLE_UINT16),
 
	SLE_CONDNULL(2, SL_MIN_VERSION, SLV_157), // _vehicle_id_ctr_day
 
	SLEG_CONDVAR(_age_cargo_skip_counter, SLE_UINT8,                   SL_MIN_VERSION, SLV_162),
 
@@ -87,16 +87,15 @@ static const SaveLoadGlobVarList _date_d
 
	    SLEG_VAR(_cur_company_tick_index, SLE_FILE_U8  | SLE_VAR_U32),
 
	SLEG_CONDVAR(_next_competitor_start,  SLE_FILE_U16 | SLE_VAR_U32,  SL_MIN_VERSION, SLV_109),
 
	SLEG_CONDVAR(_next_competitor_start,  SLE_UINT32,                SLV_109, SL_MAX_VERSION),
 
	    SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
 
	SLEG_CONDVAR(_pause_mode,             SLE_UINT8,                   SLV_4, SL_MAX_VERSION),
 
	SLE_CONDNULL(4, SLV_11, SLV_120),
 
	    SLEG_END()
 
};
 

	
 
static const SaveLoadGlobVarList _date_check_desc[] = {
 
static const SaveLoad _date_check_desc[] = {
 
	SLEG_CONDVAR(_load_check_data.current_date,  SLE_FILE_U16 | SLE_VAR_I32,  SL_MIN_VERSION,  SLV_31),
 
	SLEG_CONDVAR(_load_check_data.current_date,  SLE_INT32,                  SLV_31, SL_MAX_VERSION),
 
	    SLE_NULL(2),                       // _date_fract
 
	    SLE_NULL(2),                       // _tick_counter
 
	SLE_CONDNULL(2, SL_MIN_VERSION, SLV_157),               // _vehicle_id_ctr_day
 
	SLE_CONDNULL(1, SL_MIN_VERSION, SLV_162),               // _age_cargo_skip_counter
 
@@ -112,13 +111,12 @@ static const SaveLoadGlobVarList _date_c
 
	    SLE_NULL(1),                       // _cur_company_tick_index
 
	SLE_CONDNULL(2, SL_MIN_VERSION, SLV_109),               // _next_competitor_start
 
	SLE_CONDNULL(4, SLV_109, SL_MAX_VERSION),  // _next_competitor_start
 
	    SLE_NULL(1),                       // _trees_tick_ctr
 
	SLE_CONDNULL(1, SLV_4, SL_MAX_VERSION),    // _pause_mode
 
	SLE_CONDNULL(4, SLV_11, SLV_120),
 
	    SLEG_END()
 
};
 

	
 
/* Save load date related variables as well as persistent tick counters
 
 * XXX: currently some unrelated stuff is just put here */
 
static void SaveLoad_DATE()
 
{
 
@@ -131,19 +129,18 @@ static void Check_DATE()
 
	if (IsSavegameVersionBefore(SLV_31)) {
 
		_load_check_data.current_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
 
	}
 
}
 

	
 

	
 
static const SaveLoadGlobVarList _view_desc[] = {
 
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),
 
	    SLEG_END()
 
};
 

	
 
static void SaveLoad_VIEW()
 
{
 
	SlGlobList(_view_desc);
 
}
src/saveload/newgrf_sl.cpp
Show inline comments
 
@@ -17,13 +17,12 @@
 

	
 
/** Save and load the mapping between a spec and the NewGRF it came from. */
 
static const SaveLoad _newgrf_mapping_desc[] = {
 
	SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
 
	SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
 
	SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
 
	SLE_END()
 
};
 

	
 
/**
 
 * Save a GRF ID + local id -> OpenTTD's id mapping.
 
 * @param mapping The mapping to save.
 
 */
 
@@ -62,13 +61,12 @@ static const SaveLoad _grfconfig_desc[] 
 
	    SLE_VAR(GRFConfig, ident.grfid,      SLE_UINT32),
 
	    SLE_ARR(GRFConfig, ident.md5sum,     SLE_UINT8,  16),
 
	SLE_CONDVAR(GRFConfig, version,          SLE_UINT32, SLV_151, SL_MAX_VERSION),
 
	    SLE_ARR(GRFConfig, param,            SLE_UINT32, 0x80),
 
	    SLE_VAR(GRFConfig, num_params,       SLE_UINT8),
 
	SLE_CONDVAR(GRFConfig, palette,          SLE_UINT8,  SLV_101, SL_MAX_VERSION),
 
	SLE_END()
 
};
 

	
 

	
 
static void Save_NGRF()
 
{
 
	int index = 0;
src/saveload/object_sl.cpp
Show inline comments
 
@@ -22,14 +22,12 @@ static const SaveLoad _object_desc[] = {
 
	    SLE_VAR(Object, location.h,                 SLE_FILE_U8 | SLE_VAR_U16),
 
	    SLE_REF(Object, town,                       REF_TOWN),
 
	    SLE_VAR(Object, build_date,                 SLE_UINT32),
 
	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),
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_OBJS()
 
{
 
	/* Write the objects */
 
	for (Object *o : Object::Iterate()) {
src/saveload/order_sl.cpp
Show inline comments
 
@@ -96,13 +96,13 @@ Order UnpackOldOrder(uint16 packed)
 
	 */
 
	if (order.IsType(OT_NOTHING) && packed != 0) order.MakeDummy();
 

	
 
	return order;
 
}
 

	
 
const SaveLoad *GetOrderDescription()
 
SaveLoadTable GetOrderDescription()
 
{
 
	static const SaveLoad _order_desc[] = {
 
		     SLE_VAR(Order, type,           SLE_UINT8),
 
		     SLE_VAR(Order, flags,          SLE_UINT8),
 
		     SLE_VAR(Order, dest,           SLE_UINT16),
 
		     SLE_REF(Order, next,           REF_ORDER),
 
@@ -112,13 +112,12 @@ const SaveLoad *GetOrderDescription()
 
		 SLE_CONDVAR(Order, travel_time,    SLE_UINT16,  SLV_67, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Order, max_speed,      SLE_UINT16, SLV_172, SL_MAX_VERSION),
 

	
 
		/* Leftover from the minor savegame version stuff
 
		 * We will never use those free bytes, but we have to keep this line to allow loading of old savegames */
 
		SLE_CONDNULL(10,                                  SLV_5,  SLV_36),
 
		     SLE_END()
 
	};
 

	
 
	return _order_desc;
 
}
 

	
 
static void Save_ORDR()
 
@@ -193,17 +192,16 @@ static void Ptrs_ORDR()
 

	
 
	for (Order *o : Order::Iterate()) {
 
		SlObject(o, GetOrderDescription());
 
	}
 
}
 

	
 
const SaveLoad *GetOrderListDescription()
 
SaveLoadTable GetOrderListDescription()
 
{
 
	static const SaveLoad _orderlist_desc[] = {
 
		SLE_REF(OrderList, first,              REF_ORDER),
 
		SLE_END()
 
	};
 

	
 
	return _orderlist_desc;
 
}
 

	
 
static void Save_ORDL()
 
@@ -230,13 +228,13 @@ static void Ptrs_ORDL()
 
{
 
	for (OrderList *list : OrderList::Iterate()) {
 
		SlObject(list, GetOrderListDescription());
 
	}
 
}
 

	
 
const SaveLoad *GetOrderBackupDescription()
 
SaveLoadTable GetOrderBackupDescription()
 
{
 
	static const SaveLoad _order_backup_desc[] = {
 
		     SLE_VAR(OrderBackup, user,                     SLE_UINT32),
 
		     SLE_VAR(OrderBackup, tile,                     SLE_UINT32),
 
		     SLE_VAR(OrderBackup, group,                    SLE_UINT16),
 
		 SLE_CONDVAR(OrderBackup, service_interval,         SLE_FILE_U32 | SLE_VAR_U16,  SL_MIN_VERSION, SLV_192),
 
@@ -249,13 +247,12 @@ const SaveLoad *GetOrderBackupDescriptio
 
		 SLE_CONDVAR(OrderBackup, current_order_time,       SLE_UINT32,                SLV_176, SL_MAX_VERSION),
 
		 SLE_CONDVAR(OrderBackup, lateness_counter,         SLE_INT32,                 SLV_176, SL_MAX_VERSION),
 
		 SLE_CONDVAR(OrderBackup, timetable_start,          SLE_INT32,                 SLV_176, SL_MAX_VERSION),
 
		 SLE_CONDVAR(OrderBackup, vehicle_flags,            SLE_FILE_U8 | SLE_VAR_U16, SLV_176, SLV_180),
 
		 SLE_CONDVAR(OrderBackup, vehicle_flags,            SLE_UINT16,                SLV_180, SL_MAX_VERSION),
 
		     SLE_REF(OrderBackup, orders,                   REF_ORDER),
 
		     SLE_END()
 
	};
 

	
 
	return _order_backup_desc;
 
}
 

	
 
static void Save_BKOR()
src/saveload/saveload.cpp
Show inline comments
 
@@ -1397,74 +1397,74 @@ static void SlDeque(void *deque, VarType
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 

	
 
/** Are we going to save this object or not? */
 
static inline bool SlIsObjectValidInSavegame(const SaveLoad *sld)
 
static inline bool SlIsObjectValidInSavegame(const SaveLoad &sld)
 
{
 
	if (_sl_version < sld->version_from || _sl_version >= sld->version_to) return false;
 
	if (sld->conv & SLF_NOT_IN_SAVE) return false;
 
	if (_sl_version < sld.version_from || _sl_version >= sld.version_to) return false;
 
	if (sld.conv & SLF_NOT_IN_SAVE) return false;
 

	
 
	return true;
 
}
 

	
 
/**
 
 * Are we going to load this variable when loading a savegame or not?
 
 * @note If the variable is skipped it is skipped in the savegame
 
 * bytestream itself as well, so there is no need to skip it somewhere else
 
 */
 
static inline bool SlSkipVariableOnLoad(const SaveLoad *sld)
 
static inline bool SlSkipVariableOnLoad(const SaveLoad &sld)
 
{
 
	if ((sld->conv & SLF_NO_NETWORK_SYNC) && _sl.action != SLA_SAVE && _networking && !_network_server) {
 
		SlSkipBytes(SlCalcConvMemLen(sld->conv) * sld->length);
 
	if ((sld.conv & SLF_NO_NETWORK_SYNC) && _sl.action != SLA_SAVE && _networking && !_network_server) {
 
		SlSkipBytes(SlCalcConvMemLen(sld.conv) * sld.length);
 
		return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
/**
 
 * Calculate the size of an object.
 
 * @param object to be measured
 
 * @param sld The SaveLoad description of the object so we know how to manipulate it
 
 * @return size of given object
 
 * @param object to be measured.
 
 * @param slt The SaveLoad table with objects to save/load.
 
 * @return size of given object.
 
 */
 
size_t SlCalcObjLength(const void *object, const SaveLoad *sld)
 
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt)
 
{
 
	size_t length = 0;
 

	
 
	/* Need to determine the length and write a length tag. */
 
	for (; sld->cmd != SL_END; sld++) {
 
	for (auto &sld : slt) {
 
		length += SlCalcObjMemberLength(object, sld);
 
	}
 
	return length;
 
}
 

	
 
size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld)
 
size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
 
{
 
	assert(_sl.action == SLA_SAVE);
 

	
 
	switch (sld->cmd) {
 
	switch (sld.cmd) {
 
		case SL_VAR:
 
		case SL_REF:
 
		case SL_ARR:
 
		case SL_STR:
 
		case SL_LST:
 
		case SL_DEQUE:
 
		case SL_STDSTR:
 
			/* CONDITIONAL saveload types depend on the savegame version */
 
			if (!SlIsObjectValidInSavegame(sld)) break;
 

	
 
			switch (sld->cmd) {
 
				case SL_VAR: return SlCalcConvFileLen(sld->conv);
 
			switch (sld.cmd) {
 
				case SL_VAR: return SlCalcConvFileLen(sld.conv);
 
				case SL_REF: return SlCalcRefLen();
 
				case SL_ARR: return SlCalcArrayLen(sld->length, sld->conv);
 
				case SL_STR: return SlCalcStringLen(GetVariableAddress(object, sld), sld->length, sld->conv);
 
				case SL_ARR: return SlCalcArrayLen(sld.length, sld.conv);
 
				case SL_STR: return SlCalcStringLen(GetVariableAddress(object, sld), sld.length, sld.conv);
 
				case SL_LST: return SlCalcListLen(GetVariableAddress(object, sld));
 
				case SL_DEQUE: return SlCalcDequeLen(GetVariableAddress(object, sld), sld->conv);
 
				case SL_DEQUE: return SlCalcDequeLen(GetVariableAddress(object, sld), sld.conv);
 
				case SL_STDSTR: return SlCalcStdStringLen(GetVariableAddress(object, sld));
 
				default: NOT_REACHED();
 
			}
 
			break;
 
		case SL_WRITEBYTE: return 1; // a byte is logically of size 1
 
		case SL_VEH_INCLUDE: return SlCalcObjLength(object, GetVehicleDescription(VEH_END));
 
@@ -1478,75 +1478,75 @@ size_t SlCalcObjMemberLength(const void 
 

	
 
/**
 
 * Check whether the variable size of the variable in the saveload configuration
 
 * matches with the actual variable size.
 
 * @param sld The saveload configuration to test.
 
 */
 
static bool IsVariableSizeRight(const SaveLoad *sld)
 
static bool IsVariableSizeRight(const SaveLoad &sld)
 
{
 
	switch (sld->cmd) {
 
	switch (sld.cmd) {
 
		case SL_VAR:
 
			switch (GetVarMemType(sld->conv)) {
 
			switch (GetVarMemType(sld.conv)) {
 
				case SLE_VAR_BL:
 
					return sld->size == sizeof(bool);
 
					return sld.size == sizeof(bool);
 
				case SLE_VAR_I8:
 
				case SLE_VAR_U8:
 
					return sld->size == sizeof(int8);
 
					return sld.size == sizeof(int8);
 
				case SLE_VAR_I16:
 
				case SLE_VAR_U16:
 
					return sld->size == sizeof(int16);
 
					return sld.size == sizeof(int16);
 
				case SLE_VAR_I32:
 
				case SLE_VAR_U32:
 
					return sld->size == sizeof(int32);
 
					return sld.size == sizeof(int32);
 
				case SLE_VAR_I64:
 
				case SLE_VAR_U64:
 
					return sld->size == sizeof(int64);
 
					return sld.size == sizeof(int64);
 
				case SLE_VAR_NAME:
 
					return sld->size == sizeof(std::string);
 
					return sld.size == sizeof(std::string);
 
				default:
 
					return sld->size == sizeof(void *);
 
					return sld.size == sizeof(void *);
 
			}
 
		case SL_REF:
 
			/* These should all be pointer sized. */
 
			return sld->size == sizeof(void *);
 
			return sld.size == sizeof(void *);
 

	
 
		case SL_STR:
 
			/* These should be pointer sized, or fixed array. */
 
			return sld->size == sizeof(void *) || sld->size == sld->length;
 
			return sld.size == sizeof(void *) || sld.size == sld.length;
 

	
 
		case SL_STDSTR:
 
			/* These should be all pointers to std::string. */
 
			return sld->size == sizeof(std::string);
 
			return sld.size == sizeof(std::string);
 

	
 
		default:
 
			return true;
 
	}
 
}
 

	
 
#endif /* OTTD_ASSERT */
 

	
 
bool SlObjectMember(void *ptr, const SaveLoad *sld)
 
bool SlObjectMember(void *ptr, const SaveLoad &sld)
 
{
 
#ifdef OTTD_ASSERT
 
	assert(IsVariableSizeRight(sld));
 
#endif
 

	
 
	VarType conv = GB(sld->conv, 0, 8);
 
	switch (sld->cmd) {
 
	VarType conv = GB(sld.conv, 0, 8);
 
	switch (sld.cmd) {
 
		case SL_VAR:
 
		case SL_REF:
 
		case SL_ARR:
 
		case SL_STR:
 
		case SL_LST:
 
		case SL_DEQUE:
 
		case SL_STDSTR:
 
			/* CONDITIONAL saveload types depend on the savegame version */
 
			if (!SlIsObjectValidInSavegame(sld)) return false;
 
			if (SlSkipVariableOnLoad(sld)) return false;
 

	
 
			switch (sld->cmd) {
 
			switch (sld.cmd) {
 
				case SL_VAR: SlSaveLoadConv(ptr, conv); break;
 
				case SL_REF: // Reference variable, translate
 
					switch (_sl.action) {
 
						case SLA_SAVE:
 
							SlWriteUint32((uint32)ReferenceToInt(*(void **)ptr, (SLRefType)conv));
 
							break;
 
@@ -1560,17 +1560,17 @@ bool SlObjectMember(void *ptr, const Sav
 
						case SLA_NULL:
 
							*(void **)ptr = nullptr;
 
							break;
 
						default: NOT_REACHED();
 
					}
 
					break;
 
				case SL_ARR: SlArray(ptr, sld->length, conv); break;
 
				case SL_STR: SlString(ptr, sld->length, sld->conv); break;
 
				case SL_ARR: SlArray(ptr, sld.length, conv); break;
 
				case SL_STR: SlString(ptr, sld.length, sld.conv); break;
 
				case SL_LST: SlList(ptr, (SLRefType)conv); break;
 
				case SL_DEQUE: SlDeque(ptr, conv); break;
 
				case SL_STDSTR: SlStdString(ptr, sld->conv); break;
 
				case SL_STDSTR: SlStdString(ptr, sld.conv); break;
 
				default: NOT_REACHED();
 
			}
 
			break;
 

	
 
		/* SL_WRITEBYTE writes a value to the savegame to identify the type of an object.
 
		 * When loading, the value is read explicitly with SlReadByte() to determine which
 
@@ -1599,36 +1599,36 @@ bool SlObjectMember(void *ptr, const Sav
 
	}
 
	return true;
 
}
 

	
 
/**
 
 * Main SaveLoad function.
 
 * @param object The object that is being saved or loaded
 
 * @param sld The SaveLoad description of the object so we know how to manipulate it
 
 * @param object The object that is being saved or loaded.
 
 * @param slt The SaveLoad table with objects to save/load.
 
 */
 
void SlObject(void *object, const SaveLoad *sld)
 
void SlObject(void *object, const SaveLoadTable &slt)
 
{
 
	/* Automatically calculate the length? */
 
	if (_sl.need_length != NL_NONE) {
 
		SlSetLength(SlCalcObjLength(object, sld));
 
		SlSetLength(SlCalcObjLength(object, slt));
 
		if (_sl.need_length == NL_CALCLENGTH) return;
 
	}
 

	
 
	for (; sld->cmd != SL_END; sld++) {
 
	for (auto &sld : slt) {
 
		void *ptr = GetVariableAddress(object, sld);
 
		SlObjectMember(ptr, sld);
 
	}
 
}
 

	
 
/**
 
 * Save or Load (a list of) global variables
 
 * @param sldg The global variable that is being loaded or saved
 
 * Save or Load (a list of) global variables.
 
 * @param slt The SaveLoad table with objects to save/load.
 
 */
 
void SlGlobList(const SaveLoadGlobVarList *sldg)
 
void SlGlobList(const SaveLoadTable &slt)
 
{
 
	SlObject(nullptr, (const SaveLoad*)sldg);
 
	SlObject(nullptr, slt);
 
}
 

	
 
/**
 
 * Do something of which I have no idea what it is :P
 
 * @param proc The callback procedure that is called
 
 * @param arg The variable that will be used for the callback procedure
src/saveload/saveload.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
#ifndef SAVELOAD_H
 
#define SAVELOAD_H
 

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

	
 
/** SaveLoad versions
 
 * Previous savegame versions, the trunk revision where they were
 
 * introduced and the released version that had that particular
 
 * savegame version.
 
@@ -503,13 +504,12 @@ enum SaveLoadType : byte {
 
	SL_DEQUE       =  5, ///< Save/load a deque.
 
	SL_STDSTR      =  6, ///< Save/load a \c std::string.
 
	/* non-normal save-load types */
 
	SL_WRITEBYTE   =  8,
 
	SL_VEH_INCLUDE =  9,
 
	SL_ST_INCLUDE  = 10,
 
	SL_END         = 15
 
};
 

	
 
typedef void *SaveLoadAddrProc(void *base, size_t extra);
 

	
 
/** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
 
struct SaveLoad {
 
@@ -520,14 +520,14 @@ struct SaveLoad {
 
	SaveLoadVersion version_to;     ///< save/load the variable until this savegame version
 
	size_t size;                    ///< the sizeof size.
 
	SaveLoadAddrProc *address_proc; ///< callback proc the get the actual variable address in memory
 
	size_t extra_data;              ///< extra data for the callback proc
 
};
 

	
 
/** Same as #SaveLoad but global variables are used (for better readability); */
 
typedef SaveLoad SaveLoadGlobVarList;
 
/** A table of SaveLoad entries. */
 
using SaveLoadTable = span<const SaveLoad>;
 

	
 
/**
 
 * Storage of simple variables, references (pointers), and arrays.
 
 * @param cmd      Load/save type. @see SaveLoadType
 
 * @param base     Name of the class or struct containing the variable.
 
 * @param variable Name of the variable in the class or struct referenced by \a base.
 
@@ -678,15 +678,12 @@ typedef SaveLoad SaveLoadGlobVarList;
 
/** Translate values ingame to different values in the savegame and vv. */
 
#define SLE_WRITEBYTE(base, variable) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0)
 

	
 
#define SLE_VEH_INCLUDE() {SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0, [] (void *b, size_t) { return b; }, 0}
 
#define SLE_ST_INCLUDE() {SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0, [] (void *b, size_t) { return b; }, 0}
 

	
 
/** End marker of a struct/class save or load. */
 
#define SLE_END() {SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, 0, nullptr, 0}
 

	
 
/**
 
 * Storage of global simple variables, references (pointers), and arrays.
 
 * @param cmd      Load/save type. @see SaveLoadType
 
 * @param variable Name of the global variable.
 
 * @param type     Storage of the data in memory and in the savegame.
 
 * @param from     First savegame version that has the field.
 
@@ -799,15 +796,12 @@ typedef SaveLoad SaveLoadGlobVarList;
 
 * @param length Length of the empty space.
 
 * @param from   First savegame version that has the empty space.
 
 * @param to     Last savegame version that has the empty space.
 
 */
 
#define SLEG_CONDNULL(length, from, to) {SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, 0, nullptr, 0}
 

	
 
/** End marker of global variables save or load. */
 
#define SLEG_END() {SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, 0, nullptr, 0}
 

	
 
/**
 
 * Checks whether the savegame is below \a major.\a minor.
 
 * @param major Major number of the version to check against.
 
 * @param minor Minor number of the version to check against. If \a minor is 0 or not specified, only the major number is checked.
 
 * @return Savegame version is earlier than the specified version.
 
 */
 
@@ -880,44 +874,44 @@ static inline bool IsNumericType(VarType
 

	
 
/**
 
 * Get the address of the variable. Null-variables don't have an address,
 
 * everything else has a callback function that returns the address based
 
 * on the saveload data and the current object for non-globals.
 
 */
 
static inline void *GetVariableAddress(const void *object, const SaveLoad *sld)
 
static inline void *GetVariableAddress(const void *object, const SaveLoad &sld)
 
{
 
	/* Entry is a null-variable, mostly used to read old savegames etc. */
 
	if (GetVarMemType(sld->conv) == SLE_VAR_NULL) {
 
		assert(sld->address_proc == nullptr);
 
	if (GetVarMemType(sld.conv) == SLE_VAR_NULL) {
 
		assert(sld.address_proc == nullptr);
 
		return nullptr;
 
	}
 

	
 
	/* Everything else should be a non-null pointer. */
 
	assert(sld->address_proc != nullptr);
 
	return sld->address_proc(const_cast<void *>(object), sld->extra_data);
 
	assert(sld.address_proc != nullptr);
 
	return sld.address_proc(const_cast<void *>(object), sld.extra_data);
 
}
 

	
 
int64 ReadValue(const void *ptr, VarType conv);
 
void WriteValue(void *ptr, VarType conv, int64 val);
 

	
 
void SlSetArrayIndex(uint index);
 
int SlIterateArray();
 

	
 
void SlAutolength(AutolengthProc *proc, void *arg);
 
size_t SlGetFieldLength();
 
void SlSetLength(size_t length);
 
size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld);
 
size_t SlCalcObjLength(const void *object, const SaveLoad *sld);
 
size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
 
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
 

	
 
byte SlReadByte();
 
void SlWriteByte(byte b);
 

	
 
void SlGlobList(const SaveLoadGlobVarList *sldg);
 
void SlGlobList(const SaveLoadTable &slt);
 
void SlArray(void *array, size_t length, VarType conv);
 
void SlObject(void *object, const SaveLoad *sld);
 
bool SlObjectMember(void *object, const SaveLoad *sld);
 
void SlObject(void *object, const SaveLoadTable &slt);
 
bool SlObjectMember(void *object, const SaveLoad &sld);
 
void NORETURN SlError(StringID string, const char *extra_msg = nullptr);
 
void NORETURN SlErrorCorrupt(const char *msg);
 
void NORETURN SlErrorCorruptFmt(const char *format, ...) WARN_FORMAT(1, 2);
 

	
 
bool SaveloadCrashWithMissingNewGRFs();
 

	
src/saveload/saveload_internal.h
Show inline comments
 
@@ -20,13 +20,13 @@ StringID RemapOldStringID(StringID s);
 
std::string CopyFromOldName(StringID id);
 
void ResetOldNames();
 

	
 
void ResetOldWaypoints();
 
void MoveBuoysToWaypoints();
 
void MoveWaypointsToBaseStations();
 
const SaveLoad *GetBaseStationDescription();
 
SaveLoadTable GetBaseStationDescription();
 

	
 
void AfterLoadVehicles(bool part_of_load);
 
void FixupTrainLengths();
 
void AfterLoadStations();
 
void AfterLoadRoadStops();
 
void ResetLabelMaps();
src/saveload/signs_sl.cpp
Show inline comments
 
@@ -23,13 +23,12 @@ static const SaveLoad _sign_desc[] = {
 
	SLE_CONDVAR(Sign, y,     SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_5),
 
	SLE_CONDVAR(Sign, x,     SLE_INT32,                  SLV_5, SL_MAX_VERSION),
 
	SLE_CONDVAR(Sign, y,     SLE_INT32,                  SLV_5, SL_MAX_VERSION),
 
	SLE_CONDVAR(Sign, owner, SLE_UINT8,                  SLV_6, SL_MAX_VERSION),
 
	SLE_CONDVAR(Sign, z,     SLE_FILE_U8  | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
 
	SLE_CONDVAR(Sign, z,     SLE_INT32,                SLV_164, SL_MAX_VERSION),
 
	SLE_END()
 
};
 

	
 
/** Save all signs */
 
static void Save_SIGN()
 
{
 
	for (Sign *si : Sign::Iterate()) {
src/saveload/station_sl.cpp
Show inline comments
 
@@ -151,14 +151,12 @@ static const SaveLoad _roadstop_desc[] =
 

	
 
	SLE_REF(RoadStop, next,         REF_ROADSTOPS),
 
	SLE_CONDNULL(2, SL_MIN_VERSION, SLV_45),
 

	
 
	SLE_CONDNULL(4, SL_MIN_VERSION, SLV_25),
 
	SLE_CONDNULL(1, SLV_25, SLV_26),
 

	
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _old_station_desc[] = {
 
	SLE_CONDVAR(Station, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  SL_MIN_VERSION, SLV_6),
 
	SLE_CONDVAR(Station, xy,                         SLE_UINT32,                  SLV_6, SL_MAX_VERSION),
 
	SLE_CONDNULL(4, SL_MIN_VERSION, SLV_6),  ///< bus/lorry tile
 
@@ -210,28 +208,24 @@ static const SaveLoad _old_station_desc[
 
	SLE_CONDVAR(Station, num_specs,                  SLE_UINT8,                  SLV_27, SL_MAX_VERSION),
 

	
 
	SLE_CONDLST(Station, loading_vehicles,           REF_VEHICLE,                SLV_57, SL_MAX_VERSION),
 

	
 
	/* reserve extra space in savegame here. (currently 32 bytes) */
 
	SLE_CONDNULL(32, SLV_2, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
 

	
 
static uint16 _waiting_acceptance;
 
static uint32 _num_flows;
 
static uint16 _cargo_source;
 
static uint32 _cargo_source_xy;
 
static uint8  _cargo_days;
 
static Money  _cargo_feeder_share;
 

	
 
static const SaveLoad _station_speclist_desc[] = {
 
	SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32, SLV_27, SL_MAX_VERSION),
 
	SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8,  SLV_27, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
 

	
 
std::list<CargoPacket *> _packets;
 
uint32 _num_dests;
 

	
 
struct FlowSaveLoad {
 
@@ -244,21 +238,20 @@ struct FlowSaveLoad {
 

	
 
static const SaveLoad _flow_desc[] = {
 
	    SLE_VAR(FlowSaveLoad, source,     SLE_UINT16),
 
	    SLE_VAR(FlowSaveLoad, via,        SLE_UINT16),
 
	    SLE_VAR(FlowSaveLoad, share,      SLE_UINT32),
 
	SLE_CONDVAR(FlowSaveLoad, restricted, SLE_BOOL, SLV_187, SL_MAX_VERSION),
 
	    SLE_END()
 
};
 

	
 
/**
 
 * Wrapper function to get the GoodsEntry's internal structure while
 
 * some of the variables itself are private.
 
 * @return the saveload description for GoodsEntry.
 
 */
 
const SaveLoad *GetGoodsDesc()
 
SaveLoadTable GetGoodsDesc()
 
{
 
	static const SaveLoad goods_desc[] = {
 
		SLEG_CONDVAR(            _waiting_acceptance,  SLE_UINT16,                  SL_MIN_VERSION, SLV_68),
 
		 SLE_CONDVAR(GoodsEntry, status,               SLE_UINT8,                  SLV_68, SL_MAX_VERSION),
 
		SLE_CONDNULL(2,                                                            SLV_51, SLV_68),
 
		     SLE_VAR(GoodsEntry, time_since_pickup,    SLE_UINT8),
 
@@ -276,24 +269,22 @@ const SaveLoad *GetGoodsDesc()
 
		SLEG_CONDVAR(            _num_dests,           SLE_UINT32,                SLV_183, SL_MAX_VERSION),
 
		 SLE_CONDVAR(GoodsEntry, cargo.reserved_count, SLE_UINT,                  SLV_181, SL_MAX_VERSION),
 
		 SLE_CONDVAR(GoodsEntry, link_graph,           SLE_UINT16,                SLV_183, SL_MAX_VERSION),
 
		 SLE_CONDVAR(GoodsEntry, node,                 SLE_UINT16,                SLV_183, SL_MAX_VERSION),
 
		SLEG_CONDVAR(            _num_flows,           SLE_UINT32,                SLV_183, SL_MAX_VERSION),
 
		 SLE_CONDVAR(GoodsEntry, max_waiting_cargo,    SLE_UINT32,                SLV_183, SL_MAX_VERSION),
 
		SLE_END()
 
	};
 

	
 
	return goods_desc;
 
}
 

	
 
typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
 

	
 
static const SaveLoad _cargo_list_desc[] = {
 
	SLE_VAR(StationCargoPair, first,  SLE_UINT16),
 
	SLE_LST(StationCargoPair, second, REF_CARGO_PACKET),
 
	SLE_END()
 
};
 

	
 
/**
 
 * Swap the temporary packets with the packets without specific destination in
 
 * the given goods entry. Assert that at least one of those is empty.
 
 * @param ge Goods entry to swap with.
 
@@ -395,14 +386,12 @@ static const SaveLoad _base_station_desc
 
	      SLE_VAR(BaseStation, build_date,             SLE_INT32),
 

	
 
	/* Used by newstations for graphic variations */
 
	      SLE_VAR(BaseStation, random_bits,            SLE_UINT16),
 
	      SLE_VAR(BaseStation, waiting_triggers,       SLE_UINT8),
 
	      SLE_VAR(BaseStation, num_specs,              SLE_UINT8),
 

	
 
	      SLE_END()
 
};
 

	
 
static OldPersistentStorage _old_st_persistent_storage;
 

	
 
static const SaveLoad _station_desc[] = {
 
	SLE_WRITEBYTE(Station, facilities),
 
@@ -437,42 +426,38 @@ static const SaveLoad _station_desc[] = 
 
	      SLE_VAR(Station, time_since_unload,          SLE_UINT8),
 
	      SLE_VAR(Station, last_vehicle_type,          SLE_UINT8),
 
	      SLE_VAR(Station, had_vehicle_of_type,        SLE_UINT8),
 
	      SLE_LST(Station, loading_vehicles,           REF_VEHICLE),
 
	  SLE_CONDVAR(Station, always_accepted,            SLE_FILE_U32 | SLE_VAR_U64, SLV_127, SLV_EXTEND_CARGOTYPES),
 
	  SLE_CONDVAR(Station, always_accepted,            SLE_UINT64,                 SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
 

	
 
	      SLE_END()
 
};
 

	
 
static const SaveLoad _waypoint_desc[] = {
 
	SLE_WRITEBYTE(Waypoint, facilities),
 
	SLE_ST_INCLUDE(),
 

	
 
	      SLE_VAR(Waypoint, town_cn,                   SLE_UINT16),
 

	
 
	  SLE_CONDVAR(Waypoint, train_station.tile,        SLE_UINT32,                  SLV_124, SL_MAX_VERSION),
 
	  SLE_CONDVAR(Waypoint, train_station.w,           SLE_FILE_U8 | SLE_VAR_U16,   SLV_124, SL_MAX_VERSION),
 
	  SLE_CONDVAR(Waypoint, train_station.h,           SLE_FILE_U8 | SLE_VAR_U16,   SLV_124, SL_MAX_VERSION),
 

	
 
	      SLE_END()
 
};
 

	
 
/**
 
 * Get the base station description to be used for SL_ST_INCLUDE
 
 * @return the base station description.
 
 */
 
const SaveLoad *GetBaseStationDescription()
 
SaveLoadTable GetBaseStationDescription()
 
{
 
	return _base_station_desc;
 
}
 

	
 
static void RealSave_STNN(BaseStation *bst)
 
{
 
	bool waypoint = (bst->facilities & FACIL_WAYPOINT) != 0;
 
	SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
 
	SlObject(bst, waypoint ? SaveLoadTable(_waypoint_desc) : SaveLoadTable(_station_desc));
 

	
 
	if (!waypoint) {
 
		Station *st = Station::From(bst);
 
		for (CargoID i = 0; i < NUM_CARGO; i++) {
 
			_num_dests = (uint32)st->goods[i].cargo.Packets()->MapSize();
 
			_num_flows = 0;
 
@@ -521,13 +506,13 @@ static void Load_STNN()
 
	uint num_cargo = IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
 
	int index;
 
	while ((index = SlIterateArray()) != -1) {
 
		bool waypoint = (SlReadByte() & FACIL_WAYPOINT) != 0;
 

	
 
		BaseStation *bst = waypoint ? (BaseStation *)new (index) Waypoint() : new (index) Station();
 
		SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
 
		SlObject(bst, waypoint ? SaveLoadTable(_waypoint_desc) : SaveLoadTable(_station_desc));
 

	
 
		if (!waypoint) {
 
			Station *st = Station::From(bst);
 

	
 
			/* Before savegame version 161, persistent storages were not stored in a pool. */
 
			if (IsSavegameVersionBefore(SLV_161) && !IsSavegameVersionBefore(SLV_145) && st->facilities & FACIL_AIRPORT) {
src/saveload/storage_sl.cpp
Show inline comments
 
@@ -15,13 +15,12 @@
 

	
 
/** Description of the data to save and load in #PersistentStorage. */
 
static const SaveLoad _storage_desc[] = {
 
	 SLE_CONDVAR(PersistentStorage, grfid,    SLE_UINT32,                  SLV_6, SL_MAX_VERSION),
 
	 SLE_CONDARR(PersistentStorage, storage,  SLE_UINT32,  16,           SLV_161, SLV_EXTEND_PERSISTENT_STORAGE),
 
	 SLE_CONDARR(PersistentStorage, storage,  SLE_UINT32, 256,           SLV_EXTEND_PERSISTENT_STORAGE, SL_MAX_VERSION),
 
	 SLE_END()
 
};
 

	
 
/** Load persistent storage data. */
 
static void Load_PSAC()
 
{
 
	int index;
src/saveload/story_sl.cpp
Show inline comments
 
@@ -31,13 +31,12 @@ static const SaveLoad _story_page_elemen
 
	SLE_CONDVAR(StoryPageElement, sort_value,    SLE_UINT32,                 SLV_185, SL_MAX_VERSION),
 
	    SLE_VAR(StoryPageElement, page,          SLE_UINT16),
 
	SLE_CONDVAR(StoryPageElement, type,          SLE_FILE_U16 | SLE_VAR_U8,  SL_MIN_VERSION,   SLV_185),
 
	SLE_CONDVAR(StoryPageElement, type,          SLE_UINT8,                  SLV_185, SL_MAX_VERSION),
 
	    SLE_VAR(StoryPageElement, referenced_id, SLE_UINT32),
 
	    SLE_STR(StoryPageElement, text,          SLE_STR | SLF_ALLOW_CONTROL, 0),
 
	    SLE_END()
 
};
 

	
 
static void Save_STORY_PAGE_ELEMENT()
 
{
 
	for (StoryPageElement *s : StoryPageElement::Iterate()) {
 
		SlSetArrayIndex(s->index);
 
@@ -66,13 +65,12 @@ static const SaveLoad _story_pages_desc[
 
	SLE_CONDVAR(StoryPage, sort_value, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION,   SLV_185),
 
	SLE_CONDVAR(StoryPage, sort_value, SLE_UINT32,                 SLV_185, SL_MAX_VERSION),
 
	    SLE_VAR(StoryPage, date,       SLE_UINT32),
 
	SLE_CONDVAR(StoryPage, company,    SLE_FILE_U16 | SLE_VAR_U8,  SL_MIN_VERSION,   SLV_185),
 
	SLE_CONDVAR(StoryPage, company,    SLE_UINT8,                  SLV_185, SL_MAX_VERSION),
 
	    SLE_STR(StoryPage, title,      SLE_STR | SLF_ALLOW_CONTROL, 0),
 
	    SLE_END()
 
};
 

	
 
static void Save_STORY_PAGE()
 
{
 
	for (StoryPage *s : StoryPage::Iterate()) {
 
		SlSetArrayIndex(s->index);
src/saveload/subsidy_sl.cpp
Show inline comments
 
@@ -21,13 +21,12 @@ static const SaveLoad _subsidies_desc[] 
 
	SLE_CONDVAR(Subsidy, src_type,   SLE_UINT8,                 SLV_125, SL_MAX_VERSION),
 
	SLE_CONDVAR(Subsidy, dst_type,   SLE_UINT8,                 SLV_125, SL_MAX_VERSION),
 
	SLE_CONDVAR(Subsidy, src,        SLE_FILE_U8 | SLE_VAR_U16,   SL_MIN_VERSION, SLV_5),
 
	SLE_CONDVAR(Subsidy, src,        SLE_UINT16,                  SLV_5, SL_MAX_VERSION),
 
	SLE_CONDVAR(Subsidy, dst,        SLE_FILE_U8 | SLE_VAR_U16,   SL_MIN_VERSION, SLV_5),
 
	SLE_CONDVAR(Subsidy, dst,        SLE_UINT16,                  SLV_5, SL_MAX_VERSION),
 
	SLE_END()
 
};
 

	
 
static void Save_SUBS()
 
{
 
	for (Subsidy *s : Subsidy::Iterate()) {
 
		SlSetArrayIndex(s->index);
src/saveload/town_sl.cpp
Show inline comments
 
@@ -191,52 +191,45 @@ static const SaveLoad _town_desc[] = {
 

	
 
	SLE_CONDLST(Town, psa_list,            REF_STORAGE,                SLV_161, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(4, SLV_166, SLV_EXTEND_CARGOTYPES),  ///< cargo_produced, no longer in use
 
	SLE_CONDNULL(8, SLV_EXTEND_CARGOTYPES, SLV_REMOVE_TOWN_CARGO_CACHE),  ///< cargo_produced, no longer in use
 
	SLE_CONDNULL(30, SLV_2, SLV_REMOVE_TOWN_CARGO_CACHE), ///< old reserved space
 

	
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _town_supplied_desc[] = {
 
	SLE_CONDVAR(TransportedCargoStat<uint32>, old_max, SLE_UINT32, SLV_165, SL_MAX_VERSION),
 
	SLE_CONDVAR(TransportedCargoStat<uint32>, new_max, SLE_UINT32, SLV_165, SL_MAX_VERSION),
 
	SLE_CONDVAR(TransportedCargoStat<uint32>, old_act, SLE_UINT32, SLV_165, SL_MAX_VERSION),
 
	SLE_CONDVAR(TransportedCargoStat<uint32>, new_act, SLE_UINT32, SLV_165, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _town_received_desc[] = {
 
	SLE_CONDVAR(TransportedCargoStat<uint16>, old_max, SLE_UINT16, SLV_165, SL_MAX_VERSION),
 
	SLE_CONDVAR(TransportedCargoStat<uint16>, new_max, SLE_UINT16, SLV_165, SL_MAX_VERSION),
 
	SLE_CONDVAR(TransportedCargoStat<uint16>, old_act, SLE_UINT16, SLV_165, SL_MAX_VERSION),
 
	SLE_CONDVAR(TransportedCargoStat<uint16>, new_act, SLE_UINT16, SLV_165, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_HIDS()
 
{
 
	Save_NewGRFMapping(_house_mngr);
 
}
 

	
 
static void Load_HIDS()
 
{
 
	Load_NewGRFMapping(_house_mngr);
 
}
 

	
 
const SaveLoad *GetTileMatrixDesc()
 
SaveLoadTable GetTileMatrixDesc()
 
{
 
	/* Here due to private member vars. */
 
	static const SaveLoad _tilematrix_desc[] = {
 
		SLE_VAR(AcceptanceMatrix, area.tile, SLE_UINT32),
 
		SLE_VAR(AcceptanceMatrix, area.w,    SLE_UINT16),
 
		SLE_VAR(AcceptanceMatrix, area.h,    SLE_UINT16),
 
		SLE_END()
 
	};
 

	
 
	return _tilematrix_desc;
 
}
 

	
 
static void RealSave_Town(Town *t)
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -575,13 +575,13 @@ static uint32 _cargo_loaded_at_xy;
 

	
 
/**
 
 * Make it possible to make the saveload tables "friends" of other classes.
 
 * @param vt the vehicle type. Can be VEH_END for the common vehicle description data
 
 * @return the saveload description
 
 */
 
const SaveLoad *GetVehicleDescription(VehicleType vt)
 
SaveLoadTable GetVehicleDescription(VehicleType vt)
 
{
 
	/** Save and load of vehicles */
 
	static const SaveLoad _common_veh_desc[] = {
 
		     SLE_VAR(Vehicle, subtype,               SLE_UINT8),
 

	
 
		     SLE_REF(Vehicle, next,                  REF_VEHICLE_OLD),
 
@@ -709,17 +709,14 @@ const SaveLoad *GetVehicleDescription(Ve
 
		 SLE_CONDVAR(Vehicle, group_id,              SLE_UINT16,                  SLV_60, SL_MAX_VERSION),
 

	
 
		 SLE_CONDVAR(Vehicle, current_order_time,    SLE_UINT32,                  SLV_67, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Vehicle, lateness_counter,      SLE_INT32,                   SLV_67, SL_MAX_VERSION),
 

	
 
		SLE_CONDNULL(10,                                                           SLV_2, SLV_144), // old reserved space
 

	
 
		     SLE_END()
 
	};
 

	
 

	
 
	static const SaveLoad _train_desc[] = {
 
		SLE_WRITEBYTE(Vehicle, type),
 
		SLE_VEH_INCLUDE(),
 
		     SLE_VAR(Train, crash_anim_pos,      SLE_UINT16),
 
		     SLE_VAR(Train, force_proceed,       SLE_UINT8),
 
		     SLE_VAR(Train, railtype,            SLE_UINT8),
 
@@ -731,14 +728,12 @@ const SaveLoad *GetVehicleDescription(Ve
 

	
 
		 SLE_CONDVAR(Train, wait_counter,        SLE_UINT16,                 SLV_136, SL_MAX_VERSION),
 

	
 
		SLE_CONDNULL(2, SLV_2, SLV_20),
 
		 SLE_CONDVAR(Train, gv_flags,            SLE_UINT16,                 SLV_139, SL_MAX_VERSION),
 
		SLE_CONDNULL(11, SLV_2, SLV_144), // old reserved space
 

	
 
		     SLE_END()
 
	};
 

	
 
	static const SaveLoad _roadveh_desc[] = {
 
		SLE_WRITEBYTE(Vehicle, type),
 
		SLE_VEH_INCLUDE(),
 
		      SLE_VAR(RoadVehicle, state,                SLE_UINT8),
 
@@ -753,26 +748,22 @@ const SaveLoad *GetVehicleDescription(Ve
 

	
 
		 SLE_CONDNULL(2,                                                               SLV_6,  SLV_69),
 
		  SLE_CONDVAR(RoadVehicle, gv_flags,             SLE_UINT16,                 SLV_139, SL_MAX_VERSION),
 
		 SLE_CONDNULL(4,                                                              SLV_69, SLV_131),
 
		 SLE_CONDNULL(2,                                                               SLV_6, SLV_131),
 
		 SLE_CONDNULL(16,                                                              SLV_2, SLV_144), // old reserved space
 

	
 
		      SLE_END()
 
	};
 

	
 
	static const SaveLoad _ship_desc[] = {
 
		SLE_WRITEBYTE(Vehicle, type),
 
		SLE_VEH_INCLUDE(),
 
		      SLE_VAR(Ship, state,                     SLE_UINT8),
 
		SLE_CONDDEQUE(Ship, path,                      SLE_UINT8,                  SLV_SHIP_PATH_CACHE, SL_MAX_VERSION),
 
		  SLE_CONDVAR(Ship, rotation,                  SLE_UINT8,                  SLV_SHIP_ROTATION, SL_MAX_VERSION),
 

	
 
		SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
 

	
 
		     SLE_END()
 
	};
 

	
 
	static const SaveLoad _aircraft_desc[] = {
 
		SLE_WRITEBYTE(Vehicle, type),
 
		SLE_VEH_INCLUDE(),
 
		     SLE_VAR(Aircraft, crashed_counter,       SLE_UINT16),
 
@@ -788,14 +779,12 @@ const SaveLoad *GetVehicleDescription(Ve
 
		 SLE_CONDVAR(Aircraft, number_consecutive_turns, SLE_UINT8,                 SLV_2, SL_MAX_VERSION),
 

	
 
		 SLE_CONDVAR(Aircraft, turn_counter,          SLE_UINT8,                  SLV_136, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Aircraft, flags,                 SLE_UINT8,                  SLV_167, SL_MAX_VERSION),
 

	
 
		SLE_CONDNULL(13,                                                           SLV_2, SLV_144), // old reserved space
 

	
 
		     SLE_END()
 
	};
 

	
 
	static const SaveLoad _special_desc[] = {
 
		SLE_WRITEBYTE(Vehicle, type),
 

	
 
		     SLE_VAR(Vehicle, subtype,               SLE_UINT8),
 
@@ -818,14 +807,12 @@ const SaveLoad *GetVehicleDescription(Ve
 
		     SLE_VAR(EffectVehicle, animation_state,    SLE_UINT16),
 
		     SLE_VAR(EffectVehicle, animation_substate, SLE_UINT8),
 

	
 
		 SLE_CONDVAR(Vehicle, spritenum,             SLE_UINT8,                    SLV_2, SL_MAX_VERSION),
 

	
 
		SLE_CONDNULL(15,                                                           SLV_2, SLV_144), // old reserved space
 

	
 
		     SLE_END()
 
	};
 

	
 
	static const SaveLoad _disaster_desc[] = {
 
		SLE_WRITEBYTE(Vehicle, type),
 

	
 
		     SLE_REF(Vehicle, next,                  REF_VEHICLE_OLD),
 
@@ -859,18 +846,16 @@ const SaveLoad *GetVehicleDescription(Ve
 
		 SLE_CONDVAR(DisasterVehicle, image_override,            SLE_UINT32,                 SLV_191, SL_MAX_VERSION),
 
		 SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target,  SLE_FILE_U16 | SLE_VAR_U32,   SL_MIN_VERSION, SLV_191),
 
		 SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target,  SLE_UINT32,                 SLV_191, SL_MAX_VERSION),
 
		 SLE_CONDVAR(DisasterVehicle, flags,                     SLE_UINT8,                  SLV_194, SL_MAX_VERSION),
 

	
 
		SLE_CONDNULL(16,                                                           SLV_2, SLV_144), // old reserved space
 

	
 
		     SLE_END()
 
	};
 

	
 

	
 
	static const SaveLoad * const _veh_descs[] = {
 
	static const SaveLoadTable _veh_descs[] = {
 
		_train_desc,
 
		_roadveh_desc,
 
		_ship_desc,
 
		_aircraft_desc,
 
		_special_desc,
 
		_disaster_desc,
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -177,14 +177,12 @@ static const SaveLoad _old_waypoint_desc
 

	
 
	SLE_CONDVAR(OldWaypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32,  SLV_3, SLV_31),
 
	SLE_CONDVAR(OldWaypoint, build_date, SLE_INT32,                  SLV_31, SL_MAX_VERSION),
 
	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),
 

	
 
	SLE_END()
 
};
 

	
 
static void Load_WAYP()
 
{
 
	/* Precaution for when loading failed and it didn't get cleared */
 
	ResetOldWaypoints();
src/script/script_instance.cpp
Show inline comments
 
@@ -340,13 +340,12 @@ enum SQSaveLoadType {
 

	
 
static byte _script_sl_byte; ///< Used as source/target by the script saveload code to store/load a single byte.
 

	
 
/** SaveLoad array that saves/loads exactly one byte. */
 
static const SaveLoad _script_byte[] = {
 
	SLEG_VAR(_script_sl_byte, SLE_UINT8),
 
	SLE_END()
 
};
 

	
 
/* static */ bool ScriptInstance::SaveObject(HSQUIRRELVM vm, SQInteger index, int max_depth, bool test)
 
{
 
	if (max_depth == 0) {
 
		ScriptLog::Error("Savedata can only be nested to 25 deep. No data saved."); // SQUIRREL_MAX_DEPTH = 25
src/settings.cpp
Show inline comments
 
@@ -255,13 +255,13 @@ static bool LoadIntList(const char *str,
 
 * @param array pointer to the integer-arrays that is read from
 
 * @param nelems the number of elements the array holds.
 
 * @param type the type of elements the array holds (eg INT8, UINT16, etc.)
 
 */
 
void ListSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
 
{
 
	const byte *p = static_cast<const byte *>(GetVariableAddress(object, &this->save));
 
	const byte *p = static_cast<const byte *>(GetVariableAddress(object, this->save));
 
	int i, v = 0;
 

	
 
	for (i = 0; i != this->save.length; i++) {
 
		switch (GetVarMemType(this->save.conv)) {
 
			case SLE_VAR_BL:
 
			case SLE_VAR_I8:  v = *(const   int8 *)p; p += 1; break;
 
@@ -443,24 +443,24 @@ void IntSettingDesc::MakeValueValid(int3
 
 * Set the value of a setting.
 
 * @param object The object the setting is to be saved in.
 
 * @param val Signed version of the new value.
 
 */
 
void IntSettingDesc::Write(const void *object, int32 val) const
 
{
 
	void *ptr = GetVariableAddress(object, &this->save);
 
	void *ptr = GetVariableAddress(object, this->save);
 
	WriteValue(ptr, this->save.conv, (int64)val);
 
}
 

	
 
/**
 
 * Read the integer from the the actual setting.
 
 * @param object The object the setting is to be saved in.
 
 * @return The value of the saved integer.
 
 */
 
int32 IntSettingDesc::Read(const void *object) const
 
{
 
	void *ptr = GetVariableAddress(object, &this->save);
 
	void *ptr = GetVariableAddress(object, this->save);
 
	return (int32)ReadValue(ptr, this->save.conv);
 
}
 

	
 
/**
 
 * Make the value valid given the limitations of this setting.
 
 *
 
@@ -483,23 +483,23 @@ void StringSettingDesc::MakeValueValid(s
 
 * Write a string to the actual setting.
 
 * @param object The object the setting is to be saved in.
 
 * @param str The string to save.
 
 */
 
void StringSettingDesc::Write(const void *object, const std::string &str) const
 
{
 
	reinterpret_cast<std::string *>(GetVariableAddress(object, &this->save))->assign(str);
 
	reinterpret_cast<std::string *>(GetVariableAddress(object, this->save))->assign(str);
 
}
 

	
 
/**
 
 * Read the string from the the actual setting.
 
 * @param object The object the setting is to be saved in.
 
 * @return The value of the saved string.
 
 */
 
const std::string &StringSettingDesc::Read(const void *object) const
 
{
 
	return *reinterpret_cast<std::string *>(GetVariableAddress(object, &this->save));
 
	return *reinterpret_cast<std::string *>(GetVariableAddress(object, this->save));
 
}
 

	
 
/**
 
 * Load values from a group of an IniFile structure into the internal representation
 
 * @param ini pointer to IniFile structure that holds administrative information
 
 * @param settings_table table with SettingDesc structures whose internally pointed variables will
 
@@ -557,13 +557,13 @@ void StringSettingDesc::ParseValue(const
 
	this->Write(object, str);
 
}
 

	
 
void ListSettingDesc::ParseValue(const IniItem *item, void *object) const
 
{
 
	const char *str = (item == nullptr) ? this->def : item->value.has_value() ? item->value->c_str() : nullptr;
 
	void *ptr = GetVariableAddress(object, &this->save);
 
	void *ptr = GetVariableAddress(object, this->save);
 
	if (!LoadIntList(str, ptr, this->save.length, GetVarMemType(this->save.conv))) {
 
		ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
 
		msg.SetDParamStr(0, this->name);
 
		_settings_error_list.push_back(msg);
 

	
 
		/* Use default */
 
@@ -2022,15 +2022,15 @@ void IConsoleListSettings(const char *pr
 
 * @param object can be either nullptr in which case we load global variables or
 
 * a pointer to a struct which is getting saved
 
 */
 
static void LoadSettings(const SettingTable &settings, void *object)
 
{
 
	for (auto &osd : settings) {
 
		void *ptr = GetVariableAddress(object, &osd->save);
 
		void *ptr = GetVariableAddress(object, osd->save);
 

	
 
		if (!SlObjectMember(ptr, &osd->save)) continue;
 
		if (!SlObjectMember(ptr, osd->save)) continue;
 
		if (osd->IsIntSetting()) {
 
			const IntSettingDesc *int_setting = osd->AsIntSetting();
 
			int_setting->MakeValueValidAndWrite(object, int_setting->Read(object));
 
		}
 
	}
 
}
 
@@ -2044,19 +2044,19 @@ static void LoadSettings(const SettingTa
 
static void SaveSettings(const SettingTable &settings, void *object)
 
{
 
	/* We need to write the CH_RIFF header, but unfortunately can't call
 
	 * SlCalcLength() because we have a different format. So do this manually */
 
	size_t length = 0;
 
	for (auto &sd : settings) {
 
		length += SlCalcObjMemberLength(object, &sd->save);
 
		length += SlCalcObjMemberLength(object, sd->save);
 
	}
 
	SlSetLength(length);
 

	
 
	for (auto &sd : settings) {
 
		void *ptr = GetVariableAddress(object, &sd->save);
 
		SlObjectMember(ptr, &sd->save);
 
		void *ptr = GetVariableAddress(object, sd->save);
 
		SlObjectMember(ptr, sd->save);
 
	}
 
}
 

	
 
static void Load_OPTS()
 
{
 
	/* Copy over default setting since some might not get loaded in
src/vehicle_base.h
Show inline comments
 
@@ -19,12 +19,13 @@
 
#include "engine_type.h"
 
#include "order_func.h"
 
#include "transport_type.h"
 
#include "group_type.h"
 
#include "base_consist.h"
 
#include "network/network.h"
 
#include "saveload/saveload.h"
 
#include <list>
 
#include <map>
 

	
 
/** Vehicle status bits in #Vehicle::vehstatus. */
 
enum VehStatus {
 
	VS_HIDDEN          = 0x01, ///< Vehicle is not visible.
 
@@ -195,15 +196,14 @@ struct MutableSpriteCache {
 

	
 
/** A vehicle pool for a little over 1 million vehicles. */
 
typedef Pool<Vehicle, VehicleID, 512, 0xFF000> VehiclePool;
 
extern VehiclePool _vehicle_pool;
 

	
 
/* Some declarations of functions, so we can make them friendly */
 
struct SaveLoad;
 
struct GroundVehicleCache;
 
extern const SaveLoad *GetVehicleDescription(VehicleType vt);
 
extern SaveLoadTable GetVehicleDescription(VehicleType vt);
 
struct LoadgameState;
 
extern bool LoadOldVehicle(LoadgameState *ls, int num);
 
extern void FixOldVehicles();
 

	
 
struct GRFFile;
 

	
 
@@ -229,13 +229,13 @@ private:
 
	Vehicle *first;                     ///< NOSAVE: pointer to the first vehicle in the chain
 

	
 
	Vehicle *next_shared;               ///< pointer to the next vehicle that shares the order
 
	Vehicle *previous_shared;           ///< NOSAVE: pointer to the previous vehicle in the shared order chain
 

	
 
public:
 
	friend const SaveLoad *GetVehicleDescription(VehicleType vt); ///< So we can use private/protected variables in the saveload code
 
	friend SaveLoadTable GetVehicleDescription(VehicleType vt); ///< So we can use private/protected variables in the saveload code
 
	friend void FixOldVehicles();
 
	friend void AfterLoadVehicles(bool part_of_load);             ///< So we can set the #previous and #first pointers while loading
 
	friend bool LoadOldVehicle(LoadgameState *ls, int num);       ///< So we can set the proper next pointer while loading
 

	
 
	TileIndex tile;                     ///< Current tile index
 

	
0 comments (0 inline, 0 general)