Skip to content

Commit

Permalink
Update with most recent commit
Browse files Browse the repository at this point in the history
Merge branch 'main' into sprites
  • Loading branch information
Joppe Boeve committed Jan 25, 2024
2 parents d23c5fe + 9a89751 commit 047747e
Show file tree
Hide file tree
Showing 36 changed files with 385 additions and 156 deletions.
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"files.associations": {
"cstdlib": "c",
"stdio.h": "c"
}
"cstdlib": "c",
"stdio.h": "c",
"meta.h": "c"
}
}
2 changes: 1 addition & 1 deletion MLX42/include/MLX42/MLX42_Int.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: W2Wizard <[email protected]> +#+ */
/* +#+ */
/* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */
/* Updated: 2024/01/17 12:49:14 by jboeve ######## odam.nl */
/* Updated: 2024/01/20 00:49:21 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUN_CMD := ./$(NAME) test_maps/valid_tex.cub
# RUN_CMD := ./$(NAME) test_maps/small.cub

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

Expand Down Expand Up @@ -55,7 +55,8 @@ SRCS = parser/check_elements.c \
cub3d.c \
test_utils.c \
timer.c \
set_textures.c
set_textures.c \
game/floorcaster.c

HEADER_DIR := include
HEADERS := meta.h \
Expand Down
34 changes: 24 additions & 10 deletions include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jboeve <[email protected]>+#+ */
/* +#+ */
/* Created: 2023/11/01 20:07:37 by jboeve#+##+# */
/* Updated: 2024/01/18 11:56:06 by jboeve ######## odam.nl */
/* Updated: 2024/01/20 01:14:53 by joppe ######## odam.nl */
/**/
/* ************************************************************************** */

Expand All @@ -23,6 +23,7 @@
#include <fcntl.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>

#include "timer.h"
#include "libft.h"
Expand Down Expand Up @@ -56,16 +57,16 @@
#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 720

#define BPP 4


// Game
#define TICK_RATE (1.0 / 60.0)

#define PLAYER_MOVE_SPEED 5.0
#define PLAYER_MOVE_SPEED 3.5
#define PLAYER_RUN_MODIFIER 2.5
#define PLAYER_ROTATE_SPEED 5.0
#define PLAYER_ROTATE_SPEED 3.0
#define PLAYER_ROTATE_MODIFIER 2.5
#define PLAYER_MOV_SPEED 0.08

#define MINIMAP_WIDTH 350
#define MINIMAP_HEIGHT 230
Expand All @@ -81,7 +82,6 @@
#define VIEWPORT_COLOR_WALL_NS 0x4B0082FF
#define VIEWPORT_COLOR_WALL_EW 0x8A30E2FF

// #define FOV 0.66
#define FOV 0.85

typedef bool (t_ray_hitfunc) (const void *p, uint32_t x, uint32_t y);
Expand All @@ -92,6 +92,7 @@ typedef enum e_cell_type {
MAP_EMPTY,
MAP_WALL,
MAP_SPACE,
MAP_DOOR
} t_cell_type;

typedef enum e_font_family {
Expand Down Expand Up @@ -126,10 +127,10 @@ typedef union s_rgba


typedef enum e_side {
SIDE_N,
SIDE_S,
SIDE_E,
SIDE_W,
SIDE_N = 0,
SIDE_S = 1,
SIDE_E = 2,
SIDE_W = 3,
} t_side;

typedef struct s_ray {
Expand All @@ -147,9 +148,16 @@ typedef struct s_ray {
double step;
} t_ray;

typedef struct s_vray {
t_vec2d floor;
t_vec2d step;
} t_vray;

typedef struct s_player {
t_meta *meta;
t_ray rays[WINDOW_WIDTH];
t_vray vrays[WINDOW_HEIGHT];
bool should_render;
t_vec2d cam_plane;
t_vec2d position;
t_vec2d direction;
Expand All @@ -171,10 +179,13 @@ typedef struct s_tex {
} t_tex;

typedef struct s_attr {
t_tex n;
t_tex n; //add bit flag, if tex_path is missing then it means it is a color value
t_tex s;
t_tex e;
t_tex w;
t_tex f;
t_tex c;
t_tex c_alt;
t_rgba floor_c;
t_rgba ceiling_c;
} t_attr;
Expand Down Expand Up @@ -258,4 +269,7 @@ int set_textures(t_attr *attributes);
uint32_t pixel_picker(mlx_texture_t *texture, int32_t x, int32_t y);
void wall_texture_position(mlx_texture_t *texture, t_ray *ray, t_vec2i line_points, uint32_t h);

// floorcaster.c
t_vray floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y);

#endif
15 changes: 8 additions & 7 deletions include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,21 @@ 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);
bool is_wall(char *file);
bool is_floor_or_ceiling(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);
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
uint32_t find_width(char *map);
uint32_t find_height(char *map);
char *make_rect(char *map, uint32_t w, uint32_t h);
bool is_path(char *str);


#endif
20 changes: 10 additions & 10 deletions include/test_utils.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* ************************************************************************** */
/**/
/* :::::::: */
/* test_utils.h :+::+: */
/*+:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/02 19:56:05 by joppe #+##+# */
/* Updated: 2024/01/02 23:20:17 by joppe ######## odam.nl */
/**/
/* */
/* :::::::: */
/* test_utils.h :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/18 13:59:19 by jboeve #+# #+# */
/* Updated: 2024/01/18 14:10:07 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */


Expand All @@ -23,5 +23,5 @@ void print_cell(t_cell_type cell);
void print_map(char *map, uint32_t w, uint32_t h);
void print_map_cell(t_cell_type *level, uint32_t w, uint32_t h);
void print_ray(const char *s, const t_ray *r);

void print_direction(t_side dir);
#endif // !TEST_UTILS_H
5 changes: 3 additions & 2 deletions include/vector.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/**/
/* :::::::: */
/* vector.h :+::+: */
/* vector.h :+: :+: */
/*+:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/02 19:07:15 by joppe #+##+# */
/* Updated: 2024/01/03 18:35:23 by joppe ######## odam.nl */
/* Updated: 2024/01/19 23:36:47 by joppe ######## odam.nl */
/**/
/* ************************************************************************** */

Expand Down Expand Up @@ -35,6 +35,7 @@ typedef struct s_vec2u {
t_vec2d vec2d_add(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_sub(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_scalar_product(t_vec2d vec, double scalar);
double vec2d_dot_product(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_mul(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_rotate(t_vec2d old, double radiant);
t_vec2d vec2d_normalize(t_vec2d vec);
Expand Down
18 changes: 10 additions & 8 deletions src/cub3d.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.c :+: :+: */
/* +:+ +:+ +:+ */
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/08 15:24:47 by yzaim #+# #+# */
/* Updated: 2024/01/18 10:45:29 by jboeve ######## odam.nl */
/* :::::::: */
/* cub3d.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/08 15:24:47 by yzaim #+# #+# */
/* Updated: 2024/01/24 11:14:56 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

#include "MLX42/MLX42.h"
#include "MLX42/MLX42_Int.h"
// #include "MLX42/MLX42_Int.h"
#include "meta.h"
#include "parser.h"
#include <stdint.h>
Expand Down Expand Up @@ -111,6 +111,8 @@ int cub3d(int argc, char **argv)
printf("Tex_S: %s\n", meta.attributes.s.tex_path);
printf("Tex_E: %s\n", meta.attributes.e.tex_path);
printf("Tex_W: %s\n", meta.attributes.w.tex_path);
printf("Tex_C: %s\n", meta.attributes.c.tex_path);
printf("Tex_F: %s\n", meta.attributes.f.tex_path);

init_mlx_images(&meta);
// TODO Error check.
Expand Down
34 changes: 34 additions & 0 deletions src/game/floorcaster.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* floorcaster.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/24 13:13:37 by yzaim #+# #+# */
/* Updated: 2024/01/24 18:23:45 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */

#include "meta.h"

t_vray floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y)
{
t_vray ray;
t_vec2d raydir_left;
t_vec2d raydir_right;

raydir_left = ((t_vec2d){dir.x - cam_plane.x, dir.y - cam_plane.y});
raydir_right = ((t_vec2d){dir.x + cam_plane.x, dir.y + cam_plane.y});

int p = y - WINDOW_HEIGHT / 2;
double posZ = 0.5 * WINDOW_HEIGHT;
double row_distance = posZ / p;
ray.step.x = row_distance * (raydir_right.x - raydir_left.x) / WINDOW_WIDTH;
ray.step.y = row_distance * (raydir_right.y - raydir_left.y) / WINDOW_WIDTH;

ray.floor.x = pp.x + row_distance * raydir_left.x;
ray.floor.y = pp.y + row_distance * raydir_left.y;

return (ray);
}
22 changes: 21 additions & 1 deletion src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */
/* Updated: 2024/01/17 13:04:46 by jboeve ######## odam.nl */
/* Updated: 2024/01/25 13:22:31 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */

#include "MLX42/MLX42.h"
#include "meta.h"
#include "timer.h"
#include "vector.h"
#include <assert.h>
#include <math.h>
#include <stdint.h>
#include <unistd.h>
#include "test_utils.h"

Expand Down Expand Up @@ -54,6 +56,24 @@ void set_player_start_position(t_player *p, char dir)
p->position.y += 0.5;
}




void swap_tex(mlx_texture_t *tex)
{
assert(tex->width == tex->height);

for (size_t x = 0; x < tex->width; x++)
{
for (size_t y = 0; y < x; y++)
{
uint32_t pixel = tex->pixels[(tex->width * y + x) * BPP];
tex->pixels[(tex->width * y + x) * BPP] = tex->pixels[(tex->width * x + y) * BPP];
tex->pixels[(tex->width * x + y) * BPP] = pixel;
}
}
}

void game_init(t_meta *meta)
{
t_player* const p = &meta->player;
Expand Down
5 changes: 2 additions & 3 deletions src/game/keys.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* keys.c :+: :+: :+: */
/* keys.c :+: :+: */
/* +:+ +:+ +:+ */
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/08 15:27:07 by yzaim #+# #+# */
/* Updated: 2024/01/08 15:27:11 by yzaim ### ########.fr */
/* Updated: 2024/01/18 12:50:58 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -49,7 +49,6 @@ static void keys_handle_move(t_meta *meta, double delta_time)
pressed = true;
trans = vec2d_add(trans, (t_vec2d) {(vec2d_rotate(p->direction, PI / 2).x) * speed, (vec2d_rotate(p->direction, PI / 2).y) * speed});
}

if (pressed)
player_move(p, trans);
}
Expand Down
Loading

0 comments on commit 047747e

Please sign in to comment.