From d7dd2f06c9bde3439814dae5c8a2b5d728488a38 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 29 Jan 2019 17:03:41 +0100 Subject: [PATCH] android implement tick and frame time --- android/src/main/cpp/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/android/src/main/cpp/main.cpp b/android/src/main/cpp/main.cpp index aa91f35..6763c18 100755 --- a/android/src/main/cpp/main.cpp +++ b/android/src/main/cpp/main.cpp @@ -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(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;