Browse Source

littles change

master
nicolas-arnaud 2 years ago
parent
commit
a883e185c7
  1. 13
      includes/cub3d.h
  2. 1
      maps/tests/massive.cub
  3. 12
      maps/tests/massive2.cub
  4. 14
      src/parsing/getline.c
  5. 8
      src/parsing/map.c
  6. 6
      src/parsing/parsing.c
  7. 32
      src/render/minimap.c
  8. 8
      src/render/render.c

13
includes/cub3d.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */ /* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */
/* Updated: 2022/11/21 23:17:41 by narnaud ### ########.fr */ /* Updated: 2022/11/22 05:24:50 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -70,7 +70,6 @@ typedef struct s_img
int pixel_bits; int pixel_bits;
int line_bytes; int line_bytes;
int endian; int endian;
} t_img; } t_img;
typedef struct s_env typedef struct s_env
@ -96,13 +95,21 @@ typedef struct s_env
t_dvec cam_plan; t_dvec cam_plan;
} t_env; } t_env;
typedef struct s_minimap
{
t_vec min;
t_vec max;
t_vec delt;
} t_mmap;
// Render // Render
t_mmap measure(t_env *env);
void check_side(t_rc *rc); void check_side(t_rc *rc);
void init_ray(t_env *env, t_rc *rc); void init_ray(t_env *env, t_rc *rc);
int ray_hit(t_env *env, t_rc *rc); int ray_hit(t_env *env, t_rc *rc);
void draw_rectangle(t_env *env, t_rect rect, int borders); void draw_rectangle(t_env *env, t_rect rect, int borders);
t_rect get_mm_cell(char type, t_vec pos, t_vec delta); t_rect get_mm_cell(char type, t_vec pos, t_vec delta);
void render_minimap(t_env *env); void render_minimap(t_env *env, t_mmap mm);
void render_view(t_env *env); void render_view(t_env *env);
void render(t_env *env); void render(t_env *env);

1
maps/tests/massive.cub

@ -911,3 +911,4 @@ C 219, 213, 213
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

12
maps/tests/massive2.cub

@ -1,15 +1,15 @@
NO ./textures/redbrick.xpm NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm EA ./textures/brownbrick.xpm
SO ./textures/redbrick.xpm SO ./textures/greenbrick.xpm
WE ./textures/redbrick.xpm WE ./textures/bluebrick.xpm
DO ./textures/wood.xpm DO ./textures/wood.xpm
F 147, 159, 153 F 0, 159, 0
C 219, 213, 213 C 0,0, 213
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
100S00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100S00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001

14
src/parsing/getline.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 21:23:40 by narnaud #+# #+# */ /* Created: 2022/05/21 21:23:40 by narnaud #+# #+# */
/* Updated: 2022/08/23 16:34:20 by narnaud ### ########.fr */ /* Updated: 2022/11/22 05:00:06 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,17 +19,23 @@ char *save_buffer(char *buffer, int *i)
char *part2; char *part2;
char *ret; char *ret;
part1 = ft_calloc(512, sizeof(char)); part1 = malloc(4097 * sizeof(char));
j = 0; j = 0;
while (j < 512) while (j < 4096)
{ {
part1[j++] = buffer[*i]; part1[j++] = buffer[*i];
if (buffer[*i] == '\0' || buffer[(*i)++] == '\n') if (buffer[*i] == '\0' || buffer[(*i)++] == '\n')
{
part1[j] = 0;
return (part1); return (part1);
} }
}
part1[4097] = 0;
part2 = save_buffer(buffer, i); part2 = save_buffer(buffer, i);
ret = ft_strjoin(part1, part2); ret = ft_strjoin(part1, part2);
return (free(part1), free(part2), ret); free(part1);
free(part2);
return (ret);
} }
char *get_next_line(const int fd) char *get_next_line(const int fd)

8
src/parsing/map.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/23 09:30:50 by narnaud #+# #+# */ /* Created: 2022/08/23 09:30:50 by narnaud #+# #+# */
/* Updated: 2022/11/21 19:05:12 by narnaud ### ########.fr */ /* Updated: 2022/11/22 05:33:45 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -58,7 +58,11 @@ int find_player(t_env *env)
int is_in_open_room(t_env *env, int x, int y) int is_in_open_room(t_env *env, int x, int y)
{ {
static char *checked; static char *checked;
static int recurs;
recurs++;
if (recurs > 1000000 - 2 * (env->wide * env->deep))
return (1);
if (x < 0 || x >= env->wide || y < 0 || y >= env->deep) if (x < 0 || x >= env->wide || y < 0 || y >= env->deep)
return (1); return (1);
if (!checked) if (!checked)
@ -69,8 +73,8 @@ int is_in_open_room(t_env *env, int x, int y)
if (env->map[y][x] == '1') if (env->map[y][x] == '1')
return (0); return (0);
else if (is_in_open_room(env, x + 1, y) else if (is_in_open_room(env, x + 1, y)
|| is_in_open_room(env, x - 1, y)
|| is_in_open_room(env, x, y + 1) || is_in_open_room(env, x, y + 1)
|| is_in_open_room(env, x - 1, y)
|| is_in_open_room(env, x, y - 1)) || is_in_open_room(env, x, y - 1))
return (1); return (1);
else else

6
src/parsing/parsing.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/23 17:20:29 by narnaud #+# #+# */ /* Created: 2022/05/23 17:20:29 by narnaud #+# #+# */
/* Updated: 2022/11/21 19:43:41 by narnaud ### ########.fr */ /* Updated: 2022/11/22 05:34:10 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -96,9 +96,9 @@ t_slist *read_map_line(t_env *env, char *line)
int is_valid_map(t_env *env) int is_valid_map(t_env *env)
{ {
if (!find_player(env)) if (!find_player(env))
printf("Error: There is no player on the map.\n"); printf("Error\nYou probably somewhere but not on the map.\n");
else if (is_in_open_room(env, env->player_pos.x, env->player_pos.y)) else if (is_in_open_room(env, env->player_pos.x, env->player_pos.y))
printf("Error: You are using an open map.\n"); printf("Error\n The game can't handle infinite maps..\n");
else else
return (1); return (1);
return (0); return (0);

32
src/render/minimap.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/23 08:14:08 by narnaud #+# #+# */ /* Created: 2022/08/23 08:14:08 by narnaud #+# #+# */
/* Updated: 2022/11/21 23:33:25 by narnaud ### ########.fr */ /* Updated: 2022/11/22 03:04:16 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,29 +14,17 @@
t_rect get_mm_cell(char type, t_vec pos, t_vec delta) t_rect get_mm_cell(char type, t_vec pos, t_vec delta)
{ {
int color; if (type == '1')
return ((t_rect){vec_mult(pos, delta), delta, 0x00009F});
if (type == '0')
color = 0x009F00;
else if (type == '1')
color = 0x00009F;
else if (type == '2') else if (type == '2')
color = 0x9F709F; return ((t_rect){vec_mult(pos, delta), delta, 0x9F709F});
else else
color = 0x000000; return ((t_rect){vec_mult(pos, delta), delta, 0x009F00});
return ((t_rect){vec_mult(pos, delta), delta, color});
} }
typedef struct s_minimap t_mmap measure(t_env *env)
{
t_vec min;
t_vec max;
t_vec delt;
} t_minimap;
t_minimap measure(t_env *env)
{ {
t_minimap ret; t_mmap ret;
ret.delt = (t_vec){4, 4}; ret.delt = (t_vec){4, 4};
ret.min = (t_vec){ft_max(env->player_pos.x - 25, 0), ret.min = (t_vec){ft_max(env->player_pos.x - 25, 0),
@ -47,12 +35,10 @@ t_minimap measure(t_env *env)
return (ret); return (ret);
} }
void render_minimap(t_env *env) void render_minimap(t_env *env, t_mmap mm)
{ {
t_vec pos; t_vec pos;
t_minimap mm;
mm = measure(env);
pos.y = 0; pos.y = 0;
while (pos.y + mm.min.y < mm.max.y && env->map[pos.y + mm.min.y]) while (pos.y + mm.min.y < mm.max.y && env->map[pos.y + mm.min.y])
{ {
@ -67,7 +53,7 @@ void render_minimap(t_env *env)
} }
pos.y++; pos.y++;
} }
draw_rectangle(env, (t_rect){\ draw_rectangle(env, (t_rect){
(t_vec){(env->player_pos.x - mm.min.x) * mm.delt.x - 1, (t_vec){(env->player_pos.x - mm.min.x) * mm.delt.x - 1,
(env->player_pos.y - mm.min.y) * mm.delt.y - 1}, (env->player_pos.y - mm.min.y) * mm.delt.y - 1},
(t_vec){mm.delt.x / 2, mm.delt.y / 2}, 0xFF0000}, 0); (t_vec){mm.delt.x / 2, mm.delt.y / 2}, 0xFF0000}, 0);

8
src/render/render.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */ /* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */
/* Updated: 2022/11/21 23:17:22 by narnaud ### ########.fr */ /* Updated: 2022/11/22 00:06:15 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -39,7 +39,7 @@ void draw_wall(t_env *env, t_rc *rc, int wallHeight, int *wall_lim)
{ {
tex.y = (int)y_out & (tex_height - 1); tex.y = (int)y_out & (tex_height - 1);
y_out += step; y_out += step;
env->buffer[env->line_bytes * wall_lim[0] + rc->x] \ env->buffer[env->line_bytes * wall_lim[0] + rc->x]
= env->tex[rc->tex].buffer[tex_height * tex.y + tex.x]; = env->tex[rc->tex].buffer[tex_height * tex.y + tex.x];
wall_lim[0]++; wall_lim[0]++;
} }
@ -91,8 +91,6 @@ void render(t_env *env)
ft_bzero(env->buffer, WIN_Y_SZ * WIN_X_SZ * sizeof(int)); ft_bzero(env->buffer, WIN_Y_SZ * WIN_X_SZ * sizeof(int));
render_view(env); render_view(env);
if (env->minimap) if (env->minimap)
{ render_minimap(env, measure(env));
render_minimap(env);
}
mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0); mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0);
} }

Loading…
Cancel
Save