New date format - #504
Conversation
…been added, though it may have been 1 value too high anyway
…r/simutrans-extended into 64-second-minute
| DATE_FMT_INTERNAL_MINUTE = 8, | ||
| DATE_FMT_JAPANESE_INTERNAL_MINUTE = 9 | ||
| DATE_FMT_JAPANESE_INTERNAL_MINUTE = 9, | ||
| DATE_FMT_64_SECOND_MINUTE = 10 |
There was a problem hiding this comment.
Add DATE_FMT_LENGTH = 11 or something like that. (See below)
| uint8 old_show_month = env_t::show_month; | ||
| sint32 current_tick = world()->get_ticks(); | ||
| for( env_t::show_month = 0; env_t::show_month<10; env_t::show_month++ ) { | ||
| for( env_t::show_month = 0; env_t::show_month<11; env_t::show_month++ ) { |
There was a problem hiding this comment.
Don't use hardcoded 11, use DATE_FMT_LENGTH instead (see above)
| { | ||
| private: | ||
| char time_str[10][64]; | ||
| char time_str[11][64]; |
There was a problem hiding this comment.
use DATE_FMT_LENGTH instead of 11
There was a problem hiding this comment.
100% agree. I started writing a separate test program to make sure I understood how to use maximum values in enums correctly before I changed anything in Simutrans, so it's good you have done this.
| // Long minutes are used by DATE_FMT_64_SECOND_MINUTE | ||
| // DBG_DEBUG("sprintf_time_secs()", "Current date format is %u", env_t::show_month); | ||
| // DBG_DEBUG("sprintf_timesecs()", "Current status of long_minutes is %d", long_minutes); | ||
| unsigned int minutes = seconds; |
There was a problem hiding this comment.
You can simply declare a variable without explicit initialisation:
unsigned int minutes;
| unsigned int minutes = seconds; | ||
| if (long_minutes) { | ||
| minutes = seconds / 64; | ||
| } | ||
| else { | ||
| minutes = seconds / 60; | ||
| } | ||
| unsigned int hours = minutes / 60; | ||
| seconds %= 60; | ||
| if (long_minutes) { | ||
| seconds %= 64; | ||
| } else { | ||
| seconds %= 60; | ||
| } |
There was a problem hiding this comment.
Those conditionals seem bloated and you kind of repeat yourself.
Better do this:
unsigned int minutes;
if (long_minutes) {
minutes = seconds / 64;
seconds %= 64
}
else {
minutes = seconds / 60;
seconds %=60;
}
unsigned int hours = minutes / 60;
minutes %= 60;
Still, you repeat yourself. So finally get rid of that repetition:
const unsigned int seconds_per_minute = long_minutes ? 64 : 60;
unsigned int minutes = seconds / seconds_per_minute;
seconds %= seconds_per_minute;
unsigned int hours = minutes / 60;
minutes %= 60;
…ate with BB nightly build 2202017)
…r/simutrans-extended into 64-second-minute
…22, a.k.a. Twosday)
…h BB 220223 if no more commits)
…r/simutrans-extended into 64-second-minute
New display setting for DATE_FMT_INTERNAL_MINUTE. Explanation at https://forum.simutrans.com/index.php/topic,21433.msg199126.html.