diff --git a/Makefile b/Makefile index c890c46..ccac5a4 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: gbrochar +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/12/17 19:47:03 by gbrochar #+# #+# # -# Updated: 2020/12/22 18:57:00 by gbrochar ### ########.fr # +# Updated: 2020/12/22 20:13:54 by gbrochar ### ########.fr # # # # **************************************************************************** # @@ -44,7 +44,7 @@ WHITE = \033[0m all: $(NAME) -$(NAME): $(OBJ) +$(NAME): $(OBJ) $(INC) @$(CC) $(CFLAGS) -c $(SRC) -I $(INC_DIR) @mv $(OBJ_FILE) $(OBJ_DIR) @$(CC) $(CFLAGS) $(OBJ) -o $(NAME) $(LIB) diff --git a/inc/scop.h b/inc/scop.h index 793d48b..17f4436 100644 --- a/inc/scop.h +++ b/inc/scop.h @@ -6,7 +6,7 @@ /* By: gbrochar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/22 12:08:22 by gbrochar #+# #+# */ -/* Updated: 2020/12/22 19:13:41 by gbrochar ### ########.fr */ +/* Updated: 2020/12/22 20:15:56 by gbrochar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,8 @@ # define TRUE 1 # define FALSE 0 +# define BUFFER_SIZE 4096 + typedef enum e_gl_buf_type t_gl_buf_type; enum e_gl_buf_type @@ -59,16 +61,15 @@ struct s_window struct s_buf_d { double *data; + size_t ptr; + size_t len; }; struct s_buf_i { int *data; -}; - -struct s_buf_s -{ - short *data; + size_t ptr; + size_t len; }; struct s_obj @@ -76,11 +77,7 @@ struct s_obj t_buf_d vertices; t_buf_d uvs; t_buf_d normals; - t_buf_s indices; - int vertices_ptr; - int uvs_ptr; - int normals_ptr; - int indices_ptr; + t_buf_i indices; }; struct s_env @@ -98,7 +95,7 @@ int parse_file(t_env *e); int parse_line(t_env *e, char *line); t_gl_buf_type parse_gl_buf_type(char *token); int parse_append_data_d(t_buf_d *buffer, char *token); -int parse_append_data_s(t_buf_s *buffer, char *token); +int parse_append_data_i(t_buf_i *buffer, char *token); void free_env(t_env *e); void init_window(t_env *e); diff --git a/src/env.c b/src/env.c index 2e99296..bf86d0b 100644 --- a/src/env.c +++ b/src/env.c @@ -6,7 +6,7 @@ /* By: gbrochar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/22 18:56:21 by gbrochar #+# #+# */ -/* Updated: 2020/12/22 19:07:24 by gbrochar ### ########.fr */ +/* Updated: 2020/12/22 20:15:14 by gbrochar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,14 +37,18 @@ void init_camera(t_env *e) void init_object(t_env *e) { - e->object.vertices.data = (double *)malloc(sizeof(double) * 4096); - e->object.uvs.data = (double *)malloc(sizeof(double) * 4096); - e->object.normals.data = (double *)malloc(sizeof(double) * 4096); - e->object.indices.data = (short *)malloc(sizeof(short) * 4096); - e->object.vertices_ptr = 0; - e->object.uvs_ptr = 0; - e->object.normals_ptr = 0; - e->object.indices_ptr = 0; + e->object.vertices.data = (double *)malloc(sizeof(double) * BUFFER_SIZE); + e->object.uvs.data = (double *)malloc(sizeof(double) * BUFFER_SIZE); + e->object.normals.data = (double *)malloc(sizeof(double) * BUFFER_SIZE); + e->object.indices.data = (int *)malloc(sizeof(int) * BUFFER_SIZE); + e->object.vertices.ptr = 0; + e->object.uvs.ptr = 0; + e->object.normals.ptr = 0; + e->object.indices.ptr = 0; + e->object.vertices.len = BUFFER_SIZE; + e->object.uvs.len = BUFFER_SIZE; + e->object.normals.len = BUFFER_SIZE; + e->object.indices.len = BUFFER_SIZE; } void init_env(t_env *e) diff --git a/src/main.c b/src/main.c index 0a3fde6..b2557c3 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: gbrochar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/22 12:02:14 by gbrochar #+# #+# */ -/* Updated: 2020/12/22 19:14:00 by gbrochar ### ########.fr */ +/* Updated: 2020/12/22 20:11:50 by gbrochar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,19 @@ int main(int argc, char **argv) init_env(&e); if (parse(&e, argc, argv) == SUCCESS) { + // printf("vertices: "); + // for (size_t i = 0; i < e.object.vertices.ptr; i++) + // printf("%f ", e.object.vertices.data[i]); + // printf("\nuvs: "); + // for (size_t i = 0; i < e.object.uvs.ptr; i++) + // printf("%f ", e.object.uvs.data[i]); + // printf("\nnormals: "); + // for (size_t i = 0; i < e.object.normals.ptr; i++) + // printf("%f ", e.object.normals.data[i]); + // printf("\nindices: "); + // for (size_t i = 0; i < e.object.indices.ptr; i++) + // printf("%d ", e.object.indices.data[i]); + // printf("\n"); } else { diff --git a/src/parse_line.c b/src/parse_line.c index efd6a01..90f0149 100644 --- a/src/parse_line.c +++ b/src/parse_line.c @@ -6,7 +6,7 @@ /* By: gbrochar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/22 18:41:28 by gbrochar #+# #+# */ -/* Updated: 2020/12/22 19:13:07 by gbrochar ### ########.fr */ +/* Updated: 2020/12/22 20:15:50 by gbrochar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,15 +14,27 @@ int parse_append_data_d(t_buf_d *buffer, char *token) { - (void)buffer; - (void)token; + if (buffer->ptr == buffer->len) + { + buffer->data = (double *)realloc( + buffer->data, sizeof(double) * (buffer->len + BUFFER_SIZE)); + buffer->len += BUFFER_SIZE; + } + buffer->data[buffer->ptr] = atof(token); + buffer->ptr++; return (SUCCESS); } -int parse_append_data_s(t_buf_s *buffer, char *token) +int parse_append_data_i(t_buf_i *buffer, char *token) { - (void)buffer; - (void)token; + if (buffer->ptr == buffer->len) + { + buffer->data = (int *)realloc( + buffer->data, sizeof(int) * (buffer->len + BUFFER_SIZE)); + buffer->len += BUFFER_SIZE; + } + buffer->data[buffer->ptr] = atoi(token); + buffer->ptr++; return (SUCCESS); } @@ -55,7 +67,7 @@ int parse_token( if (gl_buf_type == NORMAL) ret = parse_append_data_d(&(e->object.normals), token); if (gl_buf_type == INDEX) - ret = parse_append_data_s(&(e->object.indices), token); + ret = parse_append_data_i(&(e->object.indices), token); return (ret); }