Mercurial > sdl-ios-xcode
comparison src/events/SDL_events.c @ 3072:9da8f57ab92c
Fixed bug #684
Reworked Pierre's patch a little bit, which added SDL_WaitEventTimeout()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 17 Feb 2009 05:59:40 +0000 |
parents | 0b160c970b7e |
children | 22ac66da0765 |
comparison
equal
deleted
inserted
replaced
3071:6f3308d4b6cd | 3072:9da8f57ab92c |
---|---|
397 /* Public functions */ | 397 /* Public functions */ |
398 | 398 |
399 int | 399 int |
400 SDL_PollEvent(SDL_Event * event) | 400 SDL_PollEvent(SDL_Event * event) |
401 { | 401 { |
402 SDL_PumpEvents(); | 402 return SDL_WaitEventTimeout(event, 0); |
403 | |
404 /* We can't return -1, just return 0 (no event) on error */ | |
405 if (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0) | |
406 return 0; | |
407 return 1; | |
408 } | 403 } |
409 | 404 |
410 int | 405 int |
411 SDL_WaitEvent(SDL_Event * event) | 406 SDL_WaitEvent(SDL_Event * event) |
412 { | 407 { |
413 while (1) { | 408 return SDL_WaitEventTimeout(event, -1); |
409 } | |
410 | |
411 int | |
412 SDL_WaitEventTimeout(SDL_Event * event, int timeout) | |
413 { | |
414 Uint32 expiration = 0; | |
415 | |
416 if (timeout > 0) | |
417 expiration = SDL_GetTicks() + timeout; | |
418 | |
419 for (;;) { | |
414 SDL_PumpEvents(); | 420 SDL_PumpEvents(); |
415 switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { | 421 switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { |
416 case -1: | 422 case -1: |
417 return 0; | 423 return 0; |
418 case 1: | 424 case 1: |
419 return 1; | 425 return 1; |
420 case 0: | 426 case 0: |
427 if (timeout == 0) { | |
428 /* Polling and no events, just return */ | |
429 return 0; | |
430 } | |
431 if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) { | |
432 /* Timeout expired and no events */ | |
433 return 0; | |
434 } | |
421 SDL_Delay(10); | 435 SDL_Delay(10); |
436 break; | |
422 } | 437 } |
423 } | 438 } |
424 } | 439 } |
425 | 440 |
426 int | 441 int |