From 7714b20abff459c52490381c5ef658bce9578d13 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 22 Mar 2009 23:02:09 +0000 Subject: TINSEL: cleanup svn-id: r39617 --- engines/tinsel/polygons.cpp | 135 ++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 74 deletions(-) (limited to 'engines/tinsel/polygons.cpp') diff --git a/engines/tinsel/polygons.cpp b/engines/tinsel/polygons.cpp index ca337e7921..34c977ddfd 100644 --- a/engines/tinsel/polygons.cpp +++ b/engines/tinsel/polygons.cpp @@ -139,7 +139,7 @@ struct LINEINFO { // of POLY's changed between TINSEL v1 and v2 class Poly { private: - const byte *_pStart; + const byte * const _pStart; const byte *_pData; int _recordSize; void nextPoly(); @@ -171,21 +171,22 @@ public: //The arrays now stored externally int32 nodecount; //!pIndex); // This polygon - nlistx = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelistx)); - nlisty = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelisty)); + nlistx = ptp.nlistx; + nlisty = ptp.nlisty; llist = (LINEINFO *)(pps + (int)FROM_LE_32(ptp.plinelist)); // Look for fit of perpendicular to lines between nodes @@ -579,40 +586,36 @@ void FindBestPoint(HPOLYGON hp, int *x, int *y, int *pline) { const int32 c = (int)FROM_LE_32(llist[i].c); #if 1 - if (true) { - //printf("a %d, b %d, c %d, a^2+b^2 = %d\n", a, b, c, a*a+b*b); - - // TODO: If the comments of the LINEINFO struct are correct, then it contains mostly - // duplicate data, probably in an effort to safe CPU cycles. Even on the slowest devices - // we support, calculatin a product of two ints is not an issue. - // So we can just load & endian convert a,b,c, then replace stuff like - // (int)FROM_LE_32(line->ab) - // by simply a*b, which makes it easier to understand what the code does, too. - // Just in case there is some bugged data, I leave this code here for verifying it. - // Let's leave it in for some time. - // - // One bad thing: We use sqrt to compute a square root. Might not be a good idea, - // speed wise. Maybe we should take Vicent's fp_sqroot. But that's a problem for later. - - LINEINFO *line = &llist[i]; - int32 a2 = (int)FROM_LE_32(line->a2); //!< a squared - int32 b2 = (int)FROM_LE_32(line->b2); //!< b squared - int32 a2pb2 = (int)FROM_LE_32(line->a2pb2); //!< a squared + b squared - int32 ra2pb2 = (int)FROM_LE_32(line->ra2pb2); //!< root(a squared + b squared) - - int32 ab = (int)FROM_LE_32(line->ab); - int32 ac = (int)FROM_LE_32(line->ac); - int32 bc = (int)FROM_LE_32(line->bc); - - assert(a*a == a2); - assert(b*b == b2); - assert(a*b == ab); - assert(a*c == ac); - assert(b*c == bc); - - assert(a2pb2 == a*a + b*b); - assert(ra2pb2 == (int)sqrt((float)a*a + (float)b*b)); - } + // TODO: If the comments of the LINEINFO struct are correct, then it contains mostly + // duplicate data, probably in an effort to safe CPU cycles. Even on the slowest devices + // we support, calculating a product of two ints is not an issue. + // So we can just load & endian convert a,b,c, then replace stuff like + // (int)FROM_LE_32(line->ab) + // by simply a*b, which makes it easier to understand what the code does, too. + // Just in case there is some bugged data, I leave this code here for verifying it. + // Let's leave it in for some time. + // + // One bad thing: We use sqrt to compute a square root. Might not be a good idea, + // speed wise. Maybe we should take Vicent's fp_sqroot. But that's a problem for later. + + LINEINFO *line = &llist[i]; + int32 a2 = (int)FROM_LE_32(line->a2); //!< a squared + int32 b2 = (int)FROM_LE_32(line->b2); //!< b squared + int32 a2pb2 = (int)FROM_LE_32(line->a2pb2); //!< a squared + b squared + int32 ra2pb2 = (int)FROM_LE_32(line->ra2pb2); //!< root(a squared + b squared) + + int32 ab = (int)FROM_LE_32(line->ab); + int32 ac = (int)FROM_LE_32(line->ac); + int32 bc = (int)FROM_LE_32(line->bc); + + assert(a*a == a2); + assert(b*b == b2); + assert(a*b == ab); + assert(a*c == ac); + assert(b*c == bc); + + assert(a2pb2 == a*a + b*b); + assert(ra2pb2 == (int)sqrt((float)a*a + (float)b*b)); #endif @@ -816,8 +819,8 @@ int NearestEndNode(HPOLYGON hPath, int x, int y) { pps = LockMem(pHandle); // All polygons Poly ptp(pps, pp->pIndex); // This polygon - nlistx = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelistx)); - nlisty = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelisty)); + nlistx = ptp.nlistx; + nlisty = ptp.nlisty; const int nodecount = (int)FROM_LE_32(ptp.nodecount); @@ -840,8 +843,6 @@ int NearEndNode(HPOLYGON hSpath, HPOLYGON hDpath) { int dist, NearDist; int NearNode; uint8 *pps; // Compiled polygon data - int32 *snlistx, *snlisty; - int32 *dnlistx, *dnlisty; CHECK_HP(hSpath, "Out of range polygon handle (9)"); CHECK_HP(hDpath, "Out of range polygon handle (10)"); @@ -855,29 +856,24 @@ int NearEndNode(HPOLYGON hSpath, HPOLYGON hDpath) { ns = (int)FROM_LE_32(ps.nodecount) - 1; nd = (int)FROM_LE_32(pd.nodecount) - 1; - snlistx = (int32 *)(pps + (int)FROM_LE_32(ps.pnodelistx)); - snlisty = (int32 *)(pps + (int)FROM_LE_32(ps.pnodelisty)); - dnlistx = (int32 *)(pps + (int)FROM_LE_32(pd.pnodelistx)); - dnlisty = (int32 *)(pps + (int)FROM_LE_32(pd.pnodelisty)); - // start[0] to dest[0] - NearDist = ABS((int)FROM_LE_32(snlistx[0]) - (int)FROM_LE_32(dnlistx[0])) + ABS((int)FROM_LE_32(snlisty[0]) - (int)FROM_LE_32(dnlisty[0])); + NearDist = ABS((int)FROM_LE_32(ps.nlistx[0]) - (int)FROM_LE_32(pd.nlistx[0])) + ABS((int)FROM_LE_32(ps.nlisty[0]) - (int)FROM_LE_32(pd.nlisty[0])); NearNode = 0; // start[0] to dest[top] - dist = ABS((int)FROM_LE_32(snlistx[0]) - (int)FROM_LE_32(dnlistx[nd])) + ABS((int)FROM_LE_32(snlisty[0]) - (int)FROM_LE_32(dnlisty[nd])); + dist = ABS((int)FROM_LE_32(ps.nlistx[0]) - (int)FROM_LE_32(pd.nlistx[nd])) + ABS((int)FROM_LE_32(ps.nlisty[0]) - (int)FROM_LE_32(pd.nlisty[nd])); if (dist < NearDist) NearDist = dist; // start[top] to dest[0] - dist = ABS((int)FROM_LE_32(snlistx[ns]) - (int)FROM_LE_32(dnlistx[0])) + ABS((int)FROM_LE_32(snlisty[ns]) - (int)FROM_LE_32(dnlisty[0])); + dist = ABS((int)FROM_LE_32(ps.nlistx[ns]) - (int)FROM_LE_32(pd.nlistx[0])) + ABS((int)FROM_LE_32(ps.nlisty[ns]) - (int)FROM_LE_32(pd.nlisty[0])); if (dist < NearDist) { NearDist = dist; NearNode = ns; } // start[top] to dest[top] - dist = ABS((int)FROM_LE_32(snlistx[ns]) - (int)FROM_LE_32(dnlistx[nd])) + ABS((int)FROM_LE_32(snlisty[ns]) - (int)FROM_LE_32(dnlisty[nd])); + dist = ABS((int)FROM_LE_32(ps.nlistx[ns]) - (int)FROM_LE_32(pd.nlistx[nd])) + ABS((int)FROM_LE_32(ps.nlisty[ns]) - (int)FROM_LE_32(pd.nlisty[nd])); if (dist < NearDist) { NearNode = ns; } @@ -894,20 +890,16 @@ int NearestNodeWithin(HPOLYGON hNpath, int x, int y) { int NumNodes; // Number of nodes in this follow nodes path int NearestYet = 0; // Number of nearest node uint8 *pps; // Compiled polygon data - int32 *nlistx, *nlisty; CHECK_HP(hNpath, "Out of range polygon handle (11)"); pps = LockMem(pHandle); // All polygons Poly ptp(pps, Polys[hNpath]->pIndex); // This polygon - nlistx = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelistx)); - nlisty = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelisty)); - NumNodes = (int)FROM_LE_32(ptp.nodecount); for (int i = 0; i < NumNodes; i++) { - ThisDistance = ABS(x - (int)FROM_LE_32(nlistx[i])) + ABS(y - (int)FROM_LE_32(nlisty[i])); + ThisDistance = ABS(x - (int)FROM_LE_32(ptp.nlistx[i])) + ABS(y - (int)FROM_LE_32(ptp.nlisty[i])); if (ThisDistance < SmallestDistance) { NearestYet = i; @@ -1067,23 +1059,18 @@ int GetBrightness(HPOLYGON hPath, int y) { */ void getNpathNode(HPOLYGON hNpath, int node, int *px, int *py) { uint8 *pps; // Compiled polygon data - int32 *nlistx, *nlisty; - CHECK_HP(hNpath, "Out of range polygon handle (15)"); assert(Polys[hNpath] != NULL && Polys[hNpath]->polyType == PATH && Polys[hNpath]->subtype == NODE); // must be given a node path! pps = LockMem(pHandle); // All polygons Poly ptp(pps, Polys[hNpath]->pIndex); // This polygon - nlistx = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelistx)); - nlisty = (int32 *)(pps + (int)FROM_LE_32(ptp.pnodelisty)); - // Might have just walked to the node from above. if (node == (int)FROM_LE_32(ptp.nodecount)) node -= 1; - *px = (int)FROM_LE_32(nlistx[node]); - *py = (int)FROM_LE_32(nlisty[node]); + *px = (int)FROM_LE_32(ptp.nlistx[node]); + *py = (int)FROM_LE_32(ptp.nlisty[node]); } /** @@ -1424,8 +1411,8 @@ void CheckNPathIntegrity() { if (rp && rp->polyType == PATH && rp->subtype == NODE) { //...if it's a node path // Get compiled polygon structure cp = (const Poly *)pps + rp->pIndex; // This polygon - nlistx = (int32 *)(pps + (int)FROM_LE_32(cp->pnodelistx)); - nlisty = (int32 *)(pps + (int)FROM_LE_32(cp->pnodelisty)); + nlistx = cp->nlistx; + nlisty = cp->nlisty; n = (int)FROM_LE_32(cp->nodecount) - 1; // Last node assert(n >= 1); // Node paths must have at least 2 nodes -- cgit v1.2.3