summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/render/Renderer.cpp83
1 files changed, 42 insertions, 41 deletions
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 8a93ee70..7a688ce8 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -825,6 +825,12 @@ CalcNewDelta(RwV2d *a, RwV2d *b)
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
CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *))
{
@@ -850,13 +856,8 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
a2 = i;
}
}
-#ifdef FIX_BUGS
- y = Floor(miny);
- yend = Floor(maxy);
-#else
- y = miny;
- yend = maxy;
-#endif
+ y = TOINT(miny);
+ yend = TOINT(maxy);
// Go left in poly to find first edge b
b2 = a2;
@@ -864,8 +865,8 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
b1 = b2--;
if(b2 < 0) b2 = numVertices-1;
if(poly[b1].x < xstart)
- xstart = poly[b1].x;
- if((int)poly[b1].y != (int)poly[b2].y)
+ xstart = TOINT(poly[b1].x);
+ if(TOINT(poly[b1].y) != TOINT(poly[b2].y))
break;
}
// Go right to find first edge a
@@ -873,8 +874,8 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
a1 = a2++;
if(a2 == numVertices) a2 = 0;
if(poly[a1].x > xend)
- xend = poly[a1].x;
- if((int)poly[a1].y != (int)poly[a2].y)
+ xend = TOINT(poly[a1].x);
+ if(TOINT(poly[a1].y) != TOINT(poly[a2].y))
break;
}
@@ -885,10 +886,10 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x;
if(y != yend){
- if(deltaB < 0.0f && (int)xB < xstart)
- xstart = xB;
- if(deltaA >= 0.0f && (int)xA > xend)
- xend = xA;
+ if(deltaB < 0.0f && TOINT(xB) < xstart)
+ xstart = TOINT(xB);
+ if(deltaA >= 0.0f && TOINT(xA) > xend)
+ xend = TOINT(xA);
}
while(y <= yend && y < NUMSECTORS_Y){
@@ -904,74 +905,74 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
xB += deltaB;
// update left side
- if(y == (int)poly[b2].y){
+ if(y == TOINT(poly[b2].y)){
// reached end of edge
if(y == yend){
if(deltaB < 0.0f){
do{
- xstart = poly[b2--].x;
+ xstart = TOINT(poly[b2--].x);
if(b2 < 0) b2 = numVertices-1;
- }while(xstart > (int)poly[b2].x);
+ }while(xstart > TOINT(poly[b2].x));
}else
- xstart = xB - deltaB;
+ xstart = TOINT(xB - deltaB);
}else{
// switch edges
if(deltaB < 0.0f)
- xstart = poly[b2].x;
+ xstart = TOINT(poly[b2].x);
else
- xstart = xB - deltaB;
+ xstart = TOINT(xB - deltaB);
do{
b1 = b2--;
if(b2 < 0) b2 = numVertices-1;
- if((int)poly[b1].x < xstart)
- xstart = poly[b1].x;
- }while(y == (int)poly[b2].y);
+ if(TOINT(poly[b1].x) < xstart)
+ xstart = TOINT(poly[b1].x);
+ }while(y == TOINT(poly[b2].y));
deltaB = CalcNewDelta(&poly[b1], &poly[b2]);
xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x;
- if(deltaB < 0.0f && (int)xB < xstart)
- xstart = xB;
+ if(deltaB < 0.0f && TOINT(xB) < xstart)
+ xstart = TOINT(xB);
}
}else{
if(deltaB < 0.0f)
- xstart = xB;
+ xstart = TOINT(xB);
else
- xstart = xB - deltaB;
+ xstart = TOINT(xB - deltaB);
}
// update right side
- if(y == (int)poly[a2].y){
+ if(y == TOINT(poly[a2].y)){
// reached end of edge
if(y == yend){
if(deltaA < 0.0f)
- xend = xA - deltaA;
+ xend = TOINT(xA - deltaA);
else{
do{
- xend = poly[a2++].x;
+ xend = TOINT(poly[a2++].x);
if(a2 == numVertices) a2 = 0;
- }while(xend < (int)poly[a2].x);
+ }while(xend < TOINT(poly[a2].x));
}
}else{
// switch edges
if(deltaA < 0.0f)
- xend = xA - deltaA;
+ xend = TOINT(xA - deltaA);
else
- xend = poly[a2].x;
+ xend = TOINT(poly[a2].x);
do{
a1 = a2++;
if(a2 == numVertices) a2 = 0;
- if((int)poly[a1].x > xend)
- xend = poly[a1].x;
- }while(y == (int)poly[a2].y);
+ if(TOINT(poly[a1].x) > xend)
+ xend = TOINT(poly[a1].x);
+ }while(y == TOINT(poly[a2].y));
deltaA = CalcNewDelta(&poly[a1], &poly[a2]);
xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x;
- if(deltaA >= 0.0f && (int)xA > xend)
- xend = xA;
+ if(deltaA >= 0.0f && TOINT(xA) > xend)
+ xend = TOINT(xA);
}
}else{
if(deltaA < 0.0f)
- xend = xA - deltaA;
+ xend = TOINT(xA - deltaA);
else
- xend = xA;
+ xend = TOINT(xA);
}
}
}