Peter Seibel <[EMAIL PROTECTED]> writes: > > Mmmm, spinning is bad, I have other uses for my CPU. Or I > misunderstand your suggestion.
Unless your FRAME-RATE is set to 0, SDL will always sleep at least 10ms between each game loop. > I know there's a patch floating around to > allow user events to be put on the SDL queue. Is that the right > solution? I have added Christopher Eineke's patch to SVN. > (As I understand it at the moment, my problem is that I want > my SDL window to be responsive to two sets of events--one generated by > SDL (mouse, video-expose, etc.) and the other generated by my Lisp code. I use two threads all the time when using Slime. I start a simple SDL game loop at the REPL (opens a window then blocks while running the SDL event loop), and then I M-X-E SDL drawing functions in an Emacs buffer. Each M-X-E creates a new thread, EVAL's the SDL function and then returns. I rewrote the SDL- EXAMPLE:SQUASHED example like this as a sort of 'live-coding' exercise. > Ideally I'd like the thread handling the SDL window to block (rather > than polling) but obviously I can't block on two queues at once. However > I could--just thinking out loud here--use an extra thread to process the > the SDL events and put them on a Lisp queue which my app can also use > to inject its own events. The WITH-EVENTS macro polls for SDL events (using SDL_PollEvent()), sleeping n milliseconds between each loop to maintain a constant frame rate. There is SDL_WaitEvent() but this does not do what one might expect. SDL_WaitEvent() uses a poll/sleep mechanism whereby the thread sleeps for 10ms, wakes up, polls for new events (using SDL_PollEvent()) and if no events are in the queue, sleeps for 10ms. > Maybe my question is this: what's the threading model of SDL (or > lispbuilder-sdl)? Can multiple threads be calling sdl methods at the > same time? Or do I want a single thread managing the SDL window? The thread that creates the SDL window must be the same thread that empties the SDL event queue. And that's about it. Other threads can freely call into any SDL function directly. - Luke _______________________________________________ application-builder mailing list [email protected] http://www.lispniks.com/mailman/listinfo/application-builder
