close
Skip to content

Removed time-based poll for joysticks and replaced with manual update#1195

Closed
JonnyPtn wants to merge 1 commit into
SFML:masterfrom
JonnyPtn:JoyLag
Closed

Removed time-based poll for joysticks and replaced with manual update#1195
JonnyPtn wants to merge 1 commit into
SFML:masterfrom
JonnyPtn:JoyLag

Conversation

@JonnyPtn

Copy link
Copy Markdown
Contributor

Added updateConnections() to JoystickImpl which is called when WM_DEVICECHANGE message is received, this replaces the old functionality of just polling every controller every 0.5s, in the hope of addressing #1179

@JonnyPtn

JonnyPtn commented Feb 22, 2017

Copy link
Copy Markdown
Contributor Author

As @MarioLiebisch pointed out on IRC, this would stop joysticks working if there is no window opened, so I've implemented his suggested changes.

The downside is that if you're using joysticks without a window then this won't change anything, but alternatives would probably change the API

Comment thread src/SFML/Window/Win32/JoystickImpl.cpp Outdated

ConnectionCache connectionCache[sf::Joystick::Count];

//if true, will only update when WM_DEVICECHANGE message is received

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: Should be // If true, ...

}
case WM_DEVICECHANGE:
{
//some sort of device change has happened, update joystick connections

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nitpicking here: // Some ...

namespace
{
unsigned int windowCount = 0;
unsigned int handleCount = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between windowCount and handleCount?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windowCount only counts windows owned by SFML

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend adding a comment to avoid any future ambiguity.


if (m_handle)
{
if (handleCount++ == 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally am not a big fan of this notation, but maybe others don't have an issue with it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly think branching conditions should be side effect free; so yeah, I've an issue with this. 😛

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too. One extra line of code vs more headache when reading the code, my choice is made.

@JonnyPtn

Copy link
Copy Markdown
Contributor Author

I've implemented the changes and squashed

@MarioLiebisch

Copy link
Copy Markdown
Member

Only alternative for all cases would be creating an invisible window just for joystick polling (which would also remove the need for public static members in the implementation). But then again that would create a window after all, which might not be wanted in some odd cases.

@eXpl0it3r

Copy link
Copy Markdown
Member

Merged in f053871 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants