News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

Pull Request: Private Car Memory Compression

Started by PJMack, May 18, 2021, 02:52:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PJMack

Building upon the work the work of freddyhayward's pull request 343 (https://forum.simutrans.com/index.php/topic,20721.0.html), this pull request has the ways (weg_t) sharing the ordered_vector_tpl.  To do this, two static vectors of ordered_vectors are created, where the ordered_vector arrays are replaced with a handle (class private_car_route_map) containing the indexes of the vector, or in the case where there is only one element, that element.  This in itself would result in about 14% memory savings (assuming a worst case average of 4 two way roads per 1 four-way intersection where all such roads lead to more than two destinations in each direction), due to the reduction in overhead of storing empty ordered_vectors.

For additional memory saving, the vectors are where appropriate, assigned to the same index, or "linked", during the back-tracing stage of the routing procedure, reducing the redundancy.  Unfortunately, this modification comes with side effects.  In order to keep the add route procedure simple, roads can now have multiple routes to a single destination.  This is mitigated by having the cars choose one of the routes at random, which appears not to have a negative effect on traffic.  A commented out define statement (NO_PRIVATE_CAR_DESTINATION_LINKING) is placed in line 1973 of weg_t.cc where uncommenting it would disable the linking, but still have the memory savings as per the paragraph above.

The save file is designed for both forwards and backwards compatibility, however backwards compatibility comes the the caveat that if a file is saved with this pull request and loaded without it, cars may end up lost until routes are recalculated.  Forwards compatibility does not have such caveat.

jamespetts

Thank you very much for this. After a little testing, this has now been incorporated.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.