feat: advancement on map parse
This commit is contained in:
parent
7321db26d9
commit
d586acba8f
11 changed files with 257 additions and 123 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/12 11:06:44 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/18 17:14:06 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,16 +26,25 @@ static void cleanup_map(t_map *map)
|
|||
(close(map->fd), map->fd = 0);
|
||||
if (map->fraw)
|
||||
(ft_free_2d((void **)map->fraw), map->fraw = NULL);
|
||||
if (map->map)
|
||||
ft_free((void **)&map->map);
|
||||
}
|
||||
|
||||
static void cleanup_mlx(t_info *info)
|
||||
{
|
||||
if (info->mlx_ptr && info->win_ptr)
|
||||
if (!info->mlx_ptr)
|
||||
return ;
|
||||
if (info->win_ptr)
|
||||
mlx_destroy_window(info->mlx_ptr, info->win_ptr);
|
||||
if (info->mlx_ptr)
|
||||
mlx_destroy_display(info->mlx_ptr);
|
||||
if (info->mlx_ptr)
|
||||
ft_free((void **)&info->mlx_ptr);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (info->map.texture[i].img)
|
||||
mlx_destroy_image(info->mlx_ptr, info->map.texture[i].img);
|
||||
if (info->map.texture[i].path)
|
||||
ft_free((void **)&info->map.texture[i].path);
|
||||
}
|
||||
mlx_destroy_display(info->mlx_ptr);
|
||||
ft_free((void **)&info->mlx_ptr);
|
||||
}
|
||||
|
||||
void cleanup_info(t_info *info)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 11:09:00 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/12 08:45:03 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/18 11:31:05 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
const char *g_error_message[] = {
|
||||
const char *const g_error_message[] = {
|
||||
"no error",
|
||||
"unknown error",
|
||||
"could not open file",
|
||||
|
|
@ -29,6 +29,7 @@ const char *g_error_message[] = {
|
|||
"parse error",
|
||||
"cli error",
|
||||
"mlx error",
|
||||
"texture format error",
|
||||
"not implemented",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/13 06:56:50 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/18 14:17:27 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,13 +18,16 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// not normed but we'll take care of this as a niceties at the last
|
||||
// possible moment :)
|
||||
void dump_info(t_info *info)
|
||||
{
|
||||
const char *bool_str[2] = { "True", "False"};
|
||||
const char *bool_str[2] = {"True", "False"};
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
printf("t_info:\n");
|
||||
printf("\tcli_ctx:\n");
|
||||
printf("\t\tfile: %s\n", info->cli_ctx.file);
|
||||
|
|
@ -35,9 +38,13 @@ void dump_info(t_info *info)
|
|||
printf("\t\tpath:%s\n", info->map.path);
|
||||
printf("\t\tfd:%d\n", info->map.fd);
|
||||
printf("\t\tsize:\t(x:%d, y:%d)\n", info->map.size.x, info->map.size.y);
|
||||
printf("\t\tplayer_pos:\t(x:%lf, y:%lf)\n", info->map.player_pos.x, info->map.player_pos.y);
|
||||
for (size_t i = 0; info->map.fraw[i]; i++)
|
||||
printf("\t\tplayer_pos:\t(x:%lf, y:%lf)\n", info->map.player_pos.x, \
|
||||
info->map.player_pos.y);
|
||||
while (info->map.fraw[i])
|
||||
{
|
||||
printf("\t\tmap.fraw[%zu]: %s\n", i, info->map.fraw[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void check_err(t_info *info)
|
||||
|
|
@ -55,6 +62,8 @@ void check_err(t_info *info)
|
|||
|
||||
void run_cub3d(t_info *info)
|
||||
{
|
||||
if (init_mlx_env(info) != NO_ERROR)
|
||||
return ;
|
||||
parse_map(info);
|
||||
if (info->cli_ctx.debug)
|
||||
dump_info(info);
|
||||
|
|
@ -62,7 +71,7 @@ void run_cub3d(t_info *info)
|
|||
return ;
|
||||
// todo: here
|
||||
// - validity check
|
||||
init_mlx_env(info);
|
||||
printf("launching mlx\n");
|
||||
mlx_loop(info->mlx_ptr);
|
||||
// - game loop : already loops over the mlx_ptr
|
||||
// -> get events if key pressed move player + run math to re-draw screen
|
||||
|
|
@ -75,7 +84,7 @@ void run_cub3d(t_info *info)
|
|||
/// @param file_arg the file path to the .cub file
|
||||
/// @param info the info structure
|
||||
/// @return false (0) if no error, true (1) if an error
|
||||
int main_cub3d(char *file_arg, t_info *info)
|
||||
int main_cub3d(char *file_arg, t_info *info)
|
||||
{
|
||||
if (info->cli_ctx.help)
|
||||
return (cleanup_info(info), EXIT_SUCCESS);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/09 01:14:09 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/09 01:37:41 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/15 09:03:03 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,21 +19,21 @@
|
|||
|
||||
int c3_options(t_info *info, int argc, char *argv[])
|
||||
{
|
||||
int parsed_args;
|
||||
int parsed_args;
|
||||
const t_opt opts[] = {
|
||||
{"file", 'f', c3_set_file, OPT_ARG | OPT_EQSIGN | OPT_OTHER},
|
||||
{"debug", 'd', c3_set_debug, 0},
|
||||
{"save", 's', c3_set_save, 0},
|
||||
{"help", 'h', c3_print_help, 0},
|
||||
{"file", 'f', c3_set_file, OPT_ARG | OPT_EQSIGN | OPT_OTHER},
|
||||
{"debug", 'd', c3_set_debug, 0},
|
||||
{"save", 's', c3_set_save, 0},
|
||||
{"help", 'h', c3_print_help, 0},
|
||||
// add more options here put the implementation in options_impl.c
|
||||
// if you want custom option see ft_args_types.h for more info
|
||||
// code example in it.
|
||||
{NULL, 0, NULL, 0}
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
(void)argc;
|
||||
ft_bzero(info, sizeof(t_info));
|
||||
ft_setup_prog((const char * const *)argv);
|
||||
ft_setup_prog((const char *const *)argv);
|
||||
ft_set_opt_list(opts);
|
||||
parsed_args = ft_parse_args((const char **)argv, &(info->cli_ctx));
|
||||
return (parsed_args);
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/09 01:12:16 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/09 01:36:19 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/15 09:08:34 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d_struct.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
void c3_set_file(void *usr_control_struct, const char *arg)
|
||||
void c3_set_file(void *usr_control_struct, const char *arg)
|
||||
{
|
||||
t_cli *cli_ctx;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ void c3_set_file(void *usr_control_struct, const char *arg)
|
|||
cli_ctx->file = ft_strdup(arg);
|
||||
}
|
||||
|
||||
void c3_set_debug(void *usr_control_struct)
|
||||
void c3_set_debug(void *usr_control_struct)
|
||||
{
|
||||
t_cli *cli_ctx;
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ void c3_set_debug(void *usr_control_struct)
|
|||
cli_ctx->debug = true;
|
||||
}
|
||||
|
||||
void c3_set_save(void *usr_control_struct)
|
||||
void c3_set_save(void *usr_control_struct)
|
||||
{
|
||||
t_cli *cli_ctx;
|
||||
|
||||
|
|
@ -37,16 +37,17 @@ void c3_set_save(void *usr_control_struct)
|
|||
cli_ctx->save = true;
|
||||
}
|
||||
|
||||
void c3_print_help(void *usr_control_struct)
|
||||
void c3_print_help(void *usr_control_struct)
|
||||
{
|
||||
t_cli *cli_ctx;
|
||||
t_cli *cli_ctx;
|
||||
const char *help_str = \
|
||||
"Usage: cub3d [options] <file>\nOptions:\n" \
|
||||
"\t-f, --file <file> : specify the file to load\n" \
|
||||
"\t-d, --debug : enable debug mode\n" \
|
||||
"\t-s, --save : save the state of the 'game' when closing\n" \
|
||||
"\t-h, --help : print this help\n";
|
||||
|
||||
cli_ctx = (t_cli *)usr_control_struct;
|
||||
cli_ctx->help = true;
|
||||
ft_putstr_fd("Usage: cub3d [options] <file>\n", STDOUT_FILENO);
|
||||
ft_putstr_fd("Options:\n", STDOUT_FILENO);
|
||||
ft_putstr_fd("\t-f, --file <file> : specify the file to load\n", STDOUT_FILENO);
|
||||
ft_putstr_fd("\t-d, --debug : enable debug mode\n", STDOUT_FILENO);
|
||||
ft_putstr_fd("\t-s, --save : save the state of the 'game' when closing\n", STDOUT_FILENO);
|
||||
ft_putstr_fd("\t-h, --help : print this help\n", STDOUT_FILENO);
|
||||
ft_putstr_fd(help_str, STDOUT_FILENO);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue