32 iReach(pObj->lightRange),
33 iFadeout(pObj->lightFadeoutRange),
34 iSize(20), gBright(0.5), colorR(1.0), colorG(1.0), colorB(1.0),
35 colorV(1.0), colorL(1.0),
48 for(
auto & section : sections)
54 for(
auto & section : sections)
55 section->Invalidate(r);
63 if (iReach == iReach2)
return;
69 for(
auto & section : sections)
70 section->Prune(iReach);
76 for(
auto & section : sections)
77 section->Dirty(iReach);
87 float min = std::min(colorR, std::min(colorG, colorB));
88 colorV = std::max(std::max(colorR, std::max(colorG, colorB)), 1e-3f);
89 colorL = (min + colorV) / 2.0f;
92 colorR = std::min(colorR / colorV, 1.0f);
93 colorG = std::min(colorG / colorV, 1.0f);
94 colorB = std::min(colorB / colorV, 1.0f);
109 if (iNX != iX || iNY != iY)
111 for(
auto & section : sections)
116 for(
auto & section : sections)
117 section->Update(Rec);
122 TriangleList triangles;
126 for(
auto & section : sections)
128 TriangleList sectionTriangles = section->CalculateTriangles(region);
132 if(!triangles.empty()) triangles.rbegin()->clipRight |= clip;
133 if(!sectionTriangles.empty()) sectionTriangles.begin()->clipLeft |= clip;
135 clip = sectionTriangles.empty();
136 triangles.splice(triangles.end(), sectionTriangles);
139 CalculateFanMaxed(triangles);
140 CalculateIntermediateFadeTriangles(triangles);
142 std::unique_ptr<C4FoWDrawStrategy>& strategy = onScreen ? OnScreenStrategy : OffScreenStrategy;
146 strategy = std::make_unique<C4FoWDrawWireframeStrategy>(
this, onScreen);
148 strategy = std::make_unique<C4FoWDrawLightTextureStrategy>(
this);
151 strategy->Begin(region);
153 DrawFan(strategy.get(), triangles);
154 DrawFanMaxed(strategy.get(), triangles);
155 DrawFade(strategy.get(), triangles);
156 DrawIntermediateFadeTriangles(strategy.get(), triangles);
161 void C4FoWLight::CalculateFanMaxed(TriangleList &triangles)
const
163 for (
auto & tri : triangles)
166 float dist = sqrt(GetSquaredDistanceTo(tri.fanLX, tri.fanLY));
168 tri.nfanLX = tri.fanLX;
169 tri.nfanLY = tri.fanLY;
174 tri.nfanLX = f * tri.fanLX + (1.0f - f) *
getX();
175 tri.nfanLY = f * tri.fanLY + (1.0f - f) *
getY();
179 dist = sqrt(GetSquaredDistanceTo(tri.fanRX, tri.fanRY));
181 tri.nfanRX = tri.fanRX;
182 tri.nfanRY = tri.fanRY;
185 tri.nfanRX = f * tri.fanRX + (1.0f - f) *
getX();
186 tri.nfanRY = f * tri.fanRY + (1.0f - f) *
getY();
191 void C4FoWLight::ProjectPointOutward(
float &x,
float &y,
float maxDistance)
const
195 x =
getX() + distanceDifference * (x-
getX());
196 y =
getY() + distanceDifference * (y-
getY());
199 void C4FoWLight::CalculateIntermediateFadeTriangles(TriangleList &triangles)
const
201 for (TriangleList::iterator it = triangles.begin(), nextIt = it; it != triangles.end(); ++it)
205 if(nextIt == triangles.end()) nextIt = triangles.begin();
210 if (tri.
clipRight || nextTri.clipLeft)
continue;
212 float distFadeR = GetSquaredDistanceTo(tri.
fadeRX, tri.
fadeRY);
213 float distNextFadeL = GetSquaredDistanceTo(nextTri.fadeLX, nextTri.fadeLY);
214 float distFanR = GetSquaredDistanceTo(tri.
fanRX, tri.
fanRY);
215 float distNextFanL = GetSquaredDistanceTo(nextTri.fanLX, nextTri.fanLY);
220 if (distFanR < distNextFadeL)
222 tri.
fadeIX = nextTri.fadeLX;
223 tri.
fadeIY = nextTri.fadeLY;
229 ProjectPointOutward(tri.
fadeIX, tri.
fadeIY, sqrt(distFadeR));
234 if (distNextFanL < distFadeR)
243 ProjectPointOutward(tri.
fadeIX, tri.
fadeIY, sqrt(distNextFadeL));
255 for (TriangleList::iterator it = triangles.begin(), nextIt = it; it != triangles.end(); ++it)
259 if(nextIt == triangles.end()) nextIt = triangles.begin();
265 if(nextIt == triangles.begin() || nextTri.nfanLX != tri.
nfanRX || nextTri.nfanLY != tri.
nfanRY)
271 void C4FoWLight::DrawFanMaxed(
C4FoWDrawStrategy* pen, TriangleList &triangles)
const
274 for (TriangleList::iterator it = triangles.begin(), nextIt = it; it != triangles.end(); ++it)
277 ++nextIt;
if(nextIt == triangles.end()) nextIt = triangles.begin();
289 if (tri.
nfanRX != nextTri.nfanLX || tri.
nfanRY != nextTri.nfanLY)
304 for (
auto & tri : triangles)
317 void C4FoWLight::DrawIntermediateFadeTriangles(
C4FoWDrawStrategy* pen, TriangleList &triangles)
const
320 for (TriangleList::iterator it = triangles.begin(), nextIt = it; it != triangles.end(); ++it)
324 if(nextIt == triangles.end()) nextIt = triangles.begin();
329 if (tri.
clipRight || nextTri.clipLeft)
continue;
340 if (tri.
fadeIY != nextTri.fadeLY || tri.
fadeIX != nextTri.fadeLX) {
367 if (!pObj || !
player)
return true;
int32_t Hostile(int32_t plr1, int32_t plr2)
int fixtoi(const C4Fixed &x)
#define GetGreenValue(rgb)
#define GetBlueValue(rgb)
virtual void BeginIntermediateFade()
virtual void DrawLightVertex(float x, float y)
virtual void EndIntermediateFade()
virtual void DrawDarkVertex(float x, float y)
virtual void EndFanMaxed()
virtual void BeginFanMaxed()
C4FoWLight(C4Object *pObj)
void SetReach(int32_t iReach, int32_t iFadeout)
void SetColor(uint32_t iValue)
void Invalidate(C4Rect r)
int32_t getTotalReach() const
bool IsVisibleForPlayer(C4Player *player) const
void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4ShaderCall &call)
int32_t getNormalSize() const
C4ValueArray * GetPropertyArray(C4PropertyName n) const
const C4Value & GetItem(int32_t iElem) const