Sort train (vehicles) list

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

Post Reply
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Sort train (vehicles) list

Post by follow »

Hello,

I have implemented new feature -- possibility of sorting train list window by:
train number, train profit, train profit last year and train age.

I'm finding this very useful when managing large number of trains.

But have a few doubts...

First of all, should I directly submit the patch to Patch tracker on SourceForge?
Or rather clear all my doubts before doing so here?
I don't want to trash OTTD repository on SF with unwanted patches.

Another issue, is that I'm aware that my patch may be a bit CPU hungry.
I don't think that can affect any recent machine (mine doesn't at all), but
I would prefer that developers tell what they think about that kind of soulutions.

I was trying to follow way of how 'Industry Directory' sorting is done.
But for trains, I believe, storing presorted array is pointless (profits data keep changing
continuously).
So I end up on resorting train list on every WE_PAINT and WE_CLICK. And this may eventually affect some old machines.

I'm attaching screenshot and will add patch after I clean it up.

Of course it will be easy to enhance it for other vehicles as well....

BTW. Do you prefer patch against latest official version or aginast CVS (or whatever you call it)?

Jan
Attachments
Example: sort train list by profit last year
Example: sort train list by profit last year
trainlist_sort.png (46.61 KiB) Viewed 8380 times
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Re: Sort train (vehicles) list

Post by Darkvater »

follow wrote:First of all, should I directly submit the patch to Patch tracker on SourceForge?...
I don't want to trash OTTD repository on SF with unwanted patches.
All patches should go to the SF repository. If a patch is wrong or messy, comments, suggestions and maybe help (if we know how to do it) will be given on how to improve the patch. No patch will be flamed or shot down because of problems. The only issue is that of course the patcher, or coder should look on SF once in a while to see if comments have been added to his post/patch/bugreport (if he/she hasn't registered, and so SF cannot send an email notification).
follow wrote:Another issue, is that I'm aware that my patch may be a bit CPU hungry.
I don't think that can affect any recent machine (mine doesn't at all), but
I would prefer that developers tell what they think about that kind of soulutions.
You do have to keep in mind that OTTD not only runs on PXII with 3TB of mem, but also on handhelds or older P100 machines. Thus best would be to try to write the code as efficiently as possible.
follow wrote:BTW. Do you prefer patch against latest official version or aginast CVS (or whatever you call it)?
All patches should be made against the latest available SVN development version. That way you can test your code with the latest code, and the developers don't have to resolve any issues and conflicts that arise because the patch was made for an old version.

I have to ask around about this patch. There has already been such a patch [ 955500 ] All vehicles lists Sorting. It has however been turned down because the general idea was to have a different setup for vehicles. As I am not sure if this will be done in any short term :?
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

Ok,

So after all:

I understand performace issues, and that's way I'm asking if you fill
that one qsort of user all trains (or other vehicles) per WE_PAINT and WE_CLICK.
per train list window may be ok or not...

Also, should I spend any more time, to prepare the patch, or this is pointless,
because it will be rejected for the same reason as 955500 you reference.

To be honest, 955500 seems to be much superior than mine (but patch itself
is no longer available, only screenshot, so I can't test myself).

My personal opinion is that if you not currently reworking vehicles array, you should
generally accept these patches.
Just let people use it for a while (or years, who knows...).
Eventually maybe you can impose condition, that patch should be written in such
way that you can change behaviour to the initial one with one click (or rather #define)
This should be doable in general.

Thanks
Jan
msalters
Engineer
Engineer
Posts: 34
Joined: 16 Jun 2004 19:21

Post by msalters »

Real programmers know when qsort isn't quick. True, the trains list may become somewhat unsorted in time, but in general it's pretty well sorted. In such cases, bubblesort performs pretty well, and naive qsorts fail miserably. qsort is not designed for nearly-sorted lists but for general-purpose sorts. So you'd use it only the first time, and use bubblesort to stay sorted.
(bubblesort is the optimal sort when your list is already sorted :D )
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

follow wrote:My personal opinion is that if you not currently reworking vehicles array, you should
generally accept these patches.
Just let people use it for a while (or years, who knows...).
Eventually maybe you can impose condition, that patch should be written in such
way that you can change behaviour to the initial one with one click (or rather #define)
This should be doable in general.

Thanks
Jan
Yes, unfortunately patch has been removed. I have talked about reworking the list. When SVN is back up I will see if that can be done easily and in a short notice. If not, then I will add your patch, since I also do feel that that list really needs to be sorted.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

msalters wrote:Real programmers know when qsort isn't quick. True, the trains list may become somewhat unsorted in time, but in general it's pretty well sorted. In such cases, bubblesort performs pretty well, and naive qsorts fail miserably. qsort is not designed for nearly-sorted lists but for general-purpose sorts. So you'd use it only the first time, and use bubblesort to stay sorted.
(bubblesort is the optimal sort when your list is already sorted :D )
I understand your point, but you overlooked one think. My patch is (or will be) giving
possibility of sorting the list by different criteria, so assumtion that list is already
(nearly) sorted, will be wrong in most cases.

There is an option is to keep sorted lists (in currently selected criteria) for every vehicle type and for every player, and yes - you can bubblesort it then, but you need to keep all these lists in memory for all the time.

So you can save some CPU, but loose some memory. And this was my question in general.
To be told by somebody experienced, which approach he likes better.
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

Darkvater wrote: Yes, unfortunately patch has been removed. I have talked about reworking the list. When SVN is back up I will see if that can be done easily and in a short notice. If not, then I will add your patch, since I also do feel that that list really needs to be sorted.
Ok, thanks for looking at this.

If you fell that patch may be accepted, let me know (here). I'll cleanup the patch agains latest
SVN, and add sorting of all vehicle types.

Or earlier, I'll try to conatct autor of patch 955500 to resubmit it to SF.

Thanks again.
Jan
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

follow wrote:<blablabla>

There is an option is to keep sorted lists (in currently selected criteria) for every vehicle type and for every player, and yes - you can bubblesort it then, but you need to keep all these lists in memory for all the time.

So you can save some CPU, but loose some memory. And this was my question in general.
To be told by somebody experienced, which approach he likes better.
If you're swapping the vehicles as you sort them, surely you could just swap entries in the vehicle array? :?:
<!-- End Of Post !-->
Image
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

BobXP wrote:If you're swapping the vehicles as you sort them, surely you could just swap entries in the vehicle array? :?:
You not really want to do that. All kinds of other stuff depend on the correct index in the vehicles array. If you sort them there, you need to update those too; then the things that depend on them, etc. etc.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

BobXP wrote:If you're swapping the vehicles as you sort them, surely you could just swap entries in the vehicle array?
Argh...
To avoid confusion...

I do not sort vehicle records. I sort only indexes to them.
Otherwise it would mean awful memory copying...
(and of course I'm not touching original array)

Sorry I didn't initially post the patch for reference, but I would prefer to review
it and add missing parts before doing so.

Jan
Cipri
Engineer
Engineer
Posts: 14
Joined: 22 Jul 2004 16:55

Post by Cipri »

Would it also be possible to sort the train list by Engine-type?
I'm sure we've all sat there at one point scrolling all the way down trough that list, to upgrade older engines to newer ones ;)
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

Cipri wrote:Would it also be possible to sort the train list by Engine-type?
I'm sure we've all sat there at one point scrolling all the way down trough that list, to upgrade older engines to newer ones ;)
You can sort by age...at least I think you can.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
User avatar
bociusz
Traffic Manager
Traffic Manager
Posts: 131
Joined: 24 Jul 2004 11:04
Location: Hungary
Contact:

Post by bociusz »

That sounds great! It could be used not only for trains but road vehicles, ships, aircrafts. When will it be included in the nightly builds?
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

Not before vehicle array rework is done...
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 38 guests