Sorry if this question sounds a bit trivial, but I haven't been able to figure it out. I want to create a loop that will loop at a constant speed, taking into account that the functions within the loop will take up some of the time.
while(1) {
//loop exactly 1 second
dosomething();
}
Could someone please give an example? It should be accurate to the millisecond if possible, but any starting point will help. I've taken a look at sceKernelLibcTime (time_t *t) and sceKernelLibcClock (void), but I'm not sure how they work.
[EDIT] I just saw clock(), so I'll take a look at that.
I tried that =/. It worked fine, but the only problem is that I'm not exactly sure how long the doSomething() method takes to execute. Also, it may not have the same timing everytime. So I end up with 1 second plus a little tiny amount, but in a rhythm game, it adds up. I need something that can take into account the execution time of the method.
Do this, call the function that tells you the current time, save the value.
Call your method that needs to run, then call the time again. Subtract times, to see how long you need to sleep for.
I know that pseudo code is always easier than real code, and I know that there are functions for getting time, and sleeping, so it's just up to good ole mr. search to find them. :)
I just fixed some weird bugs in our codebase, which uses sceRtcGetCurrentTick() and sceRtcGetTickResolution() for timing. sceRtcGetCurrentTick() seems to return really huge values, which may be a problem if you are not careful. Bottom line: ALWAYS get sceRtcGetCurrentTick() at the start of your app, and subtract that value from any further calls you make to that function before you do any processing, or you'll likely run into overflows and precision issues.
If the execution loop is short, and you don't care about the actual value of the constant time you want to achieve, then you might find a simpler solution would be to use the waitForVblank functions - these should give you a pretty accurate 1/60 sec period, if that's useful.