Patch: Improved acceleration for road vehicles [In trunk]
Moderator: OpenTTD Developers
Re: Patch: Improved acceleration for road vehicles [v15-18750]
If you cast to a pointer to a derived type (with no other types derived from it), the compiler will normally inline virtual functions then too. It assumes that if you have cast to that type, it must be that type, and as there are no types that inherit from it it is safe to inline.
Melt with the Shadows,
Embrace your destiny...
Embrace your destiny...
Re: Patch: Improved acceleration for road vehicles [v16-18772]
Since the function is templated, I'm using a cast to the templated type instead of letting the compiler use virtual functions. I get a performance boost doing this, but the functions are not inlined. I suspect that the functions I need to inline are called without using vtables (hence the performance improvement), but the compiler still can't inline them (if they appear at gprof it means they are not optimized into something else). I don't know why using the templated type is not enough for inlining the functions, though
Anyways, I finally realized how to force the compiler to inline these virtual functions: removing them. I just commented out the virtual functions at the parent class (AcceleratedVehicle). Since the child classes still implement all methods, the code works. The resulting code for UpdateTrainSpeed is even faster than trunk, requiring only 83.2% of the time to execute (I'm using TIC TOC again, check this thread to see my method). This improvement over trunk code is caused by optimizations I have implemented at the various parts of the acceleration code (I have checked these results three times, feel free to check my data as I could have some mistake).
I know that using virtual functions at the parent class is the right way of forcing all child classes to define them. But since this optimizes a key part of the code and the code still fails at compile time if any of these functions is not defined at the child class, I think that removing them from AcceleratedVehicle is for the best. Right now the virtual functions are commented at the parent class, but I'd like to know which would be the best way of documenting that all children of this class must have these functions defined.
You can find the optimized v16 version at the first post.
Anyways, I finally realized how to force the compiler to inline these virtual functions: removing them. I just commented out the virtual functions at the parent class (AcceleratedVehicle). Since the child classes still implement all methods, the code works. The resulting code for UpdateTrainSpeed is even faster than trunk, requiring only 83.2% of the time to execute (I'm using TIC TOC again, check this thread to see my method). This improvement over trunk code is caused by optimizations I have implemented at the various parts of the acceleration code (I have checked these results three times, feel free to check my data as I could have some mistake).
I know that using virtual functions at the parent class is the right way of forcing all child classes to define them. But since this optimizes a key part of the code and the code still fails at compile time if any of these functions is not defined at the child class, I think that removing them from AcceleratedVehicle is for the best. Right now the virtual functions are commented at the parent class, but I'd like to know which would be the best way of documenting that all children of this class must have these functions defined.
You can find the optimized v16 version at the first post.
- Attachments
-
- data.ods
- (2.22 MiB) Downloaded 111 times
Spanish translation of OpenTTD
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Re: Patch: Improved acceleration for road vehicles [v16-18778]
I have uploaded a part of the patch (train realistic acceleration code reorganizations and optimizations) to flyspray: http://bugs.openttd.org/task/3524
It would be very helpful for the Improved acceleration for road vehicles patch if you help testing the patch found at the flyspray task: any game involving trains with realistic acceleration on will do. Report any bugs or problem to the flyspray task.
Edit: This part of the patch is now in trunk.
It would be very helpful for the Improved acceleration for road vehicles patch if you help testing the patch found at the flyspray task: any game involving trains with realistic acceleration on will do. Report any bugs or problem to the flyspray task.
Edit: This part of the patch is now in trunk.
Last edited by Terkhen on 17 Jan 2010 07:26, edited 1 time in total.
Spanish translation of OpenTTD
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Re: Patch: Improved acceleration for road vehicles [In trunk]
This feature (except some bits) is now in trunk. Happy testing!
Spanish translation of OpenTTD
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Re: Patch: Improved acceleration for road vehicles [In trunk]
Hooray! I saw this in the nightlies list. Great work! Gotta go try it out now.
Terkhen wrote:This feature (except some bits) is now in trunk. Happy testing!
Who is John Galt?
- andythenorth
- Tycoon
- Posts: 5658
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Patch: Improved acceleration for road vehicles [In trunk]
AwesomeTerkhen wrote:This feature (except some bits) is now in trunk. Happy testing!
I'll check it with HEQS soon!
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: Patch: Improved acceleration for road vehicles [In trunk]
- Yet another thing to do in AI
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Patch: Improved acceleration for road vehicles [In trunk
andythenorth: I kept using HEQS for testing. The articulated vehicles need some tweaking (they seem to need more tractive effort), but the standard ones work fine. Thank you for your help with this patch
Kogut: I wouldn't worry too much about the standard vehicles: as always, the newest road vehicle is always the best one.
Here is one of the missing bits from the original code: power, weight and tractive effort support for callback 36 (mind the p1). It should work, but it needs some testing before commiting it. A NewGRF to test these callbacks will be welcome
A note: I have seen that some existing road vehicle sets have unset values for some of their vehicles: these vehicles will move really slow if realistic acceleration for road vehicles is on.
EDIT: Air drag was commited in r20303, and support for CB36 was commited in r21058 and r21100. Since then, every feature that was once present in this patch has made its way to trunk. I really appreciate the help I had while developing this feature. Thank you!
Kogut: I wouldn't worry too much about the standard vehicles: as always, the newest road vehicle is always the best one.
Here is one of the missing bits from the original code: power, weight and tractive effort support for callback 36 (mind the p1). It should work, but it needs some testing before commiting it. A NewGRF to test these callbacks will be welcome
A note: I have seen that some existing road vehicle sets have unset values for some of their vehicles: these vehicles will move really slow if realistic acceleration for road vehicles is on.
EDIT: Air drag was commited in r20303, and support for CB36 was commited in r21058 and r21100. Since then, every feature that was once present in this patch has made its way to trunk. I really appreciate the help I had while developing this feature. Thank you!
Spanish translation of OpenTTD
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Who is online
Users browsing this forum: No registered users and 51 guests