Quote:
Originally posted by miky
Actually, I was looking more for a function that paused the current function. And I've already found one (and it's a lot shorter than yours). Here it is:
void wait(int delay)
{
t = timer;
timer = 0;
while(delay)
{
while(timer)
{
timer--;
delay--;
UpdateControls();
}
}
timer = t;
}
I would argue that is a very inefficient way to wait a specified amount of time. People with slow computers will likely end up waiting far longer than the desired interval, and fast computers might end up finishing faster than expected.
Use this instead.
// Halts execution for the specified interval, in centiseconds.
void Wait(int delay)
{
int timestamp = systemtime;
while (systemtime - timestamp < delay)
{
UpdateControls();
}
}
It should be noted, it's very similar to how Interference goes about his Wait() function. It just uses systemtime instead of timer. I don't use timer, ever, because I never have a need to modify the timer, because timestamps are way more efficient than manually altering builtin timer variables.
Also, depending on what you're doing, using wait functions aren't a very efficient way to approach things. If you're just trying to slow down something because it's moving too fast, you might consider what I call frame throttling.