Sorting vehicles also by name

Got an idea for a new feature in TTDPatch? Post it here.

Moderator: TTDPatch Moderators

Post Reply

What do you think about this suggested feature?

Poll ended at 12 Feb 2004 17:31

It's good, I would use it
9
64%
It's useless, who need that
1
7%
I really don't care
4
29%
 
Total votes: 14

User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Sorting vehicles also by name

Post by minime »

Adding the possibility of sorting the vehicle lists by different criteria was a wonderful idea, and definitely comes in handy at times. However, I've noticed that you can't sort the vehicles by names. This feature would be handy for those of us, who prefer to name the trains to organise them better, or possibly to achive more realism.
It could be that the reason for not implementing is that it's too hard to do, but maybe it's not. If I remember right, the current sorted lists are already cached to reduce the speed impacts - this could be used for this feature as well, since the list would need to be resorted only when a consist is created, deleted or renamed.
What do you guys think?

Cheers,
minime

P.S.: Keep up the great work! What you've done for this game is hard to believe, hats down to you all. :D
goalie
Route Supervisor
Route Supervisor
Posts: 406
Joined: 28 Aug 2003 14:54
Location: Düsseldorf
Contact:

Post by goalie »

it is good i would use it
User avatar
spaceman-spiff
Retired Moderator
Retired Moderator
Posts: 20634
Joined: 28 Jul 2002 07:08
Location: Belgium
Contact:

Post by spaceman-spiff »

I would use it, but I'm doing fine with the ones I have, if I need to replace a certain model, then I sort them by speed or cargo, that can do the trick
Well, back to work, lot's of it in the near future
Patchman
Tycoon
Tycoon
Posts: 7575
Joined: 02 Oct 2002 18:57
Location: Ithaca, New York
Contact:

Post by Patchman »

This is actually surprisingly difficult, due to the fact that some names are generated automatically and some are custom. Also the numbered trains should be sorted numerically, but custom named ones alphabetically. Note easy.
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Post by minime »

Interesting,
so basically by default the consist has a blank name. And whenever a consist with a blank name is encountered the game automatically refers to it by an automatically generated name. :idea:
Hmm, that would be a real PITA to sort, definitely harder than sorting by a single byte like in the case of the consist number. (wild guess, am i right?)
That's too bad, it would have come in handy at times, mostly with passenger trains.
Anyway, thanks for your reply and clearing this up. Good luck with further patching. :wink:

Cheers,

minime
Vloris
Engineer
Engineer
Posts: 108
Joined: 13 Jan 2007 22:39
Location: Enschede, The Netherlands
Contact:

Post by Vloris »

Hello guys,

First, sorry for digging up this old thread, but I would really like this functionallity.
Actually I tried looking at the sorting code in The Patch, and I think I added a working sort-by-name algorithm.
I 'solved' the problem of sorting generated names by ignoring them and putting them after the custom names in a rather random order.

Only the vehicles that have a custom name are being sorted. Attached is the patch file with my additions, this is against svn revision 1579.

There is one thing in my code I'm not sure is acceptable: to add another sorting method, I needed to have a text-id immediately following the already existing sorting methods text-id's.
As it is very discouraged to move text-id's around I was a little hesitant to do so, but the one that needed to be moved, sort_hint, was only used in a single place as far as I could see, so it should be no big problem I hope.

Please let me know what you think of my code, I'm open to all comments!
Attachments
ttdpatch-sort-vehicle-by-name-r1579.diff
My first try at improving ttdpatch, adds sort-by-name to vehicle list.
(2.75 KiB) Downloaded 198 times
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

There is one showstoper (ourtext.inc); all the rest are relatively minor quibbles:
In ourtext.inc:
When the comments say "make sure that the order above is unchanged", they do, in fact, mean that. And when they say "ADD NEW ENTRIES DIRECTLY ABOVE THIS LINE ONLY", they mean that too.
Leave sorthint where it was and add sortname at the end, or you'll break some of NewGRF's promises.

In sortlist.asm:
The imul should indeed be replaced with "mov esi, [esi+veh.name]; shl esi, 5". In things like this, which can be called every tick, speed reigns surpreme. It might also be preferable to use a movzx and drop the and, but I'm not quite sure exactly certain of the the desired effect there.

The addr macro is depricated. Although it will still work, there is no longer any reason to use it.

At .sortname and .continue, I would have used ~7 instead of -8.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
Csaboka
Tycoon
Tycoon
Posts: 1202
Joined: 25 Nov 2002 16:30
Location: Tiszavasvári, Hungary
Contact:

Post by Csaboka »

Oops, it seems sortlist.asm needs a minor update. Back when I was writing it, the text IDs were still movable, so it seemed easier to just assume they're always one block. I'll rewrite it to use an array of textIDs, but you'll have to wait for that until tomorrow, the day of my (hopefully) last exam.
Reality is that which, when you stop believing in it, doesn't go away.—Philip K. Dick
User avatar
Pookey
Route Supervisor
Route Supervisor
Posts: 448
Joined: 15 Nov 2005 02:39
Location: NSW, Australia

Post by Pookey »

Do we have another Patch Developer Vloris?
Posted by Pookey...

For Information on TTD Patch Click Here
For Information on Building a Network (FAST) Click Here
For Information on Building a Network as a Challenge (SLOW) Click Here
For Help on the Different Signalling Types Click Here
Before Asking a Question, Please use the Forums Search Function Here and if you do Ask a Question, Please Provide as much Detail as Possible.
If you do not get a Crash Log when TTDPatch Crashes, Follow the Olly Debug Instructions Here and Post the Resulting Screenshot with your Problem.

Image
Vloris
Engineer
Engineer
Posts: 108
Joined: 13 Jan 2007 22:39
Location: Enschede, The Netherlands
Contact:

Post by Vloris »

DaleStan wrote:There is one showstoper (ourtext.inc);
Yes, I understand now it should absolutely not be changed.
DaleStan wrote: In sortlist.asm:
The imul should indeed be replaced with "mov esi, [esi+veh.name]; shl esi, 5".
The sorting is actually not called everytick, it depends on your sortvehlist setting. The imul, as well as the -8, where shamelessly copied from somewhere else in the patch code. To find out where the vehicle-name strings where stored I got to patches/gotodeo.asm lines 1590 and further.
DaleStan wrote: The addr macro is depricated. Although it will still work, there is no longer any reason to use it.
Ah, that's the reason the last sort-method hadn't addr() wrapped around it and the other ones did :)
Pookey wrote:Do we have another Patch Developer Vloris?
I don't know, maybe :) I must say, this first attempt to change anything wasn't too hard for me. I havent felt to call the insane asylum the 00readme.txt warns me about!
Csaboka wrote:you'll have to wait for that until tomorrow, the day of my (hopefully) last exam.
Well, good luck with your exam!
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

Vloris wrote:
DaleStan wrote:In sortlist.asm:
The imul should indeed be replaced with "mov esi, [esi+veh.name]; shl esi, 5".
The sorting is actually not called everytick, it depends on your sortvehlist setting. The imul, as well as the -8, where shamelessly copied from somewhere else in the patch code.
Nothing wrong with shameless copying. I've done a fair bit in my day, and I should have said "may be called". The exact line between speed-optimized and size-optimized is often fuzzy and is definitely subject to interpretation. I'm rather biased against (i)mul and (i)div, but I don't have any particularly good reason for that.
Vloris wrote:I havent felt to call the insane asylum the 00readme.txt warns me about!
You'll get there. Don't worry. :p
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
Csaboka
Tycoon
Tycoon
Posts: 1202
Joined: 25 Nov 2002 16:30
Location: Tiszavasvári, Hungary
Contact:

Post by Csaboka »

DaleStan wrote:I'm rather biased against (i)mul and (i)div, but I don't have any particularly good reason for that.
Well, according to the AMD Athlon Code Optimization Guide I downloaded some time ago, IDIVing with a 32-bit number can take up to 43 clocks. OTOH, the slowest version of IMUL (IMUL reg32, mem32, imm8) takes 18 clocks, the others can take up to 9 clocks. I guess the relative numbers are roughly the same for other CPUs. So here is your reason for not liking (I)MUL and (I)DIV. :)

In general, you should avoid (I)DIV in frequently executed code whenever you have an alternative. (I)MUL isn't that bad, but it may be worth replacing the slowest form with a MOV and an IMUL reg, imm. And, of course, for multiplying with powers of two, SHL is always preferred to (I)MUL. You can also use some LEA trickery to multiply with 3, 5 and 9.
Reality is that which, when you stop believing in it, doesn't go away.—Philip K. Dick
User avatar
m3henry
Tycoon
Tycoon
Posts: 1985
Joined: 15 Feb 2006 12:00
Location: Hampshire

Post by m3henry »

I can fit lots of clocks in my computer, but I dont have enough clocks yet. :wink:
The occasional look back at your past can teach you a great many things...
Vloris
Engineer
Engineer
Posts: 108
Joined: 13 Jan 2007 22:39
Location: Enschede, The Netherlands
Contact:

Post by Vloris »

Csaboka wrote:I'll rewrite it to use an array of textIDs, but you'll have to wait for that until tomorrow, the day of my (hopefully) last exam.
Or I have to do it myself :wink:
Here is the improved version of my patch:
- no more imul's but nice shl's;
- fixed the textID list by using an array 'sorttexts'
- undid the offensive change in ourtexts.inc, now I very nicely only appended one entry to the end.
- removed the deprecated addr() macro. (Maybe for clarity, they can be removed from all the entries in sortfuncs, but that has nothing to do with my patch so I didn't)

*edit*
Ow, damnit... stupid bug, there was another bit of code that relied on the order of the sort texts. I updated the attachment with the fix.
Attachments
ttdpatch-sort-vehicle-by-name-r1590.diff
(3.41 KiB) Downloaded 176 times
User avatar
Csaboka
Tycoon
Tycoon
Posts: 1202
Joined: 25 Nov 2002 16:30
Location: Tiszavasvári, Hungary
Contact:

Post by Csaboka »

Vloris wrote:Or I have to do it myself :wink:
Heh :D I was going to do it today, but you beat me to it.
Reality is that which, when you stop believing in it, doesn't go away.—Philip K. Dick
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Post by minime »

Considering I've requested this long long time ago, I'd like to thank both of you for implementing this. :D

Regards,
minime
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. --Albert Einstein
Image Image Image
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Post by wallyweb »

I'm running r1593 but I don't see this yet ... Has it been committed? Do I need to set a switch? I have sortvehlist 10.
User avatar
Csaboka
Tycoon
Tycoon
Posts: 1202
Joined: 25 Nov 2002 16:30
Location: Tiszavasvári, Hungary
Contact:

Post by Csaboka »

Please wait until tomorrow - Vloris reminded me to commit it, and I did so today. On the positive side, though, I've modified it a bit so it sorts unnamed vehicles by consist number.
Reality is that which, when you stop believing in it, doesn't go away.—Philip K. Dick
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Post by wallyweb »

Csaboka wrote:Please wait until tomorrow - Vloris reminded me to commit it, and I did so today. On the positive side, though, I've modified it a bit so it sorts unnamed vehicles by consist number.
ok :D
/me returns to the "picky,picky" bin for something else in need of nitpicking.
Post Reply

Return to “Suggestions”

Who is online

Users browsing this forum: No registered users and 19 guests