Archived

This topic is now archived and is closed to further replies.

Uthman

NewPost: Timing

Recommended Posts

OK- I''m in the middle of writing an extended RSN/MS3D tutorial, but I''m having a little trouble: Usually in my apps, I set max fps to 33.33. I acccomplish this by setting a DWORD fpsC = GetTickCount(); at the start of my game loop, and at the end of the game loop call a if(LockFPS==true) while(fpsC+30>GetTickCount()); 1000/30=33.33FPS. This usually works. But for some reason, in my MS3D Animation app, these lines of code cause my program to freeze on me (I think the model timer/animation code fights with it)- leaving me with only two choices- let the program run wild on some f00''z GeFource3''s or let the animation get off track on Voodoo 1.0''s. Anyone implement a clever fps locking scheme for apps with MS3D aniation? Uthman Apatira www.WiZ3Domain.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Time-based-physics is your friend. Multiply all your movement by the last frame''s time delta.


object.pos.x += object.vel.x * time_delta;
object.pos.y += object.vel.y * time_delta;


That way, it doesn''t matter what FPS it is running at.

Share this post


Link to post
Share on other sites
Hi Uthman,

I'm interested in your tutorial, but I think you are a bit misguided on the timing.

Most likely the tick count doesn't work with the timer being used (probably QueryPerformanceCounter, depending on the setup).
See the Timer and Win32Timer classes.

However, you shouldn't need to lock the frame rate - the skeletal animation tutorial and PortaLib both use the timer class mentioned to make sure the animation is played at the correct speed on any machine. So on a GeForce3 it will still play at the same speed as my TNT2. It will play at the same speed in software rendering too, but it will probably skip frames and look terrible

Have a look at the timer class and the Object3D class (I think it is in the model itself for the tutorial) to see how this is achieved, and just shoot any questions my way or back to the forum again.

Hope this helps!

~~~
Cheers!
Brett Porter
PortaLib3D : A portable 3D game/demo libary for OpenGL


Edited by - brettporter on August 8, 2001 9:19:13 PM

Share this post


Link to post
Share on other sites
hmmmmmmm now that you mention it- I think you are right! I have a dual monitor display- a voodoo5 5500 agp + 21inch monitor, and an ati all-in-wonder 4mb pci (1990 video card). WHen I move my app window from the voodoo to the ati- the animation gets choopy (drops to 4fps from 121 ) but it runs at the same speed :-D! My tutorial is almost done- I''m on day #4. If I get it done in time, I might present it at the XGDC, but I really wanted to be a spectator this year .

Uthman Apatira
www.WiZ3Domain.com

Share this post


Link to post
Share on other sites
it appears all is not fine- the animation runs well on both setups, however the movement does not.

If I move the animated object (Player1.x+=MoveAmount) it goes faster/slower depending on the framerate.. I think that I either have to lock the fps to get the same motion, or have to find some way of using the timer class or timedeltas to acheive it... but how?

Uthman Apatira
www.WiZ3Domain.com

Share this post


Link to post
Share on other sites
right now, what im gonna try is setting up a gametimer using the PL timer class, and at the end f each render, multiple the msec''s it took to draw that frame by some small value 0.00001 and use that to add to my movement. Ill tell u how it workz out..

Uthman Apatira
www.WiZ3Domain.com

Share this post


Link to post
Share on other sites
MoveAmount= float(GameTimer->getTime()-gt) / 10;
gt = GameTimer->getTime();

It works fine (give or take 0.1f) in all resolutions on the v5, on the aiw, the first move works, hence after the player does not move forward.

Uthman Apatira
www.WiZ3Domain.com

Share this post


Link to post
Share on other sites
I posted a reply to this, but it seemed to disappear in the ether....

Basically, just use the timer class as it is:
Timer *pTimer = Timer::getNewTimer();
double ms = pTimer->getTime();
I can''t remember if this is time since last call or time since reset() - there should be a function for each.

Now, if you want to go distance ''d'' after ''t'' seconds, then the actual distance ''ad'' is:

ad = d*(ms/(t*1000.0));

Hope that helps!





~~~
Cheers!
Brett Porter
PortaLib3D : A portable 3D game/demo libary for OpenGL

Share this post


Link to post
Share on other sites