8public sealed class GamepadEventPoller
10 private readonly Dictionary<string, Dictionary<string, GamepadButtonEventConfiguration>> _configsByGamepadId =
new();
17 public static GamepadEventPoller?
Instance {
get;
private set; } =
new();
22 private GamepadEventPoller(IEnumerable<IGamepadAdapter>? adapters)
24 _configsByGamepadId.Clear();
26 RefreshAdapters(adapters);
37 public static void Initialize(IEnumerable<IGamepadAdapter>? adapters)
39 Instance =
new GamepadEventPoller(adapters);
51 internal void RefreshAdapters(IEnumerable<IGamepadAdapter>? adapters)
53 var snapshot = adapters?.ToArray();
59 foreach (var adapter
in snapshot)
61 if (!_configsByGamepadId.ContainsKey(adapter.GamepadId))
62 _configsByGamepadId[adapter.GamepadId] =
new Dictionary<string, GamepadButtonEventConfiguration>();
70 public IEnumerable<IGamepadAdapter>?
Adapters {
get;
private set; }
85 public event Action<GamepadButtonDownEventArgs>?
ButtonDown;
106 internal void PollForEvents(
long tick)
112 if (!_configsByGamepadId.TryGetValue(adapter.GamepadId, out var configs))
115 foreach (var kvp
in configs)
117 var button = kvp.Key;
118 var config = kvp.Value;
120 if (config.IsPaused || !adapter.PressedButtons.Contains(button))
continue;
122 if (config.ReadyForNextEvent(tick))
124 config._lastEventTick = tick;
125 configs[button] = config;
156 public void StartMonitoringButton(
string gamepadId,
string button,
double timeBetweenEvents = -1,
bool isPaused =
false)
158 if (timeBetweenEvents < 0)
161 if (!_configsByGamepadId.TryGetValue(gamepadId, out var configMap))
163 configMap =
new Dictionary<string, GamepadButtonEventConfiguration>();
164 _configsByGamepadId[gamepadId] = configMap;
183 if (_configsByGamepadId.TryGetValue(gamepadId, out var configMap))
185 configMap.Remove(button);
199 _configsByGamepadId.Remove(gamepadId);
209 => _configsByGamepadId.ToDictionary(
211 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.