| 88 | // Returns lightmap handle if successful, -1 if otherwise |
| 89 | |
| 90 | int AllocLightmapInfo(int w, int h, int type, bool alloc_lightmap) { |
| 91 | int n, i; |
| 92 | |
| 93 | if (Dedicated_server) |
| 94 | Int3(); // Shouldn't be here! |
| 95 | |
| 96 | if (Num_of_lightmap_info > MAX_LIGHTMAP_INFOS) |
| 97 | Int3(); // Get Jason, ran out of lightmaps! |
| 98 | |
| 99 | n = Free_lmi_list[Num_of_lightmap_info++]; |
| 100 | ASSERT(LightmapInfo[n].used == 0); |
| 101 | |
| 102 | ASSERT(n >= 0 && n < MAX_LIGHTMAP_INFOS); |
| 103 | |
| 104 | /*for (i=Highest_lmi_index;i<MAX_LIGHTMAP_INFOS;i++) |
| 105 | { |
| 106 | if (LightmapInfo[i].used==0) |
| 107 | { |
| 108 | n=i; |
| 109 | break; |
| 110 | } |
| 111 | }*/ |
| 112 | |
| 113 | // If we can't find a free slot in which to alloc, bail out |
| 114 | /*if (i==MAX_LIGHTMAP_INFOS) |
| 115 | { |
| 116 | Int3(); |
| 117 | mprintf(0,"ERROR! Couldn't find a free lightmap info to alloc!\n"); |
| 118 | return -1; |
| 119 | }*/ |
| 120 | |
| 121 | memset(&LightmapInfo[n], 0, sizeof(lightmap_info)); |
| 122 | |
| 123 | ASSERT(w >= 2 && h >= 2); |
| 124 | |
| 125 | if (alloc_lightmap) { |
| 126 | LightmapInfo[n].lm_handle = lm_AllocLightmap(w, h); |
| 127 | ASSERT(LightmapInfo[n].lm_handle != BAD_LM_INDEX); // Make sure we have a valid lightmap |
| 128 | |
| 129 | uint16_t *dest_data = lm_data(LightmapInfo[n].lm_handle); |
| 130 | |
| 131 | // Set the lightmap to be transparent |
| 132 | for (i = 0; i < w * h; i++) |
| 133 | dest_data[i] = NEW_TRANSPARENT_COLOR; |
| 134 | } |
| 135 | |
| 136 | LightmapInfo[n].used = 1; |
| 137 | LightmapInfo[n].type = type; |
| 138 | LightmapInfo[n].dynamic = BAD_LM_INDEX; |
| 139 | LightmapInfo[n].spec_map = -1; |
| 140 | LightmapInfo[n].width = w; |
| 141 | LightmapInfo[n].height = h; |
| 142 | LightmapInfo[n].x1 = 0; |
| 143 | LightmapInfo[n].y1 = 0; |
| 144 | |
| 145 | return n; |
| 146 | } |
| 147 |
no test coverage detected