Use sdl mapping to determine if axes are analog

This commit is contained in:
Benau
2020-04-21 19:57:04 +08:00
parent 32e3e4a504
commit 0e023cae78
4 changed files with 30 additions and 13 deletions

View File

@@ -107,7 +107,7 @@ public:
// ------------------------------------------------------------------------
/** Returns true if this device has analog axis, so that steering values
* will not be affected by time-full-steer delays. */
virtual bool isAnalog() const { return false;}
virtual bool isAnalog(Input::InputType type, int id) const { return false;}
// ------------------------------------------------------------------------
/** Returns true if this device should desensitize its input at values
* close to 0 (to avoid 'oversteering'). */

View File

@@ -67,7 +67,6 @@ GamepadConfig::GamepadConfig( const std::string &name,
m_button_count = button_count;
m_hat_count = 0;
m_deadzone = 4096;
m_is_analog = true;
m_desensitize = false;
setDefaultBinds();
} // GamepadConfig
@@ -80,7 +79,6 @@ GamepadConfig::GamepadConfig() : DeviceConfig()
m_button_count = 0;
m_hat_count = 0;
m_deadzone = 4096;
m_is_analog = true;
m_desensitize = false;
setDefaultBinds();
} // GamepadConfig
@@ -93,7 +91,6 @@ GamepadConfig::GamepadConfig() : DeviceConfig()
bool GamepadConfig::load(const XMLNode *config)
{
config->get("deadzone", &m_deadzone );
config->get("analog", &m_is_analog );
config->get("desensitize", &m_desensitize );
bool ok = DeviceConfig::load(config);
@@ -115,9 +112,7 @@ void GamepadConfig::save (std::ofstream& stream)
{
stream << "<gamepad name =\"" << getName()
<< "\" deadzone=\"" << m_deadzone
<< "\" desensitize=\"" << m_desensitize
<< "\" analog=\"" << m_is_analog<<"\"\n";
stream << " ";
<< "\" desensitize=\"" << m_desensitize << "\" ";
DeviceConfig::save(stream);
stream << "</gamepad>\n\n";
} // save
@@ -433,6 +428,19 @@ void GamepadConfig::initSDLController(const std::string& mapping, int buttons,
}
}
}
// Save axes mapped to digital buttons
for (int i = 0; i < axes; i++)
{
auto a1 = m_sdl_mapping.find(std::make_tuple(i, Input::AD_POSITIVE));
auto a2 = m_sdl_mapping.find(std::make_tuple(i, Input::AD_NEGATIVE));
if (a1 != m_sdl_mapping.end() && a2 != m_sdl_mapping.end())
{
if (a1->second < SDL_CONTROLLER_BUTTON_MAX &&
a2->second < SDL_CONTROLLER_BUTTON_MAX)
m_digital_axes.insert(i);
}
}
#endif
} // initSDLController
@@ -577,3 +585,12 @@ fallback:
setBinding(PA_PAUSE_RACE, Input::IT_STICKBUTTON, 1);
#endif
} // initSDLMapping
// ----------------------------------------------------------------------------
bool GamepadConfig::isAnalog(Input::InputType type, int id) const
{
if (type == Input::IT_STICKBUTTON)
return false;
// If axis is mapped to button type, than it's digital too
return m_digital_axes.find(id) == m_digital_axes.end();
} // isAnalog

View File

@@ -28,6 +28,8 @@
#include <iosfwd>
#include <irrString.h>
#include <map>
#include <set>
#include <string>
#include <string>
#include <tuple>
@@ -53,16 +55,14 @@ private:
/** Deadzone of this gamepad. */
int m_deadzone;
/** If this device has analog axis, steering etc. must be set immediately
* from the input values, not having a delayed time (time-full-steer). */
bool m_is_analog;
/** If set to true, map any analog axis from x in [0,1] to x^x --> at
* values close to 0 the joystick will react less sensitive. */
bool m_desensitize;
std::map<std::tuple<int, Input::AxisDirection>, int> m_sdl_mapping;
std::set<int> m_digital_axes;
bool getMappingTuple(const std::string& rhs,
std::tuple<int, Input::AxisDirection>& t);
void setBindingFromTuple(const PlayerAction action,
@@ -83,7 +83,7 @@ public:
virtual bool load(const XMLNode *config) OVERRIDE;
// ------------------------------------------------------------------------
/** Returns if this device uses analog axes. */
virtual bool isAnalog() const OVERRIDE { return m_is_analog; }
virtual bool isAnalog(Input::InputType type, int id) const OVERRIDE;
// ------------------------------------------------------------------------
/** Returns true if this device should desensitize its input at values

View File

@@ -156,7 +156,7 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
// time-full-steer to be used to adjust actual steering values.
// To prevent this delay for analog gamesticks, make sure that
// 32767/-32768 are never used.
if(m_configuration->isAnalog())
if(m_configuration->isAnalog(type, id))
{
if(*value==32767)
*value = 32766;