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

Function CopySqueezeDataForRooms

editor/editor_lighting.cpp:171–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void CopySqueezeDataForRooms(int roomnum, int facenum, uint16_t *dest_data, int dest_x, int dest_y) {
172 room *rp = &Rooms[roomnum];
173 lightmap_info *lmi_ptr = &LightmapInfo[rp->faces[facenum].lmi_handle];
174 uint16_t *src_data = (uint16_t *)lm_data(lmi_ptr->lm_handle);
175
176 int w = lmi_ptr->width;
177 int h = lmi_ptr->height;
178
179 // Copy over the actual lightmap data
180 CopySqueezeBodyAndEdges(dest_data, src_data, w, h, dest_x, dest_y);
181
182 // Now alter all face uvs that have this lightmap info
183 float dest_u = (float)(dest_x + 1) / 128.0;
184 float dest_v = (float)(dest_y + 1) / 128.0;
185
186 float u_scalar = (float)w / 128.0;
187 float v_scalar = (float)h / 128.0;
188
189 for (int t = roomnum; t <= Highest_room_index; t++) {
190 room *this_rp = &Rooms[t];
191 if (!this_rp->used)
192 continue;
193
194 for (int j = 0; j < this_rp->num_faces; j++) {
195
196 if (!(this_rp->faces[j].flags & FF_LIGHTMAP))
197 continue;
198
199 if (this_rp->faces[j].lmi_handle == BAD_LMI_INDEX)
200 continue;
201
202 if (Lmi_spoken_for[this_rp->faces[j].lmi_handle])
203 continue;
204 if (this_rp->faces[j].lmi_handle == rp->faces[facenum].lmi_handle) {
205 lmi_ptr->x1 = dest_x + 1;
206 lmi_ptr->y1 = dest_y + 1;
207
208 // We have to alter our uvs for this face to reflect our change
209 face *fp = &this_rp->faces[j];
210 for (int k = 0; k < fp->num_verts; k++) {
211 fp->face_uvls[k].u2 *= u_scalar;
212 fp->face_uvls[k].u2 += dest_u;
213
214 fp->face_uvls[k].v2 *= v_scalar;
215 fp->face_uvls[k].v2 += dest_v;
216 }
217 }
218 }
219 }
220
221 ASSERT(rp->faces[facenum].lmi_handle != BAD_LMI_INDEX);
222
223 Lmi_spoken_for[rp->faces[facenum].lmi_handle] = 1;
224
225 // Free our old lightmap
226 GameLightmaps[lmi_ptr->lm_handle].used = 1;
227 lm_FreeLightmap(lmi_ptr->lm_handle);
228

Callers 1

SqueezeLightmapsFunction · 0.85

Calls 3

lm_dataFunction · 0.85
CopySqueezeBodyAndEdgesFunction · 0.85
lm_FreeLightmapFunction · 0.85

Tested by

no test coverage detected