Squeezes all the lightmaps down into as few 128x128s as possible
| 419 | |
| 420 | // Squeezes all the lightmaps down into as few 128x128s as possible |
| 421 | void SqueezeLightmaps(int external, int target_roomnum) { |
| 422 | int i, t, k; |
| 423 | mprintf(0, "Squeezing %s lightmaps, please wait...\n", external ? "external" : "internal"); |
| 424 | |
| 425 | Lmi_spoken_for = (uint8_t *)mem_malloc(MAX_LIGHTMAP_INFOS); |
| 426 | Lightmap_mask = (uint8_t *)mem_malloc(128 * 128); |
| 427 | Squeeze_lightmap_handle = -1; |
| 428 | |
| 429 | ASSERT(Lightmap_mask); |
| 430 | ASSERT(Lmi_spoken_for); |
| 431 | memset(Lmi_spoken_for, 0, MAX_LIGHTMAP_INFOS); |
| 432 | memset(Lightmap_mask, 0, 128 * 128); |
| 433 | |
| 434 | // Go through all the rooms and sqeeze them one by one |
| 435 | for (i = 0; i <= Highest_room_index; i++) { |
| 436 | room *rp = &Rooms[i]; |
| 437 | if (!rp->used) |
| 438 | continue; |
| 439 | if (rp->flags & RF_NO_LIGHT) |
| 440 | continue; |
| 441 | |
| 442 | if (external) { |
| 443 | if (!(rp->flags & RF_EXTERNAL)) |
| 444 | continue; |
| 445 | } else { |
| 446 | if ((rp->flags & RF_EXTERNAL)) |
| 447 | continue; |
| 448 | |
| 449 | if (target_roomnum != -1 && target_roomnum != i) |
| 450 | continue; |
| 451 | } |
| 452 | |
| 453 | // Go through each face |
| 454 | for (t = 0; t < rp->num_faces; t++) { |
| 455 | face *fp = &rp->faces[t]; |
| 456 | int lmi_handle = fp->lmi_handle; |
| 457 | |
| 458 | if (!(fp->flags & FF_LIGHTMAP)) |
| 459 | continue; |
| 460 | |
| 461 | if (lmi_handle == BAD_LMI_INDEX) |
| 462 | continue; |
| 463 | if (Lmi_spoken_for[lmi_handle]) |
| 464 | continue; |
| 465 | |
| 466 | lightmap_info *lmi = &LightmapInfo[lmi_handle]; |
| 467 | |
| 468 | int dest_x, dest_y; |
| 469 | int src_w = lmi->width; |
| 470 | int src_h = lmi->height; |
| 471 | |
| 472 | if (Squeeze_lightmap_handle == -1) { |
| 473 | memset(Lightmap_mask, 0, 128 * 128); |
| 474 | Squeeze_lightmap_handle = lm_AllocLightmap(128, 128); |
| 475 | uint16_t *fill_data = (uint16_t *)lm_data(Squeeze_lightmap_handle); |
| 476 | memset(fill_data, 0, 128 * 128 * 2); |
| 477 | } |
| 478 |
no test coverage detected