-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:(vSKAH): Fix all leaks reported by valgrind tool
- Loading branch information
Showing
13 changed files
with
602 additions
and
556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/03 03:24:55 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/10 19:35:28 by jbadaire ### ########.fr */ | ||
/* Updated: 2023/10/12 08:57:08 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -19,20 +19,18 @@ t_collectible *load_collectibles(t_world *world) { | |
|
||
pos_x = 0; | ||
pos_y = 0; | ||
collectible = malloc(sizeof (t_collectible)); | ||
if(!collectible) | ||
return (NULL); | ||
collectible = NULL; | ||
|
||
while (world->map[pos_y]) { | ||
while (world->map[pos_y] && pos_x < (int) ft_strlen(world->map[0])) { | ||
if (world->map[pos_y][pos_x] == 'C') { | ||
t_location location; | ||
location.x = ++pos_x; | ||
location.y = ++pos_y; | ||
if(!collectible->location) | ||
location.x = pos_x; | ||
location.y = pos_y; | ||
if(!collectible) | ||
collectible = create_collectible(location); | ||
else | ||
collectible->next = create_collectible(location); | ||
collectible->next = create_collectible(location); | ||
} | ||
pos_x++; | ||
} | ||
|
@@ -52,60 +50,54 @@ t_collectible *create_collectible(t_location location) | |
if(!collectible) | ||
return (NULL); | ||
|
||
collectible->location = create_location(location.x, location.y); | ||
collectible->location = location; | ||
collectible->collected = 0; | ||
collectible->is_set = _true; | ||
collectible->next = NULL; | ||
return (collectible); | ||
} | ||
|
||
int count_collectibles(t_collectible *collectibles, t_boolean o_uncollected, t_boolean o_collected) | ||
int count_collectibles(t_collectible collectibles, t_boolean o_uncollected, t_boolean o_collected) | ||
{ | ||
t_collectible *copy; | ||
int count; | ||
|
||
count = 0; | ||
copy = collectibles; | ||
|
||
if (!copy) | ||
return (0); | ||
|
||
while (copy) | ||
while (collectibles.is_set) | ||
{ | ||
if(o_uncollected && !copy->collected) | ||
if(o_uncollected && !collectibles.collected) | ||
count++; | ||
if(o_collected && copy->collected) | ||
if(o_collected && collectibles.collected) | ||
count++; | ||
copy = copy->next; | ||
if(collectibles.next != NULL) | ||
collectibles = *collectibles.next; | ||
else | ||
break; | ||
} | ||
return (count); | ||
} | ||
|
||
|
||
t_collectible *get_collectible_at(t_world *world, t_location *location) | ||
t_collectible *get_collectible_at(t_world world, t_location location) | ||
{ | ||
t_collectible *copy; | ||
copy = world->player->collectibles; | ||
while (copy) | ||
while (world.player.collectibles) | ||
{ | ||
if(loc_equals(location, copy->location)) | ||
return copy; | ||
copy = copy->next; | ||
if(loc_equals(location, world.player.collectibles->location)) | ||
return (world.player.collectibles); | ||
world.player.collectibles = world.player.collectibles->next; | ||
} | ||
return (NULL); | ||
} | ||
|
||
|
||
#include "stdio.h" | ||
void update_collectible(t_collectible *collectibles, t_location location, t_boolean collected) | ||
{ | ||
t_collectible *copy; | ||
|
||
copy = collectibles; | ||
while (copy->next) | ||
while (collectibles) | ||
{ | ||
if(copy->location->x == location.x && copy->location->y == location.y) { | ||
copy->collected = collected; | ||
if(loc_equals(collectibles->location, location)) { | ||
collectibles->collected = collected; | ||
break; | ||
} | ||
copy = copy->next; | ||
collectibles = collectibles->next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,65 +6,47 @@ | |
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/03 10:21:10 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/10 14:58:36 by jbadaire ### ########.fr */ | ||
/* Updated: 2023/10/12 19:51:21 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
|
||
void free_map(t_world *world) { | ||
int length_y; | ||
int index; | ||
|
||
length_y = 0; | ||
while (world->length_y < length_y) { | ||
free(world->map[length_y]); | ||
length_y++; | ||
index = 0; | ||
while (world->map && world->map[index]) { | ||
free(world->map[index]); | ||
index++; | ||
} | ||
free(world->map); | ||
free((world->map)); | ||
} | ||
|
||
void free_collectibles(t_list **collectibles) { | ||
|
||
t_list *list; | ||
t_list *copy; | ||
|
||
list = *collectibles; | ||
copy = list; | ||
while (copy->next) | ||
{ | ||
if(copy->next == NULL) { | ||
free(list->content); | ||
copy = list; | ||
} | ||
copy = copy->next; | ||
|
||
} | ||
free(list->content); | ||
free(list); | ||
void free_textures(t_game *game) | ||
{ | ||
t_textures *textures = &game->textures; | ||
if(textures->wall.is_set) | ||
mlx_destroy_image(game->mlx, game->textures.wall.texture); | ||
if(textures->player.is_set) | ||
mlx_destroy_image(game->mlx, game->textures.player.texture); | ||
if(textures->collectible.is_set) | ||
mlx_destroy_image(game->mlx, game->textures.collectible.texture); | ||
if(textures->grass.is_set) | ||
mlx_destroy_image(game->mlx, game->textures.grass.texture); | ||
if(textures->exit.is_set) | ||
mlx_destroy_image(game->mlx, game->textures.exit.texture); | ||
} | ||
|
||
void free_textures(t_textures *textures) | ||
void free_collectibles(t_collectible *collectible) | ||
{ | ||
if(textures == NULL) return; | ||
if(textures->wall != NULL) | ||
{ | ||
free(textures->wall->texture); | ||
free(textures->wall); | ||
} | ||
if(textures->player != NULL) | ||
{ | ||
free(textures->player->texture); | ||
free(textures->player); | ||
} | ||
if(textures->collectible != NULL) | ||
{ | ||
free(textures->collectible->texture); | ||
free(textures->collectible); | ||
} | ||
if(textures->grass != NULL) | ||
t_collectible *copy; | ||
|
||
while (collectible != NULL) | ||
{ | ||
free(textures->grass->texture); | ||
free(textures->grass); | ||
copy = collectible; | ||
collectible = collectible->next; | ||
free(copy); | ||
} | ||
free(textures); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,48 +6,35 @@ | |
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/03 12:56:12 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/10 15:20:11 by jbadaire ### ########.fr */ | ||
/* Updated: 2023/10/12 08:56:07 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
#include "minilibx-linux/mlx.h" | ||
|
||
t_textures *load_textures(void *mlx) | ||
t_textures load_textures(void *mlx) | ||
{ | ||
t_textures *textures; | ||
t_textures textures; | ||
|
||
textures = malloc(sizeof (t_textures)); | ||
if(!textures) | ||
return (NULL); | ||
|
||
textures->wall = load_texture(mlx, '1', "./textures/wall.xpm"); | ||
textures->grass = load_texture(mlx, '0', "./textures/grass.xpm"); | ||
textures->player = load_texture(mlx, 'P', "./textures/player.xpm"); | ||
textures->collectible = load_texture(mlx, 'C', "./textures/collectible.xpm"); | ||
textures->exit = load_texture(mlx, 'E', "./textures/exit.xpm"); | ||
|
||
if (textures->wall == NULL || textures->grass == NULL || textures->exit == NULL) | ||
return (NULL); | ||
if (textures->collectible == NULL || textures->player == NULL) | ||
return (NULL); | ||
textures.wall = load_texture(mlx, '1', "./textures/wall.xpm"); | ||
textures.grass = load_texture(mlx, '0', "./textures/grass.xpm"); | ||
textures.player = load_texture(mlx, 'P', "./textures/player.xpm"); | ||
textures.collectible = load_texture(mlx, 'C', "./textures/collectible.xpm"); | ||
textures.exit = load_texture(mlx, 'E', "./textures/exit.xpm"); | ||
|
||
return (textures); | ||
} | ||
|
||
|
||
t_texture *load_texture(void *mlx, char character, char *path) | ||
t_texture load_texture(void *mlx, char character, char *path) | ||
{ | ||
int img_width; | ||
int img_height; | ||
t_texture *texture; | ||
|
||
texture = malloc(sizeof(t_texture)); | ||
if(!texture) | ||
return (NULL); | ||
t_texture texture; | ||
|
||
texture->character = character; | ||
texture->texture = mlx_xpm_file_to_image(mlx, path, &img_width, &img_height); | ||
texture.character = character; | ||
texture.texture = mlx_xpm_file_to_image(mlx, path, &img_width, &img_height); | ||
texture.is_set = _true; | ||
return (texture); | ||
} | ||
|
||
|
@@ -71,3 +58,16 @@ void draw_type(void *mlx, void *mlx_window, t_world *world, t_texture texture) | |
} | ||
} | ||
|
||
void draw_collectibles(t_game game) | ||
{ | ||
t_location loc; | ||
void *texture; | ||
|
||
texture = game.textures.collectible.texture; | ||
while (game.world.player.collectibles) | ||
{ | ||
loc = game.world.player.collectibles->location; | ||
mlx_put_image_to_window(game.mlx, game.window, texture, loc.x * 128, loc.y * 128); | ||
game.world.player.collectibles = game.world.player.collectibles->next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
/* ::: :::::::: */ | ||
/* ft_strtrim.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jbadaire <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* By: jbadaire <[email protected].fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/11 10:08:19 by jbadaire #+# #+# */ | ||
/* Updated: 2023/01/17 17:50:54 by jbadaire ### ########lyon.fr */ | ||
/* Created: 2023/10/03 16:00:38 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/03 16:00:38 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.