dotnet / dotnet/Silk.NET

Unnecessary updating of joysticks and gamepads

Open
#2,362 0 comments 0 reactions 0 assignees View on GitHub
area-Input bug good first issue help wanted
Dominant language
C#
Stars
5.2k
Forks
477
Avg merge
3d 16h
Merged PRs (30d)
2

Description

# Summary
GLFW does not expose callbacks for joysticks and gamepads, meaning that in order to get updates from these devices, Silk.NET must get the state from GLFW every `Update` and manually diff the state retrieved to raise the necessary events. This causes something of an efficiency penalty (we've had a report of excessive temperatures, but most reports are profiling related) but is ultimately unavoidable. However, one of the most seemingly expensive parts of this is that we're updating all 16 gamepads/joysticks, even the disconnected ones! And interestingly GLFW does actually have a callback for joystick connection/disconnection.

I would like to propose that we change the backend to only `Update` when we have received a callback indicating that the joystick is connected (i.e. cache the result, and also within that callback we should also cache the result of `glfwJoystickIsGamepad`). This should massively reduce the amount of complaints we get with this logic.

# Steps to reproduce
- Platform: any
- Framework Version: modern .NET desktop
- API: Windowing
- API Version: SDL
1. Open a window with no input context
2. Observe performance metrics/profiling/temperature
3. Open a window that creates an input context
4. Observe lower performance metrics/profiling/temperature

# Comments
This was identified originally in discussion with @Chriz-G [in Discord](https://discord.com/channels/521092042781229087/607634593201520651/1309161249959051354). I think they indicated they might be working on a fix. Further report received from @holographicwings

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.