MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / WriteLightmapChunk

Function WriteLightmapChunk

Descent3/LoadLevel.cpp:4888–4973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4886}
4887
4888void WriteLightmapChunk(CFILE *fp) {
4889 int start_pos;
4890 int i;
4891 int lightmap_info_count = 0;
4892 int lightmap_count = 0;
4893
4894 uint16_t *lightmap_remap = (uint16_t *)mem_malloc(MAX_LIGHTMAPS * sizeof(uint16_t));
4895 uint8_t *lightmap_spoken_for = (uint8_t *)mem_malloc(MAX_LIGHTMAPS);
4896
4897 ASSERT(lightmap_remap);
4898 ASSERT(lightmap_spoken_for);
4899
4900 memset(lightmap_spoken_for, 0, MAX_LIGHTMAPS);
4901
4902 // Build a lightmap remap list
4903 for (i = 0; i < MAX_LIGHTMAP_INFOS; i++) {
4904 if (LightmapInfo[i].used && LightmapInfo[i].type != LMI_DYNAMIC) {
4905 if (!lightmap_spoken_for[LightmapInfo[i].lm_handle]) {
4906 lightmap_spoken_for[LightmapInfo[i].lm_handle] = 1;
4907 lightmap_remap[LightmapInfo[i].lm_handle] = lightmap_count;
4908
4909 lightmap_count++;
4910 }
4911
4912 LightmapInfoRemap[i] = lightmap_info_count;
4913 lightmap_info_count++;
4914 } else
4915 LightmapInfoRemap[i] = BAD_LMI_INDEX;
4916 }
4917
4918 memset(lightmap_spoken_for, 0, MAX_LIGHTMAPS);
4919 start_pos = StartChunk(fp, CHUNK_NEW_LIGHTMAPS);
4920
4921 cf_WriteInt(fp, lightmap_count);
4922
4923 // Write out lightmap texture data
4924 for (i = 0; i < MAX_LIGHTMAP_INFOS; i++) {
4925 if (LightmapInfo[i].used && LightmapInfo[i].type != LMI_DYNAMIC) {
4926 if (!lightmap_spoken_for[LightmapInfo[i].lm_handle]) {
4927 lightmap_spoken_for[LightmapInfo[i].lm_handle] = 1;
4928 int w = lm_w(LightmapInfo[i].lm_handle);
4929 int h = lm_h(LightmapInfo[i].lm_handle);
4930
4931 ASSERT(w >= 2 && w <= 128);
4932 ASSERT(h >= 2 && h <= 128);
4933
4934 cf_WriteShort(fp, w);
4935 cf_WriteShort(fp, h);
4936
4937 uint16_t *data = lm_data(LightmapInfo[i].lm_handle);
4938 ASSERT(data != NULL);
4939
4940 CheckToWriteCompressShort(fp, data, w * h);
4941 }
4942 }
4943 }
4944
4945 cf_WriteInt(fp, lightmap_info_count);

Callers 1

SaveLevelFunction · 0.85

Calls 11

StartChunkFunction · 0.85
cf_WriteIntFunction · 0.85
lm_wFunction · 0.85
lm_hFunction · 0.85
cf_WriteShortFunction · 0.85
lm_dataFunction · 0.85
lmi_wFunction · 0.85
lmi_hFunction · 0.85
cf_WriteByteFunction · 0.85
EndChunkFunction · 0.85

Tested by

no test coverage detected