[Feedback wanted] Different style vehicle movement code

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

madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

[Feedback wanted] Different style vehicle movement code

Post by madman2003 »

I'm experimenting with cutting train movement code in smaller chunks, and putting some movement functions into the vehicle class.

Functions like:

Tick()
Controller()
SingleVehicleMove()
FullVehicleMove()

I've attached what i have so far, no functional changes have been done.

The traincontroller function has been cut up into smaller parts, the rest has seen little modification. Aircraft just have a hook, because they work very differently.

I'd appreciate idea on how you would structure it, i also need to know if this viable, otherwise i will not continue working on it.

Note: This is a question to programmmers, not users wanting to test a feature.

EDIT: The entire train controller has been overhauled, with considerable performance improvement.

This also adds an m8, which contains slope information atm (5 of 8 bits).

Note: This includes a modified and optimized acceleration function based on the work of Zojj. I tried to contact him, but no responce for several days (and no post on this forum for about a week). I assume he's away, if objections from him arise i will modify the remainder of the code so it does not resemble his.
Attachments
split_new_19.patch
trunk revision r10454
(140.86 KiB) Downloaded 247 times
Last edited by madman2003 on 06 Jul 2007 16:45, edited 14 times in total.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

This last version (which i already posted yesterday) has a single Tick function for all vehicles.
If there are any ideas to further unify things, then don't hesitate to post.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

I've mostly unified the vehicle controllers, not perfect yet, but it's getting there.

EDIT: You are allowed to reply ;-)
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Post by l_Blue_l »

8) . Nice idea i like it. Just one question does it have much of an impact on game / network performance? I see you have also change the code to C++ nice work.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

l_Blue_l wrote:8) . Nice idea i like it. Just one question does it have much of an impact on game / network performance? I see you have also change the code to C++ nice work.
It's not very easy to compare with profiling, but i fairly sure the difference is minimal. The trunk seems to be a little bit slower(i did a cpu compare on a large savegame, this is a rough indication, nothing more), which is probably due to one performance optimisation i did.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

Some functions were made private and some small changes.
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

madman2003 wrote:Some functions were made private and some small changes.
Making functions private where appropriate is a very good idea :)

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Now that I have read the patch in a side by side diff I can tell you that it almost made me cry with joy.

I'm very pleased by the simple things like replacing self referencing variables with "this". For me at least it makes the code much more readable.

I like the unification effort as well, it should make it easier to make changes in the future.

About the need for a smoke handler in Vehicle that you question because it is only trains that has that currently: I think it is the right place for it, because some day some grf author might decide to put smoke on his latest steam ship or something like that.

If you keep this up I might start sending you fan mail ;)

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
User avatar
charlieg
Transport Coordinator
Transport Coordinator
Posts: 323
Joined: 08 Oct 2003 14:07
Contact:

Post by charlieg »

But is it going to get applied to the trunk? :?
Open source tycoon games
--
Free Gamer - open source and Free Software games
FreeGameDev forums - open source game development community
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

charlieg wrote:But is it going to get applied to the trunk? :?
I'm trying to redo train handling atm, not very succesfull so far, but once i feel it's ready i will ask for trunk inclusion.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Post by Rubidium »

Do not expect that we just apply your huge patch in one go. Small and simple patches is the way to go.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

Now is the time to show you what i've been doing the last week. I've changed the train controller, with considerable performance improvements. It has reached an acceptable state, so i've uploaded it. Due to the price (cpu power) of slope calculations, this is now stored in the map array (m8 has been added, first 5bits are used).

Let me know what you think of it.

EDIT: i would like to add that there are still minor graphical glitches, which need to be resolved.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

This is pretty much the final version, this includes an acceleretion based on the work of Zojj. I have been unable to reach him so far, if problems arise i will modify the code that resembles his.

I did cleanups, added more comment, some fixes.

There is one problem that i know, if a train hits the end of rail it will turn around and the distance between the first and second vehicle will be one unit longer. I will look at that problem in the near future.

Note that this acceleration is more realistic for maglevs (they won't go over mountains for example), i included an option old style beheaviour for people who have existing savegames.

It's time to speak up and let me know what you think.

If you have ideas how to split this for merging, then please tell, because as far as i know i could split it in 2 patches, maybe 3. Preferable is a single merge, but i know that isn't likely.
User avatar
Zojj
Engineer
Engineer
Posts: 97
Joined: 27 Apr 2007 17:58
Location: Vegas baby
Contact:

Post by Zojj »

madman2003 wrote:this includes an acceleretion based on the work of Zojj.
Ok by me!
I'm on the Zoloft to keep me from killing yall

My patches: Better graphs - Train acceleration - Crash rates
hertogjan
Director
Director
Posts: 560
Joined: 03 Jan 2006 20:45
Location: Netherlands

Post by hertogjan »

madman2003 wrote:Note that this acceleration is more realistic for maglevs (they won't go over mountains for example), i included an option old style beheaviour for people who have existing savegames.
Why won't maglevs go over mountains? I don't understand why it is realistic to assume that maglev trains cannot climb hills.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

hertogjan wrote:
madman2003 wrote:Note that this acceleration is more realistic for maglevs (they won't go over mountains for example), i included an option old style beheaviour for people who have existing savegames.
Why won't maglevs go over mountains? I don't understand why it is realistic to assume that maglev trains cannot climb hills.
This is mistake and it has been corrected in my working copy, a few people complained about this. I was blinded by a more tamed maglev beheaviour :-) I reverted it to old style beheaviour, so if anyone has a simple idea to restrict the massive acceleration of maglevs without killing the ability going over mountains.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

Updated version, it fixes the bug were the mass_on_slope would become incorrect when reversing on a slope. This also adds "this->" to all class based variables and functions (except static ones). As as i said, i undid the maglev thing. Feedback on what maglev should behave like and possible ideas to change beheaviour are considered.
madman2003
Engineer
Engineer
Posts: 116
Joined: 20 May 2004 17:21

Post by madman2003 »

The bugs that i know are solved now.
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

madman2003 wrote:The bugs that i know are solved now.
nice, better take a look then :)

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
User avatar
Zojj
Engineer
Engineer
Posts: 97
Joined: 27 Apr 2007 17:58
Location: Vegas baby
Contact:

Post by Zojj »

madman2003 wrote:if anyone has a simple idea to restrict the massive acceleration of maglevs without killing the ability going over mountains.
It looks like you ripped this line from my patch:

Code: Select all

max_te      =  num * 10000;  ///< 10,000N per car, limits early acceleration
Did it not work for you?
I'm on the Zoloft to keep me from killing yall

My patches: Better graphs - Train acceleration - Crash rates
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 16 guests