Merge branch 'save_ext' into day_length
This commit is contained in:
@@ -87,6 +87,20 @@ bool SlXvIsFeaturePresent(SlXvFeatureIndex feature, uint16 min_version, uint16 m
|
||||
return _sl_xv_feature_versions[feature] >= min_version && _sl_xv_feature_versions[feature] <= max_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if @p feature is present and has a version inclusively bounded by @p min_version and @p max_version
|
||||
*/
|
||||
const char *SlXvGetFeatureName(SlXvFeatureIndex feature)
|
||||
{
|
||||
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
|
||||
for (; info->index != XSLFI_NULL; ++info) {
|
||||
if (info->index == feature) {
|
||||
return info->name;
|
||||
}
|
||||
}
|
||||
return "(unknown feature)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all extended feature versions to 0
|
||||
*/
|
||||
@@ -94,6 +108,7 @@ void SlXvResetState()
|
||||
{
|
||||
_sl_is_ext_version = false;
|
||||
_sl_is_faked_ext = false;
|
||||
_sl_xv_discardable_chunk_ids.clear();
|
||||
memset(_sl_xv_feature_versions, 0, sizeof(_sl_xv_feature_versions));
|
||||
}
|
||||
|
||||
|
@@ -66,6 +66,8 @@ inline bool SlXvIsFeatureMissing(SlXvFeatureIndex feature)
|
||||
return !SlXvIsFeaturePresent(feature);
|
||||
}
|
||||
|
||||
const char *SlXvGetFeatureName(SlXvFeatureIndex feature);
|
||||
|
||||
/**
|
||||
* sub chunk flags, this is saved as-is
|
||||
* (XSCF_EXTRA_DATA_PRESENT and XSCF_CHUNK_ID_LIST_PRESENT must only be set by the save code, and read by the load code)
|
||||
|
@@ -1165,7 +1165,7 @@ static const OldChunks vehicle_chunk[] = {
|
||||
|
||||
OCL_SVAR( OC_UINT8, Vehicle, owner ),
|
||||
OCL_SVAR( OC_TILE, Vehicle, tile ),
|
||||
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, cur_image ),
|
||||
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, sprite_seq.seq[0].sprite ),
|
||||
|
||||
OCL_NULL( 8 ), ///< Vehicle sprite box, calculated automatically
|
||||
|
||||
@@ -1258,7 +1258,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
if (v == NULL) continue;
|
||||
v->refit_cap = v->cargo_cap;
|
||||
|
||||
SpriteID sprite = v->cur_image;
|
||||
SpriteID sprite = v->sprite_seq.seq[0].sprite;
|
||||
/* no need to override other sprites */
|
||||
if (IsInsideMM(sprite, 1460, 1465)) {
|
||||
sprite += 580; // aircraft smoke puff
|
||||
@@ -1269,7 +1269,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
} else if (IsInsideMM(sprite, 2516, 2539)) {
|
||||
sprite += 1385; // rotor or disaster-related vehicles
|
||||
}
|
||||
v->cur_image = sprite;
|
||||
v->sprite_seq.seq[0].sprite = sprite;
|
||||
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: {
|
||||
|
@@ -52,6 +52,7 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
@@ -1366,9 +1367,10 @@ static void *IntToReference(size_t index, SLRefType rt)
|
||||
* Return the size in bytes of a list
|
||||
* @param list The std::list to find the size of
|
||||
*/
|
||||
template<typename PtrList>
|
||||
static inline size_t SlCalcListLen(const void *list)
|
||||
{
|
||||
const std::list<void *> *l = (const std::list<void *> *) list;
|
||||
const PtrList *l = (const PtrList *) list;
|
||||
|
||||
int type_size = IsSavegameVersionBefore(69) ? 2 : 4;
|
||||
/* Each entry is saved as type_size bytes, plus type_size bytes are used for the length
|
||||
@@ -1382,23 +1384,23 @@ static inline size_t SlCalcListLen(const void *list)
|
||||
* @param list The list being manipulated
|
||||
* @param conv SLRefType type of the list (Vehicle *, Station *, etc)
|
||||
*/
|
||||
template<typename PtrList>
|
||||
static void SlList(void *list, SLRefType conv)
|
||||
{
|
||||
/* Automatically calculate the length? */
|
||||
if (_sl.need_length != NL_NONE) {
|
||||
SlSetLength(SlCalcListLen(list));
|
||||
SlSetLength(SlCalcListLen<PtrList>(list));
|
||||
/* Determine length only? */
|
||||
if (_sl.need_length == NL_CALCLENGTH) return;
|
||||
}
|
||||
|
||||
typedef std::list<void *> PtrList;
|
||||
PtrList *l = (PtrList *)list;
|
||||
|
||||
switch (_sl.action) {
|
||||
case SLA_SAVE: {
|
||||
SlWriteUint32((uint32)l->size());
|
||||
|
||||
PtrList::iterator iter;
|
||||
typename PtrList::iterator iter;
|
||||
for (iter = l->begin(); iter != l->end(); ++iter) {
|
||||
void *ptr = *iter;
|
||||
SlWriteUint32((uint32)ReferenceToInt(ptr, conv));
|
||||
@@ -1420,7 +1422,7 @@ static void SlList(void *list, SLRefType conv)
|
||||
PtrList temp = *l;
|
||||
|
||||
l->clear();
|
||||
PtrList::iterator iter;
|
||||
typename PtrList::iterator iter;
|
||||
for (iter = temp.begin(); iter != temp.end(); ++iter) {
|
||||
void *ptr = IntToReference((size_t)*iter, conv);
|
||||
l->push_back(ptr);
|
||||
@@ -1486,6 +1488,8 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld)
|
||||
case SL_ARR:
|
||||
case SL_STR:
|
||||
case SL_LST:
|
||||
case SL_DEQ:
|
||||
case SL_VEC:
|
||||
/* CONDITIONAL saveload types depend on the savegame version */
|
||||
if (!SlIsObjectValidInSavegame(sld)) break;
|
||||
|
||||
@@ -1494,7 +1498,9 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld)
|
||||
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_LST: return SlCalcListLen(GetVariableAddress(object, sld));
|
||||
case SL_LST: return SlCalcListLen<std::list<void *>>(GetVariableAddress(object, sld));
|
||||
case SL_DEQ: return SlCalcListLen<std::deque<void *>>(GetVariableAddress(object, sld));
|
||||
case SL_VEC: return SlCalcListLen<std::vector<void *>>(GetVariableAddress(object, sld));
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
@@ -1506,6 +1512,8 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef OTTD_ASSERT
|
||||
|
||||
/**
|
||||
* Check whether the variable size of the variable in the saveload configuration
|
||||
* matches with the actual variable size.
|
||||
@@ -1546,9 +1554,13 @@ static bool IsVariableSizeRight(const SaveLoad *sld)
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* OTTD_ASSERT */
|
||||
|
||||
bool SlObjectMember(void *ptr, const SaveLoad *sld)
|
||||
{
|
||||
#ifdef OTTD_ASSERT
|
||||
assert(IsVariableSizeRight(sld));
|
||||
#endif
|
||||
|
||||
VarType conv = GB(sld->conv, 0, 8);
|
||||
switch (sld->cmd) {
|
||||
@@ -1557,6 +1569,8 @@ bool SlObjectMember(void *ptr, const SaveLoad *sld)
|
||||
case SL_ARR:
|
||||
case SL_STR:
|
||||
case SL_LST:
|
||||
case SL_DEQ:
|
||||
case SL_VEC:
|
||||
/* CONDITIONAL saveload types depend on the savegame version */
|
||||
if (!SlIsObjectValidInSavegame(sld)) return false;
|
||||
if (SlSkipVariableOnLoad(sld)) return false;
|
||||
@@ -1583,7 +1597,9 @@ bool SlObjectMember(void *ptr, const SaveLoad *sld)
|
||||
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_LST: SlList<std::list<void *>>(ptr, (SLRefType)conv); break;
|
||||
case SL_DEQ: SlList<std::deque<void *>>(ptr, (SLRefType)conv); break;
|
||||
case SL_VEC: SlList<std::vector<void *>>(ptr, (SLRefType)conv); break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
@@ -2664,7 +2680,7 @@ static SaveOrLoadResult DoSave(SaveFilter *writer, bool threaded)
|
||||
SlSaveChunks();
|
||||
|
||||
SaveFileStart();
|
||||
if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread)) {
|
||||
if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread, "ottd:savegame")) {
|
||||
if (threaded) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
|
||||
|
||||
SaveOrLoadResult result = SaveFileToDisk(false);
|
||||
|
@@ -205,6 +205,8 @@ enum SaveLoadTypes {
|
||||
SL_ARR = 2, ///< Save/load an array.
|
||||
SL_STR = 3, ///< Save/load a string.
|
||||
SL_LST = 4, ///< Save/load a list.
|
||||
SL_DEQ = 5, ///< Save/load a deque.
|
||||
SL_VEC = 6, ///< Save/load a vector.
|
||||
/* non-normal save-load types */
|
||||
SL_WRITEBYTE = 8,
|
||||
SL_VEH_INCLUDE = 9,
|
||||
@@ -310,6 +312,30 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
#define SLE_CONDLST_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_LST, base, variable, type, 0, from, to, extver)
|
||||
#define SLE_CONDLST(base, variable, type, from, to) SLE_CONDLST_X(base, variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a deque in some savegame versions.
|
||||
* @param base Name of the class or struct containing the list.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
* @param from First savegame version that has the list.
|
||||
* @param to Last savegame version that has the list.
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDDEQ_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_DEQ, base, variable, type, 0, from, to, extver)
|
||||
#define SLE_CONDDEQ(base, variable, type, from, to) SLE_CONDDEQ_X(base, variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a vector in some savegame versions.
|
||||
* @param base Name of the class or struct containing the list.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
* @param from First savegame version that has the list.
|
||||
* @param to Last savegame version that has the list.
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDVEC_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_VEC, base, variable, type, 0, from, to, extver)
|
||||
#define SLE_CONDVEC(base, variable, type, from, to) SLE_CONDVEC_X(base, variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a variable in every version of a savegame.
|
||||
* @param base Name of the class or struct containing the variable.
|
||||
@@ -352,6 +378,22 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
*/
|
||||
#define SLE_LST(base, variable, type) SLE_CONDLST(base, variable, type, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Storage of a deque in every savegame version.
|
||||
* @param base Name of the class or struct containing the list.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
*/
|
||||
#define SLE_DEQ(base, variable, type) SLE_CONDDEQ(base, variable, type, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Storage of a vector in every savegame version.
|
||||
* @param base Name of the class or struct containing the list.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
*/
|
||||
#define SLE_VEC(base, variable, type) SLE_CONDVEC(base, variable, type, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Empty space in every savegame version.
|
||||
* @param length Length of the empty space.
|
||||
@@ -447,6 +489,28 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
#define SLEG_CONDLST_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_LST, variable, type, 0, from, to, extver)
|
||||
#define SLEG_CONDLST(variable, type, from, to) SLEG_CONDLST_X(variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global deque in some savegame versions.
|
||||
* @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 list.
|
||||
* @param to Last savegame version that has the list.
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLEG_CONDDEQ_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_DEQ, variable, type, 0, from, to, extver)
|
||||
#define SLEG_CONDDEQ(variable, type, from, to) SLEG_CONDDEQ_X(variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global vector in some savegame versions.
|
||||
* @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 list.
|
||||
* @param to Last savegame version that has the list.
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLEG_CONDVEC_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_VEC, variable, type, 0, from, to, extver)
|
||||
#define SLEG_CONDVEC(variable, type, from, to) SLEG_CONDVEC_X(variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global variable in every savegame version.
|
||||
* @param variable Name of the global variable.
|
||||
@@ -482,6 +546,20 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
*/
|
||||
#define SLEG_LST(variable, type) SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Storage of a global deque in every savegame version.
|
||||
* @param variable Name of the global variable.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
*/
|
||||
#define SLEG_DEQ(variable, type) SLEG_CONDDEQ(variable, type, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Storage of a global vector in every savegame version.
|
||||
* @param variable Name of the global variable.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
*/
|
||||
#define SLEG_VEC(variable, type) SLEG_CONDVEC(variable, type, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Empty global space in some savegame versions.
|
||||
* @param length Length of the empty space.
|
||||
|
@@ -436,21 +436,21 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
|
||||
case VEH_TRAIN:
|
||||
case VEH_SHIP:
|
||||
v->cur_image = v->GetImage(v->direction, EIT_ON_MAP);
|
||||
v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_seq);
|
||||
break;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
if (Aircraft::From(v)->IsNormalAircraft()) {
|
||||
v->cur_image = v->GetImage(v->direction, EIT_ON_MAP);
|
||||
v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_seq);
|
||||
|
||||
/* The plane's shadow will have the same image as the plane */
|
||||
/* The plane's shadow will have the same image as the plane, but no colour */
|
||||
Vehicle *shadow = v->Next();
|
||||
shadow->cur_image = v->cur_image;
|
||||
shadow->sprite_seq.CopyWithoutPalette(v->sprite_seq);
|
||||
|
||||
/* In the case of a helicopter we will update the rotor sprites */
|
||||
if (v->subtype == AIR_HELICOPTER) {
|
||||
Vehicle *rotor = shadow->Next();
|
||||
rotor->cur_image = GetRotorImage(Aircraft::From(v), EIT_ON_MAP);
|
||||
GetRotorImage(Aircraft::From(v), EIT_ON_MAP, &rotor->sprite_seq);
|
||||
}
|
||||
|
||||
UpdateAircraftCache(Aircraft::From(v), true);
|
||||
@@ -796,7 +796,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
|
||||
SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, 0, 163),
|
||||
SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, 164, SL_MAX_VERSION),
|
||||
|
||||
SLE_VAR(Vehicle, cur_image, SLE_FILE_U16 | SLE_VAR_U32),
|
||||
SLE_VAR(Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
|
||||
SLE_CONDNULL(5, 0, 57),
|
||||
SLE_VAR(Vehicle, progress, SLE_UINT8),
|
||||
SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
|
||||
@@ -836,7 +836,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
|
||||
SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
|
||||
SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, 5, SL_MAX_VERSION),
|
||||
|
||||
SLE_VAR(Vehicle, cur_image, SLE_FILE_U16 | SLE_VAR_U32),
|
||||
SLE_VAR(Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
|
||||
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30),
|
||||
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION),
|
||||
SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
|
||||
|
Reference in New Issue
Block a user