Index: src/viewport.cpp =================================================================== --- src/viewport.cpp (revision 10160) +++ src/viewport.cpp (working copy) @@ -89,6 +89,12 @@ int32 ymin; int32 xmax; int32 ymax; + + int32 cxmin; + int32 cymin; + int32 cxmax; + int32 cymax; + ChildScreenSpriteToDraw *child; byte unk16; byte zmin; @@ -1104,6 +1110,40 @@ static void ViewportSortParentSprites(ParentSpriteToDraw *psd[]) { + { + ParentSpriteToDraw ** psd2 = psd; + while (*psd2 != NULL) { + ParentSpriteToDraw* ps = *psd2; + const ChildScreenSpriteToDraw* cs = ps->child; +ps->cxmin=ps->xmin;ps->cymin=ps->ymin; +ps->cxmax=ps->xmax;ps->cymax=ps->ymax; + if ( cs != NULL ) { +// int xmax = 0, xmin = 0, ymax = 0, ymin = 0; + + do { + const Sprite* spr = GetSprite(cs->image); + const int csxmin = cs->x; + const int csxmax = cs->x + spr->height; + const int csymin = cs->y; + const int csymax = cs->y + spr->width; +printf("%d %d\n",spr->height,spr->width); + if ( ps->cxmin > csxmin ) ps->cxmin = csxmin; + if ( ps->cxmax < csxmax ) ps->cxmax = csxmax; + if ( ps->cymin > csymin ) ps->cymin = csymin; + if ( ps->cymax < csymax ) ps->cymax = csymax; + cs = cs->next; + } while ( cs != NULL ); +/* if ( ps->xmin > xmin ) ps->xmin = xmin; + if ( ps->xmax < xmax ) ps->xmax = xmax; + if ( ps->ymin > ymin ) ps->ymin = ymin; + if ( ps->ymax < ymax ) ps->ymax = ymax;*/ +printf("%d %d %d %d %d %d\n",ps->xmin,ps->xmax,ps->ymin,ps->ymax,ps->zmin,ps->zmax); +//printf("%d %d %d %d\n",xmin,xmax,ymin,ymax); + } + psd2++; + } + } + while (*psd != NULL) { ParentSpriteToDraw* ps = *psd; @@ -1121,8 +1161,8 @@ /* Decide which comparator to use, based on whether the bounding * boxes overlap */ - if (ps->xmax > ps2->xmin && ps->xmin < ps2->xmax && // overlap in X? - ps->ymax > ps2->ymin && ps->ymin < ps2->ymax && // overlap in Y? + if (ps->cxmax > ps2->cxmin && ps->cxmin < ps2->cxmax && // overlap in X? + ps->cymax > ps2->cymin && ps->cymin < ps2->cymax && // overlap in Y? ps->zmax > ps2->zmin && ps->zmin < ps2->zmax) { // overlap in Z? /* Use X+Y+Z as the sorting order, so sprites closer to the bottom of * the screen and with higher Z elevation, are drawn in front. @@ -1130,16 +1170,16 @@ * i.e. X=(left+right)/2, etc. * However, since we only care about order, don't actually divide / 2 */ - if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <= - ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) { + if (ps->cxmin + ps->cxmax + ps->cymin + ps->cymax + ps->zmin + ps->zmax <= + ps2->cxmin + ps2->cxmax + ps2->cymin + ps2->cymax + ps2->zmin + ps2->zmax) { continue; } } else { - if (ps->xmax < ps2->xmin || - ps->ymax < ps2->ymin || + if (ps->cxmax < ps2->cxmin || + ps->cymax < ps2->cymin || ps->zmax < ps2->zmin || ( - ps->xmin < ps2->xmax && - ps->ymin < ps2->ymax && + ps->cxmin < ps2->cxmax && + ps->cymin < ps2->cymax && ps->zmin < ps2->zmax )) { continue;