+/* Returns 1 for every button event, 2 for a quit event and 0 for no event. */
+int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events)
+{
+ int i;
+ timer_type maxdelay;
+ timer_type mindelay;
+
+ maxdelay.init(false);
+ mindelay.init(false);
+
+ if(max_delay < min_delay)
+ max_delay = min_delay;
+
+ maxdelay.start(max_delay);
+ mindelay.start(min_delay);
+
+ if(empty_events)
+ while (SDL_PollEvent(&event))
+ {}
+
+ /* Handle events: */
+
+ for(i = 0; maxdelay.check() || !i; ++i)
+ {
+ while (SDL_PollEvent(&event))
+ {
+ if(!mindelay.check())
+ {
+ if (event.type == SDL_QUIT)
+ {
+ /* Quit event - quit: */
+ return 2;
+ }
+ else if (event.type == SDL_KEYDOWN)
+ {
+ /* Keypress - skip intro: */
+
+ return 1;
+ }
+ else if (event.type == SDL_JOYBUTTONDOWN)
+ {
+ /* Fire button - skip intro: */
+
+ return 1;
+ }
+ else if (event.type == SDL_MOUSEBUTTONDOWN)
+ {
+ /* Mouse button - skip intro: */
+ return 1;
+ }
+ }
+ }
+ SDL_Delay(10);
+ }