[SDL] Collecting the keypresses without the mouse events?
Peter Mulholland
darkmatter at freeuk.com
Sun Mar 12 14:39:09 PST 2006
Hello Matt,
Sunday, March 12, 2006, 9:36:47 PM, you wrote:
MK> Hi!
MK> How to collect all the pending keypresses and avoiding to
MK> have to discard all the mouse events? This is needed
MK> in any FPS game (DooM, Quake etc..) where the user uses
MK> both the keyboard and the mouse at the same time.
<snip>
MK> The above code makes the while() stuck as long as the user
MK> keeps moving the mouse thus introducing a jerky movement in
MK> the game - That's one of the reasons why Icculus' port of Duke
MK> Nukem 3d has a Jerky mouse behavior.
MK> So I tryed to use a
MK> SDL_PumpEvents();
MK> SDL_GetMouseState(...);
MK> before doing a
MK> while (SDL_PollEvent(&event))
MK> root_sdl_event_filter(&event);
MK> because only the mouse position at the time we probe
MK> is actually needed for FPS games. But SDL_GetMouseState
MK> doesn't seem to remove the move mouse events at all, so
MK> it's pointless and the while(...) will remain very laggy.
I also had this issue. I solved it by telling SDL to ignore mouse
movement events:
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
Then I polled for mouse movement per frame with SDL_GetMouseState()
For an FPS you might be best reading key input this way too, since as
multiple keypresses will no doubt be needed. It would be far more
efficient to dump keystate into an array and check buttons in there
than process messages.
--
Best regards,
Peter mailto:darkmatter at freeuk.com
More information about the SDL
mailing list