Realtime 3.1-maybe-beta (12.2 base)

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

User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

How about an update for a change?

Post by SciFurz »

3.0k has waiting at depots enabled for all vehicles.
Trying to figure out where to inject the waiting for zaypoints, but that's been a real chore so far.

Found some code which would never seem to run, and I suspect there are more of those pieces around.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Update waiting at waypoint

Post by SciFurz »

Trains can wait at waypoints now, so I can build a train yard where trains can wait for a period of time while they're not fully loaded.
No more oversized stations or trains waiting uneccessarily.
I'll have to do the same for ships and buoys as well.

It took quite some effort to find out how and where to do this, even while looking into the JGR source code, who does this in a different manner and thus unfortunately didn't help much.
On the orther hand, I learned a new quirk (and pitfall) of the inner workings for future reference.

.
train_yard-01.jpg
train_yard-01.jpg (235.95 KiB) Viewed 3178 times
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Update waiting at waypoint

Post by wallyweb »

SciFurz wrote: 24 Jun 2022 13:21... even while looking into the JGR source code ...
Keep in mind JGR's recent addition of waypoints for roads.
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Re: Update waiting at waypoint

Post by SciFurz »

wallyweb wrote: 24 Jun 2022 13:51
SciFurz wrote: 24 Jun 2022 13:21... even while looking into the JGR source code ...
Keep in mind JGR's recent addition of waypoints for roads.
Oh, nice. Will have to see how he did that.
I had thought of adding road waypoints before but it would need the addition of graphics and the like, so when I would have added the road waypoint option to the source code, it would just look the same as a station at that time.
I simply used no unload/load road stations to guide vehicles and put road waypoints on the wish list.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Update waiting at waypoint

Post by wallyweb »

SciFurz wrote: 24 Jun 2022 14:57Oh, nice. Will have to see how he did that.
https://htmlpreview.github.io/?https:// ... llar_flags
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Pix or it didn't happen

Post by SciFurz »

Refactored the rail side of the FollowTrack functionality further today because I couldn't resist seeing how far I could go, and could go as far as pulling back to the TrackFollower usage in YAPF.
Further than that just failed to make it work and trains crashed into each other. I'll have to dig into the workings of YAPF to progress any further.

But, I do notice the effect on performance, and I did a little profiling again to see if and what changed under the hood.

First one is the vanilla version running the title game (not at the main menu but as actual game).
Process time is dominated by the FollowTrack routines for rail, which is why I first had a look there to see if I could improve performance.
The routines for road and water take up a lot less process time, as they also seem a lot less complex.
.
ttd-vanilla.png
ttd-vanilla.png (257.8 KiB) Viewed 3053 times
.
This is the game running on the current ttd-rt code (with the changes from today), and at a time factor of 1, meaning 60 ticks per day (a quarter faster than the original 74).
The FollowTrackRail processing takes up less time as can be seen by the comparative increase in size of the blitter processes.
The first column shows a much smoother difference in process time between functions with the dominant ones taking up less compared to underlying ones.
.
ttd-rt_x1.png
ttd-rt_x1.png (314.01 KiB) Viewed 3053 times
.
And this is the game running at time factor 7200, about a quarter of real time speed and my usual setting. FollowTrackRail processing has lessened again, and blitter routines
have become dominant again.
The first column shows the differences between function times have lessened even more.
.
ttd-rt_x2700.png
ttd-rt_x2700.png (252.01 KiB) Viewed 3053 times
.
These aren't exact tests, but they underline what I notice while running the game. I don't see much less CPU usage on the laptop, but when I run it at full speed, time passes faster
compared to the vanilla code. While profiling an earlier version, vanilla reached february while a run of about the same time had ttd-rt already in august.
I don't expect much improvement when I clean up the code for road and water because they aren't as process intensive as rail, but I suspect I can squeeze out more from YAPF.
But for that I'll need more motivation to take on that huge task. Or beer.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
Revenge_of_KioTheDev
Engineer
Engineer
Posts: 59
Joined: 14 Jun 2022 05:54

Re: Pix or it didn't happen

Post by Revenge_of_KioTheDev »

SciFurz wrote: 26 Jun 2022 21:14 But for that I'll need more motivation to take on that huge task. Or beer.
will this be enough? :bow:
User avatar
jfs
Tycoon
Tycoon
Posts: 1743
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Realtime 3.0-maybe-beta (12.2 base)

Post by jfs »

It would be really nice if you could do actual optimisation work in a way that can benefit the main branch of the game.
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Re: Pix or it didn't happen

Post by SciFurz »

Revenge_of_KioTheDev wrote: 26 Jun 2022 23:41
SciFurz wrote: 26 Jun 2022 21:14 But for that I'll need more motivation to take on that huge task. Or beer.
will this be enough? :bow:
*ponders* Hmmyeahh.. Still needs more alcohol content. :-p
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Re: Realtime 3.0-maybe-beta (12.2 base)

Post by SciFurz »

jfs wrote: 27 Jun 2022 07:19 It would be really nice if you could do actual optimisation work in a way that can benefit the main branch of the game.
The things I did aren't that difficult, but it means turning back on the decision to use C++.
No classes, no templates, no extra cruft that has no benefit over plain C. C++ is a theory that doesn't work in practice.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Update 3.0m

Post by SciFurz »

Cleaned up most of the road and water FollowTrack routines to match the rail one.
Moved train source code files to subdirectory vehicle.
Fixed the bug causing a crash when removing rail with a signal.
Some more minor cleanups.

Adding a seperate timetable struct to vehicles to register their own times, because in the current situation
shared orders also share the same times. I need to make some changes to orders anyway for when I integrate the
shunting patch.
I also need to add more strings for the order and timetable windows, making combinations relating to scheduled and wait times
and speed, and maybe even the current ones for loading and refitting. There will be a lot of text crammed into those lines.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Update 3.0n, now with extra picture

Post by SciFurz »

Added the prototype for vehicles with shared orders to keep their own arrival and departure times (not saved in savegame yet).
Wanted to use a vector but compiler complained too much, and adding my own conflicted with operator overload,
so I went even simpler with a currently fixed array for the times for 32 orders.

Was curious to see what I could do with the blitter class and skipped a couple of inheritances.
I skipped even more until the compiler complained about functions being pure, but then I found out the intro screen went blank.
Opening a savegame directly worked, until I tried to scroll the map and it all froze.
The few classes I skipped before the main screen stopped working already had an impact though. The blitter process takes up
less relative time now. Compare to the tests in the earlier post.
.
ttd-rt_blitter_mod-01.png
ttd-rt_blitter_mod-01.png (286.19 KiB) Viewed 2921 times
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Realtime 3.0-maybe-beta (12.2 base)

Post by ChillCore »

I have not played your version of the game (yet) and most likely I will not (lacking time to do so and such)

However, I did read the thread and am a little confused about your 'rant' about C vs. C++ ... any C code is valid C++ code ... so yeah?
If you want peak performance and go back to 'bare metal' you should go back to assembly/assembler, whichevs you want to call it


Meanwhile I agree with jfs, your talents could really beneft the main branch too ... It would be nice if you could and would ...
How much beer would that take? I can send some if needed ... :P
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Re: Realtime 3.0-maybe-beta (12.2 base)

Post by SciFurz »

ChillCore wrote: 29 Jun 2022 23:17 However, I did read the thread and am a little confused about your 'rant' about C vs. C++ ... any C code is valid C++ code ... so yeah?
If you want peak performance and go back to 'bare metal' you should go back to assembly/assembler, whichevs you want to call it
C code can be read by C++, but it's no longer the same as it was in the beginning when the few features of C++ were simply translated to C and then compiled.
C and C++ are two very different languages nowadays.
Peak performance from assembly and not wanting the overhead from unneccessary constructs like classes are not the same thing. I understand the appeal
of C++, I bought books about learning it many years ago, but all the promises of advantages that it was supposed to have are exaggerated and can be done
in C style (or even better in other languages) without the extra complexity and overhead. Discussions about C++ can be heated, but one has to face the pitfalls
of any language or code style because none are perfect.
ChillCore wrote: 29 Jun 2022 23:17 Meanwhile I agree with jfs, your talents could really beneft the main branch too ... It would be nice if you could and would ...
How much beer would that take? I can send some if needed ... :P
As I answered before, the changes in code are not difficult, I am by no means a proficient coder, but it means stepping away from the decision of using C++,
or at least the big features that aren't C-like. What I've done so far is use plain logic and keeping things simple to make the code readable and thus easier to
understand so I could make the changes that I wanted to.

The simpler things are, the more beer can be consumed before programming goes wrong. :-) Keep sending beer and I'll refactor all long functions clean code style
to begin with. ;-)
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Update 3.0o-oh

Post by SciFurz »

My original option to handle shared order timetables needed a lot of work so I looked at the alternative.
It still ended up as a lot of work, but the basics are done, shared vehicles have their own copy of the orders
and their own arrival and departure times, instead of pointing everything to one shared list.
Ctrl delete all orders will crash and timetable window doesn't refresh unles clicked now, I'll tackle that later,
but adding, deleting, moving, changing should all work.
This does not include already existing shared orders, because they are of the old linked version. You'll have
to unshare, delete all orders, and re-share to enable independent times.

One step closer to the complete revised timetabling.

Edit:
Trying to make the old shared configurations work is conflicting with the new method, so I'm dropping compatibility
for now. I'll try to add a translation for afterload later, or maybe I'll make a separate converter to convert old games
to new versions. Are there even so very old games to keep the compatibilty for more than a few older versions?
Old games should work by unsharing all vehicles in the vanilla version and loading that savegame.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Road vehicle bug

Post by SciFurz »

I was so busy with setting up a working train network that I didn't notice road vehicles cause a crash now.
I have to refactor the road vehicle process anyway like I did with trains so far, so it's not more work than
I had planned in the first place.

The trouble is trying to find the flow of events, the code doesn't read like a cleanly designed flowchart.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Preview 3.0p

Post by SciFurz »

I figured I haven´t torn enough guts out of the code, and begun removing implicit orders.
Well, not exactly for fun when I more or less had to for my plans anyway. I haven't completely removed
all implicit references yet, but the first test with a few busses and a single coal train worked, so here's
a preview.
Real orders are handled by their flags and vehicle status flags. No changing order types or inserting
implicit orders when all is done.

Replacement src directory for vanilla source:
ttd-rt_src-3.0p.zip
(9.05 MiB) Downloaded 73 times
.
Linux package:
openttd-12.2-linux-generic-amd64.tar.xz
(5.48 MiB) Downloaded 64 times
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Update 3.0q

Post by SciFurz »

Removed or commented out all references to implicit orders.

SNAFU :-p
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Update 3.0r

Post by SciFurz »

Progress will likely become slower, since changes I make now seem to trigger more side effects at various places
and take more time to straighten out. I can't even change some functions without ending up with a long list of linker
errors from the script source files where the mentioned function calls don't even exist.
I don't think this is a sign of a clean code base.

At least I was able to streamline some functions a little more.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
User avatar
SciFurz
Traffic Manager
Traffic Manager
Posts: 154
Joined: 13 Oct 2018 16:33
Contact:

Made reverse trains work again, update 3.0t

Post by SciFurz »

It took some isolating code and adding a manual trigger again, but it works.

During the time I worked on the code, I looked for a style to make multiple conditions (&& and ||) more readable, and I think
I created the final style for it. There's not much mention about style and formatting about this as it is for other parts of
code, so I had to see what worked for me. The added benefit is the ability to comment out individual conditions.
See ShouldStopAtStation() in order_cmd.cpp for an example.

I also began adding more blank lines between type definitions (3), functions (5), and other sections to make the code parts
more distinguishable from each other, and thus more readable.

And while I'm at it because wait time at stations doesn't work for road vehicles now (I did mention side effects, didn't I?)
I think I'll see if I can have them revesre at drive-through road stations as well instead of simply keep on driving into the same
direction.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 2 guests