Archived

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

Frame Rates

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

I got the blitting part of the sprite engine down, and I move onto animation, basically just moving from one piece of the sprite to the next every frame, but this is way too fast. Now I can use a timer to slow rendering down, but that seems kind of stupid, you''re wasting valuable processor time sitting in a timer loop while you could be processing other graphics... how do I solve this? -Paul-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You could for example use one thread for updating the screen (blitting, flipping or whatever..) and another one driven by a timer for updating the animation.

-Ring0

Share this post


Link to post
Share on other sites
Use interpolation, or "time based" animation. This type of animation is independant of frame rate and everyone see''s the same thing.

I think there is some info on it in the articles section, but you can also check out www.angelcode.com.

¬_¬

Share this post


Link to post
Share on other sites
For tile/sprite based animation interpolation isn''t the way to go. Interpolation is for 3D graphics. Tiles and Sprites have a limited number of displayable frames and there''s only so many pixels on the screen.

The better solution is to lock the frame rate. There are a couple ways of doing it.

The best way is to use two if statements to create a min and max timeframe to draw a frame. If it''s too soon, don''t draw anything. If it''s too late, don''t draw anything. Using this method you can keep processing everything else like keyboard input even though nothing is being updated to the screen. This method forces every computer to run at least your maximum frame rate so everything moves consistantly but drops frames if a PC can''t keep up. Which is no different than interpolation in 3D.

You can see how this is implemented by looking at the source code for the Gang Wars client.

The other method is using a while which halts your program until enough time has passed and then moves on. This is generally what the old school programs use. If you have nothing better to do, it''s a perfectly acceptable way of doing it. At 30FPS the player isn''t going to notice. However if the computer is running too slow, your program will drag. That''s what the double if method I use corrects.

The main reason I use the double if is because it''s an MMO and there''s constantly messages comming in that need to be handled. The game loop ends up running at thousands of iterations per second while only 30 frames are drawn to the screen which is a perfectly acceptable rate for tile/sprite based games.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

Share this post


Link to post
Share on other sites

  
FramesRun++;
if(GetTickCount()-LastFrameRender > 30 * FramesRendered)
{
if(GetTickCount()-LastFrameRender < 30 * (FramesRendered+1))
{
render_frame();
lpDDSPrimary->Flip(0, NULL);
}
FramesRendered++;

//process everything else even though nothing is drawn

//like user input


if (GetTickCount()-LastFrameRender>1000)
{
FPS=FramesRun;
FramesRendered=0;
FramesRun=0;
LastFrameRender=GetTickCount();
}
}


Everything outside the first if will run as fast as possible. Everything in the first if will run at 30FPS or lower. Everything in the second if will run at exactly 30FPS or not be called.

If you allow text entry, putting it in the first if is a pretty good idea so you don''t have to use an extra timer to keep input from being read too fast if they can enter text. There''s nothing more annoying than trying to type a key and having several letters come out.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

Share this post


Link to post
Share on other sites
quote:
Original post by Dovyman
Now I can use a timer to slow rendering down, but that seems kind of stupid, you''re wasting valuable processor time sitting in a timer loop while you could be processing other graphics...


Yeah, a lot of people say that locking the frame rate is a poor way of controlling animation.



¬_¬

Share this post


Link to post
Share on other sites
quote:
Original post by KalvinB
If you don''t lock your frame rate all you end up doing is drawing the same exact frame over and over and over.



You might draw the same sprite-frame over and over, but the movement of the sprite relative to the screen might change over time. Locking frame rate is a bad idea.

Basically, it all boils down to describing things in terms of Something per second or Something per frame. They are interchangeable, assuming you know the elapsed time between frames (which you can easily find). If they are interchangeable, why cripple the framerate?

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

Share this post


Link to post
Share on other sites
"You might draw the same sprite-frame over and over, but the movement of the sprite relative to the screen might change over time. Locking frame rate is a bad idea."

Depends on the game and how you do movement. As I edited into my post, Diablo II has a locked frame rate. It wouldn''t benefit from interpolation and a variable framerate because it''s purely tile based movement. You can move those 32 pixels between tiles in 32 fps or 100000 fps and it''ll look exactly the same. By locking the frame rate they freed up the CPU to handle things like AI.

2D top down shooters like Raptor or whatever would probably use interpolation since they use non-tile based movement. They use more math and physics instead of simple addition and subtraction.

They''re not entirly interchangable. Interpolation keeps you graphics card moving while the 2 ifs give it a break if it''s not needed.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

Share this post


Link to post
Share on other sites
You are correct - for some games (chess, for instance), it might not be bad to lock frame rate. There are whole classes of games where the notion of continuous framerate doesn''t make a lot of sense.

On the other hand, time based animation is not just for 3D. Asteroids is a 2D game for which locking the framerate would be a bad idea.

The original posting was fairly vague and time based animation is still the better general answer (IMHO). I have seen many postings where people need help getting used to time based animation. Once they understand that, it is trivial for them to revert to frame based movement if that makes more sense.

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

Share this post


Link to post
Share on other sites
Note that you are not REALLY locking the frame rate. locking the frame rate is when you put something like "sleep(30);" or an infinite loop in your render cycle so that it slows down everything. That is why people say locking the frame rate is a horrible idea.

¬_¬

Share this post


Link to post
Share on other sites
This is interesting, when I asked about locking the framerate a while back, I was told how terribly stupid that was, and that I should use time based animation instead, and here you go, telling Dovyman to do just that.

For Sprite Animation, I use a timer value in the sprite struct. and every frame I check if that timer value has been reached with a check to the main system timer.

basically I use gettickcount to init a value at the start of the rendering, and then I just update that every frame. And store a value in my sprite struct, of the gettickcount from the last sprite frame, plus the time I want it to take until the next update.
Then when I reached that value, I change the sprite frame, and update the sprite.timer with gettickcount + time until next anim frame.

Makes sense?

It''''s nice to be important, but it''''s more important to be nice.

Share this post


Link to post
Share on other sites
what CrazedGenius said in his first post has made the most sense to me out of these options. To me it makes more sense to allow drawing to occur as fast as possible, but control the movement of the objects on the screen in a time based manner.
How do you implement something like that? (ill probably just try both and see what works best for me)

-Paul-

Share this post


Link to post
Share on other sites
quote:
Original post by CrazedGenius

On the other hand, time based animation is not just for 3D. Asteroids is a 2D game for which locking the framerate would be a bad idea.




I have to lock my asteroids clone framerate otherwise it''ll run too fast. This is how I did this:

I lock the physics, movement, and AI to 60 frames per second, but the blitting and flipping as fast as it can go. Try my game from my signature. You''ll see what I mean.

Or did you mean something else?



Beyaan

Share this post


Link to post
Share on other sites
I know this is an old thread but I used the trusty search engine and this was the topic I was looking for. Now after reading this I get:

tile based games are ok to lock fps
3d use interpolation.

I am working on an isometric multiplayer game and want all the computers to be in sync. Should I be looking at something completely different or go with the locking the fps?

GRELLIN

"I installed a skylight in my apartment...The people who live above me are furious."

Share this post


Link to post
Share on other sites