[C SDK] High resolution timer has only millisecond precision

In the C SDK playdate->system->getElapsedTime() seems to return results that are based on milliseconds and not microseconds as described in the documentation. You cannot get value below 1ms. The issue is only when running on the console.

The equivalent function in the lua SDK is more precise and work as expected.

2 Likes

Still occurring with SDK 1.11.1.

This should be resolved in the next release.

2 Likes

I've confirmed it's fixed with 1.12.0 on the device. :+1:

2 Likes

Dear,

Although it is now possible to get a value with a float, the timer value may be swapped back and forth when the value is obtained in succession.

static int update(void* userdata)
{
    PlaydateAPI* pd = userdata;

    pd->system->resetElapsedTime();

    float t1 = pd->system->getElapsedTime();
    for (int i = 0; i < 100; ++i)
    {
        float t2 = pd->system->getElapsedTime();
        if (t1 > t2)
        {
            pd->system->logToConsole("ERR(%2d): t1:%.5f > t2:%.5f", i, t1, t2);
        }
        pd->system->drawFPS(0, 0);
        t1 = t2;
    }

    return 1;
}

This is a sample source.

In this case, t1 <= t2 should be the case, but t1 > t2 may be the case only when executed on a device.

This does not occur in the simulator.

Curiously, commenting out pd->system->drawFPS() prevents this from happening.

HDTimerTest.zip (3.9 KB)

A sample reproduction test is attached.

$ rake build:simulator:debug
$ rake build:device:debug
$ rake run

This procedure will start the simulator, so transfer it directly to the device and check the console log.

Best regards.

1 Like

Thanks for the test case, I have a fix ready to go, and it will make it into a release in the near future.

Dear,

I'm sorry for the late confirmation, but I have verified that it has been fixed in version 2.3.1.
Thank you for the correction.

1 Like