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

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

Closed
wants to merge 1 commit into from
Closed

Conversation

JonnyPtn
Copy link
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
Copy link
Contributor Author

JonnyPtn commented Feb 22, 2017

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

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

//if true, will only update when WM_DEVICECHANGE message is received
Copy link
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, ...

@@ -936,6 +950,13 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
pushEvent(event);
break;
}
case WM_DEVICECHANGE:
{
//some sort of device change has happened, update joystick connections
Copy link
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
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
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
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.

@@ -141,6 +146,9 @@ m_cursorGrabbed (false)

if (m_handle)
{
if (handleCount++ == 0)
Copy link
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
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
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
Contributor Author

I've implemented the changes and squashed

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.5.0 Feb 28, 2017
@eXpl0it3r eXpl0it3r moved this from Discussion to Review & Testing in SFML 2.5.0 Feb 28, 2017
@MarioLiebisch
Copy link
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 eXpl0it3r moved this from Review & Testing to Ready in SFML 2.5.0 Mar 1, 2017
@eXpl0it3r
Copy link
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
No open projects
SFML 2.5.0
  
Merged / Superseded
Development

Successfully merging this pull request may close these issues.

None yet

5 participants