2018-01-20 15:15:15 +01:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2018-01-20 15:15:15 +01:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
2019-07-03 20:00:56 +02:00
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
2018-01-20 15:15:15 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "taisei.h"
|
|
|
|
|
|
|
|
#include "framerate.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "video.h"
|
|
|
|
|
|
|
|
void fpscounter_reset(FPSCounter *fps) {
|
2019-01-09 04:25:10 +01:00
|
|
|
hrtime_t frametime = HRTIME_RESOLUTION / FPS;
|
2022-01-12 13:19:21 +01:00
|
|
|
const int log_size = ARRAY_SIZE(fps->frametimes);
|
2018-01-20 15:15:15 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < log_size; ++i) {
|
|
|
|
fps->frametimes[i] = frametime;
|
|
|
|
}
|
|
|
|
|
2020-05-09 08:25:38 +02:00
|
|
|
fps->fps = HRTIME_RESOLUTION / (long double)frametime;
|
2019-01-09 04:25:10 +01:00
|
|
|
fps->frametime = frametime;
|
2018-01-20 15:15:15 +01:00
|
|
|
fps->last_update_time = time_get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void fpscounter_update(FPSCounter *fps) {
|
2022-01-12 13:19:21 +01:00
|
|
|
const int log_size = ARRAY_SIZE(fps->frametimes);
|
|
|
|
hrtime_t update_time = time_get();
|
|
|
|
hrtime_t frametime = update_time - fps->last_update_time;
|
2018-01-20 15:15:15 +01:00
|
|
|
|
|
|
|
memmove(fps->frametimes, fps->frametimes + 1, (log_size - 1) * sizeof(hrtime_t));
|
|
|
|
fps->frametimes[log_size - 1] = frametime;
|
|
|
|
|
2019-01-09 04:25:10 +01:00
|
|
|
hrtime_t avg = 0;
|
2018-01-20 15:15:15 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < log_size; ++i) {
|
|
|
|
avg += fps->frametimes[i];
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:19:21 +01:00
|
|
|
fps->fps = HRTIME_RESOLUTION / (avg / (double)log_size);
|
2019-01-09 04:25:10 +01:00
|
|
|
fps->frametime = avg / log_size;
|
2022-01-12 13:19:21 +01:00
|
|
|
fps->last_update_time = update_time;
|
2018-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t get_effective_frameskip(void) {
|
|
|
|
uint32_t frameskip;
|
|
|
|
|
|
|
|
if(global.frameskip > 0) {
|
|
|
|
frameskip = global.frameskip;
|
|
|
|
} else {
|
|
|
|
frameskip = config_get_int(CONFIG_VID_FRAMESKIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
return frameskip;
|
|
|
|
}
|