RectangleList *MicroTileArray::getRectangles() { RectangleList *rects = new RectangleList(); int x, y; int x0, y0, x1, y1; int i = 0; for (y = 0; y < _tilesH; ++y) { for (x = 0; x < _tilesW; ++x) { int finish = 0; BoundingBox boundingBox = _tiles[i]; if (isBoundingBoxEmpty(boundingBox)) { ++i; continue; } x0 = (x * TileSize) + TileX0(boundingBox); y0 = (y * TileSize) + TileY0(boundingBox); y1 = (y * TileSize) + TileY1(boundingBox); if (TileX1(boundingBox) == TileSize - 1 && x != _tilesW - 1) { // check if the tile continues while (!finish) { ++x; ++i; if (x == _tilesW || i >= _tilesW * _tilesH || TileY0(_tiles[i]) != TileY0(boundingBox) || TileY1(_tiles[i]) != TileY1(boundingBox) || TileX0(_tiles[i]) != 0) { --x; --i; finish = 1; } } } x1 = (x * TileSize) + TileX1(_tiles[i]); rects->push_back(Common::Rect(x0, y0, x1 + 1, y1 + 1)); ++i; } } return rects; }
void MicroTileArray::updateBoundingBox(BoundingBox &boundingBox, byte x0, byte y0, byte x1, byte y1) { if (!isBoundingBoxEmpty(boundingBox)) { x0 = MIN(TileX0(boundingBox), x0); y0 = MIN(TileY0(boundingBox), y0); x1 = MAX(TileX1(boundingBox), x1); y1 = MAX(TileY1(boundingBox), y1); } setBoundingBox(boundingBox, x0, y0, x1, y1); }
Common::Rect * MicroTileArray::getRectangles(int *num_rects, int min_x, int min_y, int max_x, int max_y) { Common::Rect *rects = new Common::Rect[_tilesW * _tilesH]; int n_rects = 0; int x, y; int x0, y0, x1, y1; int i = 0; for (y = 0; y < _tilesH; ++y) { for (x = 0; x < _tilesW; ++x) { int start; int finish = 0; BoundingBox boundingBox; boundingBox = _tiles[i]; if (isBoundingBoxEmpty(boundingBox)) { ++i; continue; } x0 = (x * TileSize) + TileX0(boundingBox); y0 = (y * TileSize) + TileY0(boundingBox); y1 = (y * TileSize) + TileY1(boundingBox); x0 = CLIP (x0, min_x, max_x); y0 = CLIP (y0, min_y, max_y); y1 = CLIP (y1, min_y, max_y); // FIXME: Why is the following code in an #if block? #if 1 start = i; if (TileX1(boundingBox) == TileSize - 1 && x != _tilesW - 1) { // check if the tile continues while (!finish) { ++x; ++i; if (x == _tilesW || i >= _tilesW * _tilesH || TileY0(_tiles[i]) != TileY0(boundingBox) || TileY1(_tiles[i]) != TileY1(boundingBox) || TileX0(_tiles[i]) != 0) { --x; --i; finish = 1; } } } #endif x1 = (x * TileSize) + TileX1(_tiles[i]); x1 = CLIP (x1, min_x, max_x); // FIXME: Why is the following code in an #if block? #if 1 rects[n_rects].left = x0; rects[n_rects].top = y0; rects[n_rects].right = x1 + 1; rects[n_rects].bottom = y1 + 1; n_rects++; #else // FIXME: Why is this code disabled? if (glom [start] != -1 && /* try to glom */ rects [glom [start]].left == x0 && rects [glom [start]].right == x1 && rects [glom [start]].bottom == y0 - 1) { rects [glom [start]].bottom = y1; if (y != tilesH - 1) { glom [start + tilesW] = glom [start]; } } else { rects[n_rects].left = x0; rects[n_rects].top = y0; rects[n_rects].right = x1; rects[n_rects].bottom = y1; if (y != tilesH - 1) { glom [start + tilesW] = n_rects; } n_rects ++; } #endif ++i; } // for (x = 0; x < _tilesW; ++x) } // for (y = 0; y < _tilesH; ++y) *num_rects = n_rects; //delete glom; return rects; }