src/events/SDL_events.c
changeset 3072 9da8f57ab92c
parent 2984 0b160c970b7e
child 3259 22ac66da0765
     1.1 --- a/src/events/SDL_events.c	Tue Feb 17 05:57:54 2009 +0000
     1.2 +++ b/src/events/SDL_events.c	Tue Feb 17 05:59:40 2009 +0000
     1.3 @@ -399,18 +399,24 @@
     1.4  int
     1.5  SDL_PollEvent(SDL_Event * event)
     1.6  {
     1.7 -    SDL_PumpEvents();
     1.8 -
     1.9 -    /* We can't return -1, just return 0 (no event) on error */
    1.10 -    if (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0)
    1.11 -        return 0;
    1.12 -    return 1;
    1.13 +    return SDL_WaitEventTimeout(event, 0);
    1.14  }
    1.15  
    1.16  int
    1.17  SDL_WaitEvent(SDL_Event * event)
    1.18  {
    1.19 -    while (1) {
    1.20 +    return SDL_WaitEventTimeout(event, -1);
    1.21 +}
    1.22 +
    1.23 +int
    1.24 +SDL_WaitEventTimeout(SDL_Event * event, int timeout)
    1.25 +{
    1.26 +    Uint32 expiration = 0;
    1.27 +
    1.28 +    if (timeout > 0)
    1.29 +        expiration = SDL_GetTicks() + timeout;
    1.30 +
    1.31 +    for (;;) {
    1.32          SDL_PumpEvents();
    1.33          switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
    1.34          case -1:
    1.35 @@ -418,7 +424,16 @@
    1.36          case 1:
    1.37              return 1;
    1.38          case 0:
    1.39 +            if (timeout == 0) {
    1.40 +                /* Polling and no events, just return */
    1.41 +                return 0;
    1.42 +            }
    1.43 +            if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) {
    1.44 +                /* Timeout expired and no events */
    1.45 +                return 0;
    1.46 +            }
    1.47              SDL_Delay(10);
    1.48 +            break;
    1.49          }
    1.50      }
    1.51  }