Entry

posted in Rhaal's Journal
Published February 01, 2005
Advertisement
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.
Previous Entry Entry
Next Entry Entry
0 likes 2 comments

Comments

noaktree
I always feel good when I fix a logical error. Cool! [cool]
February 02, 2005 06:56 AM
Rob Loach
Optimization makes me warm.
February 02, 2005 11:44 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Elitism

1000 views

WooHoo

959 views

:)

686 views

Newest Song

1101 views

A little bugger

959 views

Entry

940 views

Entry

876 views

Entry

791 views

Entry

801 views
Advertisement