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> +#+ #
# +#+ #
# 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
RM =rm -rf
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
SRC =src/main.c\
src/init.c\
src/parse.c\
src/keys.c\
src/draw.c\
src/error.c\
src/raycast.c\
src/map.c
SRC =src/main/main.c\
src/main/init.c\
src/draw/draw.c\
src/main/error.c\
src/draw/raycast.c\
src/input/keys.c\
src/parse/parse.c\
src/parse/map.c
OBJ =$(SRC:src/%.c=obj/%.o)
all: libft getnextline mlx/build/mlx42.a $(NAME)

10
cub3d.h
View File

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

View File

@ -6,11 +6,11 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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)
{

View File

@ -6,13 +6,13 @@
/* By: djonker <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 drawstart;

View File

@ -6,13 +6,13 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 distance;

View File

@ -6,11 +6,11 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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)
{

View File

@ -6,11 +6,11 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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)
{

View File

@ -6,45 +6,35 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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)
{
char *enemies;
char *kills;
char *treasure;
char *found;
char *total;
char *current;
char *temp;
enemies = ft_itoa(vl->enemies);
kills = ft_itoa(vl->kills);
temp = ft_vastrjoin(4, "Kills: ", kills, "/", enemies);
current = ft_itoa(1 / vl->frametime);
temp = ft_strjoin(current, " FPS");
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);
free(temp);
treasure = ft_itoa(vl->tottreasure);
found = ft_itoa(vl->treasure);
temp = ft_vastrjoin(4, "Treasure: ", found, "/", treasure);
ft_vafree(3, temp, total, current);
total = ft_itoa(vl->tottreasure);
current = ft_itoa(vl->treasure);
temp = ft_vastrjoin(4, "Treasure: ", current, "/", total);
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->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)
@ -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)
{
t_varlist *vl;
vl = param;
mlx_delete_image(vl->mlx, vl->img);
mlx_delete_image(vl->mlx, vl->fps);
mlx_delete_image(vl->mlx, vl->tstat);
mlx_delete_image(vl->mlx, vl->kstat);
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
ft_raycast(vl);
ft_replaceimage(vl);
/*ft_drawceiling(vl);*/
ft_drawwalls(vl);
/*ft_drawfloor(vl);*/
ft_pickup(vl);
ft_drawsprites(vl);
ft_frametime(vl);
/*ft_drawweapon(vl);*/
vl->frametime = vl->mlx->delta_time;
ft_printstats(vl);
ft_movementkeys(vl);
ft_processinput(vl);
if (!vl->img || (mlx_image_to_window(vl->mlx, vl->img, 0, 0) < 0))
ft_errorexit("image to window failed ", "mainloop", 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.westtext);
mlx_delete_texture(vl.barreltext);
mlx_delete_image(vl.mlx, vl.fps);
mlx_delete_image(vl.mlx, vl.img);
mlx_terminate(vl.mlx);
exit (0);

View File

@ -6,12 +6,11 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 <stdio.h>
#include "../../cub3d.h"
char ft_setplayerpos(t_varlist *vl, char dir, int x, int y)
{

View File

@ -6,11 +6,11 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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)
{