Original Post
When getting events from SDL's event queue, things get pretty unresponsive when processing gets intense. I'm not sure what's going on, but key pressed and mouse movements aren't always picked up. For instance, I may press the space bar repeatedly but only three quarters of those presses are actually picked up. I'm not sure if this is a common problem or not. I'm building an event-driven system atop SDL (and other libraries; everything's abstracted). I think the way I'm pushing events back onto the queue may be part of the problem (it looks like a slow way to handle things to begin with. Take this function for example: onCycleBegin() is implemented by CycleListener objects that listen for game cycles from Application objects. Objects that need to process events from SDL (like SDLKeyboard) poll the event queue and place any unrelated events back so that other objects can handle them if and when they poll for events. In this case SDLKeyboard checks for key events during the beginning of every game cycle. notifyKeyPressed() is a private utility function that handles the call to broadcastKeyPressed() which broadcasts a KeyEvent to registerd listeners (and likewise for notifyKeyReleased()). Could this be what's slowing things down? Is this even doing what I think it does, or am I losing/ignoring events in the queue this way? I have no problems when there isn't much being done, but when I stress things (i.e., create a bunch of objects and do a lot of number crunching) events seem to slip right through the system unnoticed. Any help is appreciated. Thanks.
void SDLKeyboard::onCycleBegin(CycleEvent<Application>* e)
{
static SDL_Event events;
static vector<SDL_Event> ignored;
while (SDL_PollEvent(&events))
{
switch (events.type)
{
case SDL_KEYDOWN:
notifyKeyPressed(events.key.keysym.sym);
break;
case SDL_KEYUP:
notifyKeyReleased(events.key.keysym.sym);
break;
default:
ignored.push_back(events);
break;
}
}
for (vector<SDL_Event>::iterator i = ignored.begin(); i != ignored.end(); ++i)
SDL_PushEvent(&(*i)); // IMPORTANT: Keep unhandled events in the queue.
ignored.clear();
}