Sets up radiosity surfaces for objects in the mine Returns the number of new surfaces
| 284 | // Sets up radiosity surfaces for objects in the mine |
| 285 | // Returns the number of new surfaces |
| 286 | int ComputeSurfacesForObjects(int surface_index, int terrain) { |
| 287 | int i, t, j; |
| 288 | |
| 289 | for (i = 0; i <= Highest_object_index; i++) { |
| 290 | if ((terrain != 0) != (OBJECT_OUTSIDE(&Objects[i]) != 0)) |
| 291 | continue; |
| 292 | |
| 293 | if (Objects[i].type != OBJ_NONE && Objects[i].lighting_render_type == LRT_LIGHTMAPS) { |
| 294 | poly_model *po = &Poly_models[Objects[i].rtype.pobj_info.model_num]; |
| 295 | |
| 296 | if (!po->new_style) |
| 297 | continue; |
| 298 | |
| 299 | SetupObjectLightmapMemory(&Objects[i]); |
| 300 | |
| 301 | if (terrain) |
| 302 | CombineObjectLightmapUVs(&Objects[i], LMI_TERRAIN_OBJECT); |
| 303 | else |
| 304 | CombineObjectLightmapUVs(&Objects[i], LMI_ROOM_OBJECT); |
| 305 | |
| 306 | for (t = 0; t < po->n_models; t++) { |
| 307 | bsp_info *sm = &po->submodel[t]; |
| 308 | |
| 309 | if (IsNonRenderableSubmodel(po, t)) |
| 310 | continue; |
| 311 | |
| 312 | for (j = 0; j < sm->num_faces; j++, surface_index++) { |
| 313 | ComputeObjectSurfaceRes(&Light_surfaces[surface_index], &Objects[i], t, j); |
| 314 | |
| 315 | if (sm->faces[j].nverts > 0) { |
| 316 | Light_surfaces[surface_index].verts = (vector *)mem_malloc(sm->faces[j].nverts * sizeof(vector)); |
| 317 | ASSERT(Light_surfaces[surface_index].verts != NULL); |
| 318 | } else |
| 319 | Light_surfaces[surface_index].verts = NULL; |
| 320 | |
| 321 | if (Light_surfaces[surface_index].xresolution * Light_surfaces[surface_index].yresolution > 0) { |
| 322 | Light_surfaces[surface_index].elements = |
| 323 | (rad_element *)mem_malloc(Light_surfaces[surface_index].xresolution * |
| 324 | Light_surfaces[surface_index].yresolution * sizeof(rad_element)); |
| 325 | ASSERT(Light_surfaces[surface_index].elements != NULL); |
| 326 | } else |
| 327 | Light_surfaces[surface_index].elements = NULL; |
| 328 | |
| 329 | Light_surfaces[surface_index].flags = 0; |
| 330 | |
| 331 | if (sm->faces[j].texnum == -1) { |
| 332 | Light_surfaces[surface_index].emittance.r = 0; |
| 333 | Light_surfaces[surface_index].emittance.g = 0; |
| 334 | Light_surfaces[surface_index].emittance.b = 0; |
| 335 | Light_surfaces[surface_index].reflectivity = .5; |
| 336 | } else { |
| 337 | Light_surfaces[surface_index].emittance.r = (float)GameTextures[po->textures[sm->faces[j].texnum]].r; |
| 338 | Light_surfaces[surface_index].emittance.g = (float)GameTextures[po->textures[sm->faces[j].texnum]].g; |
| 339 | Light_surfaces[surface_index].emittance.b = (float)GameTextures[po->textures[sm->faces[j].texnum]].b; |
| 340 | Light_surfaces[surface_index].reflectivity = GameTextures[po->textures[sm->faces[j].texnum]].reflectivity; |
| 341 | if ((GetMaxColor(&Light_surfaces[surface_index].emittance)) > .005) |
| 342 | Light_surfaces[surface_index].flags |= SF_LIGHTSOURCE; |
| 343 | } |
no test coverage detected