XII Release 0.1.0
Loading...
Searching...
No Matches
xiiInputDeviceController Class Referenceabstract

This class is the base class for all controller type input devices. More...

#include <Controller.h>

Inheritance diagram for xiiInputDeviceController:
[legend]

Classes

struct  Motor
 Describes which vibration motor to configure. More...
 

Public Types

enum  { MaxControllers = 4 , VibrationSamplesPerSecond = 16 , VibrationTrackSeconds = 2 , MaxVibrationSamples = VibrationSamplesPerSecond * VibrationTrackSeconds }
 

Public Member Functions

void EnableVibration (xiiUInt8 uiVirtual, bool bEnable)
 Enables or disables vibration on the given controller (virtual index). If it is disabled, the controller will never vibrate, even if vibration profiles are sent to it.
 
bool IsVibrationEnabled (xiiUInt8 uiVirtual) const
 Checks whether vibration is enabled on the given controller (virtual index).
 
void SetVibrationStrength (xiiUInt8 uiVirtual, Motor::Enum motor, float fValue)
 Sets the vibration strength for the given controller and motor. fValue is a value between 0 and 1.
 
float GetVibrationStrength (xiiUInt8 uiVirtual, Motor::Enum motor)
 Returns the amount of (constant) vibration that is currently set on this controller.
 
void SetControllerMapping (xiiUInt8 uiVirtualController, xiiInt8 iTakeInputFromPhysical)
 Sets from which physical controller a virtual controller is supposed to take its input.
 
xiiInt8 GetPhysicalControllerMapping (xiiUInt8 uiVirtual) const
 Returns from which physical controller the given virtual controller takes its input. May be negative, which means the virtual controller is deactivated.
 
xiiInt8 GetVirtualControllerMapping (xiiUInt8 uiPhysical) const
 Returns to which virtual controller the given physical controller pushes its input. May be negative, which means the physical controller is not used.
 
virtual bool IsControllerConnected (xiiUInt8 uiPhysical) const =0
 Queries whether the controller with the given physical index is connected to the computer. This may change at any time.
 
void AddVibrationTrack (xiiUInt8 uiVirtual, Motor::Enum motor, float *pVibrationTrackValue, xiiUInt32 uiSamples, float fScalingFactor=1.0f)
 Adds a short 'vibration track' (a sequence of vibrations) to the given controller.
 
- Public Member Functions inherited from xiiInputDevice
 xiiInputDevice ()
 Default Constructor.
 
float GetInputSlotState (xiiStringView sSlot) const
 Allows to query current input values for the given slot.
 
bool HasDeviceBeenUsedLastFrame () const
 Returns true, if the device was 'used' during the last frame, ie. when it generated input due to some user interaction.
 
- Public Member Functions inherited from xiiReflectedClass
virtual const xiiRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const xiiRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T>
XII_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Protected Member Functions

void UpdateVibration (xiiTime tTimeDifference)
 Combines the constant vibration and vibration tracks and applies them on each controller.
 
- Protected Member Functions inherited from xiiInputDevice
virtual void InitializeDevice ()=0
 Override this if you need to do device specific initialization before the first use.
 
virtual void UpdateInputSlotValues ()=0
 Override this, if you need to query the state of the hardware to update the input slots.
 
virtual void ResetInputSlotValues ()
 Override this, if you need to reset certain input slot values to zero, after the xiiInputManager is finished with the current frame update.
 
virtual void RegisterInputSlots ()=0
 Override this to register all the input slots that this device exposes.
 
virtual void UpdateHardwareState (xiiTime tTimeDifference)
 This function is called once after xiiInputManager::Update with the same time delta value. It allows to update hardware state, such as the vibration of gamepad motors.
 

Private Member Functions

virtual void ApplyVibration (xiiUInt8 uiPhysicalController, Motor::Enum eMotor, float fStrength)=0
 Must be implemented by a derived controller implementation. Should set apply the vibration for the given physical controller and motor with the given strength.
 

Additional Inherited Members

- Static Public Member Functions inherited from xiiNoBase
static const xiiRTTIGetStaticRTTI ()
 
- Static Protected Member Functions inherited from xiiInputDevice
static void RegisterInputSlot (xiiStringView sName, xiiStringView sDefaultDisplayName, xiiBitflags< xiiInputSlotFlags > SlotFlags)
 Calls RegisterInputSlot() on the xiiInputManager and passes the parameters through.
 
- Protected Attributes inherited from xiiInputDevice
xiiMap< xiiString, float > m_InputSlotValues
 Stores all the values for all input slots that this device handles.
 
xiiUInt32 m_uiLastCharacter
 If this input device type handles character input, it should write the last typed character into this variable. The xiiInputManager calls RetrieveLastCharacter() to query what the user typed last.
 
- Protected Attributes inherited from xiiEnumerable< xiiInputDevice, xiiReflectedClass >
xiiEnumerablem_pNextInstance
 

Detailed Description

This class is the base class for all controller type input devices.

This class is derived from xiiInputDevice but adds some interface functions common to most controllers. This class adds functions to query and modify the state about controller vibration, about the mapping of physical controllers to virtual ones (which controller index triggers which controller input slots) and also allows to query which controller is actually connected.

Member Function Documentation

◆ AddVibrationTrack()

void xiiInputDeviceController::AddVibrationTrack ( xiiUInt8 uiVirtual,
Motor::Enum motor,
float * pVibrationTrackValue,
xiiUInt32 uiSamples,
float fScalingFactor = 1.0f )

Adds a short 'vibration track' (a sequence of vibrations) to the given controller.

Each controller has a short (typically 2 second) buffer for vibration values, that it will play. This allows to have different 'tracks' for different events, which are simply set on the controller. You can add an unlimited amount of tracks on a controller, the controller stores the maximum of all tracks and plays that. That means whenever the player shoots, or is hit etc., you can add a vibration track to the controller and it will be combined with all other tracks and played (no memory allocations are required).

Parameters
uiVirtualThe virtual index of the controller.
eMotorWhich motor to apply the track on.
fVibrationTrackValueAn array of at least uiSamples float values, each between 0 and 1.
uiSamplesHow many samples fVibrationTrackValue contains. A maximum of MaxVibrationSamples samples is used.
fScalingFactorAdditional scaling factor to apply to all values in fVibrationTrackValue.

◆ ApplyVibration()

virtual void xiiInputDeviceController::ApplyVibration ( xiiUInt8 uiPhysicalController,
Motor::Enum eMotor,
float fStrength )
privatepure virtual

Must be implemented by a derived controller implementation. Should set apply the vibration for the given physical controller and motor with the given strength.

A strength value of zero will be passed in whenever no vibration is required. No extra resetting needs to be implemented.

◆ SetControllerMapping()

void xiiInputDeviceController::SetControllerMapping ( xiiUInt8 uiVirtualController,
xiiInt8 iTakeInputFromPhysical )

Sets from which physical controller a virtual controller is supposed to take its input.

If iTakeInputFromPhysical is smaller than zero, the given virtual controller is deactivated (it will generate no input). If input is taken from a physical controller, that is already mapped to another virtual controller, that virtual controller will now take input from the physical controller that uiVirtualController was previously mapped to (ie. they will swap from which physical controller to take input). By default all virtual controllers take their input from the physical controller with the same index. You can use this feature to let the player pick up any controller, detect which one it is (e.g. by forcing him to press 'Start') and then map that physical controller index to the virtual index 0 (ie. player 1). Note that unless you specify a negative index for a mapping (which deactivates that virtual controller), mapping controllers around does never deactivate any controller, because the indices are swapped between the different virtual controllers, so which physical controller maps to which virtual controller only 'moves around'.

◆ SetVibrationStrength()

void xiiInputDeviceController::SetVibrationStrength ( xiiUInt8 uiVirtual,
Motor::Enum motor,
float fValue )

Sets the vibration strength for the given controller and motor. fValue is a value between 0 and 1.

From now on the controller will be vibrating (unless vibration is disabled), until the value is reset to zero. This kind of vibration is always combined with vibration tracks (the maximum of both values is applied at any one time). Using this function is it possible to have more direct control over vibration, while the vibration tracks are convenient for the most common (short) effects.

◆ UpdateVibration()

void xiiInputDeviceController::UpdateVibration ( xiiTime tTimeDifference)
protected

Combines the constant vibration and vibration tracks and applies them on each controller.

This function needs to be called by a derived implementation in its UpdateInputSlotValues() function. It will call ApplyVibration() for each controller and motor with the current value. It already takes care of whether vibration is enabled or disabled, and also mapping virtual to physical controllers.


The documentation for this class was generated from the following files: