1 .float(entity,entity) sort_cmp;
2 .entity sort_next, sort_prev;
13 entity Sort_New(float(entity,entity) cmp)
18 sort.sort_next = NULL;
23 void Sort_Remove(entity sort)
28 next = sort.sort_next;
35 void Sort_Add(entity sort, entity ent)
39 next = sort.sort_next;
42 if(!sort.sort_cmp(next, ent))
45 next = next.sort_next;
48 ent.sort_prev = parent;
49 parent.sort_next = ent;
54 void Sort_Reset(entity sort)
59 float Sort_HasNext(entity sort)
61 return (sort.chain.sort_next != NULL);
64 entity Sort_Next(entity sort)
67 next = sort.chain.sort_next;
70 sort.chain.sort_next = next;
71 next.sort_prev = sort.chain;
72 next.sort_next = NULL;
78 void Sort_Finish(entity sort)
87 sort = next.sort_next;
88 next.sort_next = sort.sort_next;
93 entity Sort_Get(entity sort, float i)
95 for(; sort.sort_next && i > 0; --i)
96 sort = sort.sort_next;
101 * Swap two neighbours in a sortlist.
102 * @param a FIRST entity
103 * @param b entity after a
105 #define SORT_SWAP(a,b) \
106 b.sort_prev = a.sort_prev; \
107 a.sort_next = b.sort_next; \
108 if(b.sort_next) b.sort_next.sort_prev = a; \
109 if(a.sort_prev) a.sort_prev.sort_next = b; \
113 void Sort_Erase(entity ent)
115 ent.sort_prev.sort_next = ent.sort_next;
117 ent.sort_next.sort_prev = ent.sort_prev;
121 void Sort_RemoveOld(entity sort)
124 for(tmp = sort.sort_next; tmp; tmp = tmp.sort_next)
129 Sort_Erase(tmp.sort_next);