Jump to content
  • Advertisement

Archived

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

Etus

Problem with timers and FPS

This topic is 5680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a problem regarding camera movement and animations. I''m currently developing a demo for NeHe''s contest, and I bumped into a problem - the movement and animation of things are tied to the FPS. I want to make the speed of movement and animation fixed - I don''t want it to change when the FPS changes. I looked at several tutorials, but none helped me. I want to create a speed that looks like 26 FPS. Thanks, Yuval

Share this post


Link to post
Share on other sites
Advertisement
It's curious, because the Nehe Base code uses an update function wich has a parameter that contains the time ellapsed since the previous call, thus you can calculate an animation without being tied to FPS.

[edit] ah, maybe you don't use the base code, in this case just have a look in the source.

----
David Sporn AKA Sporniket

[edited by - davidsporn on January 22, 2003 4:55:39 AM]

Share this post


Link to post
Share on other sites
Thanks a lot - I didn''t know that.
I was using a very old version of NeHe''s basecode.

Anyway, it''s working now.

- Yuval

Share this post


Link to post
Share on other sites
There are several ways to fix this problem. I haven''t looked up the updated code, but i ran into a similar problem before. The easiest way i found, was to base movement on the FPS. If its lower then you want, the unit of movement is increased. If the fps is higher then you want, the unit of movement is lowered. I dont know how nehe did it but i wrote a little thing about it a few threads down, the guy that said somthing about the CPU being used 95%.

Share this post


Link to post
Share on other sites
quote:
Original post by ThePretender
I dont know how nehe did it but i wrote a little thing about it a few threads down, the guy that said somthing about the CPU being used 95%.


From my memory, basically the solution is following :

in your main loop, you have 2 variables to store :
- the current time (GetTickCount()) just before calling the update function : let''s call it current_timer
- the last time the update function was called (initialised at the same value as current_timer) : let''s call it previous_timer

init :
current_timer = GetTickCount()
previous_timer = current_timer

loop:
current_timer = GetTickCount()
call your update with (current_timer - previous_timer)
previous_timer = current_timer

You may consider having a maximum valid value for (current_timer - previous_timer), in case the user switch to another app.

----
David Sporn AKA Sporniket

Share this post


Link to post
Share on other sites
this is a little off subject but how do u display the fps info or any text on the screen. is there a way to add a few lines of code to display the text on the HUD? every time i have tried i have ended up displaying text somewhere in the 3 dimensions of my scene.

Share this post


Link to post
Share on other sites
I have a little problem with the soltution mentioned above (decreasing movement rate when fps is high). if you do so, when you have higher fps, the program will call the movement (or other transformation) routine more times, than it does at lower fps, and it takes more hw resources. i dont really know if im right, but i had to tell this, becouse im really curious about it. so? what do you think?

Share this post


Link to post
Share on other sites
In my programs, the update of the program state and the rendering of the screen are separated.
My update() function returns true if rendering is necessary, I then call render() only in this case.

In your case, you have to choose an "ideal" best FPS (let's say 50 FPS), hence a maximal time period before rendering another frame (here 20 millisec). Thus you keep track of the time elapsed since last rendering, and the update function return true when (among other conditions) the elapsed time is longer than the time limit.

----
David Sporn AKA Sporniket

[edited by - davidsporn on January 24, 2003 2:05:00 AM]

Share this post


Link to post
Share on other sites
the other way is to keep watching fps, and calling the update routine if needed (e.g. in every 3th frame. i think its better in action oriented games where high framerate is essential)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!