In my program(C++), I'm going to use callback functions to process input from the keyboard and mouse and constantly draw a scene. How these functions process information will change depending on the state of the program; like I would have certain functionality assigned to several keys, say the arrow keys move the highlighter in the main screen, but I want their functionality to change in another screen. I'm using OpenGL with GLUT, and it's possible to change the keyboard function for example by assigning a different function pointer to it.
The method I used in the past was to define multiple processing functions, each one for a specific task. For example, I have a keyboard for the main menu, but when a different screen is viewed, the function is changed by assigning the appropriate function pointer:
glutKeyboardFunction(MainMenueKeyboardFuncPtr);
But now, I'm wondering if using conditional statements within one function is a better approach.
My question is: are there any performance issues with the conditional functions approach? I'm thinking to define a single function, say for the keyboard, to process keyboard input in all situations:
void KeyInputProcess(int key)
{
select(SCREEN)
{
case MAIN_SCREEN:
select(key)
{
/*process input*/
}
break;
case OPTIONS_SCREEN:
select(key)
{
/*process differently from MAIN_SCREEN*/
}
break;
}
}
Would the checking that takes place every time the function is called have a significant impact on the performance? Which approach is better if I want to maximize performance?