1 /* frame rate measurement
3 * (C) 2018 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "../../include/keycodes.h"
24 #include "../libsdl/sdl.h"
25 #include "framerate.h"
27 #define MAX_HISTORY 60
29 double vbl_duration = 1.0 / 60.0;
30 static uint32_t ticks_history[MAX_HISTORY];
31 static int ticks_count = 0;
33 void framerate_measure(void)
35 uint32_t ticks = ticks_sdl();
37 /* wait some ticks until to get better average when we start */
38 if (ticks_count >= 10 || ticks_count == MAX_HISTORY)
39 vbl_duration = (double)((uint32_t)(ticks - ticks_history[0])) / (double)ticks_count / 1000.0;
41 if (ticks_count == MAX_HISTORY) {
42 memmove(ticks_history, ticks_history + 1, sizeof(ticks_history[0]) * (MAX_HISTORY - 1));
45 ticks_history[ticks_count++] = ticks;