Timing system? January 22, 2009, 08:30:32 pm I am currently trying to decipher the game code's timing system, and should appreciate any help from those who know how it works. Is "ticks" in karte_t a measure of the amount of time elapsed since the map was created, whether the game has been reloaded or not? If so, what is the unit of measurement? If not, is there such a measure? Quote Selected
Re: Timing system? Reply #1 – January 22, 2009, 10:02:55 pm ticks are milliseconds since the map has synchronized the last time. Typically it will be reload, but every 134 game year (with bit_per_month=18) it has the resynchronize to prevent overflows. (With 20, this is 134/4=33). The ticks are always relative to a starting of a month.There are also two kind of month: "Real month" and month with only three days, just according to the setting of the user. (This is one reason, while the setting in the schedule window are month based.)The shortest relyable unit of time across everything are the months. Quote Selected
Re: Timing system? Reply #2 – January 22, 2009, 10:27:25 pm Thank you for the reply - very helpful :-)The shortest reliable unit is the month? Hmm. Is there no way of counting the number of synchronisations or something similar...? Quote Selected
Re: Timing system? Reply #3 – January 22, 2009, 10:29:38 pm Ticks are never negative and always relative to the starting of a month; so you can use them, if you take care against underruns. Quote Selected
Re: Timing system? Reply #4 – January 22, 2009, 10:47:43 pm Aha, useful, thank you! But I'm not sure what you mean by "underruns" here - can you elaborate? :-)Edit: And can I ask for clarification on one thing (so that I don't have to spend hours testing it with a debugger to find out how it works): does the the number of ticks get reset to 0 at every new month? Or is there a separate measure than "ticks" that is so reset? What I am after doing is using month plus ticks to get a more precise form of timing, but need to know how to handle the ticks in order to do that.Incidentally, how does all of this fit in with speed? Say at the default 18 ticks per tag - how many ticks will it take for a vehicle travelling at 100kph to traverse 100 tiles in a straight line? Quote Selected Last Edit: January 22, 2009, 11:51:16 pm by jamespetts
Re: Timing system? Reply #5 – January 23, 2009, 09:16:44 pm ticks and speed have no relation; or rather I never tried to figured that out. But since the length of an hour is different depending on display options and the length of a tile is either 25m or 1km the discussion about real speeds is futile. Quote Selected
Re: Timing system? Reply #6 – January 23, 2009, 11:48:26 pm Ahh, thank you for the reply. Does the number of ticks get reset to 0 at every new month, incidentally...? Quote Selected
Re: Timing system? Reply #7 – January 24, 2009, 02:26:58 pm No, the ticks value gets onlz reset when loading or when close to overflow in the current month. Quote Selected
Re: Timing system? Reply #8 – January 24, 2009, 03:17:21 pm Thank you :-) If that is so, then, how does the saved game manage to remember not only the month, but the day, the hour and the minute? (I have tested: these values are accurately preserved on reloading). Edit: Looking carefully at the code, the "ticks" value is actually not reset at all. (There is some resetting code hidden behind conditional compilation, but that is turned off). Can I ask, Prissi: are you planning to add new resetting code or enable the currently disabled resetting code in the foreseeable future? Because, if you are not, the raw ticks value can be used quite happily for all kinds of timing. From my tests, approximately 50 years in gameplay produces approximately 132 million ticks. The ticks variable is an unsigned 32-bit integer, which can hold values of some way over 4 billion, so there is no danger of ticks overflowing if the game is played for a reasonably ordinary length of time (if people really want to spend years playing from 1400 to 2050, then it might be necessary to set the ticks to a 64 bit value, but that seems like a somewhat marginal case). Quote Selected Last Edit: January 24, 2009, 04:59:09 pm by jamespetts
Re: Timing system? Reply #9 – January 24, 2009, 07:57:21 pm resetting is done in line 2539ff in simworld.cc Quote Selected
Re: Timing system? Reply #10 – January 24, 2009, 08:25:53 pm Ahh, I see: you mean this code:Code: [Select]if(ticks>next_month_ticks) { ticks %= karte_t::ticks_per_tag; ticks += karte_t::ticks_per_tag; next_month_ticks = ticks+karte_t::ticks_per_tag; last_step_ticks %= karte_t::ticks_per_tag; }That (sensibly) only resets the ticks if there appears to be an overflow immanent; but, with an unsigned 32-bit integer (max. value: 4,294,967,295), that is unlikely to happen (if 50 game years produced approx. 132 million ticks, then a player would have to be playing for over one and a half game millennia at the default time setting for the ticks to overflow)! Quote Selected
Re: Timing system? Reply #11 – January 24, 2009, 09:03:23 pm There was one such player... I remember something related to timing had to be fixed about one year ago (?) because somebody played until year 25000 or something like that. Don't underestimate the way users can come up with bugs Quote Selected
Re: Timing system? Reply #12 – January 24, 2009, 09:19:50 pm It was actually the year 3624 if memory serves me right. This was possible, because in the old versions, the tick count was saved too. Quote Selected
Re: Timing system? Reply #13 – January 24, 2009, 09:32:12 pm Hmm, my tests show that the tick count is also saved in the latest versions. Quote Selected
Re: Timing system? Reply #14 – January 24, 2009, 09:35:08 pm Ahh, did comment this out. Most likely because the waiting stuff for convois was added. Quote Selected