Grab events in large chunks in SDL_IterateMainCallbacks()
This is more efficient, especially since we're just going to discard them.
This commit is contained in:
@@ -81,17 +81,24 @@ int SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_
|
|||||||
|
|
||||||
int SDL_IterateMainCallbacks(void)
|
int SDL_IterateMainCallbacks(void)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
// Just pump events and empty the queue, EventWatcher sends the events to the app.
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST) == 1) {
|
|
||||||
// just empty the queue, EventWatcher sends the events to the app.
|
for (;;) {
|
||||||
switch (event.type) {
|
SDL_Event events[32];
|
||||||
|
int count = SDL_PeepEvents(events, SDL_arraysize(events), SDL_GETEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST);
|
||||||
|
if (count <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
switch (events[i].type) {
|
||||||
case SDL_EVENT_DROP_FILE:
|
case SDL_EVENT_DROP_FILE:
|
||||||
case SDL_EVENT_DROP_TEXT:
|
case SDL_EVENT_DROP_TEXT:
|
||||||
SDL_free(event.drop.file);
|
SDL_free(events[i].drop.file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int rc = SDL_main_iteration_callback();
|
int rc = SDL_main_iteration_callback();
|
||||||
if (!SDL_AtomicCAS(&apprc, 0, rc)) {
|
if (!SDL_AtomicCAS(&apprc, 0, rc)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user