Increase DateTicks to 64 bits, fix overflow after year 79455

mapgen-water-desert-removal-circular
Jonathan G Rennison 5 months ago
parent bd35b0c47c
commit 16b840d86e

@ -2730,7 +2730,7 @@ DEF_CONSOLE_CMD(ConDumpLinkgraphJobs)
for (const LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
YearMonthDay start_ymd = ConvertDateToYMD(lgj->StartDateTicks().ToDate());
YearMonthDay join_ymd = ConvertDateToYMD(lgj->JoinDateTicks().ToDate());
IConsolePrintF(CC_DEFAULT, " Job: %5u, nodes: %u, cost: " OTTD_PRINTF64U ", start: (%u, %4i-%02i-%02i, %i), end: (%u, %4i-%02i-%02i, %i), duration: %u",
IConsolePrintF(CC_DEFAULT, " Job: %5u, nodes: %u, cost: " OTTD_PRINTF64U ", start: (" OTTD_PRINTF64 ", %4i-%02i-%02i, %i), end: (" OTTD_PRINTF64 ", %4i-%02i-%02i, %i), duration: " OTTD_PRINTF64,
lgj->index, lgj->Graph().Size(), lgj->Graph().CalculateCostEstimate(),
lgj->StartDateTicks().base(), start_ymd.year, start_ymd.month + 1, start_ymd.day, lgj->StartDateTicks().ToDateFractRemainder(),
lgj->JoinDateTicks().base(), join_ymd.year, join_ymd.month + 1, join_ymd.day, lgj->JoinDateTicks().ToDateFractRemainder(),

@ -87,12 +87,12 @@ inline constexpr Year DateDeltaToYears(DateDelta date)
inline constexpr DateTicks DateToDateTicks(Date date, DateFract fract = 0)
{
return (date.base() * DAY_TICKS) + fract;
return ((int64_t)date.base() * DAY_TICKS) + fract;
}
inline constexpr DateTicksDelta DateDeltaToDateTicksDelta(DateDelta date, DateFract fract = 0)
{
return (date.base() * DAY_TICKS) + fract;
return ((int64_t)date.base() * DAY_TICKS) + fract;
}
inline DateTicks NowDateTicks()

@ -51,8 +51,8 @@ struct DateTicksOperations {
};
/* The type to store dates in when tick-precision is required */
using DateTicksDelta = StrongType::Typedef<int32_t, struct DateTicksDeltaTag, StrongType::Compare, StrongType::IntegerScalable>;
using DateTicks = StrongType::Typedef<int32_t, struct DateTicksTag, StrongType::Compare, StrongType::IntegerDelta<DateTicksDelta>, DateTicksOperations>;
using DateTicksDelta = StrongType::Typedef<int64_t, struct DateTicksDeltaTag, StrongType::Compare, StrongType::IntegerScalable>;
using DateTicks = StrongType::Typedef<int64_t, struct DateTicksTag, StrongType::Compare, StrongType::IntegerDelta<DateTicksDelta>, DateTicksOperations>;
/* Mixin for DateTicksScaledDelta */
struct DateTicksScaledDeltaOperations {

@ -284,7 +284,7 @@ void LinkGraphJobGroup::JoinThread()
DateTicks bucket_join_date = 0;
auto flush_bucket = [&]() {
if (!bucket_cost) return;
DEBUG(linkgraph, 2, "LinkGraphJobGroup::ExecuteJobSet: Creating Job Group: jobs: " PRINTF_SIZE ", cost: %u, join after: %d",
DEBUG(linkgraph, 2, "LinkGraphJobGroup::ExecuteJobSet: Creating Job Group: jobs: " PRINTF_SIZE ", cost: %u, join after: " OTTD_PRINTF64,
bucket.size(), bucket_cost, (bucket_join_date - NowDateTicks()).base());
auto group = std::make_shared<LinkGraphJobGroup>(constructor_token(), std::move(bucket));
group->SpawnThread();

@ -180,7 +180,7 @@ SaveLoadTable GetLinkGraphJobDesc()
SLE_VAR2(LinkGraphJob, "linkgraph.demand_size", settings.demand_size, SLE_UINT8),
SLE_VAR2(LinkGraphJob, "linkgraph.short_path_saturation", settings.short_path_saturation, SLE_UINT8),
SLE_VAR2(LinkGraphJob, "join_date", join_date_ticks, SLE_INT32),
SLE_VAR2(LinkGraphJob, "join_date", join_date_ticks, SLE_FILE_I32 | SLE_VAR_I64),
SLE_VAR(LinkGraphJob, link_graph.index, SLE_UINT16),
SLEG_STRUCT("linkgraph", SlLinkgraphJobProxy),
};

@ -109,7 +109,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_EXTRA_LARGE_MAP, XSCF_NULL, 0, 1, "extra_large_map", nullptr, nullptr, nullptr },
{ XSLFI_REVERSE_AT_WAYPOINT, XSCF_NULL, 1, 1, "reverse_at_waypoint", nullptr, nullptr, nullptr },
{ XSLFI_VEH_LIFETIME_PROFIT, XSCF_NULL, 1, 1, "veh_lifetime_profit", nullptr, nullptr, nullptr },
{ XSLFI_LINKGRAPH_DAY_SCALE, XSCF_NULL, 4, 4, "linkgraph_day_scale", nullptr, nullptr, nullptr },
{ XSLFI_LINKGRAPH_DAY_SCALE, XSCF_NULL, 5, 5, "linkgraph_day_scale", nullptr, nullptr, nullptr },
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 9, 9, "template_replacement", nullptr, nullptr, "TRPL,TMPL" },
{ XSLFI_MORE_RAIL_TYPES, XSCF_NULL, 0, 1, "more_rail_types", nullptr, nullptr, nullptr },
{ XSLFI_CARGO_TYPE_ORDERS, XSCF_NULL, 3, 3, "cargo_type_orders", nullptr, nullptr, "ORDX,VEOX" },

@ -83,8 +83,10 @@ SaveLoadTable GetLinkGraphJobDesc()
}
const SaveLoad job_desc[] = {
SLE_VAR(LinkGraphJob, join_date_ticks, SLE_INT32),
SLE_CONDVAR_X(LinkGraphJob, start_date_ticks, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_DAY_SCALE)),
SLE_CONDVAR_X(LinkGraphJob, join_date_ticks, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_DAY_SCALE, 0, 4)),
SLE_CONDVAR_X(LinkGraphJob, join_date_ticks, SLE_INT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_DAY_SCALE, 5)),
SLE_CONDVAR_X(LinkGraphJob, start_date_ticks, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_DAY_SCALE, 1, 4)),
SLE_CONDVAR_X(LinkGraphJob, start_date_ticks, SLE_INT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_DAY_SCALE, 5)),
SLE_VAR(LinkGraphJob, link_graph.index, SLE_UINT16),
};

Loading…
Cancel
Save