Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
XInputGamepadManager.cs
2using Microsoft.Extensions.Logging;
4
6
10public sealed class XInputGamepadManager : IGamepadManager<XInputGamepadAdapter>
11{
15 public static XInputGamepadManager? Instance { get; private set; }
16
17 private XInputGamepadManager()
18 {
19 Engine.Logger.LogInformation("XInputGamepadManager initialized. Starting to poll gamepads.");
20 }
21
26 public static XInputGamepadManager Start()
27 {
28 if (Instance is not null)
29 return Instance;
30
31 return Instance = new XInputGamepadManager();
32 }
33
37 public static void Stop()
38 {
39 Engine.Logger.LogInformation("Stopping XInputGamepadManager and removing all XInputGamepadAdapter instances.");
40 Instance = null;
41 }
42
43 private readonly Dictionary<int, XInputGamepadAdapter> _activeAdapters = new();
44
48 public IReadOnlyCollection<XInputGamepadAdapter> ConnectedAdapters => _activeAdapters.Values;
49
53 public void UpdateConnections()
54 {
55 for (int i = 0; i < 4; i++)
56 {
57 bool isConnected = GetState(i, out _) == 0;
58
59 if (isConnected)
60 {
61 if (!_activeAdapters.ContainsKey(i))
62 _activeAdapters[i] = new XInputGamepadAdapter(i);
63 }
64 else
65 {
66 _activeAdapters.Remove(i);
67 }
68 }
69 }
70
74 public void Poll()
75 {
76 foreach (var adapter in _activeAdapters.Values)
77 adapter.Poll();
78 }
79
83 [Obsolete("Use UpdateConnections() and Poll() separately.")]
84 public void Update()
85 {
87 Poll();
88 }
89}
Represents the core game engine singleton responsible for managing the main update loop,...
Definition Engine.cs:36
static ILogger< Engine > Logger
Gets the logger instance used by the engine for diagnostic and informational messages.
Definition Engine.cs:59
Provides a gamepad adapter implementation using XInput for Xbox controller support on Windows.
Manages XInput-based gamepad connections and state updates for Xbox controllers on Windows.
void UpdateConnections()
Checks the four XInput controller slots for connection and disconnection changes.
static ? XInputGamepadManager Instance
Gets the singleton instance of the XInputGamepadManager, if it has been started.
void Update()
Performs the legacy combined connection and state refresh.
void Poll()
Polls the current state of all connected XInput controllers.
IReadOnlyCollection< XInputGamepadAdapter > ConnectedAdapters
Gets the collection of currently connected XInput gamepad adapters.
static void Stop()
Stops the XInput gamepad manager and clears the singleton instance.
static XInputGamepadManager Start()
Starts the XInput gamepad manager and returns the singleton instance.