Jump to content
  • Advertisement
Sign in to follow this  
Mapster87

Problem: Too fast FPS in demo's from tutorials

This topic is 4528 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

It was hard to fiind a subject to describe my problem properly. Anyways, my problem is that when I run the examples you get in the tutorials they tend to run extremely fast, that is so fast that it's beyond 999fps. Is there anyway to solve this? I'm now on lesson 11 and the waves on the texture are so fast that it's damn ugly to look at.

Share this post


Link to post
Share on other sites
Advertisement
mesure the time it took to render the last frame (lets call it delta), then sleep for 1 / FRAME_RATE - delta.

Note that you need both sleep and time quering functions with good precisission for this to work (getimeofday, usleep on Unix systems).

alternatively you can calculate when the next frame should be drawn and add an idle loop at the end of you rendering code that does nothing as long as the current time is less than what you calculated for the next frame.

Share this post


Link to post
Share on other sites
Thx... I solved the problem, I made a simple function using the time.h header.
It doesn't contain any calculation of current framerate, all it does is run a loop for a given number of milliseconds, the given number is of your choosing. It works fine in theese simple turtorials at least. You just guess your way to a fitting number, to obtain the framerate you want.


void SlowdownFPS(int fps)
{
clock_t endwait;
int waitMs = 1000/fps;
endwait = clock() + utvid;
while (clock() < endwait) {}
}


Share this post


Link to post
Share on other sites
Oh, by FRAME_RATE I meant the limit you want to set for the framerate. For more complicated sceens (or if you target a wide array of hardware) it makes sence to take the time that the last frame took to render into account. Calculating the delta ist equivalent to 2 cals to clock and a substraction. So it isn't that much of an overhead.

busy wait is considered ok for games, but I still prefere sleep. Its nice if some long running process that runs in the backround still gets the uneeded processor time.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mapster87
Thx... I solved the problem, I made a simple function using the time.h header.
It doesn't contain any calculation of current framerate, all it does is run a loop for a given number of milliseconds, the given number is of your choosing. It works fine in theese simple turtorials at least. You just guess your way to a fitting number, to obtain the framerate you want.


void SlowdownFPS(int fps)
{
clock_t endwait;
int waitMs = 1000/fps;
endwait = clock() + utvid;
while (clock() < endwait) {}
}


For demo's/tutorials your solution is good enough. For games this would be a waste, as you are just throwing your cpu-cycles away. Most games use time-based animations, try searching for it on the forums.

Share this post


Link to post
Share on other sites
Just force vsync on your graphics drivers.

If you need help doing this, do you have ATI or NVIDIA?

Share this post


Link to post
Share on other sites
I don't have much experience in programming and I ran into a problem with measuring the time it took to render the last frame. I don't know how to convert the clock_t form to an int.

Anyways, I know it isn't good enough for a game, but at the moment I don't know a percent of what I need to make a game, though that's my goal.

edit:
Ahh.. that was another solution. worked fine that too Boder.

[Edited by - mapster on April 18, 2006 1:17:27 PM]

Share this post


Link to post
Share on other sites
VSync will be better for you, the method you were using works fine, but won't behave well on different hardware (or even on your own hardware if other tasks are taking up system resources as well).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!