improve gexit with init function and add basic mlx image gestion

This commit is contained in:
Hugo LAMY
2022-03-25 18:49:06 +01:00
parent 3a1036ccdc
commit 02b5d88ea5
45 changed files with 139 additions and 7042 deletions

View File

@@ -1,10 +1,43 @@
#include "cube3d.h"
static int comp_addr(void *to_find, void *to_compare)
/*
* gexit_init
*
*/
//-------------------------------
// gexit function
//-------------------------------
typedef void(*func_to_gexit)(void*);
typedef struct s_exit
{
return (to_find == to_compare);
func_to_gexit f;
void *param;
} t_exit;
t_exit **exit_func()
{
static t_exit *texit = NULL;
if (!texit)
texit = gmalloc(sizeof(t_exit));
return (&texit);
}
void gexit_init(void(*f)(void*), void *param)
{
t_exit **texit;
texit = exit_func();
(*texit)->param = param;
(*texit)->f = f;
}
//-------------------------------
// allocation list
//-------------------------------
t_list **alloc_lst()
{
static t_list *lst = NULL;
@@ -12,6 +45,9 @@ t_list **alloc_lst()
return (&lst);
}
//-------------------------------
// alloc, free, exit functions
//-------------------------------
void *gmalloc(size_t size)
{
void *tmp;
@@ -26,6 +62,11 @@ void *gmalloc(size_t size)
return (tmp);
}
static int comp_addr(void *to_find, void *to_compare)
{
return (to_find == to_compare);
}
void gfree(void *addr)
{
t_list **lst;
@@ -41,8 +82,12 @@ void gfree(void *addr)
void gexit(char *str)
{
t_list **lst;
t_exit **texit;
lst = alloc_lst();
texit = exit_func();
if ((*texit)->f)
(*texit)->f((*texit)->param);
ft_putstr_fd(str, 2);
ft_lstfree((*lst), free);
exit(0);