aboutsummaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-30 15:52:16 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-30 15:52:16 +0100
commit57867bbbdc24b734d85f8d3569c7ad27dcd9504d (patch)
tree1727dd02444038341746894268ecea62b84aaea1 /parse
parent3a164bce55e173d5204c4aaa66dd4eb5bc1762f9 (diff)
downloadcub3d-57867bbbdc24b734d85f8d3569c7ad27dcd9504d.tar.gz
cub3d-57867bbbdc24b734d85f8d3569c7ad27dcd9504d.tar.bz2
cub3d-57867bbbdc24b734d85f8d3569c7ad27dcd9504d.zip
files restructuration
Diffstat (limited to 'parse')
-rw-r--r--parse/parse.c142
-rw-r--r--parse/parse_check.c46
-rw-r--r--parse/parse_color.c55
-rw-r--r--parse/parse_resolution.c24
-rw-r--r--parse/parse_textures.c48
5 files changed, 0 insertions, 315 deletions
diff --git a/parse/parse.c b/parse/parse.c
deleted file mode 100644
index f4b5b66..0000000
--- a/parse/parse.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* parse.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/11/15 09:29:21 by cacharle #+# #+# */
-/* Updated: 2020/01/30 12:03:54 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "cub3d.h"
-
-t_state *parse(char *filename)
-{
- int i;
- char **lines;
- t_state *state;
-
- if ((state = state_new_empty()) == NULL)
- return (error_put_return("create empty state"));
- if ((lines = get_file_lines(filename)) == NULL)
- return (error_put_return_state_destroy("read .cub file", state));
- i = -1;
- while (lines[++i] != NULL)
- {
- if (*lines[i] == '1')
- break ;
- if (!parse_line(state, lines[i]))
- return (error_put_return_lines_state_destroy(
- "parse configuration", state, lines));
- }
- if ((state = parse_map(state, lines + i)) == NULL)
- return (error_put_return_lines_state_destroy(
- "parse map", state, lines));
- helper_free_splited(lines);
- return (state);
-}
-
-char **get_file_lines(char *filename)
-{
- int fd;
- int ret;
- char buf[CUB3D_BUFFER_SIZE + 1];
- char *file;
-
- if ((fd = open(filename, O_RDONLY)) < 0)
- return (NULL);
- if ((file = ft_strdup("")) == NULL)
- return (NULL);
- while ((ret = read(fd, buf, CUB3D_BUFFER_SIZE)) > 0)
- {
- buf[ret] = '\0';
- if ((file = ft_strjoin(file, buf)) == NULL)
- return (NULL);
- }
- if (ret == -1)
- return (NULL);
- close(fd);
- return (ft_split(file, '\n'));
-}
-
-static t_option_parser g_option_parsers[] =
-{
- {"R", parse_resolution},
- {"NO", parse_north_texture},
- {"SO", parse_south_texture},
- {"WE", parse_west_texture},
- {"EA", parse_east_texture},
- {"S", parse_sprite_texture},
- {"F", parse_floor_color},
- {"C", parse_ceilling_color}
-};
-
-#define OPTIONS_PARSERS_SIZE (sizeof(g_option_parsers) / sizeof(t_option_parser))
-
-t_bool parse_line(t_state *state, char *line)
-{
- int i;
-
- if (!*line)
- return (TRUE);
- i = -1;
- while (++i < (int)OPTIONS_PARSERS_SIZE)
- if (ft_strncmp(g_option_parsers[i].id, line,
- ft_strlen(g_option_parsers[i].id)) == 0)
- return (g_option_parsers[i].func(
- state, line + ft_strlen(g_option_parsers[i].id) + 1));
- return (FALSE);
-}
-
-t_state *parse_map(t_state *state, char **lines)
-{
- int i;
-
- i = -1;
- while (lines[++i] != NULL)
- if (*lines[i] != '1')
- return (NULL);
- state->map_height = i;
- if ((state->map = (t_map)malloc(sizeof(t_cell*) * i)) == NULL)
- return (NULL);
- state->map_width = ft_strcount(*lines, '1');
- i = -1;
- while (lines[++i] != NULL)
- if ((state->map[i] = create_map_row(lines[i])) == NULL)
- return (NULL);
- return (state);
-}
-
-t_cell *create_map_row(char *line)
-{
- int i;
- t_cell *row;
-
- if ((row = (t_cell*)malloc(sizeof(t_cell) * ft_strlen(line))) == NULL)
- return (NULL);
- i = 0;
- while (*line)
- {
- if (*line == '0' || *line == '1' || *line == '2')
- row[i++] = *line - '0';
- else if (*line == 'N')
- row[i++] = CELL_LOOK_NORTH;
- else if (*line == 'S')
- row[i++] = CELL_LOOK_SOUTH;
- else if (*line == 'W')
- row[i++] = CELL_LOOK_WEST;
- else if (*line == 'E')
- row[i++] = CELL_LOOK_EAST;
- else
- {
- free(row);
- return (NULL);
- }
- line++;
- while (*line == ' ')
- line++;
- }
- return (row);
-}
diff --git a/parse/parse_check.c b/parse/parse_check.c
deleted file mode 100644
index a65d74a..0000000
--- a/parse/parse_check.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* check.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/11 10:59:15 by cacharle #+# #+# */
-/* Updated: 2020/01/11 13:03:33 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "cub3d.h"
-
-t_state *parse_check(t_state *state)
-{
- int i;
- /* int j; */
- /* int player_count; */
-
- i = -1;
- while (++i < state->map_width)
- if (state->map[0][i] != CELL_WALL
- || state->map[state->map_height - 1][i] != CELL_WALL)
- return (error_put_return_state_destroy(
- "validate map without borders", state));
- i = -1;
- while (++i < state->map_height)
- if (state->map[i][0] != CELL_WALL
- || state->map[i][state->map_width - 1] != CELL_WALL)
- return (error_put_return_state_destroy(
- "validate map without borders", state));
- // maybe not necessary
- /* player_count = 0; */
- /* i = -1; */
- /* while (++i < state->map_height) */
- /* { */
- /* j = -1; */
- /* while (++j < state->map_width) */
- /* if (helper_is_player_cell(state->map[i][j])) */
- /* player_count++; */
- /* } */
- /* if (player_count != 1) */
- /* return (state_destroy(state)); */
- return (state);
-}
diff --git a/parse/parse_color.c b/parse/parse_color.c
deleted file mode 100644
index fd482e5..0000000
--- a/parse/parse_color.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* parse_color.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/11 09:52:34 by cacharle #+# #+# */
-/* Updated: 2020/01/30 14:17:37 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "cub3d.h"
-
-t_bool parse_ceilling_color(t_state *state, char *line)
-{
- int tmp;
-
- state->ceilling_color.hexcode = 0x0;
- if ((tmp = ft_atoi(line)) > 255 || tmp < 0) // cant do atoi due to overflow stuff, use ft_strtol
- return (FALSE);
- state->ceilling_color.rgb.r = (t_byte)tmp;
- if ((line = ft_strchr(line, ',') + 1) == NULL)
- return (FALSE);
- if ((tmp = ft_atoi(line)) > 255 || tmp < 0)
- return (FALSE);
- state->ceilling_color.rgb.g = (t_byte)tmp;
- if ((line = ft_strchr(line, ',') + 1) == NULL)
- return (FALSE);
- if ((tmp = ft_atoi(line)) > 255 || tmp < 0)
- return (FALSE);
- state->ceilling_color.rgb.b = (t_byte)tmp;
- return (TRUE);
-}
-
-t_bool parse_floor_color(t_state *state, char *line)
-{
- int tmp;
-
- state->floor_color.hexcode = 0x0;
- if ((tmp = ft_atoi(line)) > 255 || tmp < 0)
- return (FALSE);
- state->floor_color.rgb.r = (t_byte)tmp;
- if ((line = ft_strchr(line, ',') + 1) == NULL)
- return (FALSE);
- if ((tmp = ft_atoi(line)) > 255 || tmp < 0)
- return (FALSE);
- state->floor_color.rgb.g = (t_byte)tmp;
- if ((line = ft_strchr(line, ',') + 1) == NULL)
- return (FALSE);
- if ((tmp = ft_atoi(line)) > 255 || tmp < 0)
- return (FALSE);
- state->floor_color.rgb.b = (t_byte)tmp;
- return (TRUE);
-}
diff --git a/parse/parse_resolution.c b/parse/parse_resolution.c
deleted file mode 100644
index d6c5759..0000000
--- a/parse/parse_resolution.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* parse_resolution.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/11/15 09:29:27 by cacharle #+# #+# */
-/* Updated: 2020/01/11 09:44:18 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "cub3d.h"
-
-t_bool parse_resolution(t_state *state, char *line)
-{
- if ((state->window.width = ft_atoi(line)) < 0)
- return (FALSE);
- if ((line = ft_strrchr(line, ' ') + 1) == NULL)
- return (FALSE);
- if ((state->window.height = ft_atoi(line)) < 0)
- return (FALSE);
- return (TRUE);
-}
diff --git a/parse/parse_textures.c b/parse/parse_textures.c
deleted file mode 100644
index a0fb8f6..0000000
--- a/parse/parse_textures.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* parse_textures.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/11 09:47:53 by cacharle #+# #+# */
-/* Updated: 2020/01/11 09:51:03 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "cub3d.h"
-
-t_bool parse_north_texture(t_state *state, char *line)
-{
- if ((state->textures_path[TEX_NORTH] = ft_strdup(line)) == NULL)
- return (FALSE);
- return (TRUE);
-}
-
-t_bool parse_south_texture(t_state *state, char *line)
-{
- if ((state->textures_path[TEX_SOUTH] = ft_strdup(line)) == NULL)
- return (FALSE);
- return (TRUE);
-}
-
-t_bool parse_west_texture(t_state *state, char *line)
-{
- if ((state->textures_path[TEX_WEST] = ft_strdup(line)) == NULL)
- return (FALSE);
- return (TRUE);
-}
-
-t_bool parse_east_texture(t_state *state, char *line)
-{
- if ((state->textures_path[TEX_EAST] = ft_strdup(line)) == NULL)
- return (FALSE);
- return (TRUE);
-}
-
-t_bool parse_sprite_texture(t_state *state, char *line)
-{
- if ((state->textures_path[TEX_SPRITE] = ft_strdup(line)) == NULL)
- return (FALSE);
- return (TRUE);
-}