Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What about less than a second?

Status
Not open for further replies.

serpento

Programmer
Jun 16, 2002
92
GB
I know that in time.h there is a time(NULL) function that returns the number of seconds scince something and I know how to use this to make things happen every second, for instance.

But what if you want more acurate than a second, for making things happen every 0.4 seconds for instance? -Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
I found a way to do it now. If anyone's interested its:
[tt]
#include <time.h>

clock_t lastFrame = clock();
float frameSpeed=(float)0.05;

void frameWait()
{
while (clock()<lastFrame+CLOCKS_PER_SEC*frameSpeed);
lastFrame = clock();
}
[/tt]
Then when I want to wait until its time for the next frame I just call frameWait(). -Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top