[Patch] Virtual time

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

[Patch] Virtual time

Post by VVG »

Hello forum dwellers. This patch aims to bring back to life the Virtual time part of the old Improved timetable management patch by PhilSophus as a separate patch.

Here is an excerpt from original topic explaining what this patch is about:
PhilSophus wrote: Have you ever been annoyed that timetables in the game are measured in days or even an artificial unit like ticks? Than this feature is for you. It introduces a second time-scale to the game, the virtual time measured in hours, minutes and seconds. You can configure the relation between virtual time and the traditional scale (which I will call calendar-scale for now) with patch setting between 1 virtual seconds per tick and 4 vsecs/tick yielding the following relationships:

Code: Select all

vsecs per tick | 24 Virtual hours equal about
---------------+--------------------------------
1              | 3 years  73 days (38.4 months)
2              | 1 year  219 days (19.2 months)
3              | 1 year   24 days (12.8 months)
4              |         292 days ( 9.6 months)
---------------+--------------------------------
You can enable display of the virtual time in the status bar by patch setting. The patch setting timetable_in_ticks was changed to timetable_unit and allows you to choose between days, ticks, HH:MM and HH:MM:SS. This setting works for both displaying and setting timetables.

Note: Virtual times are a GUI level concept, i.e. internally ticks or days are used and conversion between virtual time and calendar scale happens when displaying or setting data. This is why the virtual time settings are purely client-side settings. It is safe to use different virtual time settings on different clients in multiplayer.
As of now, it doesn't modify savegames in any way, so it is safe to use a trunk save game for testing. However, it introduces two variables that are internally used to to achive proper conversion between virtual time and days/ticks, the actual units used by timetable. Ingame, it is not noticable. But, for the sake of not modifiyng savegame versions for now, they are not saved. As a result, you might notice that your start dates or travel times made with autofill can be a bit off if you save/load when any particular vehicle is in the middle of autofill or had its start date set but didn't yet start running according to timetable.

How it works: since vehicle always starts its timetable on midnight, a special offset value is calculated to adjust vehicle's lateness counter to simulate the starting of timetable at other times of a day than midnight. This offset value is not saved. So, if you want your vehicle to start at that particular time, it is a good idea to let it do so before saving. Ingame, you if you see the string "timetable will start at" instead of vehicle is on time/early/late, that means the timetable didn't start yet. This is the first variable, that is not saved.

Second variable is a rounding factor used in autofill. In trunk, autofill always rounds times to days, irregardless if you timetable in ticks or days.
With this patch, it rounds according with timetable unit selected. To days, to minutes, and no rouding for ticks and seconds. Default is days. If you save with vehicle in the middle of autofill, when you load a game it will round to days, despite whatever rounding factor you had when starting autofill.

I left them unsaved intentionally, to keep save games compatible with trunk.

Caring about them is not critical, since they revert to default behavior. It's here to clarify somethings in case your times a bit off.

Big thanks go to openttd devs and #openttd, who helped me tremendously to make this work!

Here is the screenie and the actual diff:
Attachments
Flunnwell Transport, 2170-07-25.png
Flunnwell Transport, 2170-07-25.png (31.46 KiB) Viewed 7049 times
vtrltmsstm-20779.patch
(54.49 KiB) Downloaded 337 times
openttd-custom-r20779M-Windows_NT.zip
(3.77 MiB) Downloaded 280 times
Last edited by VVG on 09 Sep 2010 23:18, edited 4 times in total.
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

Updated version of the patch against 20707r with a few additions:
1. Autofill now rounds time taken according to timetable unit selected.
2. Date cheat now skips 24h worth of time if timetable unit is HHMM or HHMMSS. This keeps arrival/departure times in sync with 24h cycle.
3. When reaching max year time will fall back 24h instead of 1 year if timetable unit is HHMM or HHMMSS.
Attachments
vtrltmsstm-20707.patch
(48.5 KiB) Downloaded 282 times
User avatar
Christopher
Engineer
Engineer
Posts: 94
Joined: 10 Aug 2010 20:30
Location: Clinton, United States

Re: [Patch] Virtual time

Post by Christopher »

There appears to be a slight issue. At first I thought the game was randomly crashing, but after a bit of experimentation I figured out that whenever two trains with timetables (complete or incomplete) use a station at the same time, the game crashes. perhaps the answer is somewhere in here...

Code: Select all

Stacktrace:
 [00] ./openttd(_ZNK12CrashLogUnix13LogStacktraceEPcPKc+0x43) [0x82a73b3]
 [01] ./openttd(_ZNK8CrashLog12FillCrashLogEPcPKc+0x102) [0x81ae652]
 [02] ./openttd(_ZNK8CrashLog12MakeCrashLogEv+0xc4) [0x81ae7a4]
 [03] ./openttd() [0x82a72de]
 [04] [0x9d0400]
 [05] ./openttd(_Z22UpdateVehicleTimetableP7Vehicleb+0x1a0) [0x8362840]
 [06] ./openttd(_ZN7Vehicle12BeginLoadingEv+0x162) [0x83a2652]
 [07] ./openttd() [0x83845a5]
 [08] ./openttd() [0x838c8c5]
 [09] ./openttd() [0x838e761]
 [10] ./openttd(_ZN5Train4TickEv+0x37) [0x838f5a7]
 [11] ./openttd(_Z16CallVehicleTicksv+0xd8) [0x83a3ac8]
 [12] ./openttd(_Z13StateGameLoopv+0x835) [0x8297315]
 [13] ./openttd(_Z8GameLoopv+0xd0) [0x8298a70]
 [14] ./openttd(_ZN15VideoDriver_SDL8MainLoopEv+0x1e1) [0x83b0a71]
 [15] ./openttd(_Z8ttd_mainiPPc+0xe5a) [0x829863a]
 [16] ./openttd(main+0x48) [0x82a7658]
 [17] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6) [0x334bd6]
 [18] ./openttd() [0x80e52d1]
You'll notice that there's mention of timetables and ticks in the stacktrace, which gives me reasonable suspicion that the patch is cause.
Image
Get Esperanto Town Names here! Also available on BaNaNaS!
Vi povas kuraci vian unulingvecon hodiaŭ per Esperanto!
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

Christopher wrote:There appears to be a slight issue. At first I thought the game was randomly crashing, but after a bit of experimentation I figured out that whenever two trains with timetables (complete or incomplete) use a station at the same time, the game crashes. perhaps the answer is somewhere in here...
You'll notice that there's mention of timetables and ticks in the stacktrace, which gives me reasonable suspicion that the patch is cause.
Unfortunatly, as i am no programmer, that stack trace is of no real use to me. The only familiar thing to me is updatevehicletimetable. This arises further questions: did you save/load a game while some of the vehicles had a start date set but not really started the timetable yet OR any of the vehicles were running with autofill on during save/load? There are 2 things that are not saved, but are required for proper work of the patch, so, for now it is advised to let the autofill finish or vehicle actually start its timetable before save/load.

If save/load is no the case here, i have no idea what might be wrong. In that case, i'd like step-by-step instructions how to trigger a crash to have any chance of figuring the cause.
User avatar
Christopher
Engineer
Engineer
Posts: 94
Joined: 10 Aug 2010 20:30
Location: Clinton, United States

Re: [Patch] Virtual time

Post by Christopher »

Also unfortunately, I'm not a programmer as well, just someone who really wants to use virtual time. The crash(es) (I loaded the savegame three times and let it crash to find the problem) occurred when I loaded a the savegame after playing on another game (first time.) The next two times I loaded it from the start screen. One train had a completed timetable and was unloading at its first stop, and the second train was new and its timetable was being autofilled, and it was on its last stop. I'm not exactly sure what you mean by letting a vehicle start its timetable, however.

Saving and loading might be the problem, but I can't be certain because I saved and loading plenty of times without crashes, but I only had one timetabled train. I only encountered problems once I added a second train and began to autofill the timetable.
Image
Get Esperanto Town Names here! Also available on BaNaNaS!
Vi povas kuraci vian unulingvecon hodiaŭ per Esperanto!
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

Here is a bit updated diff, that should also help with crashed caused by unsaved variables. It is still not advised to save/load if vehicle didn't start running a timetable or vehicle is in autofill mode. In these cases save/load will revert it back to default behavior.
Also, a simple workaround is loading a savegame in trunk build and letting it run for a bit - this should sort out issues caused by unsaved variables.

EDIT: A tiny bit updated diff.
Attachments
vtrltmsstm-20738.patch
(49.11 KiB) Downloaded 272 times
User avatar
Christopher
Engineer
Engineer
Posts: 94
Joined: 10 Aug 2010 20:30
Location: Clinton, United States

Re: [Patch] Virtual time

Post by Christopher »

Excellent, I appreciate it. I'll let you know if any new issues occur.
Image
Get Esperanto Town Names here! Also available on BaNaNaS!
Vi povas kuraci vian unulingvecon hodiaŭ per Esperanto!
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

Updated first post and the diff there with a bit cleaner and more commented code. r20758
bwong
Chief Executive
Chief Executive
Posts: 681
Joined: 06 Feb 2009 02:46
Location: Ontario, Canada
Contact:

Re: [Patch] Virtual time

Post by bwong »

can somebody compile this for me...
please? :(
Check out some of my work
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

bwong wrote:can somebody compile this for me...
please? :(
I updated the first post with a windows build.
bwong
Chief Executive
Chief Executive
Posts: 681
Joined: 06 Feb 2009 02:46
Location: Ontario, Canada
Contact:

Re: [Patch] Virtual time

Post by bwong »

thank you
just wondering, what trains are those in your screenie? is it the DB set?
Check out some of my work
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

bwong wrote:thank you
just wondering, what trains are those in your screenie? is it the DB set?
ICE3 from DBset and 683 Series EMU (Thunderbird) from Japanese train set
bwong
Chief Executive
Chief Executive
Posts: 681
Joined: 06 Feb 2009 02:46
Location: Ontario, Canada
Contact:

Re: [Patch] Virtual time

Post by bwong »

ahhh
is the daylength adjusted through this patch?
Check out some of my work
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

bwong wrote:ahhh
is the daylength adjusted through this patch?
No, daylength has nothing to do with this patch.

Updated first post once more with a new diff and bundle, fixed wrong asserts i had.
VVG
Engineer
Engineer
Posts: 13
Joined: 23 Aug 2010 05:55

Re: [Patch] Virtual time

Post by VVG »

tiny update, nothing gameplay wise, and a new windows build. see first post.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 8 guests