[SDL] waiting for events and callbacks
Chris Thielen
chris at luethy.net
Sat Nov 9 00:06:00 PST 2002
On Fri, 2002-11-08 at 18:55, Bob Pendleton wrote:
> On Fri, 2002-11-08 at 17:40, Chris Thielen wrote:
> > On Fri, 2002-11-08 at 10:19, Bob Pendleton wrote:
> > > On Fri, 2002-11-08 at 09:10, Chris Thielen wrote:
> > > > If I use SDL_PushEvent() while SDL_WaitEvent() is called, then
> > > > SDL_WaitEvent() will return and produce the desired effect, however, how
> > > > do I call SDL_PushEvent() while SDL_WaitEvent() is running? It's not
> > > > multithreaded, and the timer callback is only called after
> > > > SDL_WaitEvent() is returned, so that would only push the event after the
> > > > program has halted for too long on SDL_WaitEvent(). Should the program
> > > > be multithreaded or am I misunderstanding what you've said?
> > >
> > > Use a different timer to push the event.
> >
> > it wouldn't matter. the code literally goes:
> >
> > SDL_WaitEvent()
> > Check for timer event, if so, callback (for all timers)
> > repeat
>
> No, it does work. You send an event *FROM* the timer callback. That
> event causes WaitEvent to return. The code for the callback looks like:
>
> Uint32 timerCallback(Uint32 interval, void *param)
> {
> SDL_Event event;
>
> event.type = SDL_USEREVENT;
> event.user.code = MY_TIMEREVENT;
> event.user.data1 = (void *)SDL_GetTicks();
> event.user.data2 = (void *)0;
>
> SDL_PushEvent(&event);
>
> return interval;
> }
>
> The event is generated in the timer thread, not in the main thread. Think
> about it.
ah, there's the misunderstanding. the program isnt multithreaded at all.
the timers are my own c code and everything runs on one thread. the
"timer callbacks" are all my code, and SDL_WaitEvent() is just used to
receieve events. so then, multithreading _is_ the only way to go? i
dunno, is that how most games do input?
--
Chris Thielen <chris at luethy.net>
More information about the SDL
mailing list