Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android) Use ALooper_pollOnce #659

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions src/Magnum/Platform/AndroidApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,30 +662,41 @@ void AndroidApplication::exec(android_app* state, Containers::Pointer<AndroidApp
Data data{instancer, ANativeActivity_onCreate};
state->userData = &data;

for(;;) {
/* Read all pending events. Block and wait for them only if the app
doesn't want to redraw immediately WHY THIS GODDAMN THING DOESNT
HAVE SOMETHING LIKE WAIT FOR EVENT SO I NEED TO TANGLE THIS TANGLED
MESS OF HELL */
int ident, events;
android_poll_source* source;
while((ident = ALooper_pollAll(
data.instance && (data.instance->_flags & Flag::Redraw) ? 0 : -1,
nullptr, &events, reinterpret_cast<void**>(&source))) >= 0)
{
/* Process this event OH SIR MAY MY POOR EXISTENCE CALL THIS
FUNCTION FOR YOU IF YOU DON'T MIND? */
if(source) source->process(state, source);

/* Exit WHY THIS HAS TO BE HANDLED HERE WHILE EVERY OTHER THING
IS HANDLED THROUGH CALLBACK GODDAMMIT */
if(state->destroyRequested != 0) return;
/* Read all pending events. Block and wait for them only if the app
doesn't want to redraw immediately WHY THIS GODDAMN THING DOESNT
HAVE SOMETHING LIKE WAIT FOR EVENT SO I NEED TO TANGLE THIS TANGLED
MESS OF HELL

WHY THIS HAS TO BE HANDLED HERE WHILE EVERY OTHER THING
IS HANDLED THROUGH CALLBACK GODDAMMIT

reference:
https://github.com/android/ndk-samples/pull/1008/files
*/
while (!state->destroyRequested)
{
android_poll_source* source = nullptr;
const auto timeout_ms = (data.instance && (data.instance->_flags & Flag::Redraw) ?
0 : -1 /* negative value: wait indefinitely until an event appears */);

const auto result = ALooper_pollOnce(timeout_ms, nullptr, nullptr,
reinterpret_cast<void**>(&source));

if (result == ALOOPER_POLL_ERROR) {
return;
}

/* Process this event OH SIR MAY MY POOR EXISTENCE CALL THIS
FUNCTION FOR YOU IF YOU DON'T MIND? */
if(source) {
source->process(state, source);
}

/* Redraw the app if it wants to be redrawn. Frame limiting is done by
Android itself */
if(data.instance && (data.instance->_flags & Flag::Redraw))
if(data.instance && (data.instance->_flags & Flag::Redraw)) {
data.instance->drawEvent();
}
}

state->userData = nullptr;
Expand Down