Sorts the faces of a room before rendering. Used for rendering in the editor. Parameters: rp - pointer to the room to be rendered
| 2138 | // Sorts the faces of a room before rendering. Used for rendering in the editor. |
| 2139 | // Parameters: rp - pointer to the room to be rendered |
| 2140 | void RenderRoomSorted(room *rp) { |
| 2141 | int vn, fn, i, rcount; |
| 2142 | int render_order[MAX_FACES_PER_ROOM]; |
| 2143 | ASSERT(rp->num_faces <= MAX_FACES_PER_ROOM); |
| 2144 | // Rotate all the points |
| 2145 | if (rp->wpb_index == -1) { |
| 2146 | rp->wpb_index = Global_buffer_index; |
| 2147 | // Katmai enhanced rotate only in a release build, because not |
| 2148 | // everyone has the intel compiler! |
| 2149 | #if (defined(RELEASE) && defined(KATMAI)) |
| 2150 | if (Katmai) |
| 2151 | RotateRoomPoints(rp, rp->verts4); |
| 2152 | else |
| 2153 | #endif |
| 2154 | RotateRoomPoints(rp, rp->verts); |
| 2155 | |
| 2156 | Global_buffer_index += rp->num_verts; |
| 2157 | } |
| 2158 | // Build list of visible (non-backfacing) faces, & compute average face depths |
| 2159 | for (fn = rcount = 0; fn < rp->num_faces; fn++) { |
| 2160 | face *fp = &rp->faces[fn]; |
| 2161 | |
| 2162 | if ((!(fp->flags & FF_VISIBLE)) || ((fp->flags & FF_NOT_FACING))) { |
| 2163 | fp->flags &= ~(FF_NOT_FACING | FF_VISIBLE); |
| 2164 | continue; // this guy shouldn't be rendered |
| 2165 | } |
| 2166 | // Clear visibility flags |
| 2167 | fp->flags &= ~(FF_VISIBLE | FF_NOT_FACING); |
| 2168 | |
| 2169 | if (!FaceIsRenderable(rp, fp)) |
| 2170 | continue; // skip this face |
| 2171 | #ifdef EDITOR |
| 2172 | if (In_editor_mode) { |
| 2173 | if ((Shell_render_flag & SRF_NO_NON_SHELL) && (fp->flags & FF_NOT_SHELL)) |
| 2174 | continue; |
| 2175 | if ((Shell_render_flag & SRF_NO_SHELL) && !(fp->flags & FF_NOT_SHELL)) |
| 2176 | continue; |
| 2177 | } |
| 2178 | #endif |
| 2179 | face_depth[fn] = 0; |
| 2180 | for (vn = 0; vn < fp->num_verts; vn++) |
| 2181 | face_depth[fn] += World_point_buffer[rp->wpb_index + fp->face_verts[vn]].p3_z; |
| 2182 | face_depth[fn] /= fp->num_verts; |
| 2183 | // initialize order list |
| 2184 | render_order[rcount] = fn; |
| 2185 | rcount++; |
| 2186 | } |
| 2187 | // Sort the faces |
| 2188 | qsort(render_order, rcount, sizeof(*render_order), (int (*)(const void *, const void *))room_face_sort_func); |
| 2189 | // Render the faces |
| 2190 | for (i = rcount - 1; i >= 0; i--) |
| 2191 | RenderFace(rp, render_order[i]); |
| 2192 | } |
| 2193 | |
| 2194 | // Sets up fog if this room is fogged |
| 2195 | void SetupRoomFog(room *rp, vector *eye, matrix *orient, int viewer_room) { |
no test coverage detected