Skip to content

Commit f6623cb

Browse files
Merge pull request #35 from rokuz/fix_android_fps_log
[Android] Output FPS only when it was recalculated
2 parents 04393c1 + 65bf47e commit f6623cb

10 files changed

+34
-24
lines changed

samples/001_HelloTriangle.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ void android_main(android_app* app) {
184184
do {
185185
timespec newTime = {0, 0};
186186
clock_gettime(CLOCK_MONOTONIC, &newTime);
187-
fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
188-
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec));
189-
LLOGL("FPS: %.1f\n", fps_.getFPS());
187+
if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
188+
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) {
189+
LLOGL("FPS: %.1f\n", fps_.getFPS());
190+
}
190191
prevTime = newTime;
191192
if (ctx_) {
192193
render();

samples/001_HelloTriangle_Slang.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ void android_main(android_app* app) {
300300
do {
301301
timespec newTime = {0, 0};
302302
clock_gettime(CLOCK_MONOTONIC, &newTime);
303-
fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
304-
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec));
305-
LLOGL("FPS: %.1f\n", fps_.getFPS());
303+
if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
304+
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) {
305+
LLOGL("FPS: %.1f\n", fps_.getFPS());
306+
}
306307
prevTime = newTime;
307308
if (ctx_) {
308309
render();

samples/002_RenderToCubeMap.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ void android_main(android_app* app) {
339339
timespec newTime = {0, 0};
340340
clock_gettime(CLOCK_MONOTONIC, &newTime);
341341
double newTimeSec = ((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec);
342-
fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec));
343-
LLOGL("FPS: %.1f\n", fps_.getFPS());
342+
if (fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) {
343+
LLOGL("FPS: %.1f\n", fps_.getFPS());
344+
}
344345
prevTime = newTime;
345346
if (ctx_) {
346347
render((float)newTimeSec);

samples/003_RenderToCubeMapSinglePass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ void android_main(android_app* app) {
353353
timespec newTime = {0, 0};
354354
clock_gettime(CLOCK_MONOTONIC, &newTime);
355355
double newTimeSec = ((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec);
356-
fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec));
357-
LLOGL("FPS: %.1f\n", fps_.getFPS());
356+
if (fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) {
357+
LLOGL("FPS: %.1f\n", fps_.getFPS());
358+
}
358359
prevTime = newTime;
359360
if (ctx_) {
360361
render((float)newTimeSec);

samples/004_YUV.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ void android_main(android_app* app) {
300300
do {
301301
timespec newTime = {0, 0};
302302
clock_gettime(CLOCK_MONOTONIC, &newTime);
303-
fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
304-
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec));
305-
LLOGL("FPS: %.1f\n", fps_.getFPS());
303+
if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
304+
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) {
305+
LLOGL("FPS: %.1f\n", fps_.getFPS());
306+
}
306307
prevTime = newTime;
307308
if (ctx_) {
308309
render();

samples/006_RayTracingHello.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,9 @@ void android_main(android_app* app) {
402402
do {
403403
double newTime = glfwGetTime();
404404
double delta = newTime - prevTime;
405-
fps_.tick(delta);
406-
LLOGL("FPS: %.1f\n", fps_.getFPS());
405+
if (fps_.tick(delta)) {
406+
LLOGL("FPS: %.1f\n", fps_.getFPS());
407+
}
407408
prevTime = newTime;
408409
if (ctx_) {
409410
render();

samples/007_RayTracingAO.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,8 +1340,9 @@ void android_main(android_app* app) {
13401340
do {
13411341
double newTime = getCurrentTimestamp();
13421342
double delta = newTime - prevTime;
1343-
fps_.tick(delta);
1344-
LLOGL("FPS: %.1f\n", fps_.getFPS());
1343+
if (fps_.tick(delta)) {
1344+
LLOGL("FPS: %.1f\n", fps_.getFPS());
1345+
}
13451346
prevTime = newTime;
13461347
if (ctx_) {
13471348
render(delta, frameIndex);

samples/Tiny.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,10 @@ void android_main(android_app* app) {
228228
do {
229229
timespec newTime = {0, 0};
230230
clock_gettime(CLOCK_MONOTONIC, &newTime);
231-
fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
232-
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec));
233-
LLOGL("FPS: %.1f\n", fps_.getFPS());
231+
if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) -
232+
((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) {
233+
LLOGL("FPS: %.1f\n", fps_.getFPS());
234+
}
234235
prevTime = newTime;
235236
if (ctx_) {
236237
vk.render();

samples/Tiny_Mesh.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,9 @@ void android_main(android_app* app) {
554554
timespec newTime = {0, 0};
555555
clock_gettime(CLOCK_MONOTONIC, &newTime);
556556
double newTimeSec = ((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec);
557-
fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec));
558-
LLOGL("FPS: %.1f\n", fps_.getFPS());
557+
if (fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) {
558+
LLOGL("FPS: %.1f\n", fps_.getFPS());
559+
}
559560
prevTime = newTime;
560561
if (ctx_) {
561562
render(frameIndex, (float)newTimeSec);

samples/Tiny_MeshLarge.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,8 +2334,9 @@ void android_main(android_app* app) {
23342334
do {
23352335
double newTime = getCurrentTimestamp();
23362336
double delta = newTime - prevTime;
2337-
fps_.tick(delta);
2338-
LLOGL("FPS: %.1f\n", fps_.getFPS());
2337+
if (fps_.tick(delta)) {
2338+
LLOGL("FPS: %.1f\n", fps_.getFPS());
2339+
}
23392340
prevTime = newTime;
23402341
if (ctx_) {
23412342
render(delta, frameIndex);

0 commit comments

Comments
 (0)