Strong typedef: Use strong typedefs for date, date tick, minutes types
Add delta types Adjust/add type conversion functions Add various utility methods on types Remove the various minute macros Fix some minute conversion inconsistencies
This commit is contained in:
@@ -39,7 +39,7 @@ SaveLoadTable GetLinkGraphDesc()
|
||||
|
||||
void GetLinkGraphJobDayLengthScaleAfterLoad(LinkGraphJob *lgj)
|
||||
{
|
||||
lgj->join_date_ticks *= DAY_TICKS;
|
||||
lgj->join_date_ticks.edit_base() *= DAY_TICKS;
|
||||
lgj->join_date_ticks += LinkGraphSchedule::SPAWN_JOIN_TICK;
|
||||
|
||||
uint recalc_scale;
|
||||
|
@@ -162,7 +162,7 @@ static void Check_DATE()
|
||||
{
|
||||
SlGlobList(_date_check_desc);
|
||||
if (IsSavegameVersionBefore(SLV_31)) {
|
||||
_load_check_data.current_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
_load_check_data.current_date += DAYS_TILL_ORIGINAL_BASE_YEAR.AsDelta();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -395,7 +395,7 @@ static bool FixTTOEngines()
|
||||
for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i);
|
||||
}
|
||||
|
||||
Date aging_date = std::min(_date + DAYS_TILL_ORIGINAL_BASE_YEAR, ConvertYMDToDate(2050, 0, 1));
|
||||
Date aging_date = std::min(_date + DAYS_TILL_ORIGINAL_BASE_YEAR.AsDelta(), ConvertYMDToDate(2050, 0, 1));
|
||||
|
||||
for (EngineID i = 0; i < 256; i++) {
|
||||
int oi = ttd_to_tto[i];
|
||||
@@ -403,17 +403,17 @@ static bool FixTTOEngines()
|
||||
|
||||
if (oi == 255) {
|
||||
/* Default engine is used */
|
||||
_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
_date += DAYS_TILL_ORIGINAL_BASE_YEAR.AsDelta();
|
||||
StartupOneEngine(e, aging_date, 0, INT_MAX);
|
||||
CalcEngineReliability(e, false);
|
||||
e->intro_date -= DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
_date -= DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
e->intro_date -= DAYS_TILL_ORIGINAL_BASE_YEAR.AsDelta();
|
||||
_date -= DAYS_TILL_ORIGINAL_BASE_YEAR.AsDelta();
|
||||
|
||||
/* Make sure for example monorail and maglev are available when they should be */
|
||||
if (_date >= e->intro_date && HasBit(e->info.climates, 0)) {
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
e->company_avail = MAX_UVALUE(CompanyMask);
|
||||
e->age = _date > e->intro_date ? (_date - e->intro_date) / 30 : 0;
|
||||
e->age = _date > e->intro_date ? (_date - e->intro_date).base() / 30 : 0;
|
||||
}
|
||||
} else {
|
||||
/* Using data from TTO savegame */
|
||||
|
@@ -3726,7 +3726,7 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop,
|
||||
}
|
||||
|
||||
if (fop == SLO_SAVE) { // SAVE game
|
||||
DEBUG(desync, 1, "save: date{%08x; %02x; %02x}; %s", _date, _date_fract, _tick_skip_counter, filename.c_str());
|
||||
DEBUG(desync, 1, "save: date{%08x; %02x; %02x}; %s", _date.base(), _date_fract, _tick_skip_counter, filename.c_str());
|
||||
if (!_settings_client.gui.threaded_saves) threaded = false;
|
||||
|
||||
return DoSave(new FileWriter(fh), threaded);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "../scope.h"
|
||||
#include "../core/ring_buffer.hpp"
|
||||
#include "../core/tinystring_type.hpp"
|
||||
#include "../core/strong_typedef_type.hpp"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <vector>
|
||||
@@ -338,7 +339,7 @@ static inline constexpr bool SlCheckPrimitiveTypeVar(VarType type)
|
||||
if (GetVarMemType(type) == SLE_VAR_CNAME) {
|
||||
return std::is_same_v<T, char *> || std::is_same_v<T, const char *> || std::is_same_v<T, TinyString>;
|
||||
}
|
||||
if (!std::is_integral_v<T> && !std::is_enum_v<T> && !sl_is_instance<T, OverflowSafeInt>{}) return false;
|
||||
if (!std::is_integral_v<T> && !std::is_enum_v<T> && !sl_is_instance<T, OverflowSafeInt>{} && !std::is_base_of_v<StrongTypedefBase, T>) return false;
|
||||
return sizeof(T) == SlVarSize(type);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user