void GameInput::Update()

in MiniEngine/Core/GameInput.cpp [435:541]


void GameInput::Update( float frameDelta )
{
    memcpy(s_Buttons[1], s_Buttons[0], sizeof(s_Buttons[0]));
    memset(s_Buttons[0], 0, sizeof(s_Buttons[0]));
    memset(s_Analogs, 0, sizeof(s_Analogs));

#ifdef USE_XINPUT
    XINPUT_STATE newInputState;
    if (ERROR_SUCCESS == XInputGetState( 0, &newInputState ))
    {
        if (newInputState.Gamepad.wButtons & (1 << 0)) s_Buttons[0][kDPadUp] = true;
        if (newInputState.Gamepad.wButtons & (1 << 1)) s_Buttons[0][kDPadDown] = true;
        if (newInputState.Gamepad.wButtons & (1 << 2)) s_Buttons[0][kDPadLeft] = true;
        if (newInputState.Gamepad.wButtons & (1 << 3)) s_Buttons[0][kDPadRight] = true;
        if (newInputState.Gamepad.wButtons & (1 << 4)) s_Buttons[0][kStartButton] = true;
        if (newInputState.Gamepad.wButtons & (1 << 5)) s_Buttons[0][kBackButton] = true;
        if (newInputState.Gamepad.wButtons & (1 << 6)) s_Buttons[0][kLThumbClick] = true;
        if (newInputState.Gamepad.wButtons & (1 << 7)) s_Buttons[0][kRThumbClick] = true;
        if (newInputState.Gamepad.wButtons & (1 << 8)) s_Buttons[0][kLShoulder] = true;
        if (newInputState.Gamepad.wButtons & (1 << 9)) s_Buttons[0][kRShoulder] = true;
        if (newInputState.Gamepad.wButtons & (1 << 12)) s_Buttons[0][kAButton] = true;
        if (newInputState.Gamepad.wButtons & (1 << 13)) s_Buttons[0][kBButton] = true;
        if (newInputState.Gamepad.wButtons & (1 << 14)) s_Buttons[0][kXButton] = true;
        if (newInputState.Gamepad.wButtons & (1 << 15)) s_Buttons[0][kYButton] = true;

        s_Analogs[ kAnalogLeftTrigger ]        = newInputState.Gamepad.bLeftTrigger / 255.0f;
        s_Analogs[ kAnalogRightTrigger ]    = newInputState.Gamepad.bRightTrigger / 255.0f;
        s_Analogs[ kAnalogLeftStickX ]        = FilterAnalogInput(newInputState.Gamepad.sThumbLX, XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE );
        s_Analogs[ kAnalogLeftStickY ]        = FilterAnalogInput(newInputState.Gamepad.sThumbLY, XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE );
        s_Analogs[ kAnalogRightStickX ]        = FilterAnalogInput(newInputState.Gamepad.sThumbRX, XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE );
        s_Analogs[ kAnalogRightStickY ]        = FilterAnalogInput(newInputState.Gamepad.sThumbRY, XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE );
    }
#else

    IVectorView<Gamepad^>^ gamepads = Gamepad::Gamepads;
    if (gamepads->Size != 0)
    {
        IGamepad^ gamepad = gamepads->GetAt(0);
        GamepadReading reading = gamepad->GetCurrentReading();
        uint32_t Buttons = (uint32_t)reading.Buttons;
        if (Buttons & (uint32_t)GamepadButtons::DPadUp) s_Buttons[0][kDPadUp] = true;
        if (Buttons & (uint32_t)GamepadButtons::DPadDown) s_Buttons[0][kDPadDown] = true;
        if (Buttons & (uint32_t)GamepadButtons::DPadLeft) s_Buttons[0][kDPadLeft] = true;
        if (Buttons & (uint32_t)GamepadButtons::DPadRight) s_Buttons[0][kDPadRight] = true;
        if (Buttons & (uint32_t)GamepadButtons::Menu) s_Buttons[0][kStartButton] = true;
        if (Buttons & (uint32_t)GamepadButtons::View) s_Buttons[0][kBackButton] = true;
        if (Buttons & (uint32_t)GamepadButtons::LeftThumbstick) s_Buttons[0][kLThumbClick] = true;
        if (Buttons & (uint32_t)GamepadButtons::RightThumbstick) s_Buttons[0][kRThumbClick] = true;
        if (Buttons & (uint32_t)GamepadButtons::LeftShoulder) s_Buttons[0][kLShoulder] = true;
        if (Buttons & (uint32_t)GamepadButtons::RightShoulder) s_Buttons[0][kRShoulder] = true;
        if (Buttons & (uint32_t)GamepadButtons::A) s_Buttons[0][kAButton] = true;
        if (Buttons & (uint32_t)GamepadButtons::B) s_Buttons[0][kBButton] = true;
        if (Buttons & (uint32_t)GamepadButtons::X) s_Buttons[0][kXButton] = true;
        if (Buttons & (uint32_t)GamepadButtons::Y) s_Buttons[0][kYButton] = true;

        static const float kAnalogStickDeadZone = 0.18f;

        s_Analogs[ kAnalogLeftTrigger ]        = (float)reading.LeftTrigger;
        s_Analogs[ kAnalogRightTrigger ]    = (float)reading.RightTrigger;
        s_Analogs[ kAnalogLeftStickX ]        = FilterAnalogInput((float)reading.LeftThumbstickX, kAnalogStickDeadZone );
        s_Analogs[ kAnalogLeftStickY ]        = FilterAnalogInput((float)reading.LeftThumbstickY, kAnalogStickDeadZone );
        s_Analogs[ kAnalogRightStickX ]        = FilterAnalogInput((float)reading.RightThumbstickX, kAnalogStickDeadZone );
        s_Analogs[ kAnalogRightStickY ]        = FilterAnalogInput((float)reading.RightThumbstickY, kAnalogStickDeadZone );
    }

#endif

#ifdef USE_KEYBOARD_MOUSE
    KbmUpdate();

    for (uint32_t i = 0; i < kNumKeys; ++i)
    {
        s_Buttons[0][i] = (s_Keybuffer[s_DXKeyMapping[i]] & 0x80) != 0;
    }

    for (uint32_t i = 0; i < 8; ++i)
    {
        if (s_MouseState.rgbButtons[i] > 0) s_Buttons[0][kMouse0 + i] = true;
    }

    s_Analogs[kAnalogMouseX] = (float)s_MouseState.lX * .0018f;
    s_Analogs[kAnalogMouseY] = (float)s_MouseState.lY * -.0018f;

    if (s_MouseState.lZ > 0)
        s_Analogs[kAnalogMouseScroll] = 1.0f;
    else if (s_MouseState.lZ < 0)
        s_Analogs[kAnalogMouseScroll] = -1.0f;
#endif

    // Update time duration for buttons pressed
    for (uint32_t i = 0; i < kNumDigitalInputs; ++i)
    {
        if (s_Buttons[0][i])
        {
            if (!s_Buttons[1][i])
                s_HoldDuration[i] = 0.0f;
            else
                s_HoldDuration[i] += frameDelta;
        }
    }

    for (uint32_t i = 0; i < kNumAnalogInputs; ++i)
    {
        s_AnalogsTC[i] = s_Analogs[i] * frameDelta;
    }

}