OVR: Render all walls, even behind observer
[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 "../libsdl/sdl.h"
24 #include "framerate.h"
25
26 #define MAX_HISTORY 60
27
28 double vbl_duration = 1.0 / 60.0;
29 static uint32_t ticks_history[MAX_HISTORY];
30 static int ticks_count = 0;
31
32 void framerate_measure(void)
33 {
34         uint32_t ticks = ticks_sdl();
35
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;
39
40         if (ticks_count == MAX_HISTORY) {
41                 memmove(ticks_history, ticks_history + 1, sizeof(ticks_history[0]) * (MAX_HISTORY - 1));
42                 ticks_count--;
43         }
44         ticks_history[ticks_count++] = ticks;
45 }
46