player rotates and moves, rays for raycasting on map
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
t_exit **mb_exit_func();
|
||||
t_list **mb_lst();
|
||||
int mb_comp_addr(void *to_find, void *to_compare);
|
||||
void mb_set_params_exit(void (*f)(void *), void *param);
|
||||
void mb_exec_exit_func();
|
||||
t_list **mb_get_lst(void);
|
||||
int mb_comp_addr(void *to_find, void *to_compare);
|
||||
|
||||
void mb_init(void(*f)(void*), void *param)
|
||||
void mb_init(void (*f)(void *), void *param)
|
||||
{
|
||||
t_exit **texit;
|
||||
|
||||
texit = mb_exit_func();
|
||||
(*texit)->param = param;
|
||||
(*texit)->f = f;
|
||||
mb_set_params_exit(f, param);
|
||||
}
|
||||
|
||||
void *mb_alloc(size_t size)
|
||||
@@ -18,7 +15,7 @@ void *mb_alloc(size_t size)
|
||||
void *tmp;
|
||||
t_list **lst;
|
||||
|
||||
lst = mb_lst();
|
||||
lst = mb_get_lst();
|
||||
tmp = ft_memalloc(size);
|
||||
if (!tmp)
|
||||
mb_exit(B_RED"failed create new allocation"RESET"\n");
|
||||
@@ -31,7 +28,7 @@ void mb_add(void *addr)
|
||||
{
|
||||
t_list **lst;
|
||||
|
||||
lst = mb_lst();
|
||||
lst = mb_get_lst();
|
||||
if (!ft_lstpush_back(lst, ft_lstcreate(addr)))
|
||||
mb_exit(B_RED"failed add new element to list"RESET"\n");
|
||||
}
|
||||
@@ -41,22 +38,19 @@ void mb_free(void *addr)
|
||||
t_list **lst;
|
||||
t_list *tmp;
|
||||
|
||||
lst = mb_lst();
|
||||
lst = mb_get_lst();
|
||||
tmp = ft_lstfind((*lst), addr, mb_comp_addr);
|
||||
if (!tmp)
|
||||
ft_putstr_fd(B_RED"element to free doesn't exist (maybe it was already freed)"RESET"\n", 2);
|
||||
ft_putstr_fd(B_RED"you try to free not allocated address"RESET"\n", 2);
|
||||
ft_lsterase(tmp, free);
|
||||
}
|
||||
|
||||
void mb_exit(char *str)
|
||||
{
|
||||
t_list **lst;
|
||||
t_exit **texit;
|
||||
|
||||
lst = mb_lst();
|
||||
texit = mb_exit_func();
|
||||
if ((*texit)->f)
|
||||
(*texit)->f((*texit)->param);
|
||||
lst = mb_get_lst();
|
||||
mb_exec_exit_func();
|
||||
ft_putstr_fd(str, 2);
|
||||
ft_lstfree((*lst), free);
|
||||
exit(0);
|
||||
|
||||
@@ -1,15 +1,46 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
t_exit **mb_exit_func()
|
||||
{
|
||||
static t_exit *texit = NULL;
|
||||
/* private struct definition :
|
||||
* https://stackoverflow.com/questions/71724770/prototype-of-a-struct-in-c
|
||||
* it wasn't necessary after all :p I just added setters and getters here
|
||||
*/
|
||||
|
||||
if (!texit)
|
||||
texit = mb_alloc(sizeof(t_exit));
|
||||
return (&texit);
|
||||
typedef void(*t_mb_func_exit)(void*);
|
||||
|
||||
typedef struct s_mb_exit
|
||||
{
|
||||
t_mb_func_exit f;
|
||||
void *param;
|
||||
} t_mb_exit;
|
||||
|
||||
static t_mb_exit *mb_get_exit_struct(void)
|
||||
{
|
||||
static t_mb_exit *mbexit = NULL;
|
||||
|
||||
if (!mbexit)
|
||||
mbexit = mb_alloc(sizeof(t_mb_exit));
|
||||
return (mbexit);
|
||||
}
|
||||
|
||||
t_list **mb_lst()
|
||||
void mb_set_params_exit(void (*f)(void *), void *param)
|
||||
{
|
||||
t_mb_exit *mbexit;
|
||||
|
||||
mbexit = mb_get_exit_struct();
|
||||
mbexit->param = param;
|
||||
mbexit->f = f;
|
||||
}
|
||||
|
||||
void mb_exec_exit_func(void)
|
||||
{
|
||||
t_mb_exit *mbexit;
|
||||
|
||||
mbexit = mb_get_exit_struct();
|
||||
if (mbexit->f)
|
||||
mbexit->f(mbexit->param);
|
||||
}
|
||||
|
||||
t_list **mb_get_lst(void)
|
||||
{
|
||||
static t_list *lst = NULL;
|
||||
|
||||
@@ -20,4 +51,3 @@ int mb_comp_addr(void *to_find, void *to_compare)
|
||||
{
|
||||
return (to_find == to_compare);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user