Page 1 of 2
[Feedback wanted] Different style vehicle movement code
Posted: 21 Jun 2007 21:43
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.
Posted: 23 Jun 2007 09:41
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.
Posted: 23 Jun 2007 18:28
by madman2003
I've mostly unified the vehicle controllers, not perfect yet, but it's getting there.
EDIT: You are allowed to reply

Posted: 23 Jun 2007 23:31
by l_Blue_l

. 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.
Posted: 24 Jun 2007 09:55
by madman2003
l_Blue_l wrote:
. 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.
Posted: 24 Jun 2007 10:41
by madman2003
Some functions were made private and some small changes.
Posted: 24 Jun 2007 11:21
by kaan
madman2003 wrote:Some functions were made private and some small changes.
Making functions private where appropriate is a very good idea

Posted: 24 Jun 2007 12:01
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

Posted: 26 Jun 2007 09:13
by charlieg
But is it going to get applied to the trunk?

Posted: 26 Jun 2007 16:50
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.
Posted: 26 Jun 2007 17:17
by Rubidium
Do not expect that we just apply your huge patch in one go. Small and simple patches is the way to go.
Posted: 03 Jul 2007 14:53
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.
Posted: 05 Jul 2007 20:13
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.
Posted: 06 Jul 2007 04:11
by Zojj
madman2003 wrote:this includes an acceleretion based on the work of Zojj.
Ok by me!
Posted: 06 Jul 2007 08:19
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.
Posted: 06 Jul 2007 08:57
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.
Posted: 06 Jul 2007 09:26
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.
Posted: 06 Jul 2007 16:46
by madman2003
The bugs that i know are solved now.
Posted: 06 Jul 2007 17:13
by kaan
madman2003 wrote:The bugs that i know are solved now.
nice, better take a look then

Posted: 06 Jul 2007 17:44
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?