aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--cub3d.h67
-rw-r--r--header.h8
-rw-r--r--main.c9
-rw-r--r--parse.c0
-rw-r--r--parse/parse.c54
-rw-r--r--parse/parse_ceilling_color.c12
-rw-r--r--parse/parse_east_texture.c8
-rw-r--r--parse/parse_floor_color.c12
-rw-r--r--parse/parse_north_texture.c8
-rw-r--r--parse/parse_resolution.c9
-rw-r--r--parse/parse_south_texture.c8
-rw-r--r--parse/parse_sprite_texture.c8
-rw-r--r--parse/parse_west_texture.c8
-rw-r--r--subject.en.pdfbin0 -> 15025261 bytes
15 files changed, 203 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index d461a2e..e4296bb 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ LDFLAGS = -L$(LIBFT_PATH) -lft
NAME = cub3D
SRC = main.c
OBJ = $(SRC:.c=.o)
-INCLUDE = header.h
+INCLUDE = cub3d.h
all: libft_all $(NAME)
diff --git a/cub3d.h b/cub3d.h
new file mode 100644
index 0000000..78e5b84
--- /dev/null
+++ b/cub3d.h
@@ -0,0 +1,67 @@
+#ifndef CUB3D_H
+# define CUB3D_H
+
+# include <stdlib.h>
+# include "libft.h"
+
+# define TRUE 1
+# define FALSE 0
+
+typedef int t_bool;
+
+typedef struct
+{
+ int x;
+ int y;
+} t_point;
+
+typedef struct
+{
+ int r;
+ int g;
+ int b;
+} t_color;
+
+typedef enum
+{
+ CELL_EMPTY,
+ CELL_WALL,
+ CELL_ITEM,
+ CELL_LOOK_NORTH,
+ CELL_LOOK_SOUTH,
+ CELL_LOOK_WEST,
+ CELL_LOOK_EAST
+} t_cell;
+
+typedef t_cell** t_map;
+
+typedef struct
+{
+ int resolution_height;
+ int resolution_width;
+ char *north_texture_path;
+ char *south_texture_path;
+ char *west_texture_path;
+ char *east_texture_path;
+ char *sprite_texture_path;
+ t_color floor_color;
+ t_color ceilling_color;
+ t_map map;
+} t_parsing;
+
+typedef t_bool (*func)(t_parsing *parsing, char *line) t_line_parser_func;
+
+typedef struct
+{
+ char *id;
+ t_line_parser_func func;
+} t_line_parser;
+
+/*
+** parse.c
+*/
+
+t_parsing *parse(char *filename);
+t_bool parse_line(t_parsing *parsing, char *line);
+
+#endif
diff --git a/header.h b/header.h
deleted file mode 100644
index 6a35729..0000000
--- a/header.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef HEADER_H
-# define HEADER_H
-
-# include "libft.h"
-
-
-
-#endif
diff --git a/main.c b/main.c
index c59cba5..56178bb 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,14 @@
-#include "header.h"
+#include "cub3d.h"
int main(int argc, char **argv)
{
+ if (argc != 2)
+ {
+ ft_putendl("Error");
+ return (1);
+ }
+
+ t_parsing *p = parse(argv[1]);
return (0);
diff --git a/parse.c b/parse.c
deleted file mode 100644
index e69de29..0000000
--- a/parse.c
+++ /dev/null
diff --git a/parse/parse.c b/parse/parse.c
new file mode 100644
index 0000000..c882424
--- /dev/null
+++ b/parse/parse.c
@@ -0,0 +1,54 @@
+#include "cub3d.h"
+
+t_parsing *parse(char *filename)
+{
+ int fd;
+ int ret;
+ char *line;
+ t_parsing *parsing;
+
+ if ((parsing = (t_parsing*)malloc(sizeof(t_parsing))) == NULL)
+ return (NULL);
+ fd = open(filename, O_RDONLY);
+ while ((ret = get_next_line(fd, &line)) == 1)
+ if (!parse_line(parsing, line))
+ return (NULL);
+ if (ret == -1)
+ return (NULL);
+ return (parsing);
+}
+
+static t_option_parser 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_PARSER_SIZE (sizeof(line_parsers) / sizeof(t_line_parser))
+
+t_bool parse_option(t_parsing *parsing, char *line)
+{
+ int i;
+
+ if (!*line)
+ return (TRUE);
+ i = -1;
+ while (++i < LINE_PARSER_SIZE)
+ if (ft_strchr("012", *line) != NULL)
+ return (parse_map(parsing, line));
+ else if (ft_strncmp(option_parsers[i].id, line,
+ ft_strlen(option_parsers[i].id)) == 0)
+ return (option_parsers[i]
+ .func(parsing, line + ft_strlen(option_parsers[i].id));
+ return (FALSE);
+}
+
+t_bool parse_map(t_parsing *parsing, char *line)
+{
+ return (FALSE);
+}
diff --git a/parse/parse_ceilling_color.c b/parse/parse_ceilling_color.c
new file mode 100644
index 0000000..0f93ed1
--- /dev/null
+++ b/parse/parse_ceilling_color.c
@@ -0,0 +1,12 @@
+#include "cub3d.h"
+
+t_bool parse_ceilling_color(t_parsing *parsing, char *line)
+{
+ line++;
+ parsing->ceilling_color.r = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->ceilling_color.g = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->ceilling_color.b = ft_atoi(line);
+ return (TRUE);
+}
diff --git a/parse/parse_east_texture.c b/parse/parse_east_texture.c
new file mode 100644
index 0000000..e8d356a
--- /dev/null
+++ b/parse/parse_east_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_east_texture(t_parsing *parsing, char *line)
+{
+ parsing->east_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_floor_color.c b/parse/parse_floor_color.c
new file mode 100644
index 0000000..62d0a06
--- /dev/null
+++ b/parse/parse_floor_color.c
@@ -0,0 +1,12 @@
+#include "cub3d.h"
+
+t_bool parse_floor_color(t_parsing *parsing, char *line)
+{
+ line++;
+ parsing->floor_color.r = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->floor_color.g = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->floor_color.b = ft_atoi(line);
+ return (TRUE);
+}
diff --git a/parse/parse_north_texture.c b/parse/parse_north_texture.c
new file mode 100644
index 0000000..0d1af87
--- /dev/null
+++ b/parse/parse_north_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_north_texture(t_parsing *parsing, char *line)
+{
+ parsing->north_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_resolution.c b/parse/parse_resolution.c
new file mode 100644
index 0000000..c8e0c7f
--- /dev/null
+++ b/parse/parse_resolution.c
@@ -0,0 +1,9 @@
+#include "cub3d.h"
+
+t_bool parse_resolution(t_parsing *parsing, char *line)
+{
+ parsing->resolution_width = ft_atoi(line);
+ line = ft_strchr(line, ' ');
+ parsing->resolution_height = ft_atoi(line);
+ return (TRUE);
+}
diff --git a/parse/parse_south_texture.c b/parse/parse_south_texture.c
new file mode 100644
index 0000000..9ec89d0
--- /dev/null
+++ b/parse/parse_south_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_south_texture(t_parsing *parsing, char *line)
+{
+ parsing->south_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_sprite_texture.c b/parse/parse_sprite_texture.c
new file mode 100644
index 0000000..039a827
--- /dev/null
+++ b/parse/parse_sprite_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_sprite_texture(t_parsing *parsing, char *line)
+{
+ parsing->sprite_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_west_texture.c b/parse/parse_west_texture.c
new file mode 100644
index 0000000..5252ab4
--- /dev/null
+++ b/parse/parse_west_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_west_texture(t_parsing *parsing, char *line)
+{
+ parsing->west_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/subject.en.pdf b/subject.en.pdf
new file mode 100644
index 0000000..8f8ccb3
--- /dev/null
+++ b/subject.en.pdf
Binary files differ