i am confused what i am doing is right or wrong?
currently storing the state of the each key and checking it in the game loop like this
eHandler->getKey(EVENT_KEYS::KEY_LEFT_CTRL);
if it returns true than do something.
//this function is called by the function, which is passed as callback to the glfw library
void eventHandler::keyBoardHandler(int key , int scancode, int action, int mods)
{
if(action!=GLFW_KEY_UNKNOWN)
switch (key)
{
case GLFW_KEY_A:
{
if(action==GLFW_PRESS||action==GLFW_REPEAT)
{
my_keys.KEY_A=true;
if(currentCamera->TP_PERSPECTIVE)
character_controller->moveLeft(currentCamera);
}
break;
}
case GLFW_KEY_B:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_B=true;
}
break;
}
case GLFW_KEY_C:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_C=true;
}
break;
}
case GLFW_KEY_D:
{
if(action==GLFW_PRESS||action==GLFW_REPEAT)
{
my_keys.KEY_D=true;
if(currentCamera->TP_PERSPECTIVE)
character_controller->moveRight(currentCamera);
}
break;
}
case GLFW_KEY_E:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_E=true;
}
break;
}
case GLFW_KEY_F:
{
if(action==GLFW_PRESS||action==GLFW_REPEAT)
{
my_keys.KEY_F=true;
}
break;
}
case GLFW_KEY_G:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_G=true;
}
break;
}
case GLFW_KEY_H:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_H=true;
}
break;
}
case GLFW_KEY_I:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_I=true;
}
break;
}
case GLFW_KEY_J:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_J=true;
}
break;
}
case GLFW_KEY_K:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_K=true;
}
break;
}
case GLFW_KEY_L:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_L=true;
}
break;
}
case GLFW_KEY_M:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_M=true;
}
break;
}
case GLFW_KEY_N:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_N=true;
}
break;
}
case GLFW_KEY_O:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_O=true;
}
break;
}
case GLFW_KEY_P:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_P=true;
}
break;
}
case GLFW_KEY_Q:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_Q=true;
}
break;
}
case GLFW_KEY_R:
{
if(action==GLFW_PRESS||action==GLFW_REPEAT)
{
my_keys.KEY_R=true;
}
break;
}
case GLFW_KEY_S:
{
if(action==GLFW_PRESS||action==GLFW_REPEAT)
{
my_keys.KEY_S=true;
if(currentCamera->TP_PERSPECTIVE)
character_controller->moveBackward(currentCamera);
}
break;
}
case GLFW_KEY_T:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_T=true;
}
break;
}
case GLFW_KEY_U:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_U=true;
}
break;
}
case GLFW_KEY_V:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_V=true;
}
break;
}
case GLFW_KEY_W:
{
if(action==GLFW_PRESS||action==GLFW_REPEAT)
{
my_keys.KEY_W=true;
if(currentCamera->TP_PERSPECTIVE)
character_controller->moveForward(currentCamera);
}
break;
}
case GLFW_KEY_X:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_X=true;
}
break;
}
case GLFW_KEY_Y:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_Y=true;
}
break;
}
case GLFW_KEY_Z:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_Z=true;
}
break;
}
case GLFW_KEY_UP :
{
my_keys.KEY_UP = true;
currentCamera->panUp();
break;
}
case GLFW_KEY_DOWN :
{
my_keys.KEY_DOWN = true;
currentCamera->panDown();
break;
}
case GLFW_KEY_LEFT :
{
my_keys.KEY_LEFT = true;
currentCamera->panLeft();
break;
}
case GLFW_KEY_RIGHT :
{
my_keys.KEY_RIGHT = true;
currentCamera->panRight();
break;
}
case GLFW_KEY_ESCAPE:
{
my_keys.KEY_ESCAPE = true;
glfwSetWindowShouldClose(window, GLFW_TRUE);
break;
}
case GLFW_KEY_SPACE:
{
if(action==GLFW_PRESS||action==GLFW_REPEAT)
{
my_keys.KEY_SPACE = true;
if(currentCamera->TP_PERSPECTIVE)
character_controller->jump(currentCamera);
}
break;
}
case GLFW_KEY_ENTER:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_ENTER = true;
}
break;
}
case GLFW_KEY_TAB:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_TAB = true;
}
break;
}
case GLFW_KEY_LEFT_CONTROL:
{
if(action==GLFW_PRESS)
{
my_keys.KEY_LEFT_CTRL = true;
}
break;
}
default:{}
}
}
sorry that i have pasted this thing here but this is what i am really doing.
i have done this like above because i don't want to pass other pointers to event handler class example
camera,object_manger,game_world_physics and that all
so my question is
what is the correct way of doing event handling? what you people do for optimization?
????????????