Browse Source

input: expose the whole vector of key states to the client application.

legacy
Sam Hocevar 5 years ago
parent
commit
2f736356d6
4 changed files with 38 additions and 42 deletions
  1. +3
    -3
      src/input/controller.cpp
  2. +1
    -1
      src/input/controller.h
  3. +13
    -13
      src/input/input.cpp
  4. +21
    -25
      src/input/input.h

+ 3
- 3
src/input/controller.cpp View File

@@ -211,10 +211,10 @@ float AxisBinding::RetrieveCurrentValue()
for (int i = 0; i < m_keybindings.count(); ++i)
{
float value = 0.0f;
m_keybindings[i].m1->GetKey(m_keybindings[i].m2);
value += m_keybindings[i].m1->GetKey(m_keybindings[i].m3) ? 1.0f : 0.0f;
m_keybindings[i].m1->key(m_keybindings[i].m2);
value += m_keybindings[i].m1->key(m_keybindings[i].m3) ? 1.0f : 0.0f;
if (m_keybindings[i].m2 != -1)
value += m_keybindings[i].m1->GetKey(m_keybindings[i].m2) ? -1.0f : 0.0f;
value += m_keybindings[i].m1->key(m_keybindings[i].m2) ? -1.0f : 0.0f;

if (value > max_positive)
max_positive = value;


+ 1
- 1
src/input/controller.h View File

@@ -66,7 +66,7 @@ protected:
m_current = false;
for (int i = 0; i < m_keybindings.count(); ++i)
{
m_current = m_current || m_keybindings[i].m1->GetKey(m_keybindings[i].m2);
m_current = m_current || m_keybindings[i].m1->key(m_keybindings[i].m2);
}
}



+ 13
- 13
src/input/input.cpp View File

@@ -52,29 +52,29 @@ void InputDevice::SetTextInputActive(bool status)
void InputDeviceInternal::AddKey(int index, const char* name)
{
if (index == -1)
index = m_keynames.count();
index = (int)m_key_names.size();

while (index >= m_keynames.count())
while (index >= (int)m_key_names.size())
{
m_keynames.push(name);
m_keys.push(false);
m_key_names.push_back(name);
m_keys.push_back(false);
}

m_keynames[index] = name;
m_key_names[index] = name;
}

void InputDeviceInternal::AddAxis(int index, const char* name, float sensitivity)
{
if (index == -1)
index = m_axisnames.count();
index = (int)m_axis_names.size();

while (index >= m_axisnames.count())
while (index >= (int)m_axis_names.size())
{
m_axisnames.push(name);
m_axis_names.push_back(name);
m_axis.push(0.0f, 1.0f);
}

m_axisnames[index] = name;
m_axis_names[index] = name;
m_axis[index].m1 = 0.0f;
m_axis[index].m2 = sensitivity;
}
@@ -82,15 +82,15 @@ void InputDeviceInternal::AddAxis(int index, const char* name, float sensitivity
void InputDeviceInternal::AddCursor(int index, const char* name)
{
if (index == -1)
index = m_cursornames.count();
index = (int)m_cursor_names.size();

while (index >= m_cursornames.count())
while (index >= (int)m_cursor_names.size())
{
m_cursornames.push(name);
m_cursor_names.push_back(name);
m_cursors.push(vec2::zero, ivec2::zero);
}

m_cursornames[index] = name;
m_cursor_names[index] = name;
}

InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard()


+ 21
- 25
src/input/input.h View File

@@ -77,27 +77,30 @@ public:
/** Gets the index of the corresponding key, needed to call GetKey */
ptrdiff_t GetKeyIndex(std::string const &name) const
{
return GetItemIndex(name, m_keynames);
return GetItemIndex(name, m_key_names);
}

/** Gets the index of the corresponding axis, needed to call GetAxis */
ptrdiff_t GetAxisIndex(std::string const &name) const
{
return GetItemIndex(name, m_axisnames);
return GetItemIndex(name, m_axis_names);
}

/** Gets the index of the corresponding cursor, needed to call GetCursor */
ptrdiff_t GetCursorIndex(std::string const &name) const
{
return GetItemIndex(name, m_cursornames);
return GetItemIndex(name, m_cursor_names);
}

/** Gets the current state of the given key, true being pressed and
/** Get the names of all available keys on this device */
std::vector<std::string> const& key_names() const { return m_key_names; }

/** Get the current state of all keys */
std::vector<bool> const &keys() const { return m_keys; }

/** Get the current state of the given key, true being pressed and
* false being released */
bool GetKey(ptrdiff_t index) const
{
return m_keys[index];
}
bool key(ptrdiff_t index) const { return m_keys[index]; }

/** Gets the latest contents of text input. */
std::string GetText();
@@ -141,20 +144,15 @@ public:
return m_axis[index].m2;
}

/** Gets a list of the name of all available keys in this device */
const array<std::string>& GetAllKeys() const
{
return m_keynames;
}
/** Gets a list of the name of all available axis in this device */
const array<std::string>& GetAllAxis() const
const std::vector<std::string>& GetAllAxis() const
{
return m_axisnames;
return m_axis_names;
}
/** Gets a list of the name of all available cursors in this device */
const array<std::string>& GetAllCursors() const
const std::vector<std::string>& GetAllCursors() const
{
return m_cursornames;
return m_cursor_names;
}

/** Gets a list of the name of all available input devices */
@@ -195,12 +193,12 @@ protected:

std::string m_name;

array<std::string> m_keynames;
array<std::string> m_axisnames;
array<std::string> m_cursornames;
std::vector<std::string> m_key_names;
std::vector<std::string> m_axis_names;
std::vector<std::string> m_cursor_names;

/** Key states (pressed/released) */
array<bool> m_keys;
std::vector<bool> m_keys;

/** Text input state */
std::string m_text;
@@ -238,13 +236,11 @@ private:
static int joystick_count;

template <typename... T>
ptrdiff_t GetItemIndex(std::string const &name, const array<std::string, T...>& a) const
size_t GetItemIndex(std::string const &name, std::vector<std::string, T...> const& a) const
{
for (int i = 0; i < a.count(); ++i)
{
for (size_t i = 0; i < a.size(); ++i)
if (a[i] == name)
return i;
}
return -1;
}



Loading…
Cancel
Save