Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c02d2f2
refactored tests and added tests for duplicates
rodsmade Sep 27, 2022
d83b000
fixed memory leak
rodsmade Sep 30, 2022
065444c
created folder for texture files
rodsmade Sep 30, 2022
2348df8
changed fds to texture_fds in struct for semantics
rodsmade Sep 30, 2022
0d65722
new file for map validation
rodsmade Sep 30, 2022
9d9a7e6
new additions to libft
rodsmade Sep 30, 2022
9693dee
created file for memory deallocation
rodsmade Sep 30, 2022
530e320
copying map contents to an internal var
rodsmade Sep 30, 2022
8d9926e
completing valid files with valid maps
rodsmade Sep 30, 2022
5ce95db
adding logs folder to git ignore
rodsmade Sep 30, 2022
c42fe1c
deleted logs files
rodsmade Sep 30, 2022
6ffd5fb
changed tester name to avoid conflicts
rodsmade Sep 30, 2022
386d5b8
wip: wrote a broken function that automatically says the map is false
rodsmade Sep 30, 2022
5edf130
refactored test function but i'm not sure if it's great
rodsmade Sep 30, 2022
7284a3e
initializing data in main not in map validation
rodsmade Sep 30, 2022
3cfc139
creating logs directory before launching tests
rodsmade Sep 30, 2022
6944131
test_my_cub3D.sh renamed tests 2-4
rodsmade Sep 30, 2022
9fc327b
deleting files to recreate them again
rodsmade Sep 30, 2022
e89ba46
added new test files for tests 40-43 (should fix previous 'No such fi…
rodsmade Sep 30, 2022
6da4578
deleted old tst file for test 44, creating new one and now tests work…
rodsmade Sep 30, 2022
d8e7a90
renaming test file 44
rodsmade Sep 30, 2022
e0e38d9
:white_check_mark: feat: map_validation now chck if map is surrounded…
gustavdlima Oct 1, 2022
c972832
test: ✅ add test to check if map line start with space.
gustavdlima Oct 3, 2022
96c6c35
wip: contour validation for positive case works ok. for negative case…
rodsmade Oct 3, 2022
89201ac
removing static from declaration of main data structure (t_map_parame…
rodsmade Oct 3, 2022
7749b42
pruning unnecessary static keyword in variable declaration
rodsmade Oct 3, 2022
af467e6
t_position utils separated in a file
rodsmade Oct 4, 2022
08e83b4
map validation seems to be ok for positive and negative scenarios
rodsmade Oct 4, 2022
a6e9ae9
added ignore folder to git ignore
rodsmade Oct 10, 2022
6df7032
added new function to libft to return length of NULL terminated matrix
rodsmade Oct 10, 2022
adfe351
grouping testing/debugging functions in a file
rodsmade Oct 10, 2022
dc02529
hopefully map contour validation works for most of scenarios with map…
rodsmade Oct 10, 2022
a61733e
test case with valid big irregular map surrounded by ones at right an…
rodsmade Oct 10, 2022
fb3a8c1
wip: most all files refactored, only map_validation left
rodsmade Oct 11, 2022
41b890b
wip: changing strategy to pad map with spaces so that walls validatio…
rodsmade Oct 11, 2022
97588e4
renamed t_map_parameters to t_data
rodsmade Oct 11, 2022
a066609
wip: map padding is ok with no leaks, have to check walls tracing
rodsmade Oct 12, 2022
24f4787
added new function to libft - to alloc and initialise string
rodsmade Oct 31, 2022
011a91c
added character validation for map
rodsmade Oct 31, 2022
53bc2a4
refactoring
rodsmade Oct 31, 2022
4ae6762
finished refactoring
rodsmade Nov 1, 2022
dc6505c
added validation cases for map size and starting position
rodsmade Nov 7, 2022
fdb3fe4
added starting position to valid maps and added new tests for new val…
rodsmade Nov 7, 2022
beb4079
wip: player starting position validation works for simple bumps in th…
rodsmade Nov 7, 2022
76d05aa
finished validation of starting position
rodsmade Nov 7, 2022
53749b8
tests for starting position validation
rodsmade Nov 7, 2022
9d9c346
norminette check
rodsmade Nov 7, 2022
e3ebb11
Merge branch 'main' into feature-map_validation_😈
rodsmade Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# debug
.ignore

# debugger
.vscode

# end-to-end tests
tests/logs/

# Prerequisites
*.d

Expand Down
31 changes: 19 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ NAME = cub3D
CC = gcc
CFLAGS = -g -Wall -Werror -Wextra
RM = rm -f
VALGRIND = valgrind --leak-check=full --show-leak-kinds=all \
--track-origins=yes -q --tool=memcheck
VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes -q --tool=memcheck
INCLUDES_DIR = ./includes ./libs/libft ./libs/minilibx-linux
SRC_DIR = ./src
OBJ_DIR = ./obj
Expand All @@ -21,16 +20,24 @@ WINDOW_PATH = window/
DESTROY_PATH = destroy/
KEYSTROKES_PATH = keystrokes/

SRCS = cub3D.c \
error_handling.c \
init_data.c \
input_validation_utils.c \
input_validation.c \
map_params_checks.c \
params_utils.c \
$(WINDOW_PATH)window.c \
$(DESTROY_PATH)destroy.c \
$(KEYSTROKES_PATH)keystrokes.c \
SRCS = cub3D.c \
error_handling.c \
free_memory.c \
init_data.c \
input_validation_utils.c \
input_validation.c \
map_padding.c \
map_params_checks.c \
map_utils.c \
map_validation.c \
map_validation_player_position.c \
map_validation_utils.c \
params_utils.c \
t_position_utils.c \
tests_debug.c \
$(WINDOW_PATH)window.c \
$(DESTROY_PATH)destroy.c \
$(KEYSTROKES_PATH)keystrokes.c \

OBJS := $(addprefix $(OBJ_DIR)/,$(SRCS:.c=.o))
SRCS := $(addprefix $(SRC_DIR)/,$(SRCS))
Expand Down
16 changes: 16 additions & 0 deletions assets/maps/exo.cub
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
NO ./assets/textures/north_texture.xpm
SO ./assets/textures/south_texture.xpm
EA ./assets/textures/east_texture.xpm
WE ./assets/textures/west_texture.xpm
F 42, 55, 57
C 255, 255, 255

1111111 11111 11111111111111 11111
1000001 10001 10000000000001 10001 111111111
1100000111 1110001 10000000000001 10001 100000001
11100000000111 11100000111111000011110000111111000111 100000E01
1000000000000111111000000000000000001 100000000000000011 100000001
1111111111100000000000000000000000001 1000000000000000011100000001
111110000011111111111111111 1111111111111110000000011111
1000001 1001111111
1111111 1111
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions exo.cub

This file was deleted.

125 changes: 91 additions & 34 deletions includes/cub3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: gusalves <gusalves@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/20 11:52:42 by gusalves #+# #+# */
/* Updated: 2022/09/27 12:25:49 by roaraujo ### ########.fr */
/* Updated: 2022/11/07 18:32:04 by roaraujo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,13 +28,19 @@
# include <stdbool.h> // bool type

// ------------------------------------------------ MACROS -----------

# define KEY_ESC 65307 // ESC keycode
# define IMG_TEST "./img/blueMacaw.xpm"
# define KEY_ESC 65307 // ESC keycode
# define VALID_CHARS "10 NSEW" // valid map chars
# define STARTING_CHARS "NSEW" // valid starting position chars

// ------------------------------------------------ STRUCTS -----------

typedef struct s_mlx_img
typedef struct s_position
{
int line;
int column;
} t_position;

typedef struct s_mlx_struct
{
void *pointer;
char *addr;
Expand All @@ -50,71 +56,122 @@ typedef struct s_mlx_struct
t_mlx_img *img;
} t_mlx_struct;

typedef struct s_map_parameters
typedef struct s_data
{
int fds[4];
int colours[2][3];
int params_count;
char *line;
} t_map_parameters;
int input_fd;
int texture_fds[4];
int colours[2][3];
int params_count;
char *line;
char **map;
char **map_copy_for_debug;
t_position starting_position;
} t_data;

// ------------------------------------------------ ENUMS -----------

enum e_colours {ceiling, floor};
enum e_colours {
CEILING,
FLOOR
};

enum e_directions {
NO,
SO,
EA,
WE
};

enum e_ups_and_downs {
UP,
DOWN
};

enum e_err_codes {
SYSCALL_ERROR,
WRONG_ARGS_NO,
FILE_EXTENSION_ERROR,
INVALID_TEXTURE_PARAMS,
MISSING_PARAMETER,
REDUNDANT_PARAMETER_FOUND,
INVALID_COLOUR_PARAM
INVALID_COLOUR_PARAM,
INVALID_MAP,
MEMORY_ALLOCATION,
INVALID_CHAR_FOUND,
INVALID_MAP_SIZE,
STARTING_POS_ERROR,
MULTIPLE_POS_CHARS_FOUND,
PLAYER_OFF_MAP
};

// ------------------------------------------------ PROTOTYPES -----------
// tests_debug ********** APAGAR DPS ***************
void debug_print_map_read(char **map);
void debug_copy_map(t_data *data);

// error_handling.c
void print_err_exit(int errcode, t_map_parameters *map_params);
void print_err_exit(int errcode, t_data *data);

// init_data.c
void init_map_parameters(t_map_parameters *map_parameters);
void init_data(t_data *data);

// input_validation_utils.c
char *get_next_line_trimmed(int input_fd);
int jump_spaces(const char *str);
int convert_colour_to_int(char *colour, t_map_parameters *map_params);
char *get_next_line_trimmed(int input_fd);
int jump_spaces(const char *str);
int convert_colour_to_int(char *colour, t_data *data);

// input_validation.c
void validate_args(int argc, char *argv[], int *input_fd,
t_map_parameters *map_params);
void validate_input_file(int fd, t_map_parameters *map_params);
void validate_args(int argc, char *argv[], t_data *data);
void validate_input_file(t_data *data);

// window.c
void window(t_mlx_struct *mlx);
void window(t_mlx_struct *mlx);

// destroy.c
int destroy(t_mlx_struct *mlx);
int destroy(t_mlx_struct *mlx);

// free_memory.c
void free_data(t_data *data);

// key_press.c
int keystrokes_management(int keycode, t_mlx_struct *mlx);
int keystrokes_management(int keycode, t_mlx_struct *mlx);

// map_padding.c
void pad_map(t_data *data);

// map_params_checks.c
void check_for_valid_path(t_map_parameters *map_params);
void check_duplicate_parameter(t_map_parameters *map_params);
void check_colour_params_count(char **colours_array,
t_map_parameters *map_params);
void check_for_valid_colour(t_map_parameters *map_params);
void check_for_valid_path(t_data *data);
void check_duplicate_parameter(t_data *data);
void check_colour_params_count(char **colours_array, t_data *data);
void check_for_valid_colour(t_data *data);

// map_utils.c
int find_longest_line_length(char **map);

// map_validation.c
void validate_map(t_data *data);

// map_validation_utils.c
bool try_to_move_in_direction(t_position next_move, t_position *prev_pos,
t_position *next_pos, t_data *data);
void decide_where_to_go_next(t_data *data, t_position *prev_pos,
t_position curr_pos, t_position *next_pos);
void find_starting_point(t_position *starting_point, t_data *data);

// map_validation_player_position.c
void check_player_position(t_data *data);

// params_utils.c
bool is_direction_identifier(char identifier[2]);
int get_direction_index(char d);
int get_colour_index(char c);
bool is_valid_parameter_char(char c);
bool has_valid_param_identifier(char *str);
bool is_direction_identifier(char identifier[2]);
int get_direction_index(char d);
int get_colour_index(char c);
bool is_valid_parameter_char(char c);
bool has_valid_param_identifier(char *str);

// t_position_utils.c
t_position t_position_create_tuple(int line, int column);
bool t_position_compare(t_position a, t_position b);
bool t_position_compare_ptr(t_position *a, t_position *b);
void t_position_copy(t_position *destination, const t_position source);

#endif
1 change: 1 addition & 0 deletions libs/libft/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SOURCES += ft_strdup.c ft_striteri.c ft_strjoin.c ft_strlcat.c
SOURCES += ft_strlcpy.c ft_strlen.c ft_strmapi.c ft_strncmp.c
SOURCES += ft_strnstr.c ft_strrchr.c ft_strtrim.c ft_substr.c
SOURCES += ft_tolower.c ft_toupper.c get_next_line.c ft_free_ptr.c
SOURCES += ft_free_arr.c ft_charjoin.c ft_matrixlen.c ft_alloc_string.c

SOURCES_BONUS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c
SOURCES_BONUS += ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c
Expand Down
32 changes: 32 additions & 0 deletions libs/libft/ft_alloc_string.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_alloc_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roaraujo <roaraujo@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/31 06:00:39 by roaraujo #+# #+# */
/* Updated: 2022/10/31 06:00:46 by roaraujo ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

char *ft_alloc_string(int str_size, int init_value)
/**
* @brief allocates `str_size` bytes for a string, appends a terminating '\0',
* and initialises every byte in the string to `init_value`.
*/
{
char *str;
int i;

str = malloc((str_size + 1) * sizeof(char));
if (!str)
return (NULL);
i = -1;
while (++i < str_size)
str[i] = init_value;
str[i] = '\0';
return (str);
}
32 changes: 32 additions & 0 deletions libs/libft/ft_charjoin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_charjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roaraujo <roaraujo@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 22:11:10 by roaraujo #+# #+# */
/* Updated: 2022/09/29 22:13:26 by roaraujo ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

char *ft_charjoin(const char* str, const char c)
{
int i;
char *joined_str;

if (!str)
return (NULL);
joined_str = malloc((ft_strlen(str) + 1 + 1) * sizeof(char));
if (!joined_str)
return (NULL);
i = -1;
while (str[++i])
joined_str[i] = str[i];
joined_str[i] = c;
joined_str[++i] = '\0';
ft_free_ptr((void *)&str);
return (joined_str);
}
29 changes: 29 additions & 0 deletions libs/libft/ft_free_arr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free_arr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roaraujo <roaraujo@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 21:45:12 by roaraujo #+# #+# */
/* Updated: 2022/09/29 21:45:14 by roaraujo ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void ft_free_arr(void ***arr)
{
int i;

i = -1;
if (*arr != NULL)
{
while ((*arr)[++i])
{
ft_free_ptr((void *)&(*arr)[i]);
(*arr)[i] = NULL;
}
free(*arr);
}
}
Loading