8public sealed class GamepadEventPoller
10 private readonly Dictionary<string, Dictionary<string, GamepadButtonEventConfiguration>>
11 _configsByGamepadId =
new();
18 public static GamepadEventPoller?
Instance {
get;
private set; } =
new();
24 private GamepadEventPoller(IEnumerable<IGamepadAdapter>? adapters)
26 _configsByGamepadId.Clear();
28 RefreshAdapters(adapters);
39 public static void Initialize(IEnumerable<IGamepadAdapter>? adapters)
41 Instance =
new GamepadEventPoller(adapters);
53 internal void RefreshAdapters(IEnumerable<IGamepadAdapter>? adapters)
55 var snapshot = adapters?.ToArray();
61 foreach (var adapter
in snapshot)
63 if (!_configsByGamepadId.ContainsKey(adapter.GamepadId))
64 _configsByGamepadId[adapter.GamepadId] =
new Dictionary<string, GamepadButtonEventConfiguration>();
72 public IEnumerable<IGamepadAdapter>?
Adapters {
get;
private set; }
87 public event Action<GamepadButtonDownEventArgs>?
ButtonDown;
108 internal void PollForEvents(
long tick)
115 if (!_configsByGamepadId.TryGetValue(adapter.GamepadId, out var configs))
118 foreach (var kvp
in configs)
120 var button = kvp.Key;
121 var config = kvp.Value;
123 if (config.IsPaused || !adapter.PressedButtons.Contains(button))
126 if (config.ReadyForNextEvent(tick))
128 config._lastEventTick = tick;
129 configs[button] = config;
163 double timeBetweenEvents = -1,
164 bool isPaused =
false)
166 if (timeBetweenEvents < 0)
169 if (!_configsByGamepadId.TryGetValue(gamepadId, out var configMap))
171 configMap =
new Dictionary<string, GamepadButtonEventConfiguration>();
172 _configsByGamepadId[gamepadId] = configMap;
191 if (_configsByGamepadId.TryGetValue(gamepadId, out var configMap))
193 configMap.Remove(button);
207 _configsByGamepadId.Remove(gamepadId);
216 public IReadOnlyDictionary<string, IReadOnlyDictionary<string, GamepadButtonEventConfiguration>>
218 => _configsByGamepadId.ToDictionary(
220 entry => (IReadOnlyDictionary<string, GamepadButtonEventConfiguration>)entry.Value);
Represents the core game engine singleton responsible for managing the main update loop,...
static Engine Instance
Gets the singleton instance of the Engine.
EngineConfiguration Configuration
Gets the current engine configuration settings.