src/game/PuzzleGame.cpp
void PuzzleGame::processInput(float deltaTime) {
    // Workaround to check if window is "focused"
    if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) {
        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);
        auto sPress = glfwGetKey(window, GLFW_KEY_S);
        auto aPress = glfwGetKey(window, GLFW_KEY_A);
        auto dPress = glfwGetKey(window, GLFW_KEY_D);
        player->input = glm::vec2(wPress - sPress, aPress - dPress);

        auto upPress = glfwGetKey(window, GLFW_KEY_UP);
        if (upPress == GLFW_PRESS)
            camera->processKeyboard(engine::FORWARD, deltaTime);
        auto downPress = glfwGetKey(window, GLFW_KEY_DOWN);
        if (downPress == GLFW_PRESS)
            camera->processKeyboard(engine::BACKWARD, deltaTime);
        auto leftPress = glfwGetKey(window, GLFW_KEY_LEFT);
        if (leftPress == GLFW_PRESS)
            camera->processKeyboard(engine::LEFT, deltaTime);
        auto rightPress = glfwGetKey(window, GLFW_KEY_RIGHT);
        if (rightPress == 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();
        }

        // Clear is needed because insert does not overwrite existing keys
        keys->clear();
        keys->insert(
            {{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
Process all input : query GLFW whether relevant keys are pressed / released this frame and react accordingly
void PuzzleGame::processInput(float deltaTime) {
    if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) {
        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);
        auto sPress = glfwGetKey(window, GLFW_KEY_S);
        auto aPress = glfwGetKey(window, GLFW_KEY_A);
        auto dPress = glfwGetKey(window, GLFW_KEY_D);
        player->input = glm::vec2(wPress - sPress, aPress - dPress);
        auto upPress = glfwGetKey(window, GLFW_KEY_UP);
        if (upPress == GLFW_PRESS)
            camera->processKeyboard(engine::FORWARD, deltaTime);
        auto downPress = glfwGetKey(window, GLFW_KEY_DOWN);
        if (downPress == GLFW_PRESS)
            camera->processKeyboard(engine::BACKWARD, deltaTime);
        auto leftPress = glfwGetKey(window, GLFW_KEY_LEFT);
        if (leftPress == GLFW_PRESS)
            camera->processKeyboard(engine::LEFT, deltaTime);
        auto rightPress = glfwGetKey(window, GLFW_KEY_RIGHT);
        if (rightPress == 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_SPACE, spacePress}}
        );
    }
}
void PuzzleGame :: processInput ( float deltaTime ) { if ( glfwGetInputMode ( window , GLFW_CURSOR ) == GLFW_CURSOR_DISABLED ) { 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 ) ; auto sPress = glfwGetKey ( window , GLFW_KEY_S ) ; auto aPress = glfwGetKey ( window , GLFW_KEY_A ) ; auto dPress = glfwGetKey ( window , GLFW_KEY_D ) ; player -> input = glm :: vec2 ( wPress - sPress , aPress - dPress ) ; auto upPress = glfwGetKey ( window , GLFW_KEY_UP ) ; if ( upPress == GLFW_PRESS ) camera -> processKeyboard ( engine :: FORWARD , deltaTime ) ; auto downPress = glfwGetKey ( window , GLFW_KEY_DOWN ) ; if ( downPress == GLFW_PRESS ) camera -> processKeyboard ( engine :: BACKWARD , deltaTime ) ; auto leftPress = glfwGetKey ( window , GLFW_KEY_LEFT ) ; if ( leftPress == GLFW_PRESS ) camera -> processKeyboard ( engine :: LEFT , deltaTime ) ; auto rightPress = glfwGetKey ( window , GLFW_KEY_RIGHT ) ; if ( rightPress == 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_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