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

Events: Expose WaitEvent and WaitEventTimeout #136

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/centurion/events/event_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ class event_handler final {
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
}

// Waits until an event is available
void wait()
{
SDL_Event event {};
if (SDL_WaitEvent(&event)) {
store(event);
}
else {
throw sdl_error {};
}
}

// Waits until an event is available or timeout
auto wait(int timeout) noexcept -> bool
{
SDL_Event event {};
if (SDL_WaitEventTimeout(&event, timeout)) {
store(event);
return true;
}
else {
reset_state();
return false;
}
}

/// Polls the next available event, if there is one.
auto poll() noexcept -> bool
{
Expand Down Expand Up @@ -483,4 +509,4 @@ class event_handler final {

} // namespace cen

#endif // CENTURION_EVENTS_EVENT_HANDLER_HPP_
#endif // CENTURION_EVENTS_EVENT_HANDLER_HPP_