Gondwana Game Engine
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop, mobile, and web platforms using SkiaSharp for graphics and NAudio for sound.
Loading...
Searching...
No Matches
Gondwana.Input.Gamepad.GamepadEventPoller Class Referencesealed

Provides centralized polling and event management for gamepad button inputs across multiple gamepad devices. This singleton class monitors registered buttons on connected gamepads and raises events when buttons are pressed, with support for event throttling and pause states at both global and per-button levels. More...

Public Member Functions

void PollForEvents (long tick)
 Polls the configured gamepad adapters for button press events and raises the ButtonDown event for buttons that are currently pressed and ready to generate events based on their configurations.
void StartMonitoringButton (string gamepadId, string button, double timeBetweenEvents=-1, bool isPaused=false)
 Registers a button on a specific gamepad for event monitoring with optional throttling and pause configuration. Once registered, the button will be polled during calls to PollForEvents(long) and generate ButtonDown events when pressed.
void StopMonitoringButton (string gamepadId, string button)
 Unregisters a specific button on a gamepad from event monitoring. After calling this method, the button will no longer be polled and will not generate ButtonDown events until it is registered again using StartMonitoringButton.
void StopMonitoringAllButtons (string gamepadId)
 Unregisters all buttons on a specific gamepad from event monitoring. This effectively removes all button configurations for the specified gamepad, and no buttons on that gamepad will generate events until they are registered again.

Static Public Member Functions

static void Initialize (IEnumerable< IGamepadAdapter >? adapters)
 Initializes the singleton instance of the GamepadEventPoller with the specified gamepad adapters. This method replaces the existing instance and configures it to monitor the provided adapters.

Properties

static ? GamepadEventPoller Instance = new() [get]
 Gets the singleton instance of the GamepadEventPoller class. This instance is created automatically on first access and can be reinitialized using the Initialize(IEnumerable<IGamepadAdapter>?) method.
IEnumerable< IGamepadAdapter >? Adapters [get]
 Gets the collection of gamepad adapters currently being monitored by this poller. Each adapter represents a physical or virtual gamepad device and provides access to its current state.
bool PauseAllInput [get, set]
 Gets or sets a value indicating whether all input processing is globally paused. When set to true, the poller will not raise any button events regardless of individual button configuration pause states. This provides a convenient way to temporarily disable all gamepad input, such as when a game is paused or a modal dialog is displayed.
IReadOnlyDictionary< string, IReadOnlyDictionary< string, GamepadButtonEventConfiguration > > AllButtonConfigsByGamepadId [get]
 Gets a read-only view of all button configurations organized by gamepad ID. The outer dictionary maps gamepad IDs to inner dictionaries, where each inner dictionary maps button identifiers to their respective GamepadButtonEventConfiguration instances. This property is useful for inspecting the current monitoring state of all gamepads and buttons.

Events

Action< GamepadButtonDownEventArgs >? ButtonDown
 Occurs when a monitored gamepad button is pressed and the button's configuration allows the event to be raised based on throttling settings. Subscribe to this event to handle gamepad button down input in your application.

Detailed Description

Provides centralized polling and event management for gamepad button inputs across multiple gamepad devices. This singleton class monitors registered buttons on connected gamepads and raises events when buttons are pressed, with support for event throttling and pause states at both global and per-button levels.

Member Function Documentation

◆ Initialize()

void Gondwana.Input.Gamepad.GamepadEventPoller.Initialize ( IEnumerable< IGamepadAdapter >? adapters)
static

Initializes the singleton instance of the GamepadEventPoller with the specified gamepad adapters. This method replaces the existing instance and configures it to monitor the provided adapters.

Parameters
adaptersA collection of gamepad adapters representing the connected gamepad devices to be monitored. Pass null to create an instance without any adapters.

◆ PollForEvents()

void Gondwana.Input.Gamepad.GamepadEventPoller.PollForEvents ( long tick)

Polls the configured gamepad adapters for button press events and raises the ButtonDown event for buttons that are currently pressed and ready to generate events based on their configurations.

This method should be called regularly (typically once per frame or game tick) to ensure timely detection of button presses. It iterates through all configured gamepad adapters and checks each monitored button against its configuration. Events are only raised if:

  • PauseAllInput is false
  • The button's configuration is not paused
  • The button is currently pressed according to the adapter
  • Sufficient time has elapsed since the last event for that button (based on throttling settings)
Parameters
tickThe current game tick or timestamp value, used to calculate elapsed time for event throttling. This value should be monotonically increasing to ensure correct timing behavior.

◆ StartMonitoringButton()

void Gondwana.Input.Gamepad.GamepadEventPoller.StartMonitoringButton ( string gamepadId,
string button,
double timeBetweenEvents = -1,
bool isPaused = false )

Registers a button on a specific gamepad for event monitoring with optional throttling and pause configuration. Once registered, the button will be polled during calls to PollForEvents(long) and generate ButtonDown events when pressed.

Parameters
gamepadIdThe unique identifier of the gamepad device on which the button should be monitored. This must match the IGamepadAdapter.GamepadId of one of the configured adapters.
buttonThe identifier of the button to monitor (e.g., "A", "B", "X", "Y", "Start", "Back"). This should match the button naming convention used by the gamepad adapter.
timeBetweenEventsThe minimum time interval in seconds between consecutive events for this button. Use this to throttle rapid button presses. A value of -1 (default) will use the engine's default time between gamepad events from Engine.Configuration.TimeBetweenGamepadEvents. A value of 0 means no throttling.
isPausedA value indicating whether event processing for this button should be initially paused. When paused, the button will not generate events even if pressed. Default is false.

◆ StopMonitoringAllButtons()

void Gondwana.Input.Gamepad.GamepadEventPoller.StopMonitoringAllButtons ( string gamepadId)

Unregisters all buttons on a specific gamepad from event monitoring. This effectively removes all button configurations for the specified gamepad, and no buttons on that gamepad will generate events until they are registered again.

Parameters
gamepadIdThe unique identifier of the gamepad device for which all button monitoring should be stopped.

◆ StopMonitoringButton()

void Gondwana.Input.Gamepad.GamepadEventPoller.StopMonitoringButton ( string gamepadId,
string button )

Unregisters a specific button on a gamepad from event monitoring. After calling this method, the button will no longer be polled and will not generate ButtonDown events until it is registered again using StartMonitoringButton.

Parameters
gamepadIdThe unique identifier of the gamepad device from which the button should be removed.
buttonThe identifier of the button to stop monitoring.

Property Documentation

◆ Adapters

IEnumerable<IGamepadAdapter>? Gondwana.Input.Gamepad.GamepadEventPoller.Adapters
get

Gets the collection of gamepad adapters currently being monitored by this poller. Each adapter represents a physical or virtual gamepad device and provides access to its current state.

◆ AllButtonConfigsByGamepadId

IReadOnlyDictionary<string, IReadOnlyDictionary<string, GamepadButtonEventConfiguration> > Gondwana.Input.Gamepad.GamepadEventPoller.AllButtonConfigsByGamepadId
get

Gets a read-only view of all button configurations organized by gamepad ID. The outer dictionary maps gamepad IDs to inner dictionaries, where each inner dictionary maps button identifiers to their respective GamepadButtonEventConfiguration instances. This property is useful for inspecting the current monitoring state of all gamepads and buttons.

◆ Instance

? GamepadEventPoller Gondwana.Input.Gamepad.GamepadEventPoller.Instance = new()
staticget

Gets the singleton instance of the GamepadEventPoller class. This instance is created automatically on first access and can be reinitialized using the Initialize(IEnumerable<IGamepadAdapter>?) method.

◆ PauseAllInput

bool Gondwana.Input.Gamepad.GamepadEventPoller.PauseAllInput
getset

Gets or sets a value indicating whether all input processing is globally paused. When set to true, the poller will not raise any button events regardless of individual button configuration pause states. This provides a convenient way to temporarily disable all gamepad input, such as when a game is paused or a modal dialog is displayed.

Event Documentation

◆ ButtonDown

Action<GamepadButtonDownEventArgs>? Gondwana.Input.Gamepad.GamepadEventPoller.ButtonDown

Occurs when a monitored gamepad button is pressed and the button's configuration allows the event to be raised based on throttling settings. Subscribe to this event to handle gamepad button down input in your application.