]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/sortlist.qc
Add a hack to fix the use of self in .predraw functions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / sortlist.qc
1 #include "sortlist.qh"
2
3 entity Sort_Spawn()
4 {
5         entity sort = new(sortlist);
6         make_pure(sort);
7         sort.sort_next = NULL;
8         sort.chain = sort;
9         return sort;
10 }
11 /*
12 entity Sort_New(float(entity,entity) cmp)
13 {
14     entity sort;
15     sort = spawn();
16     sort.sort_cmp = cmp;
17     sort.sort_next = world;
18     sort.chain = sort;
19     return sort;
20 }
21
22 void Sort_Remove(entity sort)
23 {
24     entity next;
25     while(sort.sort_next)
26     {
27         next = sort.sort_next;
28         remove(sort);
29         sort = next;
30     }
31     remove(sort);
32 }
33
34 void Sort_Add(entity sort, entity ent)
35 {
36     entity next, parent;
37     parent = sort;
38     next = sort.sort_next;
39     while(next)
40     {
41         if(!sort.sort_cmp(next, ent))
42             break;
43         parent = next;
44         next = next.sort_next;
45     }
46     ent.sort_next = next;
47     ent.sort_prev = parent;
48     parent.sort_next = ent;
49     if(next)
50         next.sort_prev = ent;
51 }
52
53 void Sort_Reset(entity sort)
54 {
55     sort.chain = sort;
56 }
57
58 float Sort_HasNext(entity sort)
59 {
60     return (sort.chain.sort_next != world);
61 }
62
63 entity Sort_Next(entity sort)
64 {
65     entity next;
66     next = sort.chain.sort_next;
67     if(!next) {
68         next = spawn();
69         sort.chain.sort_next = next;
70         next.sort_prev = sort.chain;
71         next.sort_next = world;
72     }
73     sort.chain = next;
74     return next;
75 }
76
77 void Sort_Finish(entity sort)
78 {
79     entity next;
80     next = sort.chain;
81     if(!next)
82         return;
83
84     while(next.sort_next)
85     {
86         sort = next.sort_next;
87         next.sort_next = sort.sort_next;
88         remove(sort);
89     }
90 }
91
92 entity Sort_Get(entity sort, float i)
93 {
94     for (; sort.sort_next && i > 0; --i)
95         sort = sort.sort_next;
96     return sort;
97 }
98 */
99
100 /*
101 void Sort_Erase(entity ent)
102 {
103     ent.sort_prev.sort_next = ent.sort_next;
104     if(ent.sort_next)
105         ent.sort_next.sort_prev = ent.sort_prev;
106     remove(ent);
107 }
108
109 void Sort_RemoveOld(entity sort)
110 {
111     entity tmp;
112     for(tmp = sort.sort_next; tmp; tmp = tmp.sort_next)
113     {
114         if(tmp.frame < time)
115         {
116             tmp = tmp.sort_prev;
117             Sort_Erase(tmp.sort_next);
118         }
119     }
120 }
121 */