| 67 | } |
| 68 | |
| 69 | void AndroidApplication::Run(struct android_app* state, CreateAppEventHandlerDelegate createAppEventHandler) |
| 70 | { |
| 71 | DEATH_ASSERT(state != nullptr); |
| 72 | DEATH_ASSERT(createAppEventHandler != nullptr); |
| 73 | AndroidApplication& app = theAndroidApplication(); |
| 74 | app.state_ = state; |
| 75 | app.createAppEventHandler_ = createAppEventHandler; |
| 76 | |
| 77 | state->onAppCmd = AndroidApplication::ProcessCommand; |
| 78 | |
| 79 | state->onInputEvent = [](struct android_app* state, AInputEvent* event) -> std::int32_t { |
| 80 | return static_cast<std::int32_t>(AndroidInputManager::parseEvent(event)); |
| 81 | }; |
| 82 | |
| 83 | state->activity->callbacks->onContentRectChanged = [](ANativeActivity* act, const ARect* rect) { |
| 84 | nc::AndroidApplication& androidApp = static_cast<nc::AndroidApplication&>(nc::theApplication()); |
| 85 | if (androidApp.IsInitialized()) { |
| 86 | androidApp.HandleContentBoundsChanged(nc::Recti(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top)); |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | while (!app.ShouldQuit()) { |
| 91 | std::int32_t ident, events; |
| 92 | struct android_poll_source* source; |
| 93 | |
| 94 | while ((ident = ALooper_pollOnce(app.ShouldSuspend() ? -1 : 0, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0) { |
| 95 | if (source != nullptr) { |
| 96 | source->process(state, source); |
| 97 | } |
| 98 | if (ident == LOOPER_ID_USER) { |
| 99 | AndroidInputManager::parseAccelerometerEvent(); |
| 100 | } |
| 101 | if (state->destroyRequested) { |
| 102 | LOGD("android_app->destroyRequested not equal to zero"); |
| 103 | app.Quit(); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (app.isBackInvoked_) { |
| 108 | app.isBackInvoked_ = false; |
| 109 | app.appEventHandler_->OnBackInvoked(); |
| 110 | } |
| 111 | |
| 112 | if (app.IsInitialized() && !app.ShouldSuspend()) { |
| 113 | AndroidInputManager::updateJoystickConnections(); |
| 114 | app.Step(); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | AndroidJniWrap_Activity::finishAndRemoveTask(); |
| 119 | app.Shutdown(); |
| 120 | exit(0); |
| 121 | } |
| 122 | |
| 123 | void AndroidApplication::ProcessCommand(struct android_app* state, std::int32_t cmd) |
| 124 | { |
nothing calls this directly
no test coverage detected