feat: Added fps counter

This commit is contained in:
Theo Champion 2025-08-11 10:50:59 +02:00
parent a0967d5f93
commit 4564db6f2f
5 changed files with 1442 additions and 5 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
/* Updated: 2025/08/07 11:38:18 by tchampio ### ########.fr */
/* Updated: 2025/08/08 12:08:23 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/08/07 12:27:47 by tchampio ### ########.fr */
/* Updated: 2025/08/11 10:50:40 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,6 +35,8 @@
int game_loop(t_cub3d_data *data)
{
t_ray ray;
int fps;
char *fps_string;
data->last_tick = get_milliseconds();
mlx_destroy_image(data->mlx, data->img_data->img);
@ -49,7 +51,11 @@ int game_loop(t_cub3d_data *data)
data->img_data->img, 0, 0);
mlx_string_put(data->mlx, data->mlx_win, 10, 10, 0x00FFFFFF, COMPILED_TEXT);
data->delta = (get_milliseconds() - data->last_tick);
ft_printf("%d,%d\n", data->last_tick, data->delta);
fps = 1000000.0 / data->delta;
fps_string = ft_itoa(fps);
mlx_string_put(data->mlx, data->mlx_win, WIDTH - 20, 15, 0xFF0000, fps_string);
free(fps_string);
//ft_printf("%d,%d\n", data->last_tick, data->delta);
return (0);
}
@ -69,7 +75,7 @@ int main(int argc, char **argv)
data.sprite_list[0]->image = load_single_texture(&data, "ressources/box.xpm");
data.sprite_list[1]->x = data.map->startx;
data.sprite_list[1]->y = data.map->starty - 2;
data.sprite_list[1]->image = load_single_texture(&data, "ressources/test.xpm");
data.sprite_list[1]->image = load_single_texture(&data, "ressources/test_holed.xpm");
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask,
keyrelease_handler, &data);