Added 'isAnalog' functionality to avoid that gamepads on full left/right

steering will delay steering because of time-full-steer. Added some
virtual destructors.
This commit is contained in:
hiker 2014-10-31 15:18:26 +11:00
parent 4986deebd6
commit e2d17bcf88
5 changed files with 37 additions and 9 deletions

View File

@ -75,6 +75,8 @@ protected:
public:
virtual ~DeviceConfig() {}
static DeviceConfig* create(const XMLNode *config);
irr::core::stringw toString();
bool hasBindingFor(const int buttonID) const;
@ -97,6 +99,11 @@ public:
virtual void save(std::ofstream& stream);
virtual bool load(const XMLNode *config);
// ------------------------------------------------------------------------
/** 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;}
// ------------------------------------------------------------------------
/** Should only be called for gamepads, which has its own implementation.
* of this function. */

View File

@ -45,7 +45,8 @@ GamepadConfig::GamepadConfig( const std::string &name,
GamepadConfig::GamepadConfig() : DeviceConfig()
{
m_deadzone = 2000;
m_deadzone = 2000;
m_is_analog = true;
setDefaultBinds();
} // GamepadConfig
@ -57,6 +58,7 @@ GamepadConfig::GamepadConfig() : DeviceConfig()
bool GamepadConfig::load(const XMLNode *config)
{
config->get("deadzone", &m_deadzone);
config->get("analog", &m_is_analog);
bool ok = DeviceConfig::load(config);
if(getName()=="")
@ -77,7 +79,8 @@ bool GamepadConfig::load(const XMLNode *config)
void GamepadConfig::save (std::ofstream& stream)
{
stream << "<gamepad name =\"" << getName()
<<"\" deadzone=\""<<m_deadzone << "\"\n";
<< "\" deadzone=\"" << m_deadzone
<< "\" analog=\"" << m_is_analog<<"\"\n";
stream << " ";
DeviceConfig::save(stream);
stream << "</gamepad>\n\n";

View File

@ -46,16 +46,21 @@ 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;
public:
irr::core::stringw toString ();
GamepadConfig ();
GamepadConfig(const std::string &name,
const int axis_count=0,
const int button_ount=0);
virtual ~GamepadConfig() {}
irr::core::stringw toString();
virtual void save(std::ofstream& stream);
void setDefaultBinds ();
GamepadConfig ();
GamepadConfig (const std::string &name,
const int axis_count=0,
const int button_ount=0);
virtual bool load(const XMLNode *config) OVERRIDE;
// ------------------------------------------------------------------------
@ -69,10 +74,10 @@ public:
// ------------------------------------------------------------------------
/** Returns the number of axis of this configufation. */
virtual int getNumberOfAxes() const OVERRIDE { return m_axis_count; }
// ------------------------------------------------------------------------
/** Sets the number of axis this device has. */
void setNumberOfAxis(int count) { m_axis_count = count; }
// ~GamepadConfig();
// ------------------------------------------------------------------------
/** Return deadzone of this configuration. */

View File

@ -161,6 +161,17 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
{
if (!m_configuration->isEnabled()) return false;
// A digital input value is 32767 or -32768 (which then triggers
// 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(*value==32767)
*value = 32766;
else if(*value==-32768)
*value = -32767;
}
bool success = false;
if(m_prev_axis_directions == NULL) return false; // device not open

View File

@ -36,10 +36,12 @@ class KeyboardConfig : public DeviceConfig
public:
KeyboardConfig();
virtual ~KeyboardConfig() {}
void setDefaultBinds ();
virtual void save(std::ofstream& stream);
KeyboardConfig ();
// ------------------------------------------------------------------------
virtual bool isGamePad() const { return false; }
// ------------------------------------------------------------------------