-
Notifications
You must be signed in to change notification settings - Fork 45
/
GamepadDeviceBase.cs
43 lines (33 loc) · 1.27 KB
/
GamepadDeviceBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections.Generic;
namespace DirectX12GameEngine.Input
{
public abstract class GamepadDeviceBase : IGamepadDevice
{
public abstract bool IsWireless { get; }
public abstract GamepadVibration Vibration { get; set; }
public ISet<GamepadButtons> DownButtons { get; } = new HashSet<GamepadButtons>();
public ISet<GamepadButtons> PressedButtons { get; } = new HashSet<GamepadButtons>();
public ISet<GamepadButtons> ReleasedButtons { get; } = new HashSet<GamepadButtons>();
public abstract GamepadReading CurrentReading { get; }
public abstract BatteryReport TryGetBatteryReport();
public abstract void Update();
protected void ClearButtonStates()
{
PressedButtons.Clear();
ReleasedButtons.Clear();
}
protected void UpdateButtonState(GamepadButtons button, bool isDown)
{
if (isDown && !DownButtons.Contains(button))
{
PressedButtons.Add(button);
DownButtons.Add(button);
}
else if (!isDown && DownButtons.Contains(button))
{
ReleasedButtons.Add(button);
DownButtons.Remove(button);
}
}
}
}