Mac OS X Quartz Events Change/Suggestion

Bear with me here as I’ve skimmed the code and there might be other
issues I’m missing.

Before I made my engine cross-platform, my mouse control was much
better. After moving to SDL, it’s a lot worse. I think it has
something to do with the nature of not being able to call PumpEvents
enough during times of heavy rendering. You can’t use a thread on OS X
as this causes a crash (the event routines need to be called on the main
thread.)

In my original code, I just registered a callback for mouse movements,
buttons, and key presses. Note that this was in carbon, but you should
be able to use the same code in cocca (I had it functional when SDL was
part of my app.)

So, the suggestion is to register callbacks for the events instead of
polling for them.

Pros-----

  1. PumpEvent would now basically do nothing (except maybe update
    activity to avoid screen saver kicking in)
  2. all events actually come in on threads and can happen during times
    when PumpEvent couldn’t be called
  3. You probably don’t need all the additional cases and heavier code you
    have now (for instance, all mouse moves will
    come in as deltas, there’s no screen edges problems, and you
    just clear the delta when they request the mouse
    moved event.)

Cons

(I let you guys come up with these)

This is something I’d be interested in writting, at least at the low
level. I don’t know enough about the code to tie it together properly,
so I’d be asking a number of questions.

I’d probably try to do the mouse movement first and then post the code
here. Can I assume that QZ_DoActivate and QZ_DoDeactivate can be used
to register and then de-register the events (i.e., they will be called
before any mouse input is needed to be gathered, and after it’s done.)

[>] Brian

Bear with me here as I’ve skimmed the code and there might be other
issues I’m missing.

Before I made my engine cross-platform, my mouse control was much
better. After moving to SDL, it’s a lot worse. I think it has
something to do with the nature of not being able to call PumpEvents
enough during times of heavy rendering. You can’t use a thread on OS X
as this causes a crash (the event routines need to be called on the main
thread.)

Quick question, are you doing

if (SDL_PollEvent(&event))

or

while (SDL_Pollevent(&event))

in your main loop? If you’re using the former, try the latter. :slight_smile:

// MartinOn Thu, 9 Mar 2006, ggadwa at charter.net wrote:

Bear with me here as I’ve skimmed the code and there might be other
issues I’m missing.

Before I made my engine cross-platform, my mouse control was much
better. After moving to SDL, it’s a lot worse. I think it has
something to do with the nature of not being able to call PumpEvents
enough during times of heavy rendering.

Were you actually responding to events more than once a frame?
Was your event handling thread safe and worked in parallel to rendering?

Did you know that SDL provides a callback event interface?

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Did you know that SDL provides a callback event interface?

Do you mean SDL_event_filter?

[there’s no client data pointer! Why not?]On Thu, 2006-03-09 at 09:25 -0800, Sam Lantinga wrote:


John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net

Martin Storsj? wrote:

Quick question, are you doing

if (SDL_PollEvent(&event))

or

while (SDL_Pollevent(&event))

in your main loop? If you’re using the former, try the latter. :slight_smile:

I’m using while and emptying the queue everytime. That’s not the problem.

Sam Lantinga wrote:

Were you actually responding to events more than once a frame?
Was your event handling thread safe and worked in parallel to rendering?

Did you know that SDL provides a callback event interface?

If I still have to call PumpEvent, then that’s not going to solve the
problem. If the frame rate is high, mouse control is fine. If it’s
low, I start to get larger and larger deltas, which weights the
acceleration and overtakes the smoothing algorithm. Frankly, if there
is a low frame rate, it’s going to be harder to control, anyway, but it
seems a bit extreme.

If this callback mechanism (I can’t find any docs for it) by-passes the
queue completely (i.e., I don’t have to PumpEvents) then that might
work. I’d be interested to give it a try.

[>] Brian

Hello ggadwa,

For mouse movement, I found it was best not to process the movement
messages as it can cause huge issues with very latent movement. It’s
better to just SDL_GetMouseState() and process that per frame. I think
you do still need to pump the event loop, though.–
Best regards,
Peter mailto:@Peter_Mulholland

Thank you so much for pointing this out. I was getting weird delays when
holding down a key and moving the mouse at the same time. I had copied one of
the Ruby sdl examples which used an if. Doh!

Regards,
Mike

Martin Storsj? wrote:> On Thu, 9 Mar 2006, ggadwa at charter.net wrote:

Bear with me here as I’ve skimmed the code and there might be other
issues I’m missing.

Before I made my engine cross-platform, my mouse control was much
better. After moving to SDL, it’s a lot worse. I think it has
something to do with the nature of not being able to call PumpEvents
enough during times of heavy rendering. You can’t use a thread on OS X
as this causes a crash (the event routines need to be called on the main
thread.)

Quick question, are you doing

if (SDL_PollEvent(&event))

or

while (SDL_Pollevent(&event))

in your main loop? If you’re using the former, try the latter. :slight_smile:

// Martin