Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow fps when no joysticks #28

Closed

Conversation

dascandy
Copy link
Contributor

On my system for some reason, SDL reports one joystick. I don't know what it thinks is a joystick, but it also seems to indicate it's not a usable one. The joystick code in OpenSupaplex seems to cause the framerate to drop as a brick if it reprobes a bunch of times per second. Without this patch I get about 2 FPS in-game and in the menu, but 60FPS during transitions. With this patch, it's smooth 60FPS all around.

Let me know if you have something I can test instead of this. This patch makes it so that runtime plugged in joysticks will only work if there's at least one working joystick available at all times.

… that meets its criteria, this code causes it to slow to ~2 fps. Making it check for this case & opt out gets it to 60+.
@sergiou87
Copy link
Owner

The problem with this patch is that the game will not recognize any game controllers if they're not connected from the beginning. You should be able to enumerate the Joysticks detected by SDL and find which specific device is causing you this problem, and or why is it so slow to check if that joystick is a game controller or not.

I'm sorry but this looks more of an issue in SDL than in OpenSupaplex 😅

@dascandy
Copy link
Contributor Author

Honestly... kinda. I have no idea why it's taking so long, or why it shows a device that it already knows won't work. Will see if I can find this in SDL.

@dascandy
Copy link
Contributor Author

So I learned that SDL differentiates between "Joysticks" - things that can be accessed through the OS Joystick API, and "Game Controllers", joysticks that roughly match a typical actual joystick.

In this case, the code is re-probing the joysticks many times a frame. While I agree that SDL shouldn't be this slow, it seems to be actually using the device for the probe every time, making it really slow to check. Will create a SDL issue & link here.

@dascandy
Copy link
Contributor Author

incidentally, the "game controller" in question is called "ASRock LED Controller". Not too uncommon to have in computers, so more people might be affected.

@dascandy
Copy link
Contributor Author

Checked a few things, the SDL_IsGameController call takes on average 20-30 milliseconds. For a function that looks like a property lookup that's very long. Filing a bug on SDL, since even with checking this only once per frame would make getting 30FPS hard, and it is completely known in SDL whether it needs to be re-checked.

@dascandy
Copy link
Contributor Author

Linked SDL ticket - libsdl-org/SDL#5211

@dascandy
Copy link
Contributor Author

Fixed in latest SDL version (by ignoring the device entirely).

@dascandy dascandy closed this Jan 11, 2022
@dascandy dascandy deleted the fix-slow-fps-when-no-joysticks branch January 11, 2022 20:26
@sergiou87
Copy link
Owner

Yay! That's awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants