Hello,
I've recently gotten into PSP development, and I'm totally loving it! I have one question which I have not been able to find any answers for.
From the examples and such I've seen, the only way to do timing is through sceKernelLibcTime, which returns seconds. Is there any way to retreive time in milliseconds?
I'd like to do some simple 2d animations properly, but I've been unable to find any examples/documentation on precise timing.
Thanks in advance!
Timing
Re: Timing
clock() and gettimeofday() should both give you microseconds.vhong wrote:From the examples and such I've seen, the only way to do timing is through sceKernelLibcTime, which returns seconds. Is there any way to retreive time in milliseconds?
I'd recommend using SDL, there's plenty of documentation and example code on the net.I'd like to do some simple 2d animations properly, but I've been unable to find any examples/documentation on precise timing.
I've more recently started using the realtime clock. This gives you a fixed high-frequency timer and should be very reliable.
Example:
Example:
Code: Select all
u64 last;
u32 tickFrequency = sceRtcGetTickResolution();
sceRtcGetCurrentTick(&last);
while (1)
{
// get delta-time for current frame
u64 curr;
sceRtcGetCurrentTick(&curr);
float deltaTime = (curr-last) / (float)tickFrequency;
last = curr;
// ... do whatever you want with the delta-time
}
GE Dominator
I did a test of your claim, and I can safely say that it's false. :) Here's some info over the different methods used for timing and how often they can get called:
sceRtcGetCurrentTick() - around 511900 calls per second, or 1.953 microseconds per call.
gettimeofday() - around 120310 calls per second, or 8.311 microseconds per call.
4 times slower than using the RTC.
clock() - around 512500 calls per second, or 1.951 microseconds per call.
Actually slightly faster than the RTC, but I suspect this is because it returns a 32-bit value.
I don't know about you, but I'm sticking with the RTC timer mostly because it offers 64 bit values, and I like using native interfaces. Using gettimeofday() should be a big no-no if you want proper resolution. :)
sceRtcGetCurrentTick() - around 511900 calls per second, or 1.953 microseconds per call.
gettimeofday() - around 120310 calls per second, or 8.311 microseconds per call.
4 times slower than using the RTC.
clock() - around 512500 calls per second, or 1.951 microseconds per call.
Actually slightly faster than the RTC, but I suspect this is because it returns a 32-bit value.
I don't know about you, but I'm sticking with the RTC timer mostly because it offers 64 bit values, and I like using native interfaces. Using gettimeofday() should be a big no-no if you want proper resolution. :)
GE Dominator