OVR: Change the way to walk and rotate with the controller
[mercenary-reloaded.git] / src / libframerate / framerate.c
1 /* frame rate measurement
2  *
3  * (C) 2018 by Andreas Eversberg <jolly@eversberg.eu>
4  * All Rights Reserved
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <string.h>
23 #include "../../include/keycodes.h"
24 #include "../libsdl/sdl.h"
25 #include "framerate.h"
26
27 #define MAX_HISTORY 60
28
29 double vbl_duration = 1.0 / 60.0;
30 static uint32_t ticks_history[MAX_HISTORY];
31 static int ticks_count = 0;
32
33 void framerate_measure(void)
34 {
35         uint32_t ticks = ticks_sdl();
36
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;
40
41         if (ticks_count == MAX_HISTORY) {
42                 memmove(ticks_history, ticks_history + 1, sizeof(ticks_history[0]) * (MAX_HISTORY - 1));
43                 ticks_count--;
44         }
45         ticks_history[ticks_count++] = ticks;
46 }
47