fixed CRenderer::ScanSectorPoly again

This commit is contained in:
aap 2020-08-21 09:40:31 +02:00
parent 537b63acb5
commit 23c52c1c86

View file

@ -889,6 +889,12 @@ CalcNewDelta(RwV2d *a, RwV2d *b)
return (b->x - a->x) / (b->y - a->y); return (b->x - a->x) / (b->y - a->y);
} }
#ifdef FIX_BUGS
#define TOINT(x) ((int)Floor(x))
#else
#define TOINT(x) ((int)(x))
#endif
void void
CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *)) CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *))
{ {
@ -914,13 +920,8 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
a2 = i; a2 = i;
} }
} }
#ifdef FIX_BUGS y = TOINT(miny);
y = Floor(miny); yend = TOINT(maxy);
yend = Floor(maxy);
#else
y = miny;
yend = maxy;
#endif
// Go left in poly to find first edge b // Go left in poly to find first edge b
b2 = a2; b2 = a2;
@ -928,8 +929,8 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
b1 = b2--; b1 = b2--;
if(b2 < 0) b2 = numVertices-1; if(b2 < 0) b2 = numVertices-1;
if(poly[b1].x < xstart) if(poly[b1].x < xstart)
xstart = poly[b1].x; xstart = TOINT(poly[b1].x);
if((int)poly[b1].y != (int)poly[b2].y) if(TOINT(poly[b1].y) != TOINT(poly[b2].y))
break; break;
} }
// Go right to find first edge a // Go right to find first edge a
@ -937,8 +938,8 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
a1 = a2++; a1 = a2++;
if(a2 == numVertices) a2 = 0; if(a2 == numVertices) a2 = 0;
if(poly[a1].x > xend) if(poly[a1].x > xend)
xend = poly[a1].x; xend = TOINT(poly[a1].x);
if((int)poly[a1].y != (int)poly[a2].y) if(TOINT(poly[a1].y) != TOINT(poly[a2].y))
break; break;
} }
@ -949,10 +950,10 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x; xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x;
if(y != yend){ if(y != yend){
if(deltaB < 0.0f && (int)xB < xstart) if(deltaB < 0.0f && TOINT(xB) < xstart)
xstart = xB; xstart = TOINT(xB);
if(deltaA >= 0.0f && (int)xA > xend) if(deltaA >= 0.0f && TOINT(xA) > xend)
xend = xA; xend = TOINT(xA);
} }
while(y <= yend && y < NUMSECTORS_Y){ while(y <= yend && y < NUMSECTORS_Y){
@ -968,74 +969,74 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
xB += deltaB; xB += deltaB;
// update left side // update left side
if(y == (int)poly[b2].y){ if(y == TOINT(poly[b2].y)){
// reached end of edge // reached end of edge
if(y == yend){ if(y == yend){
if(deltaB < 0.0f){ if(deltaB < 0.0f){
do{ do{
xstart = poly[b2--].x; xstart = TOINT(poly[b2--].x);
if(b2 < 0) b2 = numVertices-1; if(b2 < 0) b2 = numVertices-1;
}while(xstart > (int)poly[b2].x); }while(xstart > TOINT(poly[b2].x));
}else }else
xstart = xB - deltaB; xstart = TOINT(xB - deltaB);
}else{ }else{
// switch edges // switch edges
if(deltaB < 0.0f) if(deltaB < 0.0f)
xstart = poly[b2].x; xstart = TOINT(poly[b2].x);
else else
xstart = xB - deltaB; xstart = TOINT(xB - deltaB);
do{ do{
b1 = b2--; b1 = b2--;
if(b2 < 0) b2 = numVertices-1; if(b2 < 0) b2 = numVertices-1;
if((int)poly[b1].x < xstart) if(TOINT(poly[b1].x) < xstart)
xstart = poly[b1].x; xstart = TOINT(poly[b1].x);
}while(y == (int)poly[b2].y); }while(y == TOINT(poly[b2].y));
deltaB = CalcNewDelta(&poly[b1], &poly[b2]); deltaB = CalcNewDelta(&poly[b1], &poly[b2]);
xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x; xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x;
if(deltaB < 0.0f && (int)xB < xstart) if(deltaB < 0.0f && TOINT(xB) < xstart)
xstart = xB; xstart = TOINT(xB);
} }
}else{ }else{
if(deltaB < 0.0f) if(deltaB < 0.0f)
xstart = xB; xstart = TOINT(xB);
else else
xstart = xB - deltaB; xstart = TOINT(xB - deltaB);
} }
// update right side // update right side
if(y == (int)poly[a2].y){ if(y == TOINT(poly[a2].y)){
// reached end of edge // reached end of edge
if(y == yend){ if(y == yend){
if(deltaA < 0.0f) if(deltaA < 0.0f)
xend = xA - deltaA; xend = TOINT(xA - deltaA);
else{ else{
do{ do{
xend = poly[a2++].x; xend = TOINT(poly[a2++].x);
if(a2 == numVertices) a2 = 0; if(a2 == numVertices) a2 = 0;
}while(xend < (int)poly[a2].x); }while(xend < TOINT(poly[a2].x));
} }
}else{ }else{
// switch edges // switch edges
if(deltaA < 0.0f) if(deltaA < 0.0f)
xend = xA - deltaA; xend = TOINT(xA - deltaA);
else else
xend = poly[a2].x; xend = TOINT(poly[a2].x);
do{ do{
a1 = a2++; a1 = a2++;
if(a2 == numVertices) a2 = 0; if(a2 == numVertices) a2 = 0;
if((int)poly[a1].x > xend) if(TOINT(poly[a1].x) > xend)
xend = poly[a1].x; xend = TOINT(poly[a1].x);
}while(y == (int)poly[a2].y); }while(y == TOINT(poly[a2].y));
deltaA = CalcNewDelta(&poly[a1], &poly[a2]); deltaA = CalcNewDelta(&poly[a1], &poly[a2]);
xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x; xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x;
if(deltaA >= 0.0f && (int)xA > xend) if(deltaA >= 0.0f && TOINT(xA) > xend)
xend = xA; xend = TOINT(xA);
} }
}else{ }else{
if(deltaA < 0.0f) if(deltaA < 0.0f)
xend = xA - deltaA; xend = TOINT(xA - deltaA);
else else
xend = xA; xend = TOINT(xA);
} }
} }
} }