Sorts our texture states using the quicksort algorithm
| 120 | } |
| 121 | // Sorts our texture states using the quicksort algorithm |
| 122 | void SortPostrenders() { |
| 123 | postrender_struct v, t; |
| 124 | int pop_val; |
| 125 | int i, j; |
| 126 | int l, r; |
| 127 | l = 0; |
| 128 | r = Num_postrenders - 1; |
| 129 | |
| 130 | uint16_t state_stack_counter = 0; |
| 131 | uint16_t state_stack[MAX_POSTRENDERS]; |
| 132 | |
| 133 | while (1) { |
| 134 | while (r > l) { |
| 135 | i = l - 1; |
| 136 | j = r; |
| 137 | v = Postrender_list[r]; |
| 138 | while (1) { |
| 139 | while (Postrender_list[++i].z < v.z) |
| 140 | ; |
| 141 | |
| 142 | while (Postrender_list[--j].z > v.z) |
| 143 | ; |
| 144 | |
| 145 | if (i >= j) |
| 146 | break; |
| 147 | |
| 148 | t = Postrender_list[i]; |
| 149 | Postrender_list[i] = Postrender_list[j]; |
| 150 | Postrender_list[j] = t; |
| 151 | } |
| 152 | |
| 153 | t = Postrender_list[i]; |
| 154 | Postrender_list[i] = Postrender_list[r]; |
| 155 | Postrender_list[r] = t; |
| 156 | |
| 157 | if (i - l > r - i) { |
| 158 | STATE_PUSH(l); |
| 159 | STATE_PUSH(i - 1); |
| 160 | l = i + 1; |
| 161 | } else { |
| 162 | STATE_PUSH(i + 1); |
| 163 | STATE_PUSH(r); |
| 164 | r = i - 1; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (!state_stack_counter) |
| 169 | break; |
| 170 | STATE_POP(); |
| 171 | r = pop_val; |
| 172 | STATE_POP(); |
| 173 | l = pop_val; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void SetupPostrenderRoom(room *rp) { |
| 178 | // Setup faces if this is a fogged room |