Compare commits

...

2 commits

Author SHA1 Message Date
Theo Champion
b9b164e32d norm: Fixed norm errors except for comments in main function 2025-08-11 11:03:51 +02:00
Theo Champion
4564db6f2f feat: Added fps counter 2025-08-11 10:50:59 +02:00
5 changed files with 1447 additions and 7 deletions

View file

@ -4,7 +4,7 @@ CC = cc
# https://github.com/google/sanitizers/wiki/AddressSanitizer
SANITIZERS = -fsanitize=address,undefined -fno-omit-frame-pointer
ifeq ($(CFLAGS),)
CFLAGS = -Wall -Wextra -Werror -g
CFLAGS = -Wall -Wextra -Werror -g -O3 -ffast-math
endif
IFLAGS = -I./mlx -I./libft

70
ressources/north_2.xpm Normal file
View file

@ -0,0 +1,70 @@
/* XPM */
static char * north_2_xpm[] = {
"64 64 3 1",
" c #897451",
". c #534530",
"+ c #000000",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" . ",
" . ",
" . ",
" . ",
" .. . ",
" .. . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" . . . ",
" .. . . ",
" . . . ",
" . . . ",
" . . . ",
" . ... ",
" . .. ",
" . .. ",
" . . ",
" . ",
" . ",
" . ",
" . ",
" ",
" ",
" ",
" +++ +++ ",
" +++ +++ ",
" +++ +++ ",
" ",
" +++ +++ ",
" +++++++++ ",
" +++++++++ ",
" +++ ",
" ",
" ",
" "};

1361
ressources/test_holed.xpm Normal file

File diff suppressed because it is too large Load diff

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 11:03:22 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);
return (0);
}
@ -60,16 +66,19 @@ int main(int argc, char **argv)
if (argc < 2)
return (ft_printf("Error: Missing cub3d file\n"), 1);
init_cub3d_data(&data, argv);
// placing a sprite next to player to ease debugging
// FIXME: Delete this whole piece of code when we will init sprites from
// map
data.sprite_list = ft_calloc(sizeof(t_sprite *), 3);
data.sprite_list[0] = ft_calloc(sizeof(t_sprite), 1);
data.sprite_list[1] = ft_calloc(sizeof(t_sprite), 1);
data.sprite_list[0]->x = data.map->startx + 1;
data.sprite_list[0]->y = data.map->starty;
data.sprite_list[0]->image = load_single_texture(&data, "ressources/box.xpm");
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);