Sign in to follow this  
najmuddin

Blits per second

Recommended Posts

Greetings!

Before anything I must say excuse me for my english, I'm trying to do my best :).

I'm developing my first game in C++ using SDL. I blit all of the surfaces into one I call buffer and then I blit that one into the screen (as I used to do when I used Allegro). I'm not using delays, I just control the time in which each object is rendered but anyway, even if nothing has changed, the whole surfaces are blitted into the screen at every cycle of the game. My questions are:

1- Should I avoid blitting if nothing has changed?
2- What could be the consequences of that if the V-Sync is disabled and the game is running al high FPS?

Thank you !

Share this post


Link to post
Share on other sites

You should cap renderer refresh rate at the monitor refresh rate, typically 60 fps.  This doesn't mean that you limit the number of game cycles to 60 hz, only the blitting.  As long as you keep it lined up at monitor refresh rate, it is okay to disable v-sync.  Otherwise v-sync might be needed on slower systems.  When the program is refreshing every say half second and there is no v-sync, this will result in tearing artifacts or partially drawn passes in cases of high fps.

 

Now if nothing changes, simply copy your last output and refresh. Sometimes it is best to draw to another target like a texture or surface(aka software renderer), then blit that until something changes.

Share this post


Link to post
Share on other sites

Thank you... 

 

So. if I want to do it could I do something like this:

 

int timerA = GetTime();   // GetTime returns miliseconds after the code started
int timerB;

while(!Esc())
{
  timerB = GetTime();

  if((TimerB - TimerA) >= 16)  // 16 is the aproximation to 1000 milisecs. / 60.
  {
    blit(buffer, screen);
    timerA = GetTime();
  }
}

 

 

Is there a better way to set the blitting at 60Hz (without using that aproximate value)? 

Share this post


Link to post
Share on other sites

Abstract away.  Personaly now that I think about it, as long as you don't blit more than the monitor refresh rate you don't need to worry about this. This should only be implimented to slow down a fast program, v-sync can be used in place of it if you want. In the cases of slow programs just let er rip and use delta time to calculate movements based on time, rather than frame number.

class TimeDif(){
     long range = 16;
     long lastTime = GetTime();

     bool getDif(){
          long dif = GetTime() - lastTime;

          if(dif >= range){
               lastTime = GetTime();
               return true;
          }

          return false;
     }

}
Edited by kd7tck

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this