aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_exit.c')
-rw-r--r--src/ft_exit.c110
1 files changed, 65 insertions, 45 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 80fd734..390f234 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -15,39 +15,52 @@
#include <mlx.h>
#include <stddef.h>
#include <stdlib.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
#include <stdint.h>
+#include <pthread.h>
+
+static void
+ ft_free_some_extras(t_cub *clist)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < 8)
+ {
+ ft_memdel((void*)&clist->sprites[i]);
+ i++;
+ }
+ ft_memdel((void*)&clist->sprites);
+ ft_memdel((void*)&clist);
+}
static void
ft_free_lists(t_cub *clist)
{
- ft_memdel((void**)&clist->mlist.filename);
- ft_memdel((void**)&clist->mlist.no_tex_path);
- ft_memdel((void**)&clist->mlist.so_tex_path);
- ft_memdel((void**)&clist->mlist.ea_tex_path);
- ft_memdel((void**)&clist->mlist.we_tex_path);
- ft_memdel((void**)&clist->mlist.nl_tex_path);
- ft_memdel((void**)&clist->mlist.fl_tex_path);
- ft_memdel((void**)&clist->mlist.ce_tex_path);
- ft_memdel((void**)&clist->mlist.nlevel_path);
- ft_memdel((void**)&clist->mlist.skybox_path);
- ft_memdel((void**)&clist->mlist.traps_path);
- ft_memdel((void**)&clist->mlist.music_path);
- ft_memdel((void**)&clist->mlist.music_cmd);
- ft_memdel((void**)&clist->mlist.mapl);
+ ft_memdel((void*)&clist->mlist.filename);
+ ft_memdel((void*)&clist->mlist.no_tex_path);
+ ft_memdel((void*)&clist->mlist.so_tex_path);
+ ft_memdel((void*)&clist->mlist.ea_tex_path);
+ ft_memdel((void*)&clist->mlist.we_tex_path);
+ ft_memdel((void*)&clist->mlist.nl_tex_path);
+ ft_memdel((void*)&clist->mlist.fl_tex_path);
+ ft_memdel((void*)&clist->mlist.ce_tex_path);
+ ft_memdel((void*)&clist->mlist.nlevel_path);
+ ft_memdel((void*)&clist->mlist.skybox_path);
+ ft_memdel((void*)&clist->mlist.traps_path);
+ ft_memdel((void*)&clist->mlist.music_path);
+ ft_memdel((void*)&clist->mlist.music_cmd);
+ ft_memdel((void*)&clist->mlist.mapl);
ft_free_words(clist->mlist.map);
- ft_free_words(clist->mlist.mcmd_words);
- ft_free_words(clist->sfx.death);
- ft_free_words(clist->sfx.pain_one);
- ft_free_words(clist->sfx.pain_two);
- ft_free_words(clist->sfx.new_lvl);
- ft_free_words(clist->sfx.trap);
+ ft_memdel((void*)&clist->sfx.death);
+ ft_memdel((void*)&clist->sfx.footstep_one);
+ ft_memdel((void*)&clist->sfx.footstep_two);
+ ft_memdel((void*)&clist->sfx.new_lvl);
+ ft_memdel((void*)&clist->sfx.pain_one);
+ ft_memdel((void*)&clist->sfx.pain_two);
+ ft_memdel((void*)&clist->sfx.trap);
ft_free_sprites(clist->mlist.sprite_path);
if (!clist->wlist.inited)
- ft_memdel((void**)&clist->wlist.winptr);
- ft_memdel((void**)&clist);
+ ft_memdel((void*)&clist->wlist.winptr);
}
static void
@@ -71,29 +84,36 @@ static void
mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img);
if (clist->mlist.istraps && clist->tlist[15].img)
mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img);
+ if (clist->tlist[16].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[16].img);
+ if (clist->mlist.isheals && clist->tlist[17].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[17].img);
ft_del_extra_sprites(clist);
}
static void
- ft_kill_forks(t_cub *clist)
+ ft_cancel_threads(t_cub *clist)
{
- pid_t tmp;
-
- if (!(tmp = waitpid(clist->mpid, NULL, WNOHANG)))
- kill(clist->mpid, SIGTERM);
- wait(&clist->mpid);
- if (!(tmp = waitpid(clist->sfx.death_pid, NULL, WNOHANG)))
- kill(clist->sfx.death_pid, SIGTERM);
- wait(&clist->sfx.death_pid);
- if (!(tmp = waitpid(clist->sfx.new_lvl_pid, NULL, WNOHANG)))
- kill(clist->sfx.new_lvl_pid, SIGTERM);
- wait(&clist->sfx.new_lvl_pid);
- if (!(tmp = waitpid(clist->sfx.pain_pid, NULL, WNOHANG)))
- kill(clist->sfx.pain_pid, SIGTERM);
- wait(&clist->sfx.pain_pid);
- if (!(tmp = waitpid(clist->sfx.trap_pid, NULL, WNOHANG)))
- kill(clist->sfx.trap_pid, SIGTERM);
- wait(&clist->sfx.trap_pid);
+ if (clist->isoldmus && clist->wlist.inited)
+ {
+ pthread_cancel(clist->mtid);
+ pthread_join(clist->mtid, NULL);
+ }
+ pthread_mutex_unlock(&clist->sfx.death_mutex);
+ pthread_cancel(clist->sfx.death_tid);
+ pthread_join(clist->sfx.death_tid, NULL);
+ pthread_mutex_unlock(&clist->sfx.footstep_mutex);
+ pthread_cancel(clist->sfx.footstep_tid);
+ pthread_join(clist->sfx.footstep_tid, NULL);
+ pthread_mutex_unlock(&clist->sfx.new_lvl_mutex);
+ pthread_cancel(clist->sfx.new_lvl_tid);
+ pthread_join(clist->sfx.new_lvl_tid, NULL);
+ pthread_mutex_unlock(&clist->sfx.pain_mutex);
+ pthread_cancel(clist->sfx.pain_tid);
+ pthread_join(clist->sfx.pain_tid, NULL);
+ pthread_mutex_unlock(&clist->sfx.trap_mutex);
+ pthread_cancel(clist->sfx.trap_tid);
+ pthread_join(clist->sfx.trap_tid, NULL);
}
int
@@ -106,10 +126,10 @@ int
if (FT_OS == 1)
mlx_destroy_image(clist->wlist.wlx, clist->img.img);
mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr);
- clist->wlist.winptr = NULL;
}
- ft_kill_forks(clist);
+ ft_cancel_threads(clist);
ft_free_lists(clist);
+ ft_free_some_extras(clist);
ft_printf("Exiting program\n");
exit(exit_code);
return (0);