Scheduled dispatch: Add per dispatch slot flags field

Add flag for slot re-use
This commit is contained in:
Jonathan G Rennison
2024-01-28 01:48:54 +00:00
parent dee611f5f3
commit 6c329871f1
11 changed files with 260 additions and 49 deletions

View File

@@ -132,15 +132,19 @@ static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waitin
btree::btree_set<DateTicksScaled> &slot_cache = dept_schedule_last[&ds];
/* Find next available slots */
for (auto current_offset : ds.GetScheduledDispatch()) {
if (current_offset >= dispatch_duration) continue;
DateTicksScaled current_departure = begin_time + current_offset;
for (const DispatchSlot &slot : ds.GetScheduledDispatch()) {
if (slot.offset >= dispatch_duration) continue;
DateTicksScaled current_departure = begin_time + slot.offset;
while (current_departure <= earliest_departure) {
current_departure += dispatch_duration;
}
/* Make sure the slots has not already been used previously in this departure board calculation */
while (slot_cache.count(current_departure) > 0) {
if (HasBit(slot.flags, DispatchSlot::SDSF_REUSE_SLOT)) {
/* Allow re-use of this slot if it's the last seen */
if (*slot_cache.rbegin() == current_departure) break;
}
current_departure += dispatch_duration;
}
@@ -151,7 +155,9 @@ static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waitin
*waiting_time = (actual_departure - date_ticks_base).AsTicks() - *previous_departure - order->GetTravelTime();
*previous_departure = (actual_departure - date_ticks_base).AsTicks();
slot_cache.insert(actual_departure);
if (!ds.GetScheduledDispatchReuseSlots()) {
slot_cache.insert(actual_departure);
}
/* Return true means that vehicle lateness should be clear from this point onward */
return true;