MLX42 1.0
MLX42
Loading...
Searching...
No Matches
mlx_list.c File Reference
#include "MLX42/MLX42_Int.h"
Include dependency graph for mlx_list.c:

Go to the source code of this file.

Functions

int32_t mlx_lstsize (mlx_list_t *lst)
 
static void mlx_lstdelone (mlx_list_t *lst, void(*del)(void *))
 
void mlx_lstclear (mlx_list_t **lst, void(*del)(void *))
 
mlx_list_tmlx_lstnew (void *content)
 
mlx_list_tmlx_lstlast (mlx_list_t *lst)
 
void mlx_lstadd_back (mlx_list_t **lst, mlx_list_t *new)
 
void mlx_lstadd_front (mlx_list_t **lst, mlx_list_t *new)
 
mlx_list_tmlx_lstremove (mlx_list_t **lst, void *value, bool(*comp)(void *, void *))
 
static int32_t mlx_getzdata (mlx_list_t *entry)
 
static void mlx_insertsort (mlx_list_t **head, mlx_list_t *new)
 
void mlx_sort_renderqueue (mlx_list_t **lst)
 

Function Documentation

◆ mlx_getzdata()

static int32_t mlx_getzdata ( mlx_list_t entry)
static

Definition at line 118 of file mlx_list.c.

119{
120 const draw_queue_t* queue = entry->content;
121
122 return (queue->image->instances[queue->instanceid].z);
123}
GLuint GLsizei GLsizei * length
Definition glad.h:3372
Here is the caller graph for this function:

◆ mlx_insertsort()

static void mlx_insertsort ( mlx_list_t **  head,
mlx_list_t new 
)
static

Definition at line 126 of file mlx_list.c.

127{
129
130 if (*head == NULL)
131 *head = new;
132 else if (mlx_getzdata(*head) >= mlx_getzdata(new))
133 {
134 new->next = *head;
135 new->next->prev = new;
136 *head = new;
137 }
138 else
139 {
140 current = *head;
141
142 // Find insertion location.
143 while (current->next != NULL && mlx_getzdata(current->next) < mlx_getzdata(new))
145 new->next = current->next;
146
147 // Insert at the end
148 if (current->next != NULL)
149 new->next->prev = new;
150 current->next = new;
151 new->prev = current;
152 }
153}
static int32_t mlx_getzdata(mlx_list_t *entry)
Definition mlx_list.c:118
struct mlx_list * next
Definition MLX42_Int.h:88
struct mlx_list * prev
Definition MLX42_Int.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_lstadd_back()

void mlx_lstadd_back ( mlx_list_t **  lst,
mlx_list_t new 
)

Definition at line 67 of file mlx_list.c.

68{
69 if (!lst || !new)
70 return;
71 if (!*lst)
72 *lst = new;
73 else
74 {
76 new->prev = temp;
77 temp->next = new;
78 }
79}
mlx_list_t * mlx_lstlast(mlx_list_t *lst)
Definition mlx_list.c:58
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_lstadd_front()

void mlx_lstadd_front ( mlx_list_t **  lst,
mlx_list_t new 
)

Definition at line 81 of file mlx_list.c.

82{
83 if (!lst || !new)
84 return;
85 if ((*lst) != NULL)
86 (*lst)->prev = new;
87 new->next = *lst;
88 new->prev = NULL;
89 *lst = new;
90}
Here is the caller graph for this function:

◆ mlx_lstclear()

void mlx_lstclear ( mlx_list_t **  lst,
void(*)(void *)  del 
)

Definition at line 33 of file mlx_list.c.

34{
36
37 while (*lst != NULL)
38 {
39 next_lst = (*lst)->next;
41 *lst = next_lst;
42 }
43}
static void mlx_lstdelone(mlx_list_t *lst, void(*del)(void *))
Definition mlx_list.c:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_lstdelone()

static void mlx_lstdelone ( mlx_list_t lst,
void(*)(void *)  del 
)
static

Definition at line 26 of file mlx_list.c.

27{
28 if (del != NULL)
29 del(lst->content);
30 free(lst);
31}
Here is the caller graph for this function:

◆ mlx_lstlast()

mlx_list_t * mlx_lstlast ( mlx_list_t lst)

Definition at line 58 of file mlx_list.c.

59{
60 if (!lst)
61 return (NULL);
62 while (lst->next)
63 lst = lst->next;
64 return (lst);
65}
Here is the caller graph for this function:

◆ mlx_lstnew()

mlx_list_t * mlx_lstnew ( void content)

All sorts of internal functions shared in the library that should not be accessible to the user! No touch!

Definition at line 45 of file mlx_list.c.

46{
48
49 if ((out = malloc(sizeof(mlx_list_t))))
50 {
51 out->content = content;
52 out->next = NULL;
53 out->prev = NULL;
54 }
55 return (out);
56}
void * content
Definition MLX42_Int.h:87
Here is the caller graph for this function:

◆ mlx_lstremove()

mlx_list_t * mlx_lstremove ( mlx_list_t **  lst,
void value,
bool(*)(void *, void *)  comp 
)

Removes the specified content from the list, if found. Also fixes any relinking that might be needed.

Parameters
[in]lstThe list
[in]compFunction to check if the content and value are the same.
Returns
The removed element, clean up as you wish.

Definition at line 100 of file mlx_list.c.

101{
103
104 while (lstcpy && !comp(lstcpy->content, value))
105 lstcpy = lstcpy->next;
106 if (lstcpy == NULL)
107 return (NULL);
108 if (lstcpy == *lst)
109 *lst = lstcpy->next;
110 if (lstcpy->next != NULL)
112 if (lstcpy->prev != NULL)
114 return (lstcpy);
115}
GLfloat value
Definition glad.h:2667
Here is the caller graph for this function:

◆ mlx_lstsize()

int32_t mlx_lstsize ( mlx_list_t lst)

Definition at line 17 of file mlx_list.c.

18{
19 int32_t i;
20
21 for (i = 0; lst != NULL; i++)
22 lst = lst->next;
23 return (i);
24}

◆ mlx_sort_renderqueue()

void mlx_sort_renderqueue ( mlx_list_t **  lst)

Okay-ish sorting algorithm to sort the render queue / doubly linked list. We need to do this to fix transparency.

Parameters
lstThe render queue.

Definition at line 161 of file mlx_list.c.

162{
165
166 while (lstcpy != NULL)
167 {
168 mlx_list_t* next = lstcpy->next;
169
170 // Separate entry out of list and insert it back but sorted.
171 lstcpy->prev = lstcpy->next = NULL;
173 lstcpy = next;
174 }
175 *lst = sorted;
176}
static void mlx_insertsort(mlx_list_t **head, mlx_list_t *new)
Definition mlx_list.c:126
Here is the call graph for this function:
Here is the caller graph for this function: