little cleanup

This commit is contained in:
djonker 2023-11-05 04:53:41 +01:00
parent b06ede9ae9
commit 30c67f5dc6
10 changed files with 63 additions and 67 deletions

View File

@ -6,7 +6,7 @@
# 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/04 02:26:44 by houtworm ######## odam.nl # # Updated: 2023/11/05 04:43:47 by houtworm ######## odam.nl #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,14 +16,14 @@ FC =-Wall -Werror -Wextra -Wunreachable-code -flto -Ofast -march=native -g #-f
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
SRC =src/main.c\ SRC =src/main/main.c\
src/init.c\ src/main/init.c\
src/parse.c\ src/draw/draw.c\
src/keys.c\ src/main/error.c\
src/draw.c\ src/draw/raycast.c\
src/error.c\ src/input/keys.c\
src/raycast.c\ src/parse/parse.c\
src/map.c src/parse/map.c
OBJ =$(SRC:src/%.c=obj/%.o) OBJ =$(SRC:src/%.c=obj/%.o)
all: libft getnextline mlx/build/mlx42.a $(NAME) all: libft getnextline mlx/build/mlx42.a $(NAME)

10
cub3d.h
View File

@ -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/11/05 04:15:30 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:50:43 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,7 +33,7 @@ typedef struct s_varlist
{ {
mlx_t *mlx; mlx_t *mlx;
mlx_image_t *img; mlx_image_t *img;
mlx_image_t *fps; mlx_image_t *fstat;
mlx_image_t *tstat; mlx_image_t *tstat;
mlx_image_t *kstat; mlx_image_t *kstat;
mlx_texture_t *curtext; mlx_texture_t *curtext;
@ -61,6 +61,7 @@ typedef struct s_varlist
double planey; double planey;
int vaim; int vaim;
int jump; int jump;
double run;
double raydirx; double raydirx;
double raydiry; double raydiry;
double sidedistx; double sidedistx;
@ -70,7 +71,6 @@ typedef struct s_varlist
double perpwalldist; double perpwalldist;
int lineheight; int lineheight;
int side; int side;
double run;
double oldmouseposx; double oldmouseposx;
double oldmouseposy; double oldmouseposy;
int32_t fcolor; int32_t fcolor;
@ -92,13 +92,13 @@ t_varlist ft_parseconfigfile(t_varlist vl, char *filename);
// map.c // map.c
char **ft_getmap(t_varlist *vl, int fd); char **ft_getmap(t_varlist *vl, int fd);
// keys.c // keys.c
void ft_movementkeys(t_varlist *vl); void ft_processinput(t_varlist *vl);
void keyhook(mlx_key_data_t kd, void *param); void keyhook(mlx_key_data_t kd, void *param);
void scrollhook(double xdelta, double ydelta, void *param); void scrollhook(double xdelta, double ydelta, void *param);
void resizehook(int x, int y, void *param); void resizehook(int x, int y, void *param);
void cursorhook(double x, double y, void *param); void cursorhook(double x, double y, void *param);
// raycast.c // raycast.c
void ft_raycast(t_varlist *vl); void ft_drawwalls(t_varlist *vl);
// draw.c // draw.c
void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend); void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend);
void ft_drawsprites(t_varlist *vl); void ft_drawsprites(t_varlist *vl);

View File

@ -6,11 +6,11 @@
/* 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/05 04:13:07 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:42:11 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
mlx_texture_t *ft_selectsprite(t_varlist *vl, int type) mlx_texture_t *ft_selectsprite(t_varlist *vl, int type)
{ {

View File

@ -6,13 +6,13 @@
/* By: djonker <codam@houtworm.net> +#+ */ /* By: djonker <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/27 14:36:42 by djonker #+# #+# */ /* Created: 2023/10/27 14:36:42 by djonker #+# #+# */
/* Updated: 2023/11/05 04:12:59 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:50:09 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
void ft_raycast(t_varlist *vl) void ft_drawwalls(t_varlist *vl)
{ {
int x; int x;
int drawstart; int drawstart;

View File

@ -6,13 +6,13 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */ /* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
/* Updated: 2023/11/05 04:05:51 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:42:20 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
void ft_movementkeys(t_varlist *vl) void ft_processinput(t_varlist *vl)
{ {
double temp; double temp;
double distance; double distance;

View File

@ -6,11 +6,11 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 17:13:58 by houtworm #+# #+# */ /* Created: 2023/10/26 17:13:58 by houtworm #+# #+# */
/* Updated: 2023/10/26 17:16:06 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:42:25 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
int ft_errorexit(char *reason, char *function, int code) int ft_errorexit(char *reason, char *function, int code)
{ {

View File

@ -6,11 +6,11 @@
/* 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/05 04:13:14 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:42:29 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
t_varlist initvarlist(void) t_varlist initvarlist(void)
{ {

View File

@ -6,45 +6,35 @@
/* 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/05 04:01:49 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:53:15 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
void ft_printstats(t_varlist *vl) void ft_printstats(t_varlist *vl)
{ {
char *enemies; char *total;
char *kills; char *current;
char *treasure;
char *found;
char *temp; char *temp;
enemies = ft_itoa(vl->enemies); current = ft_itoa(1 / vl->frametime);
kills = ft_itoa(vl->kills); temp = ft_strjoin(current, " FPS");
temp = ft_vastrjoin(4, "Kills: ", kills, "/", enemies); vl->fstat = mlx_put_string(vl->mlx, temp, 10, 10);
ft_vafree(2, temp, current);
total = ft_itoa(vl->enemies);
current = ft_itoa(vl->kills);
temp = ft_vastrjoin(4, "Kills: ", current, "/", total);
vl->tstat = mlx_put_string(vl->mlx, temp, 10, 30); vl->tstat = mlx_put_string(vl->mlx, temp, 10, 30);
free(temp); ft_vafree(3, temp, total, current);
treasure = ft_itoa(vl->tottreasure); total = ft_itoa(vl->tottreasure);
found = ft_itoa(vl->treasure); current = ft_itoa(vl->treasure);
temp = ft_vastrjoin(4, "Treasure: ", found, "/", treasure); temp = ft_vastrjoin(4, "Treasure: ", current, "/", total);
vl->kstat = mlx_put_string(vl->mlx, temp, 10, 50); vl->kstat = mlx_put_string(vl->mlx, temp, 10, 50);
ft_vafree(3, temp, total, current);
mlx_set_instance_depth(vl->fstat->instances, 2);
mlx_set_instance_depth(vl->tstat->instances, 3); mlx_set_instance_depth(vl->tstat->instances, 3);
mlx_set_instance_depth(vl->kstat->instances, 4); mlx_set_instance_depth(vl->kstat->instances, 4);
ft_vafree(5, enemies, kills, treasure, found, temp);
}
void ft_frametime(t_varlist *vl)
{
char *itoa;
char *print;
vl->frametime = vl->mlx->delta_time;
itoa = ft_itoa(1 / vl->frametime);
print = ft_strjoin(itoa, " FPS");
vl->fps = mlx_put_string(vl->mlx, print, 10, 10);
mlx_set_instance_depth(vl->fps->instances, 2);
ft_vafree(2, itoa, print);
} }
void ft_pickup(t_varlist *vl) void ft_pickup(t_varlist *vl)
@ -70,22 +60,30 @@ void ft_pickup(t_varlist *vl)
} }
} }
void ft_replaceimage(t_varlist *vl)
{
mlx_delete_image(vl->mlx, vl->img);
mlx_delete_image(vl->mlx, vl->fstat);
mlx_delete_image(vl->mlx, vl->kstat);
mlx_delete_image(vl->mlx, vl->tstat);
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
}
void mainloop(void *param) void mainloop(void *param)
{ {
t_varlist *vl; t_varlist *vl;
vl = param; vl = param;
mlx_delete_image(vl->mlx, vl->img); ft_replaceimage(vl);
mlx_delete_image(vl->mlx, vl->fps); /*ft_drawceiling(vl);*/
mlx_delete_image(vl->mlx, vl->tstat); ft_drawwalls(vl);
mlx_delete_image(vl->mlx, vl->kstat); /*ft_drawfloor(vl);*/
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
ft_raycast(vl);
ft_pickup(vl); ft_pickup(vl);
ft_drawsprites(vl); ft_drawsprites(vl);
ft_frametime(vl); /*ft_drawweapon(vl);*/
vl->frametime = vl->mlx->delta_time;
ft_printstats(vl); ft_printstats(vl);
ft_movementkeys(vl); ft_processinput(vl);
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 ", "mainloop", 1); ft_errorexit("image to window failed ", "mainloop", 1);
mlx_set_instance_depth(vl->img->instances, 1); mlx_set_instance_depth(vl->img->instances, 1);
@ -116,7 +114,6 @@ int main(int argc, char **argv)
mlx_delete_texture(vl.southtext); mlx_delete_texture(vl.southtext);
mlx_delete_texture(vl.westtext); mlx_delete_texture(vl.westtext);
mlx_delete_texture(vl.barreltext); mlx_delete_texture(vl.barreltext);
mlx_delete_image(vl.mlx, vl.fps);
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);

View File

@ -6,12 +6,11 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */ /* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */
/* Updated: 2023/11/04 04:09:24 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:42:40 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
#include <stdio.h>
char ft_setplayerpos(t_varlist *vl, char dir, int x, int y) char ft_setplayerpos(t_varlist *vl, char dir, int x, int y)
{ {

View File

@ -6,11 +6,11 @@
/* 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/11/01 15:42:55 by houtworm ######## odam.nl */ /* Updated: 2023/11/05 04:42:46 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../../cub3d.h"
int ft_settexture(t_varlist *vl, char *line, int direction) int ft_settexture(t_varlist *vl, char *line, int direction)
{ {