Skip to content

Commit

Permalink
Merge branch 'main' into raycaster
Browse files Browse the repository at this point in the history
  • Loading branch information
JopjeKnopje authored Dec 13, 2023
2 parents 11a8037 + 6ad474f commit 1a0f074
Show file tree
Hide file tree
Showing 44 changed files with 1,501 additions and 55 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: C/C++ CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: make
run: make
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ compile_commands.json
libft/build/libft.a
Session.vim
MLX42/build
tests/bin
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"files.associations": {
"enemy.h": "c",
"stdlib.h": "c"
"stdlib.h": "c",
"*.tcc": "c",
"system_error": "c"
}
}
41 changes: 27 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# **************************************************************************** #
# #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: joppe <jboeve@student.codam.nl> +#+ #
# +#+ #
# Created: 2023/11/10 00:29:31 by joppe #+# #+# #
# Updated: 2023/11/12 20:23:08 by joppe ######## odam.nl #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jboeve <ivan-mel@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/08/22 13:32:22 by jboeve #+# #+# #
# Updated: 2023/12/11 12:46:04 by yzaim ### ########.fr #
# #
# **************************************************************************** #



######################
# OS Dependend flags #
# OS Dependent flags #
######################
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
Expand All @@ -29,7 +27,7 @@ RUN_CMD := ./$(NAME)

# CFLAGS += -Wall -Wextra -Werror
CFLAGS += -Wall -Wextra
CFLAGS += -g -fsanitize=address
# CFLAGS += -g -fsanitize=address
# CFLAGS += -Ofast -flto -march=native

LIBFT := libft/build/libft.a
Expand All @@ -38,7 +36,20 @@ LIBMLX := MLX42/build/libmlx42.a
IFLAGS := -Ilibft/include -Iinclude -IMLX42/include

SRC_DIR := src
SRCS := cub3d.c \

SRCS = parser/check_elements.c \
parser/check_walls.c \
parser/parse_elements.c \
parser/parse_map.c \
parser/check_map.c \
parser/parse_textures.c \
parser/parser.c \
parser/check_colors.c \
parser/utils_one.c \
parser/utils_two.c \
utils/error.c \
utils/free.c \
cub3d.c \
game.c \
input.c \
render.c \
Expand All @@ -57,7 +68,9 @@ HEADERS := meta.h \
OBJ_DIR := obj


TEST_SRCS := test.c
TEST_L_FLAGS := -L ~/.capt/root/usr/lib/x86_64-linux-gnu
TEST_I_FLAGS := -I ~/.capt/root/usr/include
TEST_SRCS := test_parser.c
TEST := tests
TEST_SRCS := $(addprefix $(TEST)/, $(TEST_SRCS))
TEST_BINS := $(patsubst $(TEST)/%.c, $(TEST)/bin/%, $(TEST_SRCS))
Expand Down Expand Up @@ -121,7 +134,7 @@ $(TEST)/bin:
mkdir $@

$(TEST)/bin/%: $(TEST)/%.c $(OBJS)
$(CC) $(CFLAGS) $(IFLAGS) $< $(OBJS) $(LIBFT) -o $@ -lcriterion
$(CC) $(CFLAGS) $(IFLAGS) $(TEST_I_FLAGS) $(TEST_L_FLAGS) $(MLX_CFLAGS) $< $(OBJS) $(LIBFT) $(LIBMLX) -o $@ -lcriterion

test: make_libs $(OBJS) $(TEST)/bin $(TEST_BINS)
for test in $(TEST_BINS) ; do ./$$test -j1 ; done
106 changes: 103 additions & 3 deletions include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>

#include "timer.h"
#include "vector.h"
#include "libft.h"
#include "parser.h"
#include "get_next_line.h"
#include "MLX42/MLX42.h"

#define UNUSED(x) (void)(x)
Expand Down Expand Up @@ -105,20 +115,30 @@ typedef struct s_player {
} t_player;

typedef struct s_map {
t_cell_type *level;
uint32_t width;
uint32_t height;
t_cell_type *level;
} t_map;
} t_map;

typedef struct s_tex {
char *no;
char *so;
char *we;
char *ea;
t_rgba floor_c;
t_rgba ceiling_c;
} t_tex;

typedef struct s_meta {
mlx_t *mlx;
mlx_image_t *image;
t_timer update_timer;
t_timer fps_timer;
t_player player;
t_map map;
uint32_t fps;
t_map map;
t_tex tex;
char *map_file;
} t_meta;

// cub3d.c
Expand Down Expand Up @@ -159,5 +179,85 @@ float deg_to_rad(float deg);
void print_vec2f(const char *s, t_vec2f vec);
void print_vec2i(const char *s, t_vec2i vec);
void print_cell(t_cell_type cell);
void game_init(t_meta *meta);
void game_loop(void* param);

// player.c
void player_move(t_meta *meta);

// keys.c
void keyhook(mlx_key_data_t keydata, void* param);

// render.c
void render_player(t_meta *meta);
void render_clear_bg(mlx_image_t *image);
void render_map_grid(t_meta *meta);

// draw.c
void draw_square(mlx_image_t* image, uint32_t x_pos, uint32_t y_pos, uint32_t width, uint32_t height, uint32_t color);
void cube_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);

// check_map.c
int check_map(t_meta *meta, char *rect);
int find_index(t_meta *meta, uint32_t y, uint32_t x);

// free.c
void meta_free(t_meta *meta);

// PARSER

// parser.c
char *read_file(int fd);
int map_ext(char *file);
int parser(t_meta *meta, char *map_file);

// parse_map.c
bool is_map_line(char *file);
int input_map(t_meta *meta, char *file);

// parse_elements.c
int input_texture(t_tex *tex, char *file);
int input_colour(t_tex *tex, char *file);
int save_elements(t_tex *tex, char *file);
int parse_elements(t_meta *meta, char *file);

// check_colors.c
bool valid_rgb_value(char *file);
bool is_valid_color(char *file);
bool colors_valid(char *file);

// check_elements.c
bool is_valid_element(char *file);
bool only_spaces(char *file);
bool is_map_element(char *file);
bool elements_order(char *file);
bool check_missing(int *found);
bool is_missing(char *file);
bool is_duplicate(char *file);

// check_map.c
bool is_map_chars_valid(char *map);
int flood_fill(t_meta *meta, char *map, int x, int y);
bool save_start_pos(t_meta *meta, char *map);
bool is_floor_exposed(t_meta *meta, char *map);

// parse_textures.c
void get_colour_value(char *file, t_rgba *col);
char *get_tex_val(char *file);
bool is_texture(char *file);
bool is_colour(char *file);

// utils_one.c
void skip_line(char **file);
void skip_spaces(char **file);
void skip_digits(char **file);
int valid_map_char(char c);
int player_pos_char(char c);

// utils_two.c
int find_index(t_meta *meta, uint32_t y, uint32_t x);
uint32_t find_width(char *map);
uint32_t find_height(char *map);
char *make_rect(char *map, uint32_t w, uint32_t h);

#endif
60 changes: 60 additions & 0 deletions include/parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* meta.h :+: :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/11/01 20:07:37 by jboeve #+# #+# */
/* Updated: 2023/11/09 18:54:26 by yzaim ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PASER_H
#define PASER_H

# define TOO_MANY_PLAYERS "Map should not have more than one player position\n"
# define INVALID_CHAR "Map has invalid characters\n"
# define INVALID_WALLS "Map walls are not closed\n"
# define INVALID_EXT "Map extension should be .cub\n"
# define INVALID_FILE "Map file failed to open\n"
# define MALLOC_FAIL "Malloc error\n"
# define WRO_ARGS "Wrong number of arguments\n"
# define OOB_FLOOR "There are inaccessible floors in this map\n"
# define ORDER_OF_ELEMENTS "Error in map file, check that the map element is last and there are no extra characters between elements\n"
# define MISSING_PATH "Texture path missing\n"
# define DUPLICATES "Make sure you have only and at least one value for each element\n"
# define NO_PLAYER_POS "There is no player position in the map\n"
# define ELEMENT_MISSING "One or more definition of elements is missing\n"
# define NO_MAP "Map element is missing\n"
# define INV_COLOR_CODE "Please check color codes for F and C elements\nRGB values should be between 0-255\n"

# include "meta.h"

typedef enum e_err {
INV_CHAR,
INV_EXT,
INV_WALLS,
PLAY_ERR,
INV_FILE,
MALL_ERR,
ARG_ERR,
OUT_OF_BOUNDS,
FILE_ORDER,
M_PATH,
DUP_ELEMENTS,
NO_PLAYER,
MISSING_ELEMENTS,
MISSING_MAP,
COLOR_CODE_WRONG,
} t_err;

// error.c
int pr_err(t_err type);

// check_map.c
int valid_map_char(char c);
int player_pos_char(char c);
bool is_map_chars_valid(char *map);

#endif
3 changes: 2 additions & 1 deletion libft/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ DIR_STRING = ft_split.c \
ft_substr.c \
ft_strdup.c \
ft_strlen_2d.c \
ft_strisempty.c
ft_strisempty.c \
ft_strjoin_free.c

DIR_MEM = ft_bzero.c \
ft_calloc.c \
Expand Down
8 changes: 4 additions & 4 deletions libft/include/libft.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* libft.h :+: :+: */
/* libft.h :+: :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/10/12 10:41:54 by jboeve #+# #+# */
/* Updated: 2023/08/20 23:16:51 by joppe ######## odam.nl */
/* Updated: 2023/11/09 18:53:50 by yzaim ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -43,8 +43,8 @@ void *ft_calloc(size_t nmemb, size_t size);
char *ft_strdup(const char *s);
int ft_atoi(const char *nptr);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strjoin_free(char *s1, char const *s2);
char *ft_strjoin(char *s1, char const *s2);
char *ft_strjoin_free(char *s1, char *s2);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
void ft_putstr_fd(char *s, int fd);
Expand Down
2 changes: 1 addition & 1 deletion libft/src/str/ft_strjoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "libft.h"

char *ft_strjoin(char const *s1, char const *s2)
char *ft_strjoin(char *s1, char const *s2)
{
char *buf;
size_t total_size;
Expand Down
9 changes: 5 additions & 4 deletions libft/src/str/ft_strjoin_free.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin_free.c :+: :+: */
/* ft_strjoin.c :+: :+: */
/* +:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/03/18 21:56:37 by joppe #+# #+# */
/* Updated: 2023/03/18 21:57:43 by joppe ######## odam.nl */
/* Created: 2022/10/12 19:59:09 by joppe #+# #+# */
/* Updated: 2022/11/03 15:36:43 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */

#include "libft.h"

char *ft_strjoin_free(char *s1, char const *s2)
char *ft_strjoin_free(char *s1, char *s2)
{
char *buf;
size_t total_size;
Expand All @@ -24,5 +24,6 @@ char *ft_strjoin_free(char *s1, char const *s2)
ft_strlcpy(buf, s1, ft_strlen(s1) + 1);
ft_strlcat(buf, s2, total_size);
free(s1);
free(s2);
return (buf);
}
Loading

0 comments on commit 1a0f074

Please sign in to comment.