News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

Sort files in Load Height Map dialog

Started by jk271, November 08, 2015, 06:23:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jk271

Currently, files in Load Height Map dialog are sorted according to time (of modification or creation or ...). Sorting according to time is nice with saved games, but not so much nice with height maps.

It would be nice if height maps are sorted by name. It it much easier (at leatst for me) to find the required map in list sorted by name than in a list sorted by date.

The attachment contains patch with solution to the above mentioned wish.

Dwachs

This is a nice idea. Might as well be applied to scenario selection. However, sorting the full list ruins the dialog, if scenarios from multiple locations are added (ie scenarios in program/pak/scenario and in addons/pak/scenario).

The right place to modify sorting would be imho upon insertion of entry in savegame_frame_t::add_file.
Parsley, sage, rosemary, and maggikraut.

jk271

Thank you for pointing to savegame_frame_t::add_file().

I am little bit lost with pointers and interators in the add_file() function.
I can sort the "enties" using the sort() function at the end of add_file() function, but it may be slow, if add_file() is called many times.
It gives me impression, that "entries" variable should be sorted according to some rule by default.
Can I use structure with defined order of its items (e.g. red-black tree) for "entries"? (Instead of slist_tpl)
I mean "Can" as "Is it acceptable to be included?"

How many items shell I expect to appear in maps directory for performance testing purposes?
Is 2000 items enough?

I was not aware of multiple location for maps, I will take them into account in reworked patch.

Dwachs

I was thinking of the following simple change to savegame_frame.cc:

add_file is already sorting the entries. There are two places (strcmp with date) that do this. These two comparisons could be replaced by virtual functions doing the comparison.

2000 items (savegames) should be more than enough to test. The current implementation already will not scale well with large amount of files.
Parsley, sage, rosemary, and maggikraut.

jk271

Quote from: Dwachs on November 15, 2015, 05:45:45 PM
I was thinking of the following simple change to savegame_frame.cc:

add_file is already sorting the entries. There are two places (strcmp with date) that do this. These two comparisons could be replaced by virtual functions doing the comparison.

2000 items (savegames) should be more than enough to test. The current implementation already will not scale well with large amount of files.

I did chages to the code as it  had been suggested.

I created virtual function compare_items(), defining the order. The default sorting is by file name. The dialog for saving and loading games sorts by time in descending order - it shall be sorted as it had been sorted.

Dwachs

Parsley, sage, rosemary, and maggikraut.