🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

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

1055 views

WooHoo

1015 views

:)

686 views

Newest Song

1155 views

A little bugger

1013 views

Entry

1000 views

Entry

929 views

Entry

846 views

Entry

855 views
Advertisement