ezEngine Release 26.9
Loading...
Searching...
No Matches
ezMcpInputDevice Class Reference

A synthetic input device that writes whatever an agent tells it to. More...

#include <McpInputDevice.h>

Inheritance diagram for ezMcpInputDevice:

Classes

struct  HeldSlot
 What this device is currently writing, and for how much longer. More...
 

Public Member Functions

void SetSlotValue (ezStringView sSlot, float fValue, ezUInt32 uiFrames)
 Sets a slot's value, held until it is changed again or cleared.
 
void ClearSlot (ezStringView sSlot)
 Stops writing a slot entirely. Anything else writing it is then the only source again.
 
void ClearAllSlots ()
 Stops writing every slot.
 
void QueueText (ezStringView sText)
 Injects typed text in one call, as if the OS had delivered every character within the same frame.
 
void GetHeldSlots (ezDynamicArray< HeldSlot > &out_slots) const
 
- Public Member Functions inherited from ezInputDevice
 ezInputDevice ()
 Default Constructor.
 
float GetInputSlotState (ezStringView 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 ezReflectedClass
virtual const ezRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T >
EZ_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Static Public Member Functions

static ezMcpInputDeviceGetInstance ()
 The one instance, or nullptr while the plugin's input tool does not exist.
 
- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()
 

Private Member Functions

virtual void InitializeDevice () override
 Override this if you need to do device specific initialization before the first use.
 
virtual void RegisterInputSlots () override
 Override this to register all the input slots that this device exposes.
 
virtual void UpdateInputSlotValues () override
 Override this, if you need to query the state of the hardware to update the input slots.
 

Additional Inherited Members

- Protected Member Functions inherited from ezInputDevice
virtual void ResetInputSlotValues ()
 Override this, if you need to reset certain input slot values to zero, after the ezInputManager is finished with the current frame update.
 
virtual void UpdateHardwareState (ezTime tTimeDifference)
 This function is called once after ezInputManager::Update with the same time delta value. It allows to update hardware state, such as the vibration of gamepad motors.
 
- Static Protected Member Functions inherited from ezInputDevice
static void RegisterInputSlot (ezStringView sName, ezStringView sDefaultDisplayName, ezBitflags< ezInputSlotFlags > SlotFlags)
 Calls RegisterInputSlot() on the ezInputManager and passes the parameters through.
 
- Protected Attributes inherited from ezInputDevice
bool m_bOverridesAbsoluteInput = false
 Whether this device is authoritative for absolute-value slots (a position, not a delta) it writes, such as the mouse position - see ezInputManager::GatherDeviceInputSlotValues().
 
ezMap< ezString, float > m_InputSlotValues
 Stores all the values for all input slots that this device handles.
 
ezStringBuilder m_sLastCharacters
 If this input device type handles character input, append every typed character (Unicode codepoint) it receives to this, one Append() call per character event. Append rather than overwrite, so several characters typed within one frame - which happens whenever the OS delivers input faster than the game updates - are all preserved instead of all but the last being silently dropped. The ezInputManager calls RetrieveLastCharacters() to query what the user typed since the last update.
 
- Protected Attributes inherited from ezEnumerable< ezInputDevice, ezReflectedClass >
ezEnumerablem_pNextInstance
 

Detailed Description

A synthetic input device that writes whatever an agent tells it to.

A real ezInputDevice rather than ezInputManager::InjectInputSlotValue(), for three reasons that all fall out of how the manager works:

  • GatherDeviceInputSlotValues() merges every device per slot with ezMath::Max, so this coexists with the actual keyboard and mouse instead of fighting them. A human at the machine keeps control.
  • Key down/up transitions and dead zones are computed by the manager from the merged value, so ezKeyState::Pressed and Released come out correct without this class knowing anything about them.
  • Holding a key for several frames is just leaving the value in m_InputSlotValues, and letting go is erasing it. There is no per-slot bookkeeping to get wrong.

It registers no slots of its own. It writes the names that the real devices already registered - 'keyboard_w', 'mouse_button_0' - which is what makes the Max merge meaningful in the first place. A slot nobody registered can still be written, it just never reaches anything that reads input.

The header of ezInputDevice warns that a device may need integration into window message handling. That applies to hardware; there is no hardware here.

Member Function Documentation

◆ InitializeDevice()

virtual void ezMcpInputDevice::InitializeDevice ( )
inlineoverrideprivatevirtual

Override this if you need to do device specific initialization before the first use.

Implements ezInputDevice.

◆ QueueText()

void ezMcpInputDevice::QueueText ( ezStringView  sText)

Injects typed text in one call, as if the OS had delivered every character within the same frame.

Unlike SetSlotValue(), this is not held: it is consumed the next time something reads ezInputManager::RetrieveLastCharacters() - same as a real keystroke - and gone afterwards. Queuing again before that happens appends, it does not replace.

◆ RegisterInputSlots()

virtual void ezMcpInputDevice::RegisterInputSlots ( )
inlineoverrideprivatevirtual

Override this to register all the input slots that this device exposes.

This is called once during initialization. It needs to call RegisterInputSlot() once for every input slot that this device exposes to the system.

Implements ezInputDevice.

◆ SetSlotValue()

void ezMcpInputDevice::SetSlotValue ( ezStringView  sSlot,
float  fValue,
ezUInt32  uiFrames 
)

Sets a slot's value, held until it is changed again or cleared.

Parameters
uiFramesHow many frames to hold it for, counted down once per input update. 0 means indefinitely - which is what a caller who wants to press a key now and release it later wants, and also the way to leave a movement axis held down.

◆ UpdateInputSlotValues()

void ezMcpInputDevice::UpdateInputSlotValues ( )
overrideprivatevirtual

Override this, if you need to query the state of the hardware to update the input slots.

Note
This function might be called multiple times before ResetInputSlotValues() is called. This will be the case when ezInputManager::PollHardware is used to make more frequent hardware updates than input is actually processed. Just make sure to always accumulate delta values (such as mouse move values) and don't expect ResetInputSlotValues() to be called in tandem with this function and it will be fine.

Implements ezInputDevice.


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