… | |
… | |
1216 | vol += op->volume (); |
1216 | vol += op->volume (); |
1217 | |
1217 | |
1218 | return vol; |
1218 | return vol; |
1219 | } |
1219 | } |
1220 | |
1220 | |
1221 | bool |
1221 | maptile * |
1222 | maptile::tile_available (int dir, bool load) |
1222 | maptile::tile_available (int dir, bool load) |
1223 | { |
1223 | { |
1224 | if (!tile_path[dir]) |
1224 | if (tile_path[dir]) |
1225 | return 0; |
1225 | { |
1226 | |
|
|
1227 | if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE)) |
1226 | if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE)) |
1228 | return 1; |
1227 | return tile_map[dir]; |
1229 | |
1228 | |
1230 | if ((tile_map[dir] = find_async (tile_path[dir], this, load))) |
1229 | if ((tile_map[dir] = find_async (tile_path[dir], this, load))) |
1231 | return 1; |
1230 | return tile_map[dir]; |
|
|
1231 | } |
1232 | |
1232 | |
1233 | return 0; |
1233 | return 0; |
1234 | } |
1234 | } |
1235 | |
1235 | |
1236 | /* this returns TRUE if the coordinates (x,y) are out of |
1236 | /* this returns TRUE if the coordinates (x,y) are out of |
… | |
… | |
1628 | if (distance <= MAX_SOUND_DISTANCE) |
1628 | if (distance <= MAX_SOUND_DISTANCE) |
1629 | ns->play_sound (sound, dx, dy); |
1629 | ns->play_sound (sound, dx, dy); |
1630 | } |
1630 | } |
1631 | } |
1631 | } |
1632 | |
1632 | |
|
|
1633 | static void |
|
|
1634 | split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy) |
|
|
1635 | { |
|
|
1636 | // clip to map to the left |
|
|
1637 | if (x0 < 0) |
|
|
1638 | { |
|
|
1639 | if (maptile *tile = m->tile_available (TILE_LEFT, 1)) |
|
|
1640 | split_to_tiles (buf, tile, x0 + tile->width, y0, min (x1 + tile->width, tile->width), y1, dx - tile->width, dy); |
|
|
1641 | |
|
|
1642 | if (x1 < 0) // entirely to the left |
|
|
1643 | return; |
|
|
1644 | |
|
|
1645 | x0 = 0; |
|
|
1646 | } |
|
|
1647 | |
|
|
1648 | // clip to map to the right |
|
|
1649 | if (x1 > m->width) |
|
|
1650 | { |
|
|
1651 | if (maptile *tile = m->tile_available (TILE_RIGHT, 1)) |
|
|
1652 | split_to_tiles (buf, tile, max (x0 - m->width, 0), y0, x1 - m->width, y1, dx + m->width, dy); |
|
|
1653 | |
|
|
1654 | if (x0 > m->width) // entirely to the right |
|
|
1655 | return; |
|
|
1656 | |
|
|
1657 | x1 = m->width; |
|
|
1658 | } |
|
|
1659 | |
|
|
1660 | // clip to map above |
|
|
1661 | if (y0 < 0) |
|
|
1662 | { |
|
|
1663 | if (maptile *tile = m->tile_available (TILE_UP, 1)) |
|
|
1664 | split_to_tiles (buf, tile, x0, y0 + tile->height, x1, min (y1 + tile->height, tile->height), dx, dy - tile->height); |
|
|
1665 | |
|
|
1666 | if (y1 < 0) // entirely above |
|
|
1667 | return; |
|
|
1668 | |
|
|
1669 | y0 = 0; |
|
|
1670 | } |
|
|
1671 | |
|
|
1672 | // clip to map below |
|
|
1673 | if (y1 > m->height) |
|
|
1674 | { |
|
|
1675 | if (maptile *tile = m->tile_available (TILE_DOWN, 1)) |
|
|
1676 | split_to_tiles (buf, tile, x0, max (y0 - m->height, 0), x1, y1 - m->height, dx, dy + m->height); |
|
|
1677 | |
|
|
1678 | if (y0 > m->height) // entirely below |
|
|
1679 | return; |
|
|
1680 | |
|
|
1681 | y1 = m->height; |
|
|
1682 | } |
|
|
1683 | |
|
|
1684 | // if we get here, the rect is within the current map |
|
|
1685 | maprect *r = (maprect *)buf.alloc (sizeof (maprect)); |
|
|
1686 | |
|
|
1687 | r->m = m; |
|
|
1688 | r->x0 = x0; |
|
|
1689 | r->y0 = y0; |
|
|
1690 | r->x1 = x1; |
|
|
1691 | r->y1 = y1; |
|
|
1692 | r->dx = dx; |
|
|
1693 | r->dy = dy; |
|
|
1694 | } |
|
|
1695 | |
|
|
1696 | maprect * |
|
|
1697 | maptile::split_to_tiles (int x0, int y0, int x1, int y1) |
|
|
1698 | { |
|
|
1699 | static dynbuf buf (sizeof (maprect) * 8, sizeof (maprect) * 8); |
|
|
1700 | buf.clear (); |
|
|
1701 | |
|
|
1702 | ::split_to_tiles (buf, this, x0, y0, x1, y1, 0, 0); |
|
|
1703 | |
|
|
1704 | // add end marker |
|
|
1705 | maprect *r = (maprect *)buf.alloc (sizeof (maprect)); |
|
|
1706 | r->m = 0; |
|
|
1707 | |
|
|
1708 | return (maprect *)buf.linearise (); |
|
|
1709 | } |
|
|
1710 | |