23public sealed class TouchEventPoller :
ITouchInput, IDisposable
30 public static TouchEventPoller?
Instance {
get;
private set; }
49 ArgumentNullException.ThrowIfNull(adapter);
55 Instance =
new TouchEventPoller(adapter, config);
67 private readonly Dictionary<int, TouchPoint> _activeTouches =
new();
71 public IReadOnlyList<TouchPoint>
ActiveTouches => _activeTouchesSnapshot;
129 private bool _isDisposed;
143 PinchRecognizer.PinchStarted += OnPinch;
144 PinchRecognizer.PinchUpdated += OnPinch;
145 PinchRecognizer.PinchEnded += OnPinch;
178 internal void PollForEvents(
long tick)
180 if (_isDisposed ||
Adapter is
null)
return;
194 foreach (var beganPoint
in began)
196 if (_activeTouches.ContainsKey(beganPoint.Id))
204 _activeTouches[normalized.Id] = normalized;
208 foreach (var endedPoint
in ended)
212 if (_activeTouches.Remove(endedPoint.Id))
216 var currentActive =
Adapter.ActiveTouches;
219 foreach (var point
in currentActive)
221 if (!_activeTouches.ContainsKey(point.Id))
224 _activeTouches[normalized.Id] = normalized;
225 TouchBegan?.Invoke(
this,
new TouchEventArgs(normalized, tick));
229 bool movementEmitted =
false;
232 foreach (var point
in currentActive)
234 if (!_activeTouches.TryGetValue(point.Id, out var known) ||
235 known.Position == point.Position)
239 _activeTouches[point.Id] = movedPoint;
240 TouchMoved?.Invoke(
this,
new TouchEventArgs(movedPoint, tick));
241 movementEmitted =
true;
245 _activeTouchesSnapshot = _activeTouches.Values.ToArray();
248 Configuration._lastEventTick = tick;
269 if (timeBetweenEvents < 0)
285 private void ClearContactState()
287 _activeTouches.Clear();
288 _activeTouchesSnapshot = Array.Empty<
TouchPoint>();
306 PinchRecognizer.PinchStarted -= OnPinch;
307 PinchRecognizer.PinchUpdated -= OnPinch;
308 PinchRecognizer.PinchEnded -= OnPinch;
314 _activeTouches.Clear();
315 _activeTouchesSnapshot = Array.Empty<
TouchPoint>();
317 if (ReferenceEquals(
Instance,
this))
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.