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 "../libsdl/sdl.h"
24 #include "framerate.h"
26 #define MAX_HISTORY 60
28 double vbl_duration = 1.0 / 60.0;
29 static uint32_t ticks_history[MAX_HISTORY];
30 static int ticks_count = 0;
32 void framerate_measure(void)
34 uint32_t ticks = ticks_sdl();
36 /* wait some ticks until to get better average when we start */
37 if (ticks_count >= 10 || ticks_count == MAX_HISTORY)
38 vbl_duration = (double)((uint32_t)(ticks - ticks_history[0])) / (double)ticks_count / 1000.0;
40 if (ticks_count == MAX_HISTORY) {
41 memmove(ticks_history, ticks_history + 1, sizeof(ticks_history[0]) * (MAX_HISTORY - 1));
44 ticks_history[ticks_count++] = ticks;