Kaynağa Gözat

sdl: improve input support stability and handle return/tab/backspace in text input mode.

legacy
Sam Hocevar 6 yıl önce
ebeveyn
işleme
a822785879
3 değiştirilmiş dosya ile 40 ekleme ve 42 silme
  1. +25
    -33
      src/input/controller.cpp
  2. +4
    -7
      src/input/controller.h
  3. +11
    -2
      src/platform/sdl/sdlinput.cpp

+ 25
- 33
src/input/controller.cpp Dosyayı Görüntüle

@@ -276,13 +276,6 @@ void Controller::ClearProfile()
UnbindProfile(); UnbindProfile();
} }


//Init mode 2: By hand, key/axis by key/axis ----------------------------------
void Controller::SetInputCount(int nb_keys, int nb_axis)
{
m_keys.resize(nb_keys);
m_axis.resize(nb_axis);
}

//Layer mask stuff ------------------------------------------------------------ //Layer mask stuff ------------------------------------------------------------
void Controller::SetLayerMask(uint32_t layer_mask) void Controller::SetLayerMask(uint32_t layer_mask)
{ {
@@ -302,46 +295,48 @@ KeyBinding& Controller::GetKey(int index)
{ {
return m_keys[index]; return m_keys[index];
} }
KeyBinding const& Controller::GetKey(int index) const
{
return m_keys[index];
}

AxisBinding& Controller::GetAxis(int index) AxisBinding& Controller::GetAxis(int index)
{ {
return m_axis[index]; return m_axis[index];
} }
AxisBinding const& Controller::GetAxis(int index) const
{
return m_axis[index];
}


//Key methods: should not go directly to binding ------------------------------
// Key methods: should not go directly to binding
bool Controller::IsKeyPressed(int index) const bool Controller::IsKeyPressed(int index) const
{ {
//#error do something better IsLayerActive()
return GetKey(index).IsPressed();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.IsPressed();
} }

bool Controller::IsKeyReleased(int index) const bool Controller::IsKeyReleased(int index) const
{ {
return GetKey(index).IsReleased();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.IsReleased();
} }

bool Controller::WasKeyPressedThisFrame(int index) const bool Controller::WasKeyPressedThisFrame(int index) const
{ {
return GetKey(index).WasPressedThisFrame();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.WasPressedThisFrame();
} }

bool Controller::WasKeyReleasedThisFrame(int index) const bool Controller::WasKeyReleasedThisFrame(int index) const
{ {
return GetKey(index).WasReleasedThisFrame();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.WasReleasedThisFrame();
} }


//Axis methods: should not go directly to binding ----------------------------- //Axis methods: should not go directly to binding -----------------------------
float Controller::GetAxisValue(int index) const float Controller::GetAxisValue(int index) const
{ {
return GetAxis(index).GetValue();
auto axis = m_axis.find(index);
return axis != m_axis.end() ? axis->second.GetValue() : 0.f;
} }

float Controller::GetAxisDelta(int index) const float Controller::GetAxisDelta(int index) const
{ {
return GetAxis(index).GetDelta();
auto axis = m_axis.find(index);
return axis != m_axis.end() ? axis->second.GetDelta() : 0.f;
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -403,10 +398,7 @@ void Controller::BindProfile(InputProfile const& setup)
m_mutex.lock(); m_mutex.lock();
m_profile = setup; m_profile = setup;


m_keys.resize(m_profile.GetKeyCount());
m_axis.resize(m_profile.GetAxisCount());

//Keyboard
// Keyboard
m_keyboard = InputDevice::GetKeyboard(); m_keyboard = InputDevice::GetKeyboard();
if (m_keyboard) if (m_keyboard)
{ {
@@ -414,7 +406,7 @@ void Controller::BindProfile(InputProfile const& setup)
GetKey(key.m_idx).BindKeyboard(key.m_name); GetKey(key.m_idx).BindKeyboard(key.m_name);
} }


//Mouse
// Mouse
m_mouse = InputDevice::GetMouse(); m_mouse = InputDevice::GetMouse();
if (m_mouse) if (m_mouse)
{ {
@@ -424,7 +416,7 @@ void Controller::BindProfile(InputProfile const& setup)
GetAxis(axis.m_idx).BindMouse(axis.m_name); GetAxis(axis.m_idx).BindMouse(axis.m_name);
} }


//Joystick
// Joystick
for (uint64_t joy_idx : m_profile.m_joystick) for (uint64_t joy_idx : m_profile.m_joystick)
{ {
class InputDevice* joystick = InputDevice::GetJoystick(joy_idx); class InputDevice* joystick = InputDevice::GetJoystick(joy_idx);
@@ -455,11 +447,11 @@ void Controller::tick_game(float seconds)


if (m_active) if (m_active)
{ {
for (int i = 0; i < m_keys.count(); ++i)
m_keys[i].Update();
for (auto &kv : m_keys)
kv.second.Update();


for (int i = 0; i < m_axis.count(); ++i)
m_axis[i].Update();
for (auto &kv : m_axis)
kv.second.Update();
} }


if (m_activate_nextframe) if (m_activate_nextframe)


+ 4
- 7
src/input/controller.h Dosyayı Görüntüle

@@ -386,9 +386,6 @@ public:
void Init(InputProfile const& profile); void Init(InputProfile const& profile);
void ClearProfile(); void ClearProfile();


/** Init mode 2: By hand, key/axis by key/axis */
void SetInputCount(int nb_keys, int nb_axis);

/** layer mask stuff */ /** layer mask stuff */
void SetLayerMask(uint32_t layer_mask); void SetLayerMask(uint32_t layer_mask);
uint32_t GetLayerMask(); uint32_t GetLayerMask();
@@ -427,11 +424,11 @@ protected:
void BindProfile(InputProfile const& setup); void BindProfile(InputProfile const& setup);


private: private:
uint32_t m_layer_mask = 1; //plugged on the first by default
array<KeyBinding> m_keys;
array<AxisBinding> m_axis;
uint32_t m_layer_mask = 1; // plugged on the first by default
std::map<int, KeyBinding> m_keys;
std::map<int, AxisBinding> m_axis;


static uint32_t m_active_layer; //All active by default
static uint32_t m_active_layer; // All active by default
static array<Controller*> controllers; static array<Controller*> controllers;
std::string m_name; std::string m_name;
bool m_activate_nextframe; bool m_activate_nextframe;


+ 11
- 2
src/platform/sdl/sdlinput.cpp Dosyayı Görüntüle

@@ -165,9 +165,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)
* - HDAPS, it's not a real joystick. * - HDAPS, it's not a real joystick.
* - X360 controllers, Xinput handles them better since * - X360 controllers, Xinput handles them better since
* it won't think there is only one trigger axis. */ * it won't think there is only one trigger axis. */
# if LOL_USE_SDL
char const *name = SDL_JoystickName(sdlstick); char const *name = SDL_JoystickName(sdlstick);
# endif
if (strstr(name, "HDAPS") if (strstr(name, "HDAPS")
# if LOL_USE_XINPUT # if LOL_USE_XINPUT
|| strstr(name, "XBOX 360 For Windows") || strstr(name, "XBOX 360 For Windows")
@@ -302,6 +300,17 @@ void SdlInputData::Tick(float seconds)
(int)m_keyboard, ScanCodeToText(sc).C(), ScanCodeToName(sc).C(), (int)m_keyboard, ScanCodeToText(sc).C(), ScanCodeToName(sc).C(),
event.type == SDL_KEYDOWN ? "up" : "down", event.key.repeat); event.type == SDL_KEYDOWN ? "up" : "down", event.key.repeat);
*/ */

// These are arguably text input characters, too.
if (event.type == SDL_KEYDOWN && m_keyboard->IsTextInputActive())
{
switch (sc)
{
case SDLOL_Return: m_keyboard->AddText("\n"); break;
case SDLOL_Tab: m_keyboard->AddText("\t"); break;
case SDLOL_Backspace: m_keyboard->AddText("\x08"); break;
}
}
} }
/* DEBUG STUFF /* DEBUG STUFF
else else


Yükleniyor…
İptal
Kaydet