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;
130 private bool _isDisposed;
144 PinchRecognizer.PinchStarted += OnPinch;
145 PinchRecognizer.PinchUpdated += OnPinch;
146 PinchRecognizer.PinchEnded += OnPinch;
179 internal void PollForEvents(
long tick)
181 if (_isDisposed ||
Adapter is
null)
196 foreach (var beganPoint
in began)
198 if (_activeTouches.ContainsKey(beganPoint.Id))
206 _activeTouches[normalized.Id] = normalized;
210 foreach (var endedPoint
in ended)
214 if (_activeTouches.Remove(endedPoint.Id))
218 var currentActive =
Adapter.ActiveTouches;
221 foreach (var point
in currentActive)
223 if (!_activeTouches.ContainsKey(point.Id))
226 _activeTouches[normalized.Id] = normalized;
227 TouchBegan?.Invoke(
this,
new TouchEventArgs(normalized, tick));
231 bool movementEmitted =
false;
235 foreach (var point
in currentActive)
237 if (!_activeTouches.TryGetValue(point.Id, out var known) ||
238 known.Position == point.Position)
242 _activeTouches[point.Id] = movedPoint;
243 TouchMoved?.Invoke(
this,
new TouchEventArgs(movedPoint, tick));
244 movementEmitted =
true;
248 _activeTouchesSnapshot = _activeTouches.Values.ToArray();
251 Configuration._lastEventTick = tick;
272 if (timeBetweenEvents < 0)
288 private void ClearContactState()
290 _activeTouches.Clear();
291 _activeTouchesSnapshot = Array.Empty<
TouchPoint>();
309 PinchRecognizer.PinchStarted -= OnPinch;
310 PinchRecognizer.PinchUpdated -= OnPinch;
311 PinchRecognizer.PinchEnded -= OnPinch;
317 _activeTouches.Clear();
318 _activeTouchesSnapshot = Array.Empty<
TouchPoint>();
320 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.