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