Skip to content

Fix event polling #242

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

Merged
merged 1 commit into from
Mar 10, 2022
Merged

Conversation

hanst99
Copy link
Contributor

@hanst99 hanst99 commented Feb 7, 2022

pollEvents was apparently broken by a recent-ish
patch to SDL.

This should fix that. As an aside, this attempts to make polling events
a bit more efficient; We just statically allocate a single buffer for
events (AFAIK you can only call Poll from the main thread anyway, so the
fact that this isn't thread safe shouldn't be an issue), this way we avoid a bunch of unnecessary heap allocations we'd normally get via alloca.


I hope adding the pumpEvents call should be relatively noncontroversial, if people don't like the other bit I'll remove it. T reason I've added it is that the previous implementation would call PollEvent twice and allocatea once for each event, which is quite a loss because PollEvent needs to lock the event queue each time it's called and alloca adds additional GC garbage. This is probably not the one thing that makes/breaks anyone's performance targets, but it is unnecessary extra work.

Fixes issues like:

#241

@hanst99 hanst99 force-pushed the fix/poll-events-pump branch 4 times, most recently from fd153a9 to 7384512 Compare February 7, 2022 18:43
pollEvents was apparently broken by a recent-ish
[patch](libsdl-org/SDL#4794) to SDL.

This should fix that. As an aside, this attempts to make polling events
a bit more efficient; We just statically allocate a single buffer for
events (AFAIK you can only call Poll from the main thread anyway, so the
fact that this isn't thread safe shouldn't be an issue).
@hanst99 hanst99 force-pushed the fix/poll-events-pump branch from 7384512 to 4b2303e Compare February 7, 2022 18:50
Raw.SDL_FIRSTEVENT
Raw.SDL_LASTEVENT
peeped <- peekArray (fromIntegral numPeeped) Raw.eventBuffer
if numPeeped == Raw.eventBufferSize -- are there more events to peep?
Copy link
Contributor Author

@hanst99 hanst99 Feb 9, 2022

Choose a reason for hiding this comment

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

Note this is unlikely in a typical scenario because I picked the buffer size to be pretty generous, unless there's a high frequency input device involved or
pollEvents is called very infrequently.

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