/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ /* Updated: 2025/07/31 13:57:08 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft/includes/libft.h" #include "../mlx/mlx.h" #include "consts.h" #include "cub3d_data.h" #include "player/move.h" #include "draw/draw_map.h" #include "raycast/raycaster.h" #include "renderer/render.h" #include "raycast/ray.h" #include "utils/hooks.h" #include "utils/inits.h" #include #include #include #include #include #include #include "utils/time.h" int game_loop(t_cub3d_data *data) { t_ray ray; data->delta = (get_milliseconds() - data->last_tick); mlx_destroy_image(data->mlx, data->img_data->img); data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT); reset_matrix(data); raycaster(data, &ray); move_player(data); matrix_to_image(data); draw_map(data->map, &data->player, data->img_data); mlx_put_image_to_window(data->mlx, data->mlx_win, data->img_data->img, 0, 0); mlx_string_put(data->mlx, data->mlx_win, 10, 10, 0x00FFFFFF, COMPILED_TEXT); data->last_tick = get_milliseconds(); return (0); } int main(int argc, char **argv) { t_cub3d_data data; if (argc < 2) return (ft_printf("Error: Missing cub3d file\n"), 1); init_cub3d_data(&data, argv); mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data); mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask, keyrelease_handler, &data); mlx_loop_hook(data.mlx, game_loop, &data); mlx_loop(data.mlx); }