Browse Source

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

legacy
Sam Hocevar sam 12 years ago
parent
commit
c0141debea
3 changed files with 29 additions and 8 deletions
  1. +19
    -8
      src/input/stick.cpp
  2. +2
    -0
      src/input/stick.h
  3. +8
    -0
      src/platform/sdl/sdlinput.cpp

+ 19
- 8
src/input/stick.cpp View File

@@ -32,8 +32,9 @@ public:
StickData() { }

private:
Array<float> m_axes;
Array<int> m_buttons;
/* First element is the remap target */
Array<int, float> m_axes;
Array<int, int> m_buttons;
}
stickdata;

@@ -55,24 +56,34 @@ void Stick::SetAxisCount(int n)
{
m_data->m_axes.Empty();
for (int i = 0; i < n; i++)
m_data->m_axes.Push(0.f);
m_data->m_axes.Push(i, 0.f);
}

void Stick::SetButtonCount(int n)
{
m_data->m_buttons.Empty();
for (int i = 0; i < n; i++)
m_data->m_buttons.Push(0);
m_data->m_buttons.Push(i, 0);
}

void Stick::SetAxis(int n, float val)
{
m_data->m_axes[n] = val;
m_data->m_axes[m_data->m_axes[n].m1].m2 = val;
}

void Stick::SetButton(int n, int val)
{
m_data->m_buttons[n] = val;
m_data->m_buttons[m_data->m_buttons[n].m1].m2 = val;
}

void Stick::RemapAxis(int src, int dst)
{
m_data->m_axes[src].m1 = dst;
}

void Stick::RemapButton(int src, int dst)
{
m_data->m_buttons[src].m1 = dst;
}

int Stick::GetAxisCount()
@@ -87,12 +98,12 @@ int Stick::GetButtonCount()

float Stick::GetAxis(int n)
{
return m_data->m_axes[n];
return m_data->m_axes[n].m2;
}

int Stick::GetButton(int n)
{
return m_data->m_buttons[n];
return m_data->m_buttons[n].m2;
}

} /* namespace lol */


+ 2
- 0
src/input/stick.h View File

@@ -32,6 +32,8 @@ public:
void SetButtonCount(int n);
void SetAxis(int n, float val);
void SetButton(int n, int val);
void RemapAxis(int src, int dst);
void RemapButton(int src, int dst);

int GetAxisCount();
int GetButtonCount();


+ 8
- 0
src/platform/sdl/sdlinput.cpp View File

@@ -67,6 +67,14 @@ SdlInput::SdlInput()
Stick *stick = Input::CreateStick();
stick->SetAxisCount(SDL_JoystickNumAxes(sdlstick));
stick->SetButtonCount(SDL_JoystickNumButtons(sdlstick));

/* It's possible to remap axes */
if (strstr(name, "XBOX 360 For Windows"))
{
//stick->RemapAxis(4, 2);
//stick->RemapAxis(2, 4);
}

m_data->m_joysticks.Push(sdlstick, stick);
}
#endif


Loading…
Cancel
Save