ezEngine  Milestone 7
ezInputDeviceController Class Referenceabstract

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

#include <Controller.h>

Inheritance diagram for ezInputDeviceController:

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 (ezUInt8 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 (ezUInt8 uiVirtual) const
 Checks whether vibration is enabled on the given controller (virtual index).
 
void SetVibrationStrength (ezUInt8 uiVirtual, Motor::Enum eMotor, float fValue)
 Sets the vibration strength for the given controller and motor. fValue is a value between 0 and 1. More...
 
float GetVibrationStrength (ezUInt8 uiVirtual, Motor::Enum eMotor)
 Returns the amount of (constant) vibration that is currently set on this controller.
 
void SetControllerMapping (ezUInt8 uiVirtualController, ezInt8 iTakeInputFromPhysical)
 Sets from which physical controller a virtual controller is supposed to take its input. More...
 
ezInt8 GetControllerMapping (ezUInt8 uiVirtual) const
 Returns from which physical controller the given virtual controller takes its input. May be negative, which means the virtual controller is deactivated.
 
virtual bool IsControllerConnected (ezUInt8 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 (ezUInt8 uiVirtual, Motor::Enum eMotor, float *fVibrationTrackValue, ezUInt32 uiSamples, float fScalingFactor=1.0f)
 Adds a short 'vibration track' (a sequence of vibrations) to the given controller. More...
 
- Public Member Functions inherited from ezInputDevice
 ezInputDevice ()
 Default Constructor.
 

Protected Member Functions

void UpdateVibration (ezTime tTimeDifference)
 Combines the constant vibration and vibration tracks and applies them on each controller. More...
 

Private Member Functions

 EZ_ADD_DYNAMIC_REFLECTION (ezInputDeviceController)
 
virtual void ApplyVibration (ezUInt8 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. More...
 

Private Attributes

ezUInt32 m_uiVibrationTrackPos
 
float m_fVibrationTracks [MaxControllers][Motor::ENUM_COUNT][MaxVibrationSamples]
 
bool m_bVibrationEnabled [MaxControllers]
 
ezInt8 m_iControllerMapping [MaxControllers]
 
float m_fVibrationStrength [MaxControllers][Motor::ENUM_COUNT]
 

Additional Inherited Members

- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()
 
- Static Protected Member Functions inherited from ezInputDevice
static void RegisterInputSlot (const char *szName, const char *szDefaultDisplayName, ezBitflags< ezInputSlotFlags > SlotFlags)
 Calls RegisterInputSlot() on the ezInputManager and passes the parameters through.
 
- Protected Attributes inherited from ezInputDevice
ezMap< ezString, float > m_InputSlotValues
 Stores all the values for all input slots that this device handles. More...
 
ezUInt32 m_LastCharacter
 If this input device type handles character input, it should write the last typed character into this variable. The ezInputManager calls RetrieveLastCharacter() to query what the user typed last.
 

Detailed Description

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

This class is derived from ezInputDevice 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

void ezInputDeviceController::AddVibrationTrack ( ezUInt8  uiVirtual,
Motor::Enum  eMotor,
float *  fVibrationTrackValue,
ezUInt32  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.
virtual void ezInputDeviceController::ApplyVibration ( ezUInt8  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.

void ezInputDeviceController::SetControllerMapping ( ezUInt8  uiVirtualController,
ezInt8  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'.

void ezInputDeviceController::SetVibrationStrength ( ezUInt8  uiVirtual,
Motor::Enum  eMotor,
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.

void ezInputDeviceController::UpdateVibration ( ezTime  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: