TerryCavanagh / VVVVVV

The source code to VVVVVV! http://thelettervsixtim.es/
Other
7k stars 559 forks source link

Simplify time formatting functions #858

Closed Daaaav closed 2 years ago

Daaaav commented 2 years ago

Changes:

(The commit message says it all:)

Here's my notes on all the existing functions and what kind of time formats they output:

This is kind of a mess, and there's a lot of functions that do the same thing except using different variables. For localization, I also want translators to be able to localize all these time formats - many languages use the decimal comma instead of the decimal point (12:34,56) maybe some languages really prefer something like 1時02分11秒44瞬... Which I don't know to be correct, but it's good to be prepared for it and not restrict translators arbitrarily to only changing ":" and "." when we can start making the system better in the first place.

I added a new function, UtilityClass::format_time. This is the place where all time formats come together, given the number of seconds and optionally frames. I have simplified the above-mentioned functions somewhat, but I haven't given them a complete refactor or renaming - I mainly made sure that they all use the same backend so I can make the formats consistent and properly localizable.

(And before we start shoving more temporary char buffers everywhere just to get rid of the std::string's, maybe we need to think of a globally used working buffer of size SCREEN_WIDTH_CHARS+1, as a register of sorts, for when any line of text needs to be made or processed, then printed, and then goes unused. Maybe help.textrow, or something like that.)

As for this commit, the available time formats are now more consistent and changed a little in some places. Leading zeroes for the first unit are now no longer included, time trial results and the Super Gravitron can now display hours when they went to 60 minutes before, and we now always use .CC instead of :CC. These are the formats:

Here's what changes to the current functions:

Spot the differences:

In a time trial Time trial menu In-game stats Super Gravitron highscore screen In the Super Gravitron In the normal Gravitron

Legal Stuff:

By submitting this pull request, I confirm that...

InfoTeddy commented 2 years ago

They look fine to me too, I'll merge if testing doesn't reveal anything bad...

flibitijibibo commented 2 years ago

Oh also, the scratch buffer idea makes sense too. It would definitely help avoid stack overflows which is probably less scary than the 2.2 days but is still worth being careful about.

InfoTeddy commented 2 years ago

Yep, I can definitely agree on that too.