mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:49:58 +00:00
Merge pull request #1366 from julianko/merge_input_events
Merge redundant input events
This commit is contained in:
commit
a687a20aef
1 changed files with 29 additions and 4 deletions
|
@ -49,17 +49,42 @@ InputWrapper::InputWrapper(SDL_Window* window, osg::ref_ptr<osgViewer::Viewer> v
|
|||
|
||||
SDL_PumpEvents();
|
||||
|
||||
SDL_Event evt;
|
||||
SDL_Event event;
|
||||
|
||||
if (windowEventsOnly)
|
||||
{
|
||||
// During loading, just handle window events, and keep others for later
|
||||
while (SDL_PeepEvents(&evt, 1, SDL_GETEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT))
|
||||
handleWindowEvent(evt);
|
||||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT))
|
||||
handleWindowEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
while(SDL_PollEvent(&evt))
|
||||
// Merge redundant events to avoid unnecessary listener calls
|
||||
std::vector<SDL_Event> events;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
if (events.empty() || events.back().type != event.type)
|
||||
{
|
||||
events.emplace_back(event);
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_Event& previousEvent = events.back();
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_MOUSEMOTION:
|
||||
previousEvent.motion.x = event.motion.x;
|
||||
previousEvent.motion.y = event.motion.y;
|
||||
previousEvent.motion.xrel += event.motion.xrel;
|
||||
previousEvent.motion.yrel += event.motion.yrel;
|
||||
break;
|
||||
default:
|
||||
events.emplace_back(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (const SDL_Event& evt : events)
|
||||
{
|
||||
switch(evt.type)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue