Render the objects and viseffects in a room. Do a simple sort
| 3118 | uint8_t Trick_type = 0; |
| 3119 | // Render the objects and viseffects in a room. Do a simple sort |
| 3120 | void RenderRoomObjects(room *rp) { |
| 3121 | int n_objs = 0, objnum, i, visnum; |
| 3122 | float zdist; |
| 3123 | if (!Render_mirror_for_room && UseHardware) |
| 3124 | return; // This function only works for mirrors now |
| 3125 | |
| 3126 | // Add objects to sort list |
| 3127 | for (objnum = rp->objects; (objnum != -1) && (n_objs < MAX_OBJECTS_PER_ROOM); objnum = Objects[objnum].next) { |
| 3128 | ASSERT(objnum != Objects[objnum].next); |
| 3129 | object *obj = &Objects[objnum]; |
| 3130 | |
| 3131 | if (obj->render_type == RT_NONE) |
| 3132 | continue; |
| 3133 | if (obj == Viewer_object && !Render_mirror_for_room) |
| 3134 | continue; |
| 3135 | float size = obj->size; |
| 3136 | // Special case weapons with streamers |
| 3137 | if (obj->type == OBJ_WEAPON && (Weapons[obj->id].flags & WF_STREAMER)) |
| 3138 | size = Weapons[obj->id].phys_info.velocity.z; |
| 3139 | // Check if object is trivially rejected |
| 3140 | bool isVisible = IsPointVisible(&obj->pos, size, &zdist) ? true : false; |
| 3141 | if (Render_mirror_for_room || (obj->type == OBJ_WEAPON && Weapons[obj->id].flags & WF_ELECTRICAL) || isVisible) { |
| 3142 | obj_sort_list[n_objs].vis_effect = 0; |
| 3143 | obj_sort_list[n_objs].objnum = objnum; |
| 3144 | obj_sort_list[n_objs].dist = zdist; |
| 3145 | n_objs++; |
| 3146 | } |
| 3147 | } |
| 3148 | // Add vis effects to sort list |
| 3149 | for (visnum = rp->vis_effects; (visnum != -1) && (n_objs < MAX_OBJECTS_PER_ROOM); visnum = VisEffects[visnum].next) { |
| 3150 | ASSERT(visnum != VisEffects[visnum].next); |
| 3151 | if (VisEffects[visnum].type == VIS_NONE || VisEffects[visnum].flags & VF_DEAD) |
| 3152 | continue; |
| 3153 | |
| 3154 | bool pointIsVisible = IsPointVisible(&VisEffects[visnum].pos, VisEffects[visnum].size, &zdist) ? true : false; |
| 3155 | if (Render_mirror_for_room || pointIsVisible) { |
| 3156 | obj_sort_list[n_objs].vis_effect = 1; |
| 3157 | obj_sort_list[n_objs].objnum = visnum; |
| 3158 | obj_sort_list[n_objs].dist = zdist; |
| 3159 | n_objs++; |
| 3160 | } |
| 3161 | } |
| 3162 | ASSERT(objnum == -1); // if not -1, ran out of space in render_order[] |
| 3163 | ASSERT(visnum == -1); // if not -1, ran out of space in render_order[] |
| 3164 | // Sort the objects |
| 3165 | qsort(obj_sort_list, n_objs, sizeof(*obj_sort_list), (int (*)(const void *, const void *))obj_sort_func); |
| 3166 | #ifdef _DEBUG |
| 3167 | bool save_polymodel_outline_mode = Polymodel_outline_mode; |
| 3168 | Polymodel_outline_mode = OUTLINE_ON(OM_OBJECTS); |
| 3169 | #endif |
| 3170 | // Render the objects |
| 3171 | if (UseHardware && Render_mirror_for_room) { |
| 3172 | // Render the mirror stuff if present |
| 3173 | room *mirror_rp = &Rooms[Mirror_room]; |
| 3174 | vector *mirror_vec = &mirror_rp->verts[mirror_rp->faces[mirror_rp->mirror_face].face_verts[0]]; |
| 3175 | face *mirror_fp = &mirror_rp->faces[mirror_rp->mirror_face]; |
| 3176 | vector *norm = &mirror_fp->normal; |
| 3177 | // This is how far the mirror face is from the normalized plane |
no test coverage detected