+void wait_for_event(float min_delay, float max_delay)
+{
+ assert(min_delay <= max_delay);
+
+ Uint32 min = (Uint32) (min_delay * 1000);
+ Uint32 max = (Uint32) (max_delay * 1000);
+
+ SDL_Delay(min);
+
+ // clear even queue
+ SDL_Event event;
+ while (SDL_PollEvent(&event))
+ {}
+
+ /* Handle events: */
+ bool running = false;
+ Uint32 ticks = SDL_GetTicks();
+ while(running) {
+ while(SDL_PollEvent(&event)) {
+ switch(event.type) {
+ case SDL_QUIT:
+ throw std::runtime_error("received window close");
+ case SDL_KEYDOWN:
+ case SDL_JOYBUTTONDOWN:
+ case SDL_MOUSEBUTTONDOWN:
+ running = false;
+ }
+ }
+ if(SDL_GetTicks() - ticks >= (max - min))
+ running = false;
+ SDL_Delay(10);
+ }
+}
+