optimizations
This commit is contained in:
parent
75c55fd629
commit
8c5d85c11d
4
Makefile
4
Makefile
@ -6,13 +6,13 @@
|
|||||||
# By: houtworm <codam@houtworm.net> +#+ #
|
# By: houtworm <codam@houtworm.net> +#+ #
|
||||||
# +#+ #
|
# +#+ #
|
||||||
# Created: 2023/10/26 10:46:29 by houtworm #+# #+# #
|
# Created: 2023/10/26 10:46:29 by houtworm #+# #+# #
|
||||||
# Updated: 2023/11/01 14:10:13 by houtworm ######## odam.nl #
|
# Updated: 2023/11/01 14:59:05 by houtworm ######## odam.nl #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME =cub3d
|
NAME =cub3d
|
||||||
CC =gcc
|
CC =gcc
|
||||||
FC =-Ofast -g -fsanitize=address
|
FC =-Wall -Werror -Wextra -Wunreachable-code -Ofast -g -fsanitize=address
|
||||||
HEAD =-I ./include -I $(MLX)/include
|
HEAD =-I ./include -I $(MLX)/include
|
||||||
RM =rm -rf
|
RM =rm -rf
|
||||||
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
|
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
|
||||||
|
@ -6,8 +6,6 @@ Cub3D is a simple raycasting game using the mlx library
|
|||||||
### Parsing
|
### Parsing
|
||||||
- Flood fill the map starting from the player to check if it is a closed map
|
- Flood fill the map starting from the player to check if it is a closed map
|
||||||
- Check if all needed elements are present in the closed part of the map
|
- Check if all needed elements are present in the closed part of the map
|
||||||
### Raycasting
|
|
||||||
- Directional textures
|
|
||||||
### Bonus
|
### Bonus
|
||||||
- Doors
|
- Doors
|
||||||
- Minimap
|
- Minimap
|
||||||
@ -39,6 +37,7 @@ Cub3D is a simple raycasting game using the mlx library
|
|||||||
- Render walls by raycasting
|
- Render walls by raycasting
|
||||||
- Walk in 4 directions
|
- Walk in 4 directions
|
||||||
- Rotate with arrow keys
|
- Rotate with arrow keys
|
||||||
|
- Directional textures
|
||||||
### Bonus
|
### Bonus
|
||||||
- Wall Collision
|
- Wall Collision
|
||||||
- Rotate with the mouse
|
- Rotate with the mouse
|
||||||
|
11
cub3d.h
11
cub3d.h
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
|
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/31 16:29:47 by houtworm ######## odam.nl */
|
/* Updated: 2023/11/01 15:42:29 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,6 +27,11 @@ typedef struct s_varlist
|
|||||||
mlx_image_t *img;
|
mlx_image_t *img;
|
||||||
mlx_image_t *fps;
|
mlx_image_t *fps;
|
||||||
mlx_texture_t *curtext;
|
mlx_texture_t *curtext;
|
||||||
|
mlx_texture_t *northtext;
|
||||||
|
mlx_texture_t *easttext;
|
||||||
|
mlx_texture_t *southtext;
|
||||||
|
mlx_texture_t *westtext;
|
||||||
|
mlx_texture_t *barreltext;
|
||||||
int fpsrefresh;
|
int fpsrefresh;
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
@ -61,10 +66,6 @@ typedef struct s_varlist
|
|||||||
double oldmouseposx;
|
double oldmouseposx;
|
||||||
int32_t fcolor;
|
int32_t fcolor;
|
||||||
int32_t ccolor;
|
int32_t ccolor;
|
||||||
char *northwt;
|
|
||||||
char *eastwt;
|
|
||||||
char *southwt;
|
|
||||||
char *westwt;
|
|
||||||
int resize;
|
int resize;
|
||||||
} t_varlist;
|
} t_varlist;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
C 0,100,255
|
C 50,50,50
|
||||||
F 100,100,100
|
F 100,100,100
|
||||||
|
|
||||||
NO ./assets/bluestone.png
|
NO ./assets/bluestone.png
|
||||||
|
21
src/draw.c
21
src/draw.c
@ -6,12 +6,30 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */
|
/* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/11/01 14:16:57 by houtworm ######## odam.nl */
|
/* Updated: 2023/11/01 14:39:54 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../cub3d.h"
|
#include "../cub3d.h"
|
||||||
|
|
||||||
|
void ft_selecttexture(t_varlist *vl)
|
||||||
|
{
|
||||||
|
if (vl->side == 0)
|
||||||
|
{
|
||||||
|
if (vl->raydirx > 0)
|
||||||
|
vl->curtext = vl->northtext;
|
||||||
|
else
|
||||||
|
vl->curtext = vl->southtext;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (vl->raydiry > 0)
|
||||||
|
vl->curtext = vl->westtext;
|
||||||
|
else
|
||||||
|
vl->curtext = vl->easttext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend)
|
void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend)
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
@ -27,6 +45,7 @@ void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend)
|
|||||||
wallx = vl->posy + vl->perpwalldist * vl->raydiry;
|
wallx = vl->posy + vl->perpwalldist * vl->raydiry;
|
||||||
else
|
else
|
||||||
wallx = vl->posx + vl->perpwalldist * vl->raydirx;
|
wallx = vl->posx + vl->perpwalldist * vl->raydirx;
|
||||||
|
ft_selecttexture(vl);
|
||||||
wallx -= floor(wallx);
|
wallx -= floor(wallx);
|
||||||
int textx;
|
int textx;
|
||||||
textx = wallx * 64.0;
|
textx = wallx * 64.0;
|
||||||
|
11
src/init.c
11
src/init.c
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
|
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/11/01 14:14:08 by houtworm ######## odam.nl */
|
/* Updated: 2023/11/01 15:43:34 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,10 +21,11 @@ t_varlist initvarlist(void)
|
|||||||
vl.hoffset = 50;
|
vl.hoffset = 50;
|
||||||
vl.ccolor = 0;
|
vl.ccolor = 0;
|
||||||
vl.fcolor = 0;
|
vl.fcolor = 0;
|
||||||
vl.northwt = NULL;
|
vl.northtext = NULL;
|
||||||
vl.eastwt = NULL;
|
vl.easttext = NULL;
|
||||||
vl.southwt = NULL;
|
vl.southtext = NULL;
|
||||||
vl.westwt = NULL;
|
vl.westtext = NULL;
|
||||||
|
vl.barreltext = mlx_load_png("./assets/barrel.png");
|
||||||
vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true);
|
vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true);
|
||||||
if (!vl.mlx)
|
if (!vl.mlx)
|
||||||
ft_errorexit("MLX failed to init", "initvarlist", 1);
|
ft_errorexit("MLX failed to init", "initvarlist", 1);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
|
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/11/01 14:17:09 by houtworm ######## odam.nl */
|
/* Updated: 2023/11/01 15:42:14 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -56,7 +56,6 @@ int main(int argc, char **argv)
|
|||||||
ft_errorexit("Please include a .cub file ", "", 2); // we could start with a menu here
|
ft_errorexit("Please include a .cub file ", "", 2); // we could start with a menu here
|
||||||
if (!vl.img || (mlx_image_to_window(vl.mlx, vl.img, 0, 0) < 0))
|
if (!vl.img || (mlx_image_to_window(vl.mlx, vl.img, 0, 0) < 0))
|
||||||
ft_errorexit("image to window failed ", "main", 1);
|
ft_errorexit("image to window failed ", "main", 1);
|
||||||
vl.curtext = mlx_load_png(vl.southwt);
|
|
||||||
mlx_key_hook(vl.mlx, &keyhook, &vl);
|
mlx_key_hook(vl.mlx, &keyhook, &vl);
|
||||||
mlx_resize_hook(vl.mlx, &resizehook, &vl);
|
mlx_resize_hook(vl.mlx, &resizehook, &vl);
|
||||||
mlx_scroll_hook(vl.mlx, &scrollhook, &vl);
|
mlx_scroll_hook(vl.mlx, &scrollhook, &vl);
|
||||||
@ -64,7 +63,11 @@ int main(int argc, char **argv)
|
|||||||
mlx_cursor_hook(vl.mlx, &cursorhook, &vl);
|
mlx_cursor_hook(vl.mlx, &cursorhook, &vl);
|
||||||
mlx_loop_hook(vl.mlx, &mainloop, &vl);
|
mlx_loop_hook(vl.mlx, &mainloop, &vl);
|
||||||
mlx_loop(vl.mlx);
|
mlx_loop(vl.mlx);
|
||||||
mlx_delete_texture(vl.curtext);
|
mlx_delete_texture(vl.northtext);
|
||||||
|
mlx_delete_texture(vl.easttext);
|
||||||
|
mlx_delete_texture(vl.southtext);
|
||||||
|
mlx_delete_texture(vl.westtext);
|
||||||
|
mlx_delete_texture(vl.barreltext);
|
||||||
mlx_delete_image(vl.mlx, vl.img);
|
mlx_delete_image(vl.mlx, vl.img);
|
||||||
mlx_terminate(vl.mlx);
|
mlx_terminate(vl.mlx);
|
||||||
exit (0);
|
exit (0);
|
||||||
|
20
src/parse.c
20
src/parse.c
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */
|
/* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/29 16:32:12 by houtworm ######## odam.nl */
|
/* Updated: 2023/11/01 15:42:55 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,13 +20,13 @@ int ft_settexture(t_varlist *vl, char *line, int direction)
|
|||||||
while (line[i] != '.')
|
while (line[i] != '.')
|
||||||
i++;
|
i++;
|
||||||
if (direction == 1)
|
if (direction == 1)
|
||||||
vl->northwt = ft_strdup(&line[i]);
|
vl->northtext = mlx_load_png(&line[i]);
|
||||||
if (direction == 2)
|
if (direction == 2)
|
||||||
vl->eastwt = ft_strdup(&line[i]);
|
vl->easttext = mlx_load_png(&line[i]);
|
||||||
if (direction == 3)
|
if (direction == 3)
|
||||||
vl->southwt = ft_strdup(&line[i]);
|
vl->southtext = mlx_load_png(&line[i]);
|
||||||
if (direction == 4)
|
if (direction == 4)
|
||||||
vl->westwt = ft_strdup(&line[i]);
|
vl->westtext = mlx_load_png(&line[i]);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ char *ft_checkline(t_varlist *vl, char *line)
|
|||||||
}
|
}
|
||||||
else if (!ft_strncmp(line, "NO ", 3))
|
else if (!ft_strncmp(line, "NO ", 3))
|
||||||
{
|
{
|
||||||
if (!vl->northwt)
|
if (!vl->northtext)
|
||||||
ft_settexture(vl, line, 1);
|
ft_settexture(vl, line, 1);
|
||||||
else
|
else
|
||||||
return (" north texture");
|
return (" north texture");
|
||||||
@ -88,21 +88,21 @@ char *ft_checkline2(t_varlist *vl, char *line)
|
|||||||
{
|
{
|
||||||
if (!ft_strncmp(line, "EA ", 3))
|
if (!ft_strncmp(line, "EA ", 3))
|
||||||
{
|
{
|
||||||
if (!vl->eastwt)
|
if (!vl->easttext)
|
||||||
ft_settexture(vl, line, 2);
|
ft_settexture(vl, line, 2);
|
||||||
else
|
else
|
||||||
return (" east texture");
|
return (" east texture");
|
||||||
}
|
}
|
||||||
else if (!ft_strncmp(line, "SO ", 3))
|
else if (!ft_strncmp(line, "SO ", 3))
|
||||||
{
|
{
|
||||||
if (!vl->southwt)
|
if (!vl->southtext)
|
||||||
ft_settexture(vl, line, 3);
|
ft_settexture(vl, line, 3);
|
||||||
else
|
else
|
||||||
return (" south texture");
|
return (" south texture");
|
||||||
}
|
}
|
||||||
else if (!ft_strncmp(line, "WE ", 3))
|
else if (!ft_strncmp(line, "WE ", 3))
|
||||||
{
|
{
|
||||||
if (!vl->westwt)
|
if (!vl->westtext)
|
||||||
ft_settexture(vl, line, 4);
|
ft_settexture(vl, line, 4);
|
||||||
else
|
else
|
||||||
return (" west texture");
|
return (" west texture");
|
||||||
@ -126,7 +126,7 @@ t_varlist ft_parseconfigfile(t_varlist vl, char *filename)
|
|||||||
error = ft_checkline2(&vl, line);
|
error = ft_checkline2(&vl, line);
|
||||||
if (error)
|
if (error)
|
||||||
ft_errorexit("Double config declaration in .cub file", error, 1);
|
ft_errorexit("Double config declaration in .cub file", error, 1);
|
||||||
if (vl.ccolor && vl.fcolor && vl.northwt && vl.eastwt && vl.southwt && vl.westwt)
|
if (vl.ccolor && vl.fcolor && vl.northtext && vl.easttext && vl.southtext && vl.westtext)
|
||||||
{
|
{
|
||||||
vl.map = ft_getmap(&vl, fd);
|
vl.map = ft_getmap(&vl, fd);
|
||||||
break ;
|
break ;
|
||||||
|
Loading…
Reference in New Issue
Block a user