| 851 | } |
| 852 | |
| 853 | int32_t AndroidPlatform::loop() { |
| 854 | IXRInterface *xr = CC_GET_XR_INTERFACE(); |
| 855 | while (true) { |
| 856 | struct android_poll_source *source; |
| 857 | |
| 858 | // suspend thread while _loopTimeOut set to -1 |
| 859 | while (ALooper_pollOnce(_loopTimeOut, nullptr, nullptr, |
| 860 | reinterpret_cast<void **>(&source)) >= 0) { |
| 861 | // Process event |
| 862 | if (source != nullptr) { |
| 863 | source->process(_app, source); |
| 864 | } |
| 865 | |
| 866 | // Exit the game loop when the Activity is destroyed |
| 867 | if (_app->destroyRequested) { |
| 868 | break; |
| 869 | } |
| 870 | } |
| 871 | // Exit the game loop when the Activity is destroyed |
| 872 | if (_app->destroyRequested) { |
| 873 | break; |
| 874 | } |
| 875 | if (xr && !xr->platformLoopStart()) continue; |
| 876 | _inputProxy->handleInput(); |
| 877 | if (_inputProxy->isAnimating() && (xr ? xr->getXRConfig(xr::XRConfigKey::SESSION_RUNNING).getBool() : true)) { |
| 878 | runTask(); |
| 879 | if (_inputProxy->isActive()) { |
| 880 | flushTasksOnGameThreadAtForegroundJNI(); |
| 881 | } |
| 882 | } |
| 883 | flushTasksOnGameThreadJNI(); |
| 884 | |
| 885 | #if CC_ENABLE_SUSPEND_GAME_THREAD |
| 886 | if (_isLowFrequencyLoopEnabled) { |
| 887 | // Suspend a game thread after it has been running in the background for a specified amount of time |
| 888 | if (_lowFrequencyTimer.getSeconds() > LOW_FREQUENCY_EXPIRED_DURATION_SECONDS) { |
| 889 | _isLowFrequencyLoopEnabled = false; |
| 890 | _loopTimeOut = -1; |
| 891 | } |
| 892 | } |
| 893 | #endif |
| 894 | if (xr) xr->platformLoopEnd(); |
| 895 | } |
| 896 | onDestroy(); |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | void AndroidPlatform::pollEvent() { |
| 901 | // |
nothing calls this directly
no test coverage detected