Hi, This patch fixes _SDL_WaitEvent a bit; SDL_WaitEvent returns an integer and not a SDL_Event. It also introduces _SDL_PollEvent which is mostly a copy of _SDL_WaitEvent. Finally, _SDL_loop is modified to allow an "idle" event entry that gets called if no events are pending. If such an event is defined, _SDL_PollEvent is used to check whether events are pending. The idle callback is made every 50ms, "timer callback" might be a better name.
Maybe it can even be extenended to a more general timer callback; SDL supports timer itself, but the problem that C callbacks are not yet supported well enough. It is also necessary to add code for SDL_PollEvent to library/sdl.pasm. I propose to rename this file to sdl_init.pasm; I'am working on a sdl.imc file that makes it much easier to use SDL with PIR, because it hides much of the 'internals'. I will send the file to the list in a few minutes (the documentation if not yet sufficient at the moment). jens
diff -u -w -r1.6 sdl_types.imc --- library/sdl_types.imc 12 Feb 2004 18:42:37 -0000 1.6 +++ library/sdl_types.imc 13 Feb 2004 16:51:18 -0000 @@ -345,10 +345,12 @@ .sym pmc WaitEvent WaitEvent = global "SDL::WaitEvent" + .sym int ret + .pcc_begin prototyped .arg event .nci_call WaitEvent - .result event + .result ret .pcc_end # dunno what this is @@ -357,6 +359,38 @@ .pcc_begin_return .return event + .return ret + .pcc_end_return +.end + +=item _SDL_Poll_Event() + +XXX - not ready to expose this one yet + +=cut + +.pcc_sub _SDL_PollEvent + .sym pmc event + event = _new_SDL_Event() + + .sym pmc PollEvent + PollEvent = global "SDL::PollEvent" + + .sym int ret + + .pcc_begin prototyped + .arg event + .nci_call PollEvent + .result ret + .pcc_end + + # dunno what this is + .local string type + typeof type, event + + .pcc_begin_return + .return event + .return ret .pcc_end_return .end @@ -375,19 +409,43 @@ .param pmc events .sym pmc event + .sym int type + .sym Sub callback + .sym num nexttime + .sym num curtime + + time nexttime + add nexttime, 0.05 loop: + defined type, events["idle"] + if type goto poll + branch wait +poll: + type = _SDL_PollEvent() + event = P5 + + time curtime + if curtime < nexttime goto noidle + set callback, events["idle"] + .pcc_begin prototyped + .pcc_call callback + .pcc_end + time nexttime + add nexttime, 0.05 +noidle: + if type == 1 goto process + sleep 0.025 + branch poll +wait: event = _SDL_WaitEvent() - - .sym int type +process: set type, event['type'] if type == 0 goto loop exists $I0, events[type] if $I0 == 0 goto loop - - .sym Sub callback if type == 2 goto _key_event if type == 3 goto _key_event