Advertisement

Timer and fps

Started by February 27, 2000 01:40 PM
1 comment, last by JD 24 years, 6 months ago
In my 3d demos I''ve been using timeGetTime() and always had rendering times somewhere in the 100ms range. So I took my constant velocity and multiplied by time in seconds and out comes a FLOAT value. Now I am doing 2d stuff and everyone knows that we move in pixels that are integers. So now I am getting my frames rendered below zero milliseconds using QueryPerformanceCounter() (to get better resolution below 1ms) and my time in seconds for frame is like 0.000615163 seconds. If this time value is multiplied by velocity of 20m/s the value still comes below zero thus I can''t move. I don''t want to increase the velocity vector because on slow computers I would then move huge amount per frame. I mean the time in seconds could be 0.1s multiplied by 2000m/s you get 200 pixel move per frame. Yet on very fast computers I don''t move at all. I''ve seen a lot of code that doesn''t take into consideration that the time delta between frames can go below 1ms then the code blows up (if using timeGetTime()). We can forget about timeGetTime() since very fast cpus will be able to process the frames below one ms, while there will always be slow computers and will take them 100ms to do the frame. How are people coping with this, or is there another way to get same movement per second while we''re rendering at 200fps or 1fps. I let the card spit out as many frames as necessary and really don''t want to limit the game to 30fps by throwing out frames on fast computers. Thanks for any help. Jerry
One thing that you might consider trying is to keep a running total of how far the object has moved in a float. Then, changes of less than one pixel will still be added in. Whenever this new variable reaches 1.0 or greater, you can move the object one pixel and reset the counter.

For example, if your calculations show that the image should move .25 pixels this frame, just add that value to the running total. After four frames, your image will move one pixel just like you want it to.

I hope that is helpful and answers the question that you had.
Advertisement
Thank you very much for that piece of advice. Before checking here if anyone answered my post, I did precisely that. My x_pos variable was an integer so I changed it to float and like you said it takes many frames before it reaches a 1.0 then 1.000001, 1.000002, etc... until 2.0 but it works Thank you for taking your time to answer my question, very much appreciated.

Jerry

This topic is closed to new replies.

Advertisement