Author Topic: Good and passenger transfer on stations  (Read 1299 times)

0 Members and 1 Guest are viewing this topic.

Online Ves

Good and passenger transfer on stations
« on: May 01, 2017, 07:08:06 PM »
I am working to get the good that is transferring on a station from a vehicle to another, and have made some progress. The actual good that is transferring is now a visible list in the good section of the station window along with how long time until it is 'done' transferring.
What I come to notice is that one not equals one:
A train with 64 coal empties its load in a station and a bunch of good shows up as transferring. However, only 8 'pieces' of good shows up and the
Code: [Select]
sprintf(transferring, "%i %s", halt->get_transferring_cargoes_count(), translator::translate("units transferring"));which I have made visible, also shows 8.
I would expect this number to be 64 and I would expect there to be 64 entries of 'coal' that is transferring.

How should I handle this you think?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #1 on: May 01, 2017, 07:14:41 PM »
Are you possibly confusing the number of packets with the size of  the packets? Passengers, mail and goods come in packets that may have different sizes: the total number is the number of units in each packet added together, not just the number of packets.
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.

Online Ves

Re: Good and passenger transfer on stations
« Reply #2 on: May 01, 2017, 07:25:00 PM »
Aahh, its the number of packages! Ok thanks, I will look in the code to see if I can extract the number of good in each packet! Thanks

Online Ves

Re: Good and passenger transfer on stations
« Reply #3 on: May 06, 2017, 01:49:23 PM »
I managed to get it to show up on the station window in a good way I think:



It took a while to figure out, but I ended up having simply added this to the get_freight_info()
Code: [Select]
vector_tpl<ware_t> ware_transfers;
ware_t ware;
const sint64 current_time = welt->get_ticks();

#ifdef MULTI_THREAD
sint32 po = world()->get_parallel_operations();
#else
sint32 po = 1;
#endif

for (sint32 i = 0; i < po; i++)
{
FOR(vector_tpl<transferring_cargo_t>, tc, transferring_cargoes[i])
{
ware = tc.ware;
ware_transfers.append(ware);
}
}
// show new info
freight_list_sorter_t::sort_freight(ware_transfers, buf, (freight_list_sorter_t::sort_mode_t)sortierung, NULL, "transferring");

and the freight_list_sorter_t takes care of all the sorting stuff. That means that it now sorts the same way as the waiting good is sorting. Im not sure if all those sorting options is needed or how it should otherwise sort, but I do like how the freight_list_sorter is putting it all in nice categories. I was thinking of adding another sort criteria that sorts everything by remaining time.

The window is not finished in its layout either, there should be some more distinction between the waiting good and the transferring good to avoid confusion.

I need to find a way to get the remaining transferring time into the freight_list_sorter, so I can use that and compare. There doesnt seem to be any really good get_xxxx to get the information. Would I have to create those my self?

Also, Im having troubles with updating the window automatically. Now I think it updates at the same time as the other good in the window, due to it being put under the "if (resort_freight_info)". If not putted under there, it will just repeat itself in eternity!
I guess however, that I will have to have a resort_transfer_info which would work the same way as the resort_freight_info, I just cant figure out where to put the resort_transfer_info=true that would be used to call the window?
« Last Edit: May 06, 2017, 02:02:03 PM by Ves »

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #4 on: May 06, 2017, 02:12:04 PM »
Excellent - this is looking very good! Thank you for your work on this. You will probably want to remove the "xxx packages transferring" from the top of the window, as that was a crude debugging implementation of what you have now done properly, and will be confusing if maintained.

There is no straightforward method for getting information as to the remaining transfer time at present, as there is nothing that would use such a method. The only way of extracting these data is as shown in void haltestelle_t::check_transferring_cargoes(): see tc.ready_time (and see also the ready_seconds, ready_minutes and ready_hours as a method of extrapolating the user-friendly time from the internal measure of time in ticks: these methods are actually unnecessary in check_transferring_cargoes() and were inserted for debugging, so I am about to push an update in which these are commented out, but you might find similar code useful for sorting the cargo by ready time.

As to when to update the window, if this does not automatically update at the right times, then I suggest that you insert a call to the method for updating it into the method for adding transferring goods to the stop's list of transferring goods.
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.

Online Ves

Re: Good and passenger transfer on stations
« Reply #5 on: May 06, 2017, 02:39:26 PM »
Thank you!
Yes, the xxx packages transferring is planned to be scrapped, I just  keep it there for debugging, as I know (or very much higly assume) that that is correct and I can see if that shows a number but my new window shows zero, then somethings wrong!

Ok, yes I will add a call (resort_freight_info = 1) to the check_transferring_cargoes(). I add it inside the FOR(vector_tpl<transferring_cargo_t>,tc, transferring cargoes) loop right?

I have figured out how to show the times if I show it directly from the simhalt.cc. What Im unsure about is how to forward that to freight_list_sorter_cc? the check_transferring_cargoes() is declared as private, so I cant take from that

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #6 on: May 06, 2017, 03:18:01 PM »
You wouldn't call check_transferring_cargoes() from anything in the UI (as this would cause desyncs in multi-player games among other problems); instead, you'd use similar code to extract the waiting time from the transferring_cargoes vectors to display them in the dialogue without actually altering them in any way.
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.

Offline Vladki

Re: Good and passenger transfer on stations
« Reply #7 on: May 09, 2017, 08:16:17 PM »
Wow, this would be very nice when included.

Online Ves

Re: Good and passenger transfer on stations
« Reply #8 on: May 13, 2017, 08:35:45 PM »
hmm.. Im struggling a bit:

I think I have decided to go with the approach to use the freight_list_sorter, like I wanted to initially doo. In there one get some nice sorting mechanic like the picture shows. Now I want to add a sort by_transfer_time, as I think that would be quite handy. I think I have successfully created one part of the sorting mechanism in the freight_list_sorter_t::compare_ware:
Code: [Select]
case by_transfer_time: // Should only be used with transfer goods
{
const sint64 current_time = welt->get_ticks();

transferring_cargo_t tc1;
transferring_cargo_t tc2;
tc1.ware = w1;
tc2.ware = w2;
const uint32 rs1 = world()->ticks_to_seconds((tc1.ready_time - current_time));
const uint32 rs2 = world()->ticks_to_seconds((tc2.ready_time - current_time));


int const order = rs2 - rs1;
if (order != 0)
{
return order < 0;
}
/* FALLTHROUGH */
}
I have not had a chance to test it yet, as it is the actual building of the list that I am struggling with and that is holded in freight_list_sorter_t::sort_freight.
In there, there are a bunch of wlist entries and I want to add a similar entry, but where it is the ready_time that is used. But since ready_time is not a part of way_t, I struggle to make it work. How would I make the way_t look for the ready_time? I have tried to pair it in different ways, like I did in the section above, but without luck.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #9 on: May 13, 2017, 09:33:10 PM »
Thank you for your work on this. However, I am a little confused as to the relevance of way_t here - can you elaborate?
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.

Online Ves

Re: Good and passenger transfer on stations
« Reply #10 on: May 13, 2017, 10:48:39 PM »
If you look in freight_list_sorter.cc you will find a section which is called: freight_list_sorter_t::sort_freight and there you will find declared that ware_t *wlist; and later on wlist[ pos ] = ware;
That wlist[ pos ] are used to put the pieces of freight together in the forthcoming section and all the sorting parameters are taken from ware_t.
I need to take the ware, pair it with transferring_cargo_t, so it gets the ready_time, and then make it work with the [ pos ] and [ i ]. It is that conversion I am a bit unsure of.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #11 on: May 13, 2017, 11:55:23 PM »
Did you mean ware_t instead of way_t?
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.

Online Ves

Re: Good and passenger transfer on stations
« Reply #12 on: May 14, 2017, 05:08:59 AM »
Oh, im sorry, yes I mean ware_t and not way_t :p

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #13 on: May 14, 2017, 09:42:28 AM »
In which case, your question makes much more sense!

The trouble is that the ready time data that you wish to implement is not a member of ware_t, so you will have to find another way of getting these data to the method. There are many ways of potentially doing this (e.g. adding parameters to the method with default values of zero or UINT32_MAX_VALUE and only passing actual values to these when the ware_t packets are part of a transferring_cargo_t class), and you have some flexibility as the sorting algorithm here is not very computationally intensive, but one solution that you should not use is to make the times part of the ware_t packets themselves, as this would add an additional 8 bytes to every single packet of goods, passengers or mail in the game, which could be significant in a very large game (especially in terms of memory bandwidth) and is unnecessary.

I hope that this has helped.
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.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #14 on: May 20, 2017, 08:15:21 PM »
If you are having trouble with adding a feature to sort by waiting time, may I suggest that you leave that for the time being and complete the feature (if it is not already complete) without that? It can always be added later, after all. May I ask whether this GUI work is now complete except for the sorting by transfer time?
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.

Online Ves

Re: Good and passenger transfer on stations
« Reply #15 on: May 20, 2017, 11:29:44 PM »
I have also had a bit of trouble to get the waiting time to show correctly. Firstly to make it show the correct value of the remaining time (which should be a clock that is ticking down), and secondly to make the clock tick down automatically. It tend to freeze and stay so for a moment. I have made several variations of the window using different approaches and all with different results, but all with major flaws (the one I screenshooted being without the actual times).

I have had lots of work this week, so I have not been doing alot of work on this recently, but I hope I will get some time in next week, maybe even tomorrow. I could finish it to the state of the screenshoot, which i think is working properly, if you like?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #16 on: May 20, 2017, 11:59:20 PM »
Splendid, thank you for your work on this - sorry that you are having trouble. I am more than happy with a finished version of what you put in the screen-shot - that would be splendid. Thank you again for this.
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.

Online Ves

Re: Good and passenger transfer on stations
« Reply #17 on: May 21, 2017, 11:38:29 AM »
So, there should be a working version now on my github here: https://github.com/VictorErik/Simutrans-Experimental-Ves/commits/station-window

I have commented out some of my attempts to make it sort by the time for the future. You can decide if you want to keep that or you want to throw them away and start from scratch later on. Therefore, the only file that actually is changed to give the current representation of the window is the simhalt.cc (edit: and the translation files, obviusly!). The rest is commented out remnants from some of my attempts.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #18 on: May 21, 2017, 12:58:16 PM »
Now incorporated - thank you very much! I am just about to upload the translation texts to the translator, incidentally.
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.

Online Ves

Re: Good and passenger transfer on stations
« Reply #19 on: May 21, 2017, 01:06:16 PM »
Thanks!
Regarding the translation texts, I was hoping to be using that new file to incorporate future translations, would that still be possible?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 15816
  • Total likes: 404
  • Helpful: 177
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Good and passenger transfer on stations
« Reply #20 on: May 21, 2017, 01:11:01 PM »
Thanks!
Regarding the translation texts, I was hoping to be using that new file to incorporate future translations, would that still be possible?

It is best to use a separate file for each set of features so that we do not keep uploading the same file with the same translations in it.
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.

Offline Jando

Re: Good and passenger transfer on stations
« Reply #21 on: May 22, 2017, 10:34:48 PM »
Many thanks for this new feature. Good job!

Now I can see where all the coal is that I was missing. :)