Changeset 1355


Ignore:
Timestamp:
May 9, 2012, 6:40:38 PM (11 years ago)
Author:
sam
Message:

input: allow to remap gamepad axes in the generic input layer.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/input/stick.cpp

    r1342 r1355  
    3333
    3434private:
    35     Array<float> m_axes;
    36     Array<int> m_buttons;
     35    /* First element is the remap target */
     36    Array<int, float> m_axes;
     37    Array<int, int> m_buttons;
    3738}
    3839stickdata;
     
    5657    m_data->m_axes.Empty();
    5758    for (int i = 0; i < n; i++)
    58         m_data->m_axes.Push(0.f);
     59        m_data->m_axes.Push(i, 0.f);
    5960}
    6061
     
    6364    m_data->m_buttons.Empty();
    6465    for (int i = 0; i < n; i++)
    65         m_data->m_buttons.Push(0);
     66        m_data->m_buttons.Push(i, 0);
    6667}
    6768
    6869void Stick::SetAxis(int n, float val)
    6970{
    70     m_data->m_axes[n] = val;
     71    m_data->m_axes[m_data->m_axes[n].m1].m2 = val;
    7172}
    7273
    7374void Stick::SetButton(int n, int val)
    7475{
    75     m_data->m_buttons[n] = val;
     76    m_data->m_buttons[m_data->m_buttons[n].m1].m2 = val;
     77}
     78
     79void Stick::RemapAxis(int src, int dst)
     80{
     81    m_data->m_axes[src].m1 = dst;
     82}
     83
     84void Stick::RemapButton(int src, int dst)
     85{
     86    m_data->m_buttons[src].m1 = dst;
    7687}
    7788
     
    8899float Stick::GetAxis(int n)
    89100{
    90     return m_data->m_axes[n];
     101    return m_data->m_axes[n].m2;
    91102}
    92103
    93104int Stick::GetButton(int n)
    94105{
    95     return m_data->m_buttons[n];
     106    return m_data->m_buttons[n].m2;
    96107}
    97108
  • trunk/src/input/stick.h

    r1342 r1355  
    3333    void SetAxis(int n, float val);
    3434    void SetButton(int n, int val);
     35    void RemapAxis(int src, int dst);
     36    void RemapButton(int src, int dst);
    3537
    3638    int GetAxisCount();
  • trunk/src/platform/sdl/sdlinput.cpp

    r1346 r1355  
    6868        stick->SetAxisCount(SDL_JoystickNumAxes(sdlstick));
    6969        stick->SetButtonCount(SDL_JoystickNumButtons(sdlstick));
     70
     71        /* It's possible to remap axes */
     72        if (strstr(name, "XBOX 360 For Windows"))
     73        {
     74            //stick->RemapAxis(4, 2);
     75            //stick->RemapAxis(2, 4);
     76        }
     77
    7078        m_data->m_joysticks.Push(sdlstick, stick);
    7179    }
Note: See TracChangeset for help on using the changeset viewer.