Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    11
  • comments
    26
  • views
    5909

Entry

Sign in to follow this  
Rhaal

328 views

5:55 PM - Stupid Optimization Tricks


I discovered a solution to a little problem I was having with tehtris. Input was slightly laggy, and I thought that I had some major resource issues going on! I passed it off as exactly that and decided that I didn't want to deal with it.

Well I was breaking up some code since main.cpp was getting too large, and it just jumped out at me!

void gsMainMenu()
{
// See if it's time to render a new frame.
if((SDL_GetTicks() - gTimer) >= FRAME_RATE)
{
// Handle user input.
InputMainMenu();

// Get rid of the last frame.
ClearScreen();

// Draw background image.
Renderer.Blit(*sfTitle, *sfScreen, 0, 0);

// Show the main menu text.
DisplayText(ftForgotLg, "Press any key.", 310, 300, 255, 255, 255);

// Display the backbuffer.
SDL_Flip(sfScreen);

// Set the timer.
gTimer = SDL_GetTicks();
}
}


My intentions were to have the frame rendered if the time was right. However, including the input handling into that if statement was causing input to only be read if it was time to render! Thus...

void gsMainMenu()
{
// Handle user input.
InputMainMenu();

// See if it's time to render a new frame.
if((SDL_GetTicks() - gTimer) >= FRAME_RATE)
{
// Get rid of the last frame.
ClearScreen();

// Draw background image.
Renderer.Blit(*sfTitle, *sfScreen, 0, 0);

// Show the main menu text.
DisplayText(ftForgotLg, "Press any key.", 310, 300, 255, 255, 255);

// Display the backbuffer.
SDL_Flip(sfScreen);

// Set the timer.
gTimer = SDL_GetTicks();
}
}


...is MUCH smoother! It's almost like I know what I'm doing.
Sign in to follow this  


2 Comments


Recommended Comments

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
  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!