Is it safe to use clock()?
A script kiddie tool I used a while ago it simply used ticks (ie, clock()) to do get sub second time. Some research seems to indicate it's bad, it might change if you swap to another computer that fails on a multiple of 66MHz
I want to have a character affected by many forces at once, IE: wind, gravity, weapons and jumping. Traditionally I get the players original position, and then add the time on this. But with these forces, I need to get a small amount of time since last update. Being dead accurate isn't important, but if your game runs twice as slow as it should there are going to be problems. Irrlichts getFPS() has problems, and I want to keep the code cross compatible.
How do you solve this problem?
Clock() for Frame Independent Animation
Thanks for your replies, Irrlichts timer tends to jump, but I realized such a small jump in time isn't noticeable. It still can be used for animations as long as I don't divide by the difference (newtime-oldtime is often 0):
I was scared off by irrlichts getTimer function because:
Would print out:
The time isn't updated every render loop.
Code: Select all
endTime = timer->getTime()
main loop{
// I use this variable to animate stuff
difference = timer->getTime() - endTime
// do stuff here
// end loop
endTime = timer->getTime()
}
Code: Select all
Itimer* timer = device->getTimer();
while(main loop) {
std::cout << timer->getTime() <<"\n";
}
Code: Select all
120
120
120
120
120
160
160
160
160
160
160
The system timer is only so accurate. The real issue is that the loop executes more frequently than the system timer updates. In a real program your main loop will do something that takes up some time, then you won't see the problem.torleif wrote: I was scared off by irrlichts getTimer function because:Would print out:Code: Select all
Itimer* timer = device->getTimer(); while(main loop) { std::cout << timer->getTime() <<"\n"; }
The time isn't updated every render loop.Code: Select all
120 120 120 120 120 160 160 160 160 160 160
Assuming the high performance counters are being used, you can check the timer update interval with a call to QueryPerformanceFrequency(). If the counters are not being used, then the GetTickCount() API is used (on windows) and I believe that function is subject to a 15ms update interval.
Travis
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
If you update to the SVN trunk, you'll get a fixed version that uses the HPC on Windows.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way