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.