Issue #303 resolved

Timer module initialization and precision

Boolsheet avatarBoolsheet created an issue

Dead variable

The love::timer::sdl::Timer class has an unsigned integer called time_init. It is set to 0 in the constructor and used as a subtrahend in Timer::getTime.

I believe its intended purpose was to offset the value SDL_GetTicks returns to 0 so love.timer.getTime always returns the seconds since initialization. SDL already takes care of that which makes time_init useless.

Precision loss

love.timer.getTime and love.timer.getMicroTime are affected by precision loss after 1.165 hours and 4.1943 seconds respectively. Switching from single precision to double precision floating-point numbers increases these numbers to more than a hundred years.

Of course that doesn't change the limitation by their time providers (around 49.71 days for SDL_GetTicks).

Comments (5)

  1. Boolsheet

    Alright, that did it.

    I noticed the 24 hour limit on getMicroTime again. I take this chance and propose another API slaughter. The new gained precision gives us a hundred years, let's drop that silly limit! ;)

    Attached a patch which drops the 24h limit and suggests some optimizations for Windows. Also attached a script that tests the 2 functions in another way. It shows function name, current value, smallest difference of two subsequent calls and then the 20 largest differences. Example:

       0.00000077 -- My system provides a resolution of 0.6 microseconds.
  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.