|
|
|
@ -336,13 +336,19 @@ void CPrimChecker::render(CPrimZone *zone, uint8 bits)
|
|
|
|
|
*/
|
|
|
|
|
void CPrimChecker::render(const CPolygon &poly, uint16 value)
|
|
|
|
|
{
|
|
|
|
|
static const sint centerOffset = 20480; // zones are max 40960
|
|
|
|
|
CPolygon polyOffset = poly;
|
|
|
|
|
for (ptrdiff_t i = 0; i < (ptrdiff_t)polyOffset.Vertices.size(); ++i)
|
|
|
|
|
// center to computeBorders range (-32k to 32k)
|
|
|
|
|
polyOffset.Vertices[i] += CVector(-centerOffset, centerOffset, 0);
|
|
|
|
|
|
|
|
|
|
list<CPolygon> convex;
|
|
|
|
|
|
|
|
|
|
// divide poly in convex polys
|
|
|
|
|
if (!poly.toConvexPolygons(convex, CMatrix::Identity))
|
|
|
|
|
if (!polyOffset.toConvexPolygons(convex, CMatrix::Identity))
|
|
|
|
|
{
|
|
|
|
|
convex.clear();
|
|
|
|
|
CPolygon reverse = poly;
|
|
|
|
|
CPolygon reverse = polyOffset;
|
|
|
|
|
std::reverse(reverse.Vertices.begin(), reverse.Vertices.end());
|
|
|
|
|
if (!reverse.toConvexPolygons(convex, CMatrix::Identity))
|
|
|
|
|
return;
|
|
|
|
@ -357,6 +363,7 @@ void CPrimChecker::render(const CPolygon &poly, uint16 value)
|
|
|
|
|
sint ymin;
|
|
|
|
|
|
|
|
|
|
convex2d.computeBorders(rasterized, ymin);
|
|
|
|
|
ymin -= centerOffset; // uncenter
|
|
|
|
|
|
|
|
|
|
sint dy;
|
|
|
|
|
for (dy=0; dy<(sint)rasterized.size(); ++dy)
|
|
|
|
@ -365,19 +372,19 @@ void CPrimChecker::render(const CPolygon &poly, uint16 value)
|
|
|
|
|
|
|
|
|
|
for (x=rasterized[dy].first; x<=rasterized[dy].second; ++x)
|
|
|
|
|
{
|
|
|
|
|
uint8 prevBits = _Grid.get((uint)x, (uint)(ymin+dy));
|
|
|
|
|
uint8 prevBits = _Grid.get((uint)x + centerOffset, (uint)(ymin + dy));
|
|
|
|
|
|
|
|
|
|
// only set if there was not a water shape there or if previous was lower
|
|
|
|
|
if ((prevBits & Water) != 0)
|
|
|
|
|
{
|
|
|
|
|
uint16 prevWS = _Grid.index((uint)x, (uint)(ymin+dy));
|
|
|
|
|
uint16 prevWS = _Grid.index((uint)x + centerOffset, (uint)(ymin + dy));
|
|
|
|
|
|
|
|
|
|
if (_WaterHeight[value] < _WaterHeight[prevWS])
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_Grid.index((uint)x, (uint)(ymin+dy), value);
|
|
|
|
|
_Grid.set((uint)x, (uint)(ymin+dy), Water);
|
|
|
|
|
_Grid.index((uint)x + centerOffset, (uint)(ymin + dy), value);
|
|
|
|
|
_Grid.set((uint)x + centerOffset, (uint)(ymin + dy), Water);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -389,13 +396,19 @@ void CPrimChecker::render(const CPolygon &poly, uint16 value)
|
|
|
|
|
*/
|
|
|
|
|
void CPrimChecker::renderBits(const CPolygon &poly, uint8 bits)
|
|
|
|
|
{
|
|
|
|
|
static const sint centerOffset = 20480; // zones are max 40960
|
|
|
|
|
CPolygon polyOffset = poly;
|
|
|
|
|
for (ptrdiff_t i = 0; i < (ptrdiff_t)polyOffset.Vertices.size(); ++i)
|
|
|
|
|
// center to computeBorders range (-32k to 32k)
|
|
|
|
|
polyOffset.Vertices[i] += CVector(-centerOffset, centerOffset, 0);
|
|
|
|
|
|
|
|
|
|
list<CPolygon> convex;
|
|
|
|
|
|
|
|
|
|
// divide poly in convex polys
|
|
|
|
|
if (!poly.toConvexPolygons(convex, CMatrix::Identity))
|
|
|
|
|
if (!polyOffset.toConvexPolygons(convex, CMatrix::Identity))
|
|
|
|
|
{
|
|
|
|
|
convex.clear();
|
|
|
|
|
CPolygon reverse = poly;
|
|
|
|
|
CPolygon reverse = polyOffset;
|
|
|
|
|
std::reverse(reverse.Vertices.begin(), reverse.Vertices.end());
|
|
|
|
|
if (!reverse.toConvexPolygons(convex, CMatrix::Identity))
|
|
|
|
|
return;
|
|
|
|
@ -410,6 +423,7 @@ void CPrimChecker::renderBits(const CPolygon &poly, uint8 bits)
|
|
|
|
|
sint ymin;
|
|
|
|
|
|
|
|
|
|
convex2d.computeBorders(rasterized, ymin);
|
|
|
|
|
ymin -= centerOffset; // uncenter
|
|
|
|
|
|
|
|
|
|
sint dy;
|
|
|
|
|
for (dy=0; dy<(sint)rasterized.size(); ++dy)
|
|
|
|
@ -418,7 +432,7 @@ void CPrimChecker::renderBits(const CPolygon &poly, uint8 bits)
|
|
|
|
|
|
|
|
|
|
for (x=rasterized[dy].first; x<=rasterized[dy].second; ++x)
|
|
|
|
|
{
|
|
|
|
|
_Grid.set((uint)x, (uint)(ymin+dy), bits);
|
|
|
|
|
_Grid.set((uint)x + centerOffset, (uint)(ymin + dy), bits);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|