Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix travel times stored in the linkgraph #9693

Merged
merged 4 commits into from
Oct 29, 2022

Conversation

nchappe
Copy link
Contributor

@nchappe nchappe commented Nov 13, 2021

Motivation / Problem

This PR fixes a few problems with travel times in the linkgraph (#9457).

Description

To fix #9665, I added a member variable BaseConsist::time_since_last_loading that is incremented whenever current_order_time is, and that is reset when the vehicle loads cargo at a station, just like last_loading_station.

This fully fixes the travel times in the example savegame of #9665. I also tested with a go to depot order and with a basic conditional order.

Limitations

This PR needs a savegame upgrade.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@frosch123
Copy link
Member

The counter time_since_last_loading added here seems to be similar to last_station_departure_date from #9093.

Is it the same? or is there an important difference that makes it necessary to add two similar but distinct time stamps?

@nchappe
Copy link
Contributor Author

nchappe commented Nov 13, 2021

I thought about using a date, the code would be a bit simpler but it would be a bit less precise. More importantly, it would break when using the cheat that changes the current year. While working on this PR I found out that setting the current year does break date_of_last_service a bit in master, I will probably open a bug or a PR about that later.

The time I store does not exactly correspond to the date of last station departure because to fix #9665 the variable introduced by my PR has to be exactly the time since last_loading_station was last updated, which is very specific (see Vehicle::LeaveStation() for the exact conditions). So it makes sense to have three similar but separate variables current_order_time, time_since_last_loading and last_station_departure_date.

@glx22
Copy link
Contributor

glx22 commented Nov 13, 2021

Isn't it possible to just store current vehicle tick and do some math when the exact value is needed ? And remove most counters.

@nchappe
Copy link
Contributor Author

nchappe commented Nov 13, 2021

Without the time since last loading, you would probably need to store the date of last loading, which has its advantages (no need to increment the counters) and drawbacks (lower resolution, problems when using cheats and when reaching last valid year).

I grep'd for current_order_time to determine where I should increment time_since_last_loading, so assuming the former works fine, hopefully the latter will too.

@nchappe
Copy link
Contributor Author

nchappe commented Nov 13, 2021

I looked a bit more into your suggestion and I think _date * DAY_TICKS + _date_frac as an int64 would probably work as a tick counter. Should I replace the counter introduced in this PR with a timestamp in ticks and deduce the travel time from it?

@nchappe
Copy link
Contributor Author

nchappe commented Dec 20, 2021

As suggested, I replaced the tick counter with a date in the fix to #9665. I also added a trivial fix to #9708.

@nchappe
Copy link
Contributor Author

nchappe commented Mar 26, 2022

Could someone please have another look at this PR?

@nchappe
Copy link
Contributor Author

nchappe commented Jul 20, 2022

Ping. Cargodist is severely broken for some networks since OpenTTD 12.0 (#9665, #9708), and this PR aims to fix it.
I can always split it into several PRs if you are not convinced by some of the commits.

@LordAro LordAro requested a review from frosch123 August 29, 2022 19:07
LordAro
LordAro previously approved these changes Aug 29, 2022
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me, but I'd like another pair of eyes on it

(Please disregard that I screwed up the rebase, we can fix that on merge... or you can fix it :) )

@nchappe
Copy link
Contributor Author

nchappe commented Oct 29, 2022

I rebased onto master. #10035 makes the third commit simpler, I now use _tick_counter instead of _date_frac to compute durations in ticks.

@michicc michicc merged commit 8bf56f3 into OpenTTD:master Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Travel times stored in linkgraph are incorrect for all non-direct journey types
6 participants