Refactor code to improve consistency and readability by changing variable types to unsigned int where appropriate, updating shader initialization function signature, and adjusting function calls accordingly. Update comments and versioning in multiple files for clarity and maintenance.

This commit is contained in:
Quinten 2025-06-10 14:46:38 +02:00
parent 22e67c1ff4
commit 62f20996d0
26 changed files with 140 additions and 147 deletions

View File

@ -11,7 +11,6 @@
# **************************************************************************** #
NAME = cub3D
FLAGS = ""
DIST_PATH = dist
SRC_PATH = src
@ -47,7 +46,7 @@ SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))
# Build configurations
BUILD_CONFIGS = release debug asan tsan
release_CFLAGS = -Wall -Werror -Werror -flto -Ofast -march=native -mtune=native -ffast-math -DFULLSCREEN=0
release_CFLAGS = -Wall -Wextra -Werror -flto -Ofast -march=native -mtune=native -ffast-math -DFULLSCREEN=0
unity_CFLAGS = -Wall -Werror -Werror -Ofast -march=native -mtune=native -ffast-math
debug_CFLAGS = -Wall -Werror -Werror -g3 -DDEBUG -DDBG='fprintf(stderr, RED "DEBUG: " RESET "%s:%d (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);'
asan_CFLAGS = -Wall -Werror -Werror -flto -fsanitize=address,leak,undefined -g3 -DFULLSCREEN=0

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
/* Updated: 2025/06/04 18:54:18 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:42:13 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -71,7 +71,7 @@
# include "monster.h"
int initialize_cub3d(t_game **game, const char *mapfile);
int shader_init(t_game **game);
int shader_init();
void set_uniforms(t_game *game);
int load_uniforms(t_game **game);
void count_scores(t_game *game);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 15:07:48 by qmennen #+# #+# */
/* Updated: 2025/06/05 18:48:10 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:28:20 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,6 +26,6 @@ t_menu *menu_create(t_game_manager *manager, char *b_path,
t_menu_item *menu_item_create(t_screen *screen, const char *text,
void (*act)(struct s_menu_item *item, t_game_manager *manager));
void menu_free(t_menu *menu, t_screen *screen);
void menu_toggle(t_menu *menu, t_screen *screen);
void menu_toggle(t_menu *menu);
#endif

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */
/* Updated: 2025/06/04 18:15:26 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:30:30 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,7 +28,7 @@ unsigned int get_texture_color(mlx_texture_t *texture,
void sort_sprites(t_game *game);
void calculate_sprite_dist(t_game *game);
void cam_fraction(t_game *game, t_sprite *sprite);
unsigned int calculate_alpha(int x, int y, double dist);
unsigned int calculate_alpha(double dist);
unsigned int sample_texture_color(t_sprite *sprite,
t_vec2_int tex, int n);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
/* Updated: 2025/06/05 18:41:12 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:41:31 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,10 +34,10 @@ static void damage_player(t_player *player, float amount)
int collision_sprite(t_game *game, double xa, double ya)
{
t_player *player;
t_map *map;
t_sprite *sprites;
int i;
t_player *player;
t_map *map;
t_sprite *sprites;
unsigned int i;
player = game->player;
map = game->map;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/03 16:20:35 by qmennen #+# #+# */
/* Updated: 2025/06/05 17:12:02 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:29:07 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -72,7 +72,7 @@ void draw_end_screen(t_game_manager *manager, t_menu *menu)
slideshow(game);
if (menu->hidden)
{
menu_toggle(menu, game->screen);
menu_toggle(menu);
count_scores(game);
}
menu->selector->instances[0].y = manager->game->screen->height / 2

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 14:14:11 by qmennen #+# #+# */
/* Updated: 2025/06/05 18:44:51 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:28:51 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,15 +21,13 @@ static void game_exit(struct s_menu_item *item, t_game_manager *manager)
static void game_start(struct s_menu_item *item, t_game_manager *manager)
{
t_game *game;
t_screen *screen;
(void)item;
game = manager->game;
screen = game->screen;
game->screen->minimap->instances[0].enabled = true;
game->screen->hud->instances[0].enabled = true;
game->scoreboard->start_time = mlx_get_time();
menu_toggle(*(manager->active_menu), screen);
menu_toggle(*(manager->active_menu));
manager->state = GAME_STATE_PLAYING;
}

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 14:31:53 by qmennen #+# #+# */
/* Updated: 2025/06/05 18:49:23 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:28:28 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,13 +36,11 @@ t_menu *menu_create(t_game_manager *manager, char *b_path,
void menu_display(t_menu *menu, t_screen *screen)
{
int i;
int half_w;
int half_h;
half_w = screen->width / 2;
half_h = screen->height / 2;
if (menu->hidden)
menu_toggle(menu, screen);
menu_toggle(menu);
menu->selector->instances[0].x = 150;
menu->selector->instances[0].y = half_h + menu->selected_option * 50;
i = 0;
@ -54,7 +52,7 @@ void menu_display(t_menu *menu, t_screen *screen)
}
}
void menu_toggle(t_menu *menu, t_screen *screen)
void menu_toggle(t_menu *menu)
{
int i;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* monster.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/28 17:15:52 by qmennen #+# #+# */
/* Updated: 2025/06/03 14:51:23 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* monster.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 17:15:52 by qmennen #+# #+# */
/* Updated: 2025/06/10 14:45:44 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,14 +14,14 @@
void update_monsters(t_game *game)
{
int i;
t_vec2 d;
t_sprite *sprite;
double dist_squared;
double inv_dist;
unsigned int i;
t_vec2 d;
t_sprite *sprite;
double dist_squared;
double inv_dist;
i = -1;
while (++i < game->map->n_sprites)
i = 0;
while (i++ < game->map->n_sprites)
{
sprite = &game->map->sprites[i];
if (sprite->type != SPRITE_TYPE_ENEMY)

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* find_player_or_empty.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/23 12:13:50 by whaffman #+# #+# */
/* Updated: 2025/04/24 11:55:22 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* find_player_or_empty.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/23 12:13:50 by whaffman #+# #+# */
/* Updated: 2025/06/10 14:39:59 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
int find_player_or_empty(t_map *map, int *x, int *y)
{
int i;
unsigned int i;
if (!map || !x || !y)
return (FAILURE);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* floodfill.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/23 12:14:58 by whaffman #+# #+# */
/* Updated: 2025/04/23 12:20:18 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* floodfill.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/23 12:14:58 by whaffman #+# #+# */
/* Updated: 2025/06/10 14:38:14 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
int floodfill(t_map *map, int x, int y)
{
if (!map || x < 0 || y < 0 || x >= map->width || y >= map->height)
if (!map || x < 0 || y < 0 || x >= (int) map->width || y >= (int) map->height)
return (FAILURE);
if (map->grid[y][x] == TILE_VOID)
return (FAILURE);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* get_tile.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/23 12:23:05 by whaffman #+# #+# */
/* Updated: 2025/05/07 11:51:33 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* get_tile.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/23 12:23:05 by whaffman #+# #+# */
/* Updated: 2025/06/10 14:37:58 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
t_tile get_tile(t_map *map, int x, int y)
{
if (x < 0 || y < 0 || x >= map->width || y >= map->height)
if (x < 0 || y < 0 || x >= (int) map->width || y >= (int) map->height)
return (TILE_WALL);
return (map->grid[y][x]);
}

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* map_width.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/22 13:13:07 by whaffman #+# #+# */
/* Updated: 2025/05/07 11:48:00 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* map_width.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:13:07 by whaffman #+# #+# */
/* Updated: 2025/06/10 14:38:27 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ int map_width(char **lines)
width = 0;
while (lines[i])
{
if (ft_strlen(lines[i]) > width)
if ((int) ft_strlen(lines[i]) > width)
width = ft_strlen(lines[i]);
i++;
}

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
/* Updated: 2025/06/05 17:15:42 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:39:39 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,6 +27,7 @@ mlx_texture_t *load_texture(const char *path)
t_token_handler handle_config_token(const char *token, t_map *map)
{
(void)map;
const char *config_tokens[] = {
"NO", "SO", "WE", "EA", "D", "F", "C", "FT", "CT", "-c", "-s", "-e",
NULL

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */
/* Updated: 2025/05/28 17:07:32 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:39:03 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,8 +48,8 @@ int parse_player(t_game *game, int y, int x, char c)
int parse_map_line(char **lines, t_game *game, int y)
{
int x;
t_map *map;
unsigned int x;
t_map *map;
map = game->map;
map->grid[y] = malloc(sizeof(t_tile) * (map->width + 1));
@ -148,8 +148,8 @@ int parse_map_line_sprites(char *line, t_game *game, int y)
int parse_map(char **lines, t_game *game)
{
int y;
t_map *map;
unsigned int y;
t_map *map;
map = game->map;
if (!prepare_map(lines, game))

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* print_map.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/23 12:11:12 by whaffman #+# #+# */
/* Updated: 2025/04/23 12:20:12 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* print_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/23 12:11:12 by whaffman #+# #+# */
/* Updated: 2025/06/10 14:40:11 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,8 +15,8 @@
void print_map(t_map *map)
{
const int chars[] = {'X', ' ', '.', '#', 'P'};
int i;
int j;
unsigned int i;
unsigned int j;
if (!map)
return ;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */
/* Updated: 2025/06/04 18:32:57 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:35:17 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -68,9 +68,9 @@ int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map)
map_pos.x += step.x * (1 - side);
map_pos.y += step.y * side;
if (map_pos.x < 0
|| map_pos.x >= map->width
|| map_pos.x >= (int) map->width
|| map_pos.y < 0
|| map_pos.y >= map->height)
|| map_pos.y >= (int) map->height)
printf("Out of bounds: %d %d\n", map_pos.x, map_pos.y);
if (map->grid[map_pos.y][map_pos.x] == TILE_EMPTY)
map->grid[map_pos.y][map_pos.x] = TILE_VISITED;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */
/* Updated: 2025/06/03 22:17:23 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:34:55 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,11 +14,12 @@
void create_screenshot(t_game *game)
{
int i;
int j;
int idx1;
int idx2;
mlx_image_t *screenshot;
unsigned int i;
unsigned int j;
int idx1;
int idx2;
mlx_image_t *screenshot;
if (!game->screenshots[game->screenshot_idx % MAX_SCREENSHOTS])
{
game->screenshots[game->screenshot_idx % MAX_SCREENSHOTS] = mlx_new_image(game->screen->mlx, game->screen->width / 3, game->screen->height / 3);
@ -52,8 +53,8 @@ void create_screenshot(t_game *game)
void flash(t_game *game)
{
mlx_image_t *img;
int x;
int y;
unsigned int x;
unsigned int y;
if (game->screen->flash == 0)
return ;
@ -76,8 +77,8 @@ void flash(t_game *game)
void cast_rays(t_game *game)
{
int x;
t_render render[WIDTH];
unsigned int x;
t_render render[WIDTH];
x = 0;
draw_floor(game);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */
/* Updated: 2025/06/05 17:01:36 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:45:54 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,14 +33,14 @@ static void draw_floor_ceiling_pixel(t_game *game,
color = game->map->floor_color << 8 | (int)(1.0 / row_dist * 255);
else
color = get_texture_color(game->map->texture_floor,
(t_render){row_dist, 0, 0}, tex);
(t_render){.perp_dist = row_dist, .sign = 0, .door = 0, .side = SIDE_DOOR, .wall_x = 0}, tex);
mlx_put_pixel(game->screen->img,
coord.x, coord.y, color);
if (game->map->texture_ceiling == NULL)
color = game->map->ceiling_color << 8 | (int)(1.0 / row_dist * 255);
else
color = get_texture_color(game->map->texture_ceiling,
(t_render){row_dist, 0, 0}, tex);
(t_render){.perp_dist = row_dist, .sign = 0, .door = 0, .side = SIDE_DOOR, .wall_x = 0}, tex);
mlx_put_pixel(game->screen->img,
coord.x, game->screen->height - coord.y - 1, color);
}
@ -58,7 +58,7 @@ static void draw_floor_row(t_game *game,
floor_pos = add(game->player->pos, mul(left_ray, row_dist));
if (isinf(floor_pos.x) || isinf(floor_pos.y))
return ;
while (coord.x < game->screen->width)
while (coord.x < (int) game->screen->width)
{
draw_floor_ceiling_pixel(game, coord, row_dist, floor_pos);
floor_pos = add(floor_pos, floor_step);
@ -74,7 +74,7 @@ void draw_floor(t_game *game)
coord.y = game->screen->height / 2;
coord.x = 0;
while (coord.y < game->screen->height)
while (coord.y < (int) game->screen->height)
{
draw_floor_row(game, coord, left_ray, right_ray);
coord.y++;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */
/* Updated: 2025/06/03 22:15:19 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:34:01 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,13 +34,12 @@ static int sprite_visible(t_game *game,
return (!isnan(sprite->cam_frac)
&& sprite->dist > MIN_SPRITE_DIST
&& x > 0
&& x < game->screen->width
&& x < (int) game->screen->width
&& sprite->dist <= render[x].perp_dist);
}
static void draw_sprite_column(
t_game *game, t_sprite *sprite, t_render *render,
t_sprite_column column)
t_game *game, t_sprite *sprite, t_sprite_column column)
{
t_vec2_int tex;
t_vec2 inv_range;
@ -52,8 +51,7 @@ static void draw_sprite_column(
frame %= sprite->n_frames;
inv_range.y = 1.0 / (column.end.y - column.start.y);
inv_range.x = 1.0 / (column.end.x - column.start.x);
sprite->alpha = calculate_alpha(column.start.x,
column.start.y, sprite->dist);
sprite->alpha = calculate_alpha(sprite->dist);
tex.x = column.x - column.start.x;
tex.x *= sprite->texture->width / sprite->n_frames;
tex.x *= inv_range.x;
@ -63,7 +61,7 @@ static void draw_sprite_column(
tex.y = (y - column.start.y) * sprite->texture->height;
tex.y *= inv_range.y;
color = sample_texture_color(sprite, tex, frame);
if (y > 0 && y < game->screen->height && (color & 0xFF) != 0)
if (y > 0 && y < (int) game->screen->height && (color & 0xFF) != 0)
mlx_put_pixel(game->screen->img, column.x, y, color);
y++;
}
@ -88,7 +86,7 @@ void draw_sprite(t_game *game, t_sprite *sprite, t_render *render)
column.start = start;
column.end = end;
column.x = x;
draw_sprite_column(game, sprite, render, column);
draw_sprite_column(game, sprite, column);
}
x++;
}
@ -96,7 +94,7 @@ void draw_sprite(t_game *game, t_sprite *sprite, t_render *render)
void render_sprites(t_render *render, t_game *game)
{
int i;
unsigned int i;
calculate_sprite_dist(game);
sort_sprites(game);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* render_sprite_utils.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/14 21:21:57 by whaffman #+# #+# */
/* Updated: 2025/05/18 12:51:23 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* render_sprite_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/14 21:21:57 by whaffman #+# #+# */
/* Updated: 2025/06/10 14:30:19 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,9 +14,9 @@
void sort_sprites(t_game *game)
{
int i;
int j;
t_sprite key;
unsigned int i;
int j;
t_sprite key;
i = 1;
while (i < game->map->n_sprites)
@ -35,8 +35,8 @@ void sort_sprites(t_game *game)
void calculate_sprite_dist(t_game *game)
{
t_vec2 player_pos;
int i;
t_vec2 player_pos;
unsigned int i;
i = 0;
player_pos = game->player->pos;
@ -70,7 +70,7 @@ void cam_fraction(t_game *game, t_sprite *sprite)
return ;
}
unsigned int calculate_alpha(int x, int y, double dist)
unsigned int calculate_alpha(double dist)
{
int alpha;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/14 13:05:28 by whaffman #+# #+# */
/* Updated: 2025/06/04 18:17:33 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:45:19 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,6 +40,7 @@ t_render cast_ray(t_game *game, int x)
double perp_dist;
render.door = 0;
render.sign = 1;
ray_dir = add(game->player->dir,
mul(game->player->camera,
(2.0f * x / (double)game->screen->width - 1)));
@ -84,7 +85,7 @@ static int set_range(t_game *game, t_render render, t_range *range, int height)
tex_start = range->start;
range->start = (range->start > 0) * range->start;
range->end = height / 2 + game->screen->height / 2;
if (range->end >= game->screen->height)
if (range->end >= (int) game->screen->height)
range->end = game->screen->height - 1;
return (tex_start);
}
@ -109,9 +110,9 @@ void draw_line(t_game *game, t_render render, int x)
color = get_texture_color(game->map->textures[render.side],
render, tex);
if (x < 0
|| x >= game->screen->width
|| x >= (int) game->screen->width
|| range.start < 0
|| range.start >= game->screen->height)
|| range.start >= (int) game->screen->height)
break ;
mlx_put_pixel(game->screen->img, x, range.start, color);
range.start++;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
/* Updated: 2025/06/05 17:15:05 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:41:07 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,8 +43,8 @@ int screen_create(t_game **game)
void fill_background(mlx_image_t *image, int color)
{
int i;
int j;
unsigned int i;
unsigned int j;
i = 0;
while (i < image->width)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */
/* Updated: 2025/06/05 17:26:44 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:42:39 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,9 +16,6 @@
void set_uniforms(t_game *game)
{
mlx_ctx_t *ctx;
ctx = (mlx_ctx_t *)game->screen->mlx->context;
glUniform1f(game->screen->u_time_location, (float)mlx_get_time());
glUniform1f(game->screen->u_battery_location, game->player->battery);
glUniform2f(game->screen->u_resolution_location,
@ -58,7 +55,7 @@ static const char *read_vertex_shader(void)
char *shader;
int fd;
int file_size;
size_t bytes_read;
ssize_t bytes_read;
file_size = get_file_size(target);
fd = open(target, O_RDONLY);
@ -85,7 +82,7 @@ static const char *read_fragment_shader(void)
char *shader;
int fd;
int file_size;
size_t bytes_read;
ssize_t bytes_read;
file_size = get_file_size(target);
fd = open(target, O_RDONLY);
@ -108,7 +105,7 @@ static const char *read_fragment_shader(void)
return (close(fd), shader);
}
int shader_init(t_game **game)
int shader_init()
{
vert_shader = read_vertex_shader();
if (!vert_shader)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
/* Updated: 2025/06/04 19:51:13 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:42:24 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -47,7 +47,7 @@ int initialize_cub3d(t_game **game, const char *mapfile)
return (FAILURE);
if (!texture_load(*game))
return (FAILURE);
if (!shader_init(game))
if (!shader_init())
return (FAILURE);
if (!screen_create(game))
return (FAILURE);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/25 20:54:23 by whaffman #+# #+# */
/* Updated: 2025/06/03 21:42:54 by qmennen ### ########.fr */
/* Updated: 2025/06/10 14:40:40 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,9 +14,9 @@
int count_tiles(t_map *map, t_tile tile_type)
{
int count;
int x;
int y;
int count;
unsigned int x;
unsigned int y;
count = 0;
y = 0;
@ -36,8 +36,8 @@ int count_tiles(t_map *map, t_tile tile_type)
int count_collected(t_game *game)
{
int collected;
int i;
int collected;
unsigned int i;
i = 0;
collected = 0;