-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Remove event._joy_instance_map
#2048
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break code as implemented.
joy_instance_map does not map instance_id
to instance_id
, it maps instance_id
to device_index
(or it tries its best to). Which is needed for backwards compatibility. With your implementation, we will be returning instance_ids instead of device_indices Every code that uses event.joy
with joystick.get_id
will break, but not instantly. Only after they unplug and plug a joystick back in (since until this happens, the to ids should match up, though it is not guaranteed). And not in an obvious way, like an error, but their event just won't match up with their joystick.
However I do agree with removing the mapping dictionary. A better solution to this would be to add a joystick function that returns a joystick object from an instance id. This should work since 1) joysticks don't send events 'till created and 2) the pgJoystickObject
keeps track of its id already (or if it cannot find it, it would just set the joy attribute to -1 or something like that. There is no proper way to fix this, since the two ids don't properly match up). It would fix the bug mentioned and would work in a backwards compatible manner. The only place where this is not needed is the JOYDEVICEADDED
event (which already uses device_indices).
If you need help, or are unsure of something, I'd be happy to help you complete the pr. I'd also be open to implementing the change myself on this branch directly.
Sorry about this. It's my bad. |
I added a new c api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks for the pr!🎉
But there's a issue, when a joystick is initialized by controller module instead of joystick module, the "joy" attribute will be always -1 because the joystick object is not created.
Yeah, that is fine. We should deprecate event.joy
anyway, since it is not really supposed to be used anymore (but instance_id
instead)
Also, sorry for the long delay. I should be (hopefully) more active now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zoldalma walked me through what this does, and it seems legit.
Fix issues:
#2047
pygame/pygame#3634
Removing for 2 reasons.
_joy_instance_map
is mappinginstance_id
toinstance_id
, which is pointless._joy_instance_map
also causesKeyError
(which is not caught and causes theSystemError
) when a controller is being unplugged but was not in the dict.