aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-10 22:04:35 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-10 22:04:35 +0200
commitd153f42e732ffe1c4cac1c13207fa0ce1781b193 (patch)
tree83e5eb6b41a23f98bd3ad10edf4b0769deccee1a
parent0ae5be6c6697f5f5f578a27c5ad9ba845aec43c9 (diff)
downloadscop-d153f42e732ffe1c4cac1c13207fa0ce1781b193.tar.gz
scop-d153f42e732ffe1c4cac1c13207fa0ce1781b193.tar.bz2
scop-d153f42e732ffe1c4cac1c13207fa0ce1781b193.zip
Basic parsing
-rw-r--r--.gitignore1
-rw-r--r--Makefile4
-rw-r--r--inc/scop.h6
-rw-r--r--src/main.c19
-rw-r--r--src/parse.c63
m---------vendor/libft0
-rw-r--r--vendor/libftm/libft.abin12818 -> 0 bytes
7 files changed, 66 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 78a4013..1bee866 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.o
+*.a
*.ghc
a.out
scop
diff --git a/Makefile b/Makefile
index ac009ed..d8d99a3 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/05/09 10:24:52 by charles #+# #+# #
-# Updated: 2020/05/09 10:42:39 by charles ### ########.fr #
+# Updated: 2020/05/10 21:06:25 by charles ### ########.fr #
# #
# **************************************************************************** #
@@ -22,7 +22,7 @@ OBJ_DIR = obj
CC = gcc
CCFLAGS = -I$(LIBFT_DIR)/include -I$(INC_DIR) \
- -Wall -Wextra #-Werror
+ -Wall -Wextra -Werror
LDFLAGS = -L$(LIBFT_DIR) -lft
ifeq ($(shell uname),Linux)
diff --git a/inc/scop.h b/inc/scop.h
index 8ae9864..d6cf415 100644
--- a/inc/scop.h
+++ b/inc/scop.h
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/09 10:41:44 by charles #+# #+# */
-/* Updated: 2020/05/09 11:41:48 by charles ### ########.fr */
+/* Updated: 2020/05/10 21:18:15 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,7 +23,9 @@
typedef struct
{
float *vertices;
- unsigned int indices;
+ unsigned int *indices;
+ size_t vertices_len;
+ size_t indices_len;
} t_object;
/*
diff --git a/src/main.c b/src/main.c
index 3eb0acc..3e8ab44 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/09 10:20:09 by charles #+# #+# */
-/* Updated: 2020/05/09 11:08:59 by charles ### ########.fr */
+/* Updated: 2020/05/10 22:02:36 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,7 @@
int main(int argc, char **argv)
{
/* GLFWwindow *window; */
- float *buffer;
+ t_object object;
if (argc != 2)
{
@@ -24,9 +24,20 @@ int main(int argc, char **argv)
ft_putendl(" [obj file]");
return (1);
}
- if ((buffer = parse(argv[1])) == NULL)
- return 1;
+ if (parse(argv[1], &object) == -1)
+ {
+ ft_putstr("Error: couldn't parse ");
+ ft_putendl(argv[1]);
+ return (1);
+ }
+
+ for (size_t i = 0; i < object.indices_len; i++)
+ printf("%u\n", object.indices[i]);
+ for (size_t i = 0; i < object.vertices_len; i++)
+ printf("%f\n", object.vertices[i]);
+ free(object.vertices);
+ free(object.indices);
/* if (!glfwInit()) */
/* return 1; */
/* window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); */
diff --git a/src/parse.c b/src/parse.c
index 4add0b3..fa9f2b5 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/09 11:02:00 by charles #+# #+# */
-/* Updated: 2020/05/09 12:07:36 by charles ### ########.fr */
+/* Updated: 2020/05/10 22:04:05 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,34 +14,54 @@
#define SCOP_VEC_DEFAULT_SIZE 32
-static int st_parse_line(char *line, t_ftvec *vertices, t_ftvec *indices)
+static int st_parse_face(char **indexes_strs, t_ftvec *indices)
{
+ size_t i;
+ size_t len;
unsigned int tmp;
- float tmpf;
- if (*line == 'v')
- {
- tmpf = ft_strtof(line, &line);
- ft_vecpush(indices, *((void**)&tmp));
- tmpf = ft_strtof(line, &line);
- ft_vecpush(indices, *((void**)&tmp));
- tmpf = ft_strtof(line, &line);
- ft_vecpush(indices, *((void**)&tmp));
- }
- if (*line == 'f')
+ len = ft_split_len(indexes_strs);
+ i = -1;
+ while (++i < len)
{
- tmp = ft_strtol(line, &line, 10);
- ft_vecpush(indices, *((void**)&tmp));
- tmp = ft_strtol(line, &line, 10);
- ft_vecpush(indices, *((void**)&tmp));
- tmp = ft_strtol(line, &line, 10);
- ft_vecpush(indices, *((void**)&tmp));
+ tmp = ft_atoi(indexes_strs[i]);
+ if (ft_vecpush(indices, *(void**)&tmp) == NULL)
+ return (-1);
}
+ return (0);
+}
+static int st_parse_vertex(char **positions_strs, t_ftvec *vertices)
+{
+ float tmp;
+ tmp = ft_atof(positions_strs[0]);
+ ft_vecpush(vertices, *((void**)&tmp));
+ tmp = ft_atof(positions_strs[1]);
+ ft_vecpush(vertices, *((void**)&tmp));
+ tmp = ft_atof(positions_strs[2]);
+ ft_vecpush(vertices, *((void**)&tmp));
return (0);
}
+static int st_parse_line(char *line, t_ftvec *vertices, t_ftvec *indices)
+{
+ int ret;
+ char **split;
+
+ if (*line != 'v' && *line != 'f')
+ return (0);
+ if ((split = ft_split(line + 1, ' ')) == NULL)
+ return (-1);
+ ret = -1;
+ if (*line == 'v' && ft_split_len(split) == 3)
+ ret = st_parse_vertex(split, vertices);
+ if (*line == 'f' && ft_split_len(split) >= 3)
+ ret = st_parse_face(split, indices);
+ ft_split_destroy(split);
+ return (ret);
+}
+
static int st_parse_file(int fd, t_ftvec *vertices, t_ftvec *indices)
{
char *line;
@@ -61,6 +81,7 @@ static int st_parse_file(int fd, t_ftvec *vertices, t_ftvec *indices)
free(line);
return (-1);
}
+ free(line);
return (0);
}
@@ -79,5 +100,9 @@ int parse(char *filepath, t_object *object)
st_parse_file(fd, vertices, indices);
object->vertices = (float*)ft_vectobuf32(vertices);
object->indices = (unsigned int*)ft_vectobuf32(indices);
+ object->vertices_len = vertices->size;
+ object->indices_len = indices->size;
+ ft_vecdestroy(vertices, NULL);
+ ft_vecdestroy(indices, NULL);
return (0);
}
diff --git a/vendor/libft b/vendor/libft
-Subproject 02abc030a68cb2fdd2f21c96db830ec8cb9176a
+Subproject d3fb362c2e0b83cc9754a05ae5bc4a68a5f9269
diff --git a/vendor/libftm/libft.a b/vendor/libftm/libft.a
deleted file mode 100644
index dc5b185..0000000
--- a/vendor/libftm/libft.a
+++ /dev/null
Binary files differ