Non centralised event polling?

I’m using C++, and I’m wondering how I can get an object such as for example
"CMouse" to query the event queue and only remove mouse related events from
it. What I want is to be able to simply call Mouse.Update() and perhaps also
Keyboard.Update() once every frame and let the objects take care of the
event
handling themselves.

Robin EIdissen wrote:

What I want is to be able to simply call Mouse.Update() and perhaps also
Keyboard.Update() once every frame and let the objects take care of the
event
handling themselves.

Thats exactly how I do it in libksd!! The relevent functions are:

SDL_GetKeyState
SDL_GetMouseState

They don’t affect the event queue though. If you use ONLY these then
just ignore the key/mouse events.

-- David Snopek

/-- libksd –
| The C++ Cross-Platform Game Framework
| Only want to write it once??
| http://libksd.sourceforge.net
------------

Yes I tried it and it worked, but I’m thinking that it might be cleaner to
do it using events.
Is this even possible?

Hmm. I’ve looked a bit into SDL_PeekEvents and think that might be viable.
What would be fastest; using the event method or the one you described?

SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEEVENTMASK);
Should do what you want.
Speed comparision between the two methods is irrelevant, they both rely
on the same internal mechanisms.On Wed, Mar 28, 2001 at 03:02:32PM -0800, Robin Eidissen wrote:

Hmm. I’ve looked a bit into SDL_PeekEvents and think that might be viable.
What would be fastest; using the event method or the one you described?


Martin

Bother, said Pooh, and nuked Iraq!

Ok I tried using SDL_PeepEvents but couldn’t get it to work.
Here’s my code:

void CKeyboard::Update()
{
SDL_Event Event;

while(SDL_PeepEvents(&Event, 1, SDL_GETEVENT, SDL_KEYUPMASK |

SDL_KEYDOWNMASK) > 0)
{
switch(Event.type)
{
case SDL_KEYDOWN:
Keys[int(Event.key.keysym.sym)] = true;
break;
case SDL_KEYUP:
Keys[int(Event.key.keysym.sym)] = false;
break;
}
}
}

What’s wrong here? I have an empty while(SDL_PollEvents(&Event)) function in
my game loop as the game won’t
work without it. Could it be that this removes all events? It’s after the
Keyboard.Update() function though so I don’t
see that it could.

Will SDL_PeepEvents check only the first element of the queue or will it
search through it?

Will SDL_PeepEvents check only the first element of the queue or will it
search through it?

It will search through it.

-Sam Lantinga, Lead Programmer, Loki Entertainment Software

What’s wrong here? I have an empty while(SDL_PollEvents(&Event)) function in
my game loop as the game won’t
work without it. Could it be that this removes all events?

Yes, PollEvent removes events from the queue. Use SDL_PumpEvents();

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software