Skip to content

Commit

Permalink
Input|Client|Refactor: Xbox One preset added; axis scaling factor def…
Browse files Browse the repository at this point in the history
…ault is 1.0

The SDL range of 10000 units should not be exposed to the user in
the form of the scale factor being 1/10000. Instead, apply the SDL
scaling internally and have a 1.0 scaling factor as the cvar.

Added a new axis parameter for offsetting the values.

The _controllers.de_ script now has bindings and configuration preset
for the Xbox One controller. The PS3 buttons preset was slightly
tweaked.

Renamed input device classes according to preferred conventions.
  • Loading branch information
skyjake committed Aug 23, 2016
1 parent 73dfe0e commit 0e843e2
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 277 deletions.
@@ -1,4 +1,4 @@
/** @file inputdeviceaxiscontrol.h Axis control for a logical input device.
/** @file axisinputcontrol.h Axis control for a logical input device.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,8 +17,8 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_INPUTSYSTEM_INPUTDEVICEAXISCONTROL_H
#define CLIENT_INPUTSYSTEM_INPUTDEVICEAXISCONTROL_H
#ifndef CLIENT_UI_AXISINPUTCONTROL_H
#define CLIENT_UI_AXISINPUTCONTROL_H

#include <de/types.h>
#include <de/String>
Expand All @@ -34,7 +34,7 @@
*
* @ingroup ui
*/
class InputDeviceAxisControl : public InputDeviceControl
class AxisInputControl : public InputDevice::Control
{
public:
enum Type {
Expand All @@ -47,8 +47,8 @@ class InputDeviceAxisControl : public InputDeviceControl
* @param name Symbolic name of the axis.
* @param type Logical axis type.
*/
InputDeviceAxisControl(de::String const &name, Type type);
virtual ~InputDeviceAxisControl();
AxisInputControl(de::String const &name, Type type);
virtual ~AxisInputControl();

Type type() const;
void setRawInput(bool yes = true);
Expand Down Expand Up @@ -83,6 +83,9 @@ class InputDeviceAxisControl : public InputDeviceControl
de::dfloat scale() const;
void setScale(de::dfloat newScale);

de::dfloat offset() const;
void setOffset(de::dfloat newOffset);

/**
* When the state of the control last changed, in milliseconds since app init.
*/
Expand All @@ -99,4 +102,4 @@ class InputDeviceAxisControl : public InputDeviceControl
DENG2_PRIVATE(d)
};

#endif // CLIENT_INPUTSYSTEM_INPUTDEVICEAXISCONTROL_H
#endif // CLIENT_UI_AXISINPUTCONTROL_H
@@ -1,4 +1,4 @@
/** @file inputdevicebuttoncontrol.h Button control for a logical input device.
/** @file buttoninputcontrol.h Button control for a logical input device.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,8 +17,8 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_INPUTSYSTEM_INPUTDEVICEBUTTONCONTROL_H
#define CLIENT_INPUTSYSTEM_INPUTDEVICEBUTTONCONTROL_H
#ifndef CLIENT_UI_BUTTONINPUTCONTROL_H
#define CLIENT_UI_BUTTONINPUTCONTROL_H

#include <de/String>
#include "inputdevice.h"
Expand All @@ -28,11 +28,11 @@
*
* @ingroup ui
*/
class InputDeviceButtonControl : public InputDeviceControl
class ButtonInputControl : public InputDevice::Control
{
public:
explicit InputDeviceButtonControl(de::String const &name = de::String());
virtual ~InputDeviceButtonControl();
explicit ButtonInputControl(de::String const &name = de::String());
virtual ~ButtonInputControl();

/**
* Returns @c true if the button is currently in the down (i.e., pressed) state.
Expand All @@ -58,4 +58,4 @@ class InputDeviceButtonControl : public InputDeviceControl
de::duint _time = 0;
};

#endif // CLIENT_INPUTSYSTEM_INPUTDEVICEBUTTONCONTROL_H
#endif // CLIENT_UI_BUTTONINPUTCONTROL_H
@@ -1,4 +1,4 @@
/** @file inputdevicehatcontrol.h Hat control for a logical input device.
/** @file hatinputcontrol.h Hat control for a logical input device.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,8 +17,8 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_INPUTSYSTEM_INPUTDEVICEHATCONTROL_H
#define CLIENT_INPUTSYSTEM_INPUTDEVICEHATCONTROL_H
#ifndef CLIENT_UI_HATINPUTCONTROL_H
#define CLIENT_UI_HATINPUTCONTROL_H

#include "inputdevice.h"

Expand All @@ -27,11 +27,11 @@
*
* @ingroup ui
*/
class InputDeviceHatControl : public InputDeviceControl
class HatInputControl : public InputDevice::Control
{
public:
explicit InputDeviceHatControl(de::String const &name = de::String());
virtual ~InputDeviceHatControl();
explicit HatInputControl(de::String const &name = de::String());
virtual ~HatInputControl();

/**
* Returns the current position of the hat.
Expand All @@ -56,4 +56,4 @@ class InputDeviceHatControl : public InputDeviceControl
de::duint _time = 0; ///< Timestamp of the latest change.
};

#endif // CLIENT_INPUTSYSTEM_INPUTDEVICEHATCONTROL_H
#endif // CLIENT_UI_HATINPUTCONTROL_H
25 changes: 11 additions & 14 deletions doomsday/apps/client/include/ui/inputdevice.h
Expand Up @@ -27,12 +27,9 @@
#include <de/String>

class BindContext;

/// @todo remove:
class InputDeviceAxisControl;
class InputDeviceButtonControl;
class InputDeviceHatControl;
/// end todo
class AxisInputControl;
class ButtonInputControl;
class HatInputControl;

/**
* Base class for modelling a "physical" input device.
Expand Down Expand Up @@ -237,7 +234,7 @@ class InputDevice
/**
* Returns information about the device as styled text.
*/
de::String description() const;
virtual de::String description() const;

/**
* Reset the state of all controls to their "initial" positions (i.e., buttons
Expand Down Expand Up @@ -269,14 +266,14 @@ class InputDevice
*
* @return Axis control associated with the given @a id.
*/
InputDeviceAxisControl &axis(de::dint id) const;
AxisInputControl &axis(de::dint id) const;

/**
* Add an @a axis control to the input device.
*
* @param axis Axis control to add. Ownership is given to the device.
*/
void addAxis(InputDeviceAxisControl *axis);
void addAxis(AxisInputControl *axis);

/**
* Returns the number of axis controls of the device.
Expand All @@ -302,14 +299,14 @@ class InputDevice
*
* @return Button control associated with the given @a id.
*/
InputDeviceButtonControl &button(de::dint id) const;
ButtonInputControl &button(de::dint id) const;

/**
* Add a @a button control to the input device.
*
* @param button Button control to add. Ownership is given to the device.
*/
void addButton(InputDeviceButtonControl *button);
void addButton(ButtonInputControl *button);

/**
* Returns the number of button controls of the device.
Expand All @@ -328,14 +325,14 @@ class InputDevice
*
* @return Hat control associated with the given @a id.
*/
InputDeviceHatControl &hat(de::dint id) const;
HatInputControl &hat(de::dint id) const;

/**
* Add a @a hat control to the input device.
*
* @param hat Hat control to add. Ownership is given to the device.
*/
void addHat(InputDeviceHatControl *hat);
void addHat(HatInputControl *hat);

/**
* Returns the number of hat controls of the device.
Expand All @@ -353,6 +350,6 @@ class InputDevice

Q_DECLARE_OPERATORS_FOR_FLAGS(InputDevice::Control::BindContextAssociation)

typedef InputDevice::Control InputDeviceControl;
typedef InputDevice::Control InputControl;

#endif // CLIENT_INPUTSYSTEM_INPUTDEVICE_H
118 changes: 107 additions & 11 deletions doomsday/apps/client/net.dengine.client.pack/modules/controllers.de
Expand Up @@ -25,7 +25,13 @@ record Gamepad()

def resetDeadzones()
for var in Console.listVars('input-joy-.*-deadzone')
Console.set(var, Input.DEADZONE_DEFAULT)
Console.set(var, Input.DEFAULT_STICK_DEADZONE)
end
for var in Console.listVars('input-joy-.*-factor')
Console.set(var, Input.DEFAULT_STICK_FACTOR)
end
for var in Console.listVars('input-joy-.*-offset')
Console.set(var, 0)
end
end
end
Expand Down Expand Up @@ -79,7 +85,7 @@ record PlaystationGamepad(Gamepad)
rightVert = 'joy-w'

# Common controls, suitable for all games.
event('shortcut', select, 'menu')
event('shortcut', play, 'menu')

event('menu', o, 'menuback')
event('menu', x, 'menuselect')
Expand All @@ -88,24 +94,24 @@ record PlaystationGamepad(Gamepad)
event('menu', left, 'menuleft', repeat=True)
event('menu', right, 'menuright', repeat=True)

event('game', play, 'pause')
event('game', L1, 'pause')
event('game', o, 'impulse jump')
event('game', sqr, 'impulse use')
event('game', x, 'impulse use')
event('game', up, 'impulse nextweapon')
event('game', down, 'impulse prevweapon')
event('game', rightPress, 'impulse lookcenter', condition='modifier-2-up')
event('game', L1, 'impulse automap')
event('game', select, 'impulse automap')

control(R2, 'flymode') # modifier 2
control(R1, 'flymode') # modifier 2
control(rightVert, 'zfly', inverse=True, condition='modifier-2-down')
event('game', rightPress, 'impulse falldown', condition='modifier-2-down')

control(leftHoriz, 'sidestep')
control(leftVert, 'walk', inverse=True)
control(rightHoriz, 'turn')
control(rightVert, 'look', inverse=True, condition='modifier-2-up')
control(R1, 'attack')
control(x, 'attack')
control(R2, 'attack')
control(L2, 'speed')

event('map', rightPress, 'impulse follow')
Expand All @@ -118,17 +124,107 @@ record PlaystationGamepad(Gamepad)

# Inventory controls for Heretic and Hexen.
if App.gamePlugin() in ['heretic', 'hexen']
event('game', left, 'impulse previtem')
event('game', left, 'impulse previtem')
event('game', right, 'impulse nextitem')
event('game', tri, 'impulse useitem')
event('game', tri, 'impulse useitem')
end

self.resetDeadzones()

# Deadzones.
for axis in ['x', 'y', 'z', 'w']
Console.set('input-joy-%s-deadzone' % axis, 0.15)
end
end
end

GenericGamepad().register()
PlaystationGamepad('PS3', ['PLAYSTATION\(R\)3 Controller']).register()
record XboxOneGamepad(Gamepad)
def __init__(id, regex): self.Gamepad->__init__(id, regex)
def bind()
# Names for buttons and other controls.
a = 'joy-button1'
b = 'joy-button2'
x = 'joy-button3'
y = 'joy-button4'
leftPress = 'joy-button7'
rightPress = 'joy-button8'
menu = 'joy-button9'
view = 'joy-button10'
xbox = 'joy-button11'
up = 'joy-button12'
down = 'joy-button13'
left = 'joy-button14'
right = 'joy-button15'
LB = 'joy-button5'
RB = 'joy-button6'
LT = 'joy-z'
RT = 'joy-axis06'
leftHoriz = 'joy-x'
leftVert = 'joy-y'
rightHoriz = 'joy-w'
rightVert = 'joy-axis05'

# Common controls, suitable for all games.
event('shortcut', menu, 'menu')
event('shortcut', xbox, 'menu')

event('menu', b, 'menuback')
event('menu', a, 'menuselect')
event('menu', up, 'menuup', repeat=True)
event('menu', down, 'menudown', repeat=True)
event('menu', left, 'menuleft', repeat=True)
event('menu', right, 'menuright', repeat=True)

event('game', LB, 'pause')
event('game', view, 'impulse automap')
event('game', b, 'impulse jump')
event('game', x, 'impulse use')
event('game', up, 'impulse nextweapon')
event('game', down, 'impulse prevweapon')
event('game', rightPress, 'impulse lookcenter', condition='modifier-2-up')

control(RB, 'flymode') # modifier 2
control(rightVert, 'zfly', inverse=True, condition='modifier-2-down')
event('game', rightPress, 'impulse falldown', condition='modifier-2-down')

control(leftHoriz, 'sidestep')
control(leftVert, 'walk', inverse=True)
control(rightHoriz, 'turn')
control(rightVert, 'look', inverse=True, condition='modifier-2-up')
control(a, 'attack')
control(RT, 'attack')
control(LT, 'speed')

event('map', rightPress, 'impulse follow')
event('map', leftPress, 'impulse rotate')

control(rightHoriz, 'mappanx')
control(rightVert, 'mappany', inverse=True)
control(RT, 'mapzoom')
control(RB, 'mapzoom', inverse=True)

# Inventory controls for Heretic and Hexen.
if App.gamePlugin() in ['heretic', 'hexen']
event('game', left, 'impulse previtem')
event('game', right, 'impulse nextitem')
event('game', y, 'impulse useitem')
end

self.resetDeadzones()

# Deadzones.
for axis in ['x', 'y', 'w', 'axis05']
Console.set('input-joy-%s-deadzone' % axis, 0.15)
end

# Thrusters are stick axes, but we want them to go from 0 to 1.
Console.set('input-%s-factor' % LT, Input.DEFAULT_STICK_FACTOR/2)
Console.set('input-%s-offset' % LT, 0.5)
Console.set('input-%s-factor' % RT, Input.DEFAULT_STICK_FACTOR/2)
Console.set('input-%s-offset' % RT, 0.5)
end
end

GenericGamepad ().register()
PlaystationGamepad('PS3', ['PLAYSTATION\(R\)3 Controller']).register()
XboxOneGamepad ('Xbox One', ['.*Xbox One.*']).register()

0 comments on commit 0e843e2

Please sign in to comment.