android implement tick and frame time
This commit is contained in:
@@ -684,6 +684,8 @@ static int engine_init_display(struct engine* engine) {
|
||||
* Just the current frame in the display.
|
||||
*/
|
||||
static void engine_draw_frame(struct engine* engine) {
|
||||
static auto start = std::chrono::high_resolution_clock::now();
|
||||
static float elapsed = 0;
|
||||
locker _lock(engine);
|
||||
|
||||
/*
|
||||
@@ -703,11 +705,18 @@ static void engine_draw_frame(struct engine* engine) {
|
||||
}
|
||||
*/
|
||||
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto dt = std::chrono::duration<float>(now - start);
|
||||
start = now;
|
||||
elapsed += dt.count();
|
||||
App::I.tick(dt.count());
|
||||
|
||||
if (engine->display == NULL || !(App::I.redraw || App::I.animate))
|
||||
return;
|
||||
|
||||
App::I.clear();
|
||||
App::I.update(0);
|
||||
App::I.update(elapsed);
|
||||
elapsed = 0;
|
||||
|
||||
eglSwapBuffers(engine->display, engine->surface);
|
||||
}
|
||||
@@ -1048,17 +1057,18 @@ void android_main(struct android_app* state) {
|
||||
}
|
||||
|
||||
// If a sensor has data, process it now.
|
||||
/*
|
||||
if (ident == LOOPER_ID_USER) {
|
||||
if (g_engine.accelerometerSensor != NULL) {
|
||||
ASensorEvent event;
|
||||
while (ASensorEventQueue_getEvents(g_engine.sensorEventQueue,
|
||||
&event, 1) > 0) {
|
||||
while (ASensorEventQueue_getEvents(g_engine.sensorEventQueue, &event, 1) > 0) {
|
||||
// LOGI("accelerometer: x=%f y=%f z=%f",
|
||||
// event.acceleration.x, event.acceleration.y,
|
||||
// event.acceleration.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (ident == ALOOPER_POLL_TIMEOUT || ident == ALOOPER_POLL_CALLBACK){
|
||||
App::I.redraw = true;
|
||||
|
||||
Reference in New Issue
Block a user