aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_fps_count.c
blob: 1ac415bdc3b167dde0b3dff9fa0a178f916e77ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_get_fps_count.c                                 :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: joelecle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/17 20:06:26 by joelecle          #+#    #+#             */
/*   Updated: 2020/02/17 20:06:29 by joelecle         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <cub3d.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>

void
	ft_get_fps_count(clock_t before, t_cub *cl)
{
	static clock_t	dt = 0;
	static uint16_t	ticks = 0;
	clock_t			curr;

	curr = clock();
	dt += curr - before;
	ticks += 1;
	if (dt > 0 && ft_clock_to_ms(dt) > 1000.0)
	{
		ft_sprintf(cl->fps_count, "fps: %hu", ticks);
		ticks = 0;
		dt = 0;
	}
}