src/game/demo/DemoGame.cpp
// Process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
Process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
Process all input : query GLFW whether relevant keys are pressed / released this frame and react accordingly
void DemoGame::processInput(float deltaTime) {
    if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) {
        auto camera = state->getCamera();
        auto keys = state->getKeys();
        if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
            glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
        }
        auto wPress = glfwGetKey(window, GLFW_KEY_W);
        if (wPress == GLFW_PRESS)
            camera->processKeyboard(engine::FORWARD, deltaTime);
        auto sPress = glfwGetKey(window, GLFW_KEY_S);
        if (sPress == GLFW_PRESS)
            camera->processKeyboard(engine::BACKWARD, deltaTime);
        auto aPress = glfwGetKey(window, GLFW_KEY_A);
        if (aPress == GLFW_PRESS)
            camera->processKeyboard(engine::LEFT, deltaTime);
        auto dPress = glfwGetKey(window, GLFW_KEY_D);
        if (dPress == GLFW_PRESS)
            camera->processKeyboard(engine::RIGHT, deltaTime);
        auto spacePress = glfwGetKey(window, GLFW_KEY_SPACE);
        if (!keys->contains(GLFW_KEY_SPACE))
            keys->insert({GLFW_KEY_SPACE, GLFW_RELEASE});
        if (keys->at(GLFW_KEY_SPACE) == GLFW_RELEASE && spacePress == GLFW_PRESS) {
            camera->toggleMode();
        }
        keys->clear();
        keys->insert(
            {
                {GLFW_KEY_W,     wPress},
                {GLFW_KEY_S,     sPress},
                {GLFW_KEY_A,     aPress},
                {GLFW_KEY_D,     dPress},
                {GLFW_KEY_SPACE, spacePress}
            }
        );
    }
}
void DemoGame :: processInput ( float deltaTime ) { if ( glfwGetInputMode ( window , GLFW_CURSOR ) == GLFW_CURSOR_DISABLED ) { auto camera = state -> getCamera ( ) ; auto keys = state -> getKeys ( ) ; if ( glfwGetKey ( window , GLFW_KEY_ESCAPE ) == GLFW_PRESS ) { glfwSetInputMode ( window , GLFW_CURSOR , GLFW_CURSOR_NORMAL ) ; } auto wPress = glfwGetKey ( window , GLFW_KEY_W ) ; if ( wPress == GLFW_PRESS ) camera -> processKeyboard ( engine :: FORWARD , deltaTime ) ; auto sPress = glfwGetKey ( window , GLFW_KEY_S ) ; if ( sPress == GLFW_PRESS ) camera -> processKeyboard ( engine :: BACKWARD , deltaTime ) ; auto aPress = glfwGetKey ( window , GLFW_KEY_A ) ; if ( aPress == GLFW_PRESS ) camera -> processKeyboard ( engine :: LEFT , deltaTime ) ; auto dPress = glfwGetKey ( window , GLFW_KEY_D ) ; if ( dPress == GLFW_PRESS ) camera -> processKeyboard ( engine :: RIGHT , deltaTime ) ; auto spacePress = glfwGetKey ( window , GLFW_KEY_SPACE ) ; if ( ! keys -> contains ( GLFW_KEY_SPACE ) ) keys -> insert ( { GLFW_KEY_SPACE , GLFW_RELEASE } ) ; if ( keys -> at ( GLFW_KEY_SPACE ) == GLFW_RELEASE && spacePress == GLFW_PRESS ) { camera -> toggleMode ( ) ; } keys -> clear ( ) ; keys -> insert ( { { GLFW_KEY_W , wPress } , { GLFW_KEY_S , sPress } , { GLFW_KEY_A , aPress } , { GLFW_KEY_D , dPress } , { GLFW_KEY_SPACE , spacePress } } ) ; } }
Process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
Process all input : query GLFW whether relevant keys are pressed / released this frame and react accordingly
// Workaround to check if window is "focused" // Clear is needed because insert does not overwrite existing keys