Skip to content

Commit

Permalink
Clean up SetObjectLight a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
SiriusTR committed Dec 12, 2019
1 parent fd3d26e commit 449a495
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/LightManager.Illuminate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,34 +879,35 @@ return (cornerLights [0] != 0.0) || (cornerLights [1] != 0.0) || (cornerLights [
void CLightManager::SetObjectLight (bool bAll, bool bDynSegLights)
{
double fLight = m_fObjectLight / 100.0;
long nLight = D2X (fLight) * 12; //24.0 * 327.68);
// SegmentTool scales light values by about 12. I don't really know why, and haven't found anything
// that explains it in D1/D2 source, but it looks about right when examining in-built levels.
// So leaving it like this for now.
long nLight = D2X (fLight) * 12;

undoManager.Begin (__FUNCTION__, udSegments);
int nSegments = segmentManager.Count ();
for (int si = 0; si < nSegments; si++) {
CSegment* pSegment = segmentManager.Segment (si);
if (!bDynSegLights) {
if (bAll || (pSegment->IsTagged ()))
if (bAll || (pSegment->IsTagged ())) {
if (!bDynSegLights) {
pSegment->m_info.staticLight = nLight;
}
else {
int l = 0;
int c = 0;
CSide* pSide = pSegment->m_sides;
for (short nSide = 0; nSide < 6; nSide++) {
if (bAll || pSide->IsTagged ()) {
for (short nCorner = 0; nCorner < 4; nCorner++) {
uint h = (uint) pSide [nSide].m_info.uvls [nCorner].l;
if (h || !pSide->IsVisible ()) {
l += h;
}
else {
int l = 0;
int c = 0;
CSide* pSide = pSegment->m_sides;
for (short nSide = 0; nSide < 6; nSide++) {
if (pSide->FaceCount () > 0) {
for (short nCorner = 0; nCorner < pSide->VertexCount (); nCorner++) {
l += pSide [nSide].m_info.uvls [nCorner].l;
c++;
}
}
}
pSegment->Backup ();
// Multiply by an extra 2 because of how corner lights are scaled (65536 = 200%)
pSegment->m_info.staticLight = c ? D2X (fLight * (X2D (l) / (double) c)) * 2 * 12 : nLight;
}
pSegment->Backup ();
// Segment light values seem to be higher than corner light values - factor of about 12
pSegment->m_info.staticLight = (int) (c ? fLight * ((double) l / (double) c) * 2 * 12 : nLight);
}
}
undoManager.End (__FUNCTION__);
Expand Down

0 comments on commit 449a495

Please sign in to comment.