Poll/RFQ on glfwSetTime

I’ve been mulling over time handling in glfw, and decided that I don’t really know what the intended use-case is for glfwSetTime. Does anyone actively use this function, or can think of a reason to keep it in the API in glfw 4 and beyond?

glfwGetTime is super-useful when you just want a floating-point time value without thinking too hard. glfwGetTimerValue and glfwGetTimerFrequency are for people who want to get more serious with time-related code, as they do not lose precision as the values get larger (theoretical problem when using floating-point). With both of these options, it is absolutely trivial for the user to subtract a “base time” from the returned value if they need to, rather than requiring glfw to do it internally.

In my eyes, removing glfwSetTime would have one main benefit: it would remove a potential failure point for multi-threaded programs (the function is not atomic, so the user already has to wrap it in some sort of synchronisation to avoid weird behaviour). Additionally, it would go to simplifying the API, which is in general A Good Thing™.

I’m admittedly biased against this function because of the time I tried to use (or abuse) it to keep track of frame deltas in a program I was writing, and inadvertently discovered that it misbehaved when called with negative arguments… it’s always fun trying to debug code where the behaviour depends on execution time!

What do you think?

1 Like

I agree. glfwSetTime should be removed and this is a good summary of why.