![]() |
Plasma Engine
2.0
|
This class is the base class for all controller type input devices. More...
#include <Controller.h>
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 (plUInt8 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 (plUInt8 uiVirtual) const |
Checks whether vibration is enabled on the given controller (virtual index). | |
void | SetVibrationStrength (plUInt8 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 (plUInt8 uiVirtual, Motor::Enum motor) |
Returns the amount of (constant) vibration that is currently set on this controller. | |
void | SetControllerMapping (plUInt8 uiVirtualController, plInt8 iTakeInputFromPhysical) |
Sets from which physical controller a virtual controller is supposed to take its input. | |
plInt8 | GetControllerMapping (plUInt8 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 (plUInt8 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 (plUInt8 uiVirtual, Motor::Enum motor, float *pVibrationTrackValue, plUInt32 uiSamples, float fScalingFactor=1.0f) |
Adds a short 'vibration track' (a sequence of vibrations) to the given controller. | |
![]() | |
plInputDevice () | |
Default Constructor. | |
float | GetInputSlotState (plStringView 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. | |
![]() | |
virtual const plRTTI * | GetDynamicRTTI () const |
bool | IsInstanceOf (const plRTTI *pType) const |
Returns whether the type of this instance is of the given type or derived from it. | |
template<typename T > | |
PL_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 (plTime tTimeDifference) |
Combines the constant vibration and vibration tracks and applies them on each controller. | |
![]() | |
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 plInputManager 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 (plTime tTimeDifference) |
This function is called once after plInputManager::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 (plUInt8 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 const plRTTI * | GetStaticRTTI () |
![]() | |
static void | RegisterInputSlot (plStringView sName, plStringView sDefaultDisplayName, plBitflags< plInputSlotFlags > SlotFlags) |
Calls RegisterInputSlot() on the plInputManager and passes the parameters through. | |
![]() | |
plMap< plString, float > | m_InputSlotValues |
Stores all the values for all input slots that this device handles. | |
plUInt32 | m_uiLastCharacter |
If this input device type handles character input, it should write the last typed character into this variable. The plInputManager calls RetrieveLastCharacter() to query what the user typed last. | |
![]() | |
plEnumerable * | m_pNextInstance |
This class is the base class for all controller type input devices.
This class is derived from plInputDevice 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.
void plInputDeviceController::AddVibrationTrack | ( | plUInt8 | uiVirtual, |
Motor::Enum | motor, | ||
float * | pVibrationTrackValue, | ||
plUInt32 | 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).
uiVirtual | The virtual index of the controller. |
eMotor | Which motor to apply the track on. |
fVibrationTrackValue | An array of at least uiSamples float values, each between 0 and 1. |
uiSamples | How many samples fVibrationTrackValue contains. A maximum of MaxVibrationSamples samples is used. |
fScalingFactor | Additional scaling factor to apply to all values in fVibrationTrackValue. |
|
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.
|
pure virtual |
Queries whether the controller with the given physical index is connected to the computer. This may change at any time.
Implemented in plInputDeviceXBox360.
void plInputDeviceController::SetControllerMapping | ( | plUInt8 | uiVirtualController, |
plInt8 | 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 plInputDeviceController::SetVibrationStrength | ( | plUInt8 | 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.
|
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.