I have a simple Game Activity and I am using the default code. It looks like the polling rate of the loop, as measured like this, is around 2 microseconds.
Is it normal? I was wondering where to put the input polling and rendering code, and examples put it in this loop. But if the loop is called that often it's terrible for CPU usage. Is there anything I'm missing here?
double averageTiming = 0.0;
int totalIterations = 0;
do {
// Process all pending events before running game logic.
while (ALooper_pollAll(0, nullptr, &events, (void **) &pSource) >= 0) {
if (pSource) {
pSource->process(app, pSource);
}
}
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
long long now = now.tv_sec*1000000000LL + now.tv_nsec;
averageTiming += double(now - lastTime) / 1.0_secs_in_ns;
totalIterations += 1;
if (totalIterations >= 100000) {
LOG("TEMP: elapsed time: %f", averageTiming / totalIterations);
totalIterations = 0;
averageTiming = 0;
}
lastTime = now;
} while (!app->destroyRequested);
Result:
2023-08-21 11:26:18.995 25866-25915 DEBUG com.example.minimalandroid D TEMP: elapsed time: 0.000002
2023-08-21 11:26:19.150 25866-25915 DEBUG com.example.minimalandroid D TEMP: elapsed time: 0.000002
2023-08-21 11:26:19.305 25866-25915 DEBUG com.example.minimalandroid D TEMP: elapsed time: 0.000002
2023-08-21 11:26:19.461 25866-25915 DEBUG com.example.minimalandroid D TEMP: elapsed time: 0.000002