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 NAME = cub3D
FLAGS = ""
DIST_PATH = dist DIST_PATH = dist
SRC_PATH = src SRC_PATH = src
@ -47,7 +46,7 @@ SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))
# Build configurations # Build configurations
BUILD_CONFIGS = release debug asan tsan 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 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__);' 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 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> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ /* 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" # include "monster.h"
int initialize_cub3d(t_game **game, const char *mapfile); int initialize_cub3d(t_game **game, const char *mapfile);
int shader_init(t_game **game); int shader_init();
void set_uniforms(t_game *game); void set_uniforms(t_game *game);
int load_uniforms(t_game **game); int load_uniforms(t_game **game);
void count_scores(t_game *game); void count_scores(t_game *game);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 15:07:48 by qmennen #+# #+# */ /* 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, t_menu_item *menu_item_create(t_screen *screen, const char *text,
void (*act)(struct s_menu_item *item, t_game_manager *manager)); void (*act)(struct s_menu_item *item, t_game_manager *manager));
void menu_free(t_menu *menu, t_screen *screen); 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 #endif

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */ /* 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 sort_sprites(t_game *game);
void calculate_sprite_dist(t_game *game); void calculate_sprite_dist(t_game *game);
void cam_fraction(t_game *game, t_sprite *sprite); 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, unsigned int sample_texture_color(t_sprite *sprite,
t_vec2_int tex, int n); t_vec2_int tex, int n);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */ /* 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) int collision_sprite(t_game *game, double xa, double ya)
{ {
t_player *player; t_player *player;
t_map *map; t_map *map;
t_sprite *sprites; t_sprite *sprites;
int i; unsigned int i;
player = game->player; player = game->player;
map = game->map; map = game->map;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/03 16:20:35 by qmennen #+# #+# */ /* 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); slideshow(game);
if (menu->hidden) if (menu->hidden)
{ {
menu_toggle(menu, game->screen); menu_toggle(menu);
count_scores(game); count_scores(game);
} }
menu->selector->instances[0].y = manager->game->screen->height / 2 menu->selector->instances[0].y = manager->game->screen->height / 2

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 14:14:11 by qmennen #+# #+# */ /* 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) static void game_start(struct s_menu_item *item, t_game_manager *manager)
{ {
t_game *game; t_game *game;
t_screen *screen;
(void)item; (void)item;
game = manager->game; game = manager->game;
screen = game->screen;
game->screen->minimap->instances[0].enabled = true; game->screen->minimap->instances[0].enabled = true;
game->screen->hud->instances[0].enabled = true; game->screen->hud->instances[0].enabled = true;
game->scoreboard->start_time = mlx_get_time(); game->scoreboard->start_time = mlx_get_time();
menu_toggle(*(manager->active_menu), screen); menu_toggle(*(manager->active_menu));
manager->state = GAME_STATE_PLAYING; manager->state = GAME_STATE_PLAYING;
} }

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 14:31:53 by qmennen #+# #+# */ /* 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) void menu_display(t_menu *menu, t_screen *screen)
{ {
int i; int i;
int half_w;
int half_h; int half_h;
half_w = screen->width / 2;
half_h = screen->height / 2; half_h = screen->height / 2;
if (menu->hidden) if (menu->hidden)
menu_toggle(menu, screen); menu_toggle(menu);
menu->selector->instances[0].x = 150; menu->selector->instances[0].x = 150;
menu->selector->instances[0].y = half_h + menu->selected_option * 50; menu->selector->instances[0].y = half_h + menu->selected_option * 50;
i = 0; 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; int i;

View File

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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* :::::::: */ /* ::: :::::::: */
/* get_tile.c :+: :+: */ /* get_tile.c :+: :+: :+: */
/* +:+ */ /* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/23 12:23:05 by whaffman #+# #+# */ /* Created: 2025/04/23 12:23:05 by whaffman #+# #+# */
/* Updated: 2025/05/07 11:51:33 by whaffman ######## odam.nl */ /* 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) 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 (TILE_WALL);
return (map->grid[y][x]); return (map->grid[y][x]);
} }

View File

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

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */ /* 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) t_token_handler handle_config_token(const char *token, t_map *map)
{ {
(void)map;
const char *config_tokens[] = { const char *config_tokens[] = {
"NO", "SO", "WE", "EA", "D", "F", "C", "FT", "CT", "-c", "-s", "-e", "NO", "SO", "WE", "EA", "D", "F", "C", "FT", "CT", "-c", "-s", "-e",
NULL NULL

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */ /* 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 parse_map_line(char **lines, t_game *game, int y)
{ {
int x; unsigned int x;
t_map *map; t_map *map;
map = game->map; map = game->map;
map->grid[y] = malloc(sizeof(t_tile) * (map->width + 1)); 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 parse_map(char **lines, t_game *game)
{ {
int y; unsigned int y;
t_map *map; t_map *map;
map = game->map; map = game->map;
if (!prepare_map(lines, game)) if (!prepare_map(lines, game))

View File

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

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */ /* 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.x += step.x * (1 - side);
map_pos.y += step.y * side; map_pos.y += step.y * side;
if (map_pos.x < 0 if (map_pos.x < 0
|| map_pos.x >= map->width || map_pos.x >= (int) map->width
|| map_pos.y < 0 || 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); printf("Out of bounds: %d %d\n", map_pos.x, map_pos.y);
if (map->grid[map_pos.y][map_pos.x] == TILE_EMPTY) if (map->grid[map_pos.y][map_pos.x] == TILE_EMPTY)
map->grid[map_pos.y][map_pos.x] = TILE_VISITED; map->grid[map_pos.y][map_pos.x] = TILE_VISITED;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */ /* 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) void create_screenshot(t_game *game)
{ {
int i; unsigned int i;
int j; unsigned int j;
int idx1; int idx1;
int idx2; int idx2;
mlx_image_t *screenshot; mlx_image_t *screenshot;
if (!game->screenshots[game->screenshot_idx % MAX_SCREENSHOTS]) 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); 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) void flash(t_game *game)
{ {
mlx_image_t *img; mlx_image_t *img;
int x; unsigned int x;
int y; unsigned int y;
if (game->screen->flash == 0) if (game->screen->flash == 0)
return ; return ;
@ -76,8 +77,8 @@ void flash(t_game *game)
void cast_rays(t_game *game) void cast_rays(t_game *game)
{ {
int x; unsigned int x;
t_render render[WIDTH]; t_render render[WIDTH];
x = 0; x = 0;
draw_floor(game); draw_floor(game);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */ /* 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); color = game->map->floor_color << 8 | (int)(1.0 / row_dist * 255);
else else
color = get_texture_color(game->map->texture_floor, 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, mlx_put_pixel(game->screen->img,
coord.x, coord.y, color); coord.x, coord.y, color);
if (game->map->texture_ceiling == NULL) if (game->map->texture_ceiling == NULL)
color = game->map->ceiling_color << 8 | (int)(1.0 / row_dist * 255); color = game->map->ceiling_color << 8 | (int)(1.0 / row_dist * 255);
else else
color = get_texture_color(game->map->texture_ceiling, 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, mlx_put_pixel(game->screen->img,
coord.x, game->screen->height - coord.y - 1, color); 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)); floor_pos = add(game->player->pos, mul(left_ray, row_dist));
if (isinf(floor_pos.x) || isinf(floor_pos.y)) if (isinf(floor_pos.x) || isinf(floor_pos.y))
return ; return ;
while (coord.x < game->screen->width) while (coord.x < (int) game->screen->width)
{ {
draw_floor_ceiling_pixel(game, coord, row_dist, floor_pos); draw_floor_ceiling_pixel(game, coord, row_dist, floor_pos);
floor_pos = add(floor_pos, floor_step); floor_pos = add(floor_pos, floor_step);
@ -74,7 +74,7 @@ void draw_floor(t_game *game)
coord.y = game->screen->height / 2; coord.y = game->screen->height / 2;
coord.x = 0; 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); draw_floor_row(game, coord, left_ray, right_ray);
coord.y++; coord.y++;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */ /* 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) return (!isnan(sprite->cam_frac)
&& sprite->dist > MIN_SPRITE_DIST && sprite->dist > MIN_SPRITE_DIST
&& x > 0 && x > 0
&& x < game->screen->width && x < (int) game->screen->width
&& sprite->dist <= render[x].perp_dist); && sprite->dist <= render[x].perp_dist);
} }
static void draw_sprite_column( static void draw_sprite_column(
t_game *game, t_sprite *sprite, t_render *render, t_game *game, t_sprite *sprite, t_sprite_column column)
t_sprite_column column)
{ {
t_vec2_int tex; t_vec2_int tex;
t_vec2 inv_range; t_vec2 inv_range;
@ -52,8 +51,7 @@ static void draw_sprite_column(
frame %= sprite->n_frames; frame %= sprite->n_frames;
inv_range.y = 1.0 / (column.end.y - column.start.y); inv_range.y = 1.0 / (column.end.y - column.start.y);
inv_range.x = 1.0 / (column.end.x - column.start.x); inv_range.x = 1.0 / (column.end.x - column.start.x);
sprite->alpha = calculate_alpha(column.start.x, sprite->alpha = calculate_alpha(sprite->dist);
column.start.y, sprite->dist);
tex.x = column.x - column.start.x; tex.x = column.x - column.start.x;
tex.x *= sprite->texture->width / sprite->n_frames; tex.x *= sprite->texture->width / sprite->n_frames;
tex.x *= inv_range.x; 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 = (y - column.start.y) * sprite->texture->height;
tex.y *= inv_range.y; tex.y *= inv_range.y;
color = sample_texture_color(sprite, tex, frame); 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); mlx_put_pixel(game->screen->img, column.x, y, color);
y++; y++;
} }
@ -88,7 +86,7 @@ void draw_sprite(t_game *game, t_sprite *sprite, t_render *render)
column.start = start; column.start = start;
column.end = end; column.end = end;
column.x = x; column.x = x;
draw_sprite_column(game, sprite, render, column); draw_sprite_column(game, sprite, column);
} }
x++; 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) void render_sprites(t_render *render, t_game *game)
{ {
int i; unsigned int i;
calculate_sprite_dist(game); calculate_sprite_dist(game);
sort_sprites(game); sort_sprites(game);

View File

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

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/14 13:05:28 by whaffman #+# #+# */ /* 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; double perp_dist;
render.door = 0; render.door = 0;
render.sign = 1;
ray_dir = add(game->player->dir, ray_dir = add(game->player->dir,
mul(game->player->camera, mul(game->player->camera,
(2.0f * x / (double)game->screen->width - 1))); (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; tex_start = range->start;
range->start = (range->start > 0) * range->start; range->start = (range->start > 0) * range->start;
range->end = height / 2 + game->screen->height / 2; 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; range->end = game->screen->height - 1;
return (tex_start); 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], color = get_texture_color(game->map->textures[render.side],
render, tex); render, tex);
if (x < 0 if (x < 0
|| x >= game->screen->width || x >= (int) game->screen->width
|| range.start < 0 || range.start < 0
|| range.start >= game->screen->height) || range.start >= (int) game->screen->height)
break ; break ;
mlx_put_pixel(game->screen->img, x, range.start, color); mlx_put_pixel(game->screen->img, x, range.start, color);
range.start++; range.start++;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */ /* 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) void fill_background(mlx_image_t *image, int color)
{ {
int i; unsigned int i;
int j; unsigned int j;
i = 0; i = 0;
while (i < image->width) while (i < image->width)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */ /* 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) 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_time_location, (float)mlx_get_time());
glUniform1f(game->screen->u_battery_location, game->player->battery); glUniform1f(game->screen->u_battery_location, game->player->battery);
glUniform2f(game->screen->u_resolution_location, glUniform2f(game->screen->u_resolution_location,
@ -58,7 +55,7 @@ static const char *read_vertex_shader(void)
char *shader; char *shader;
int fd; int fd;
int file_size; int file_size;
size_t bytes_read; ssize_t bytes_read;
file_size = get_file_size(target); file_size = get_file_size(target);
fd = open(target, O_RDONLY); fd = open(target, O_RDONLY);
@ -85,7 +82,7 @@ static const char *read_fragment_shader(void)
char *shader; char *shader;
int fd; int fd;
int file_size; int file_size;
size_t bytes_read; ssize_t bytes_read;
file_size = get_file_size(target); file_size = get_file_size(target);
fd = open(target, O_RDONLY); fd = open(target, O_RDONLY);
@ -108,7 +105,7 @@ static const char *read_fragment_shader(void)
return (close(fd), shader); return (close(fd), shader);
} }
int shader_init(t_game **game) int shader_init()
{ {
vert_shader = read_vertex_shader(); vert_shader = read_vertex_shader();
if (!vert_shader) if (!vert_shader)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */ /* 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); return (FAILURE);
if (!texture_load(*game)) if (!texture_load(*game))
return (FAILURE); return (FAILURE);
if (!shader_init(game)) if (!shader_init())
return (FAILURE); return (FAILURE);
if (!screen_create(game)) if (!screen_create(game))
return (FAILURE); return (FAILURE);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/25 20:54:23 by whaffman #+# #+# */ /* 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_tiles(t_map *map, t_tile tile_type)
{ {
int count; int count;
int x; unsigned int x;
int y; unsigned int y;
count = 0; count = 0;
y = 0; y = 0;
@ -36,8 +36,8 @@ int count_tiles(t_map *map, t_tile tile_type)
int count_collected(t_game *game) int count_collected(t_game *game)
{ {
int collected; int collected;
int i; unsigned int i;
i = 0; i = 0;
collected = 0; collected = 0;