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.
|
* Just the current frame in the display.
|
||||||
*/
|
*/
|
||||||
static void engine_draw_frame(struct engine* engine) {
|
static void engine_draw_frame(struct engine* engine) {
|
||||||
|
static auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
static float elapsed = 0;
|
||||||
locker _lock(engine);
|
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))
|
if (engine->display == NULL || !(App::I.redraw || App::I.animate))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
App::I.clear();
|
App::I.clear();
|
||||||
App::I.update(0);
|
App::I.update(elapsed);
|
||||||
|
elapsed = 0;
|
||||||
|
|
||||||
eglSwapBuffers(engine->display, engine->surface);
|
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 a sensor has data, process it now.
|
||||||
|
/*
|
||||||
if (ident == LOOPER_ID_USER) {
|
if (ident == LOOPER_ID_USER) {
|
||||||
if (g_engine.accelerometerSensor != NULL) {
|
if (g_engine.accelerometerSensor != NULL) {
|
||||||
ASensorEvent event;
|
ASensorEvent event;
|
||||||
while (ASensorEventQueue_getEvents(g_engine.sensorEventQueue,
|
while (ASensorEventQueue_getEvents(g_engine.sensorEventQueue, &event, 1) > 0) {
|
||||||
&event, 1) > 0) {
|
|
||||||
// LOGI("accelerometer: x=%f y=%f z=%f",
|
// LOGI("accelerometer: x=%f y=%f z=%f",
|
||||||
// event.acceleration.x, event.acceleration.y,
|
// event.acceleration.x, event.acceleration.y,
|
||||||
// event.acceleration.z);
|
// event.acceleration.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (ident == ALOOPER_POLL_TIMEOUT || ident == ALOOPER_POLL_CALLBACK){
|
if (ident == ALOOPER_POLL_TIMEOUT || ident == ALOOPER_POLL_CALLBACK){
|
||||||
App::I.redraw = true;
|
App::I.redraw = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user