… | |
… | |
1600 | |
1600 | |
1601 | // first pass: determine smooth_max |
1601 | // first pass: determine smooth_max |
1602 | // rather ugly, if you ask me |
1602 | // rather ugly, if you ask me |
1603 | // could also be stored inside mapcell and updated on change |
1603 | // could also be stored inside mapcell and updated on change |
1604 | memset (smooth_max, 0, sizeof (smooth_max)); |
1604 | memset (smooth_max, 0, sizeof (smooth_max)); |
|
|
1605 | memset (smooth_level, 0, sizeof (smooth_level)); |
1605 | |
1606 | |
1606 | for (y = 0; y < sh; y++) |
1607 | for (y = 0; y < sh; y++) |
1607 | if (0 <= y + my && y + my < self->rows) |
1608 | if (0 <= y + my && y + my < self->rows) |
1608 | { |
1609 | { |
1609 | maprow *row = self->row + (y + my); |
1610 | maprow *row = self->row + (y + my); |
… | |
… | |
1620 | } |
1621 | } |
1621 | } |
1622 | } |
1622 | |
1623 | |
1623 | for (z = 0; z <= 2; z++) |
1624 | for (z = 0; z <= 2; z++) |
1624 | { |
1625 | { |
1625 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
1626 | |
|
|
1627 | for (y = 0; y < sh; y++) |
1626 | for (y = 0; y < sh; y++) |
1628 | if (0 <= y + my && y + my < self->rows) |
1627 | if (0 <= y + my && y + my < self->rows) |
1629 | { |
1628 | { |
1630 | maprow *row = self->row + (y + my); |
1629 | maprow *row = self->row + (y + my); |
1631 | |
1630 | |
… | |
… | |
1716 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
1715 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
1717 | } |
1716 | } |
1718 | } |
1717 | } |
1719 | } |
1718 | } |
1720 | } |
1719 | } |
|
|
1720 | } |
1721 | |
1721 | |
1722 | // go through all smoothlevels, lowest to highest, then draw. |
1722 | // go through all smoothlevels, lowest to highest, then draw. |
1723 | // this is basically counting sort |
1723 | // this is basically counting sort |
|
|
1724 | { |
|
|
1725 | int w, b; |
|
|
1726 | |
|
|
1727 | for (w = 0; w < 256 / 32; ++w) |
1724 | { |
1728 | { |
1725 | int w, b; |
|
|
1726 | |
|
|
1727 | for (w = 0; w < 256 / 32; ++w) |
|
|
1728 | { |
|
|
1729 | uint32_t smask = smooth_level [w]; |
1729 | uint32_t smask = smooth_level [w]; |
1730 | if (smask) |
1730 | if (smask) |
1731 | for (b = 0; b < 32; ++b) |
1731 | for (b = 0; b < 32; ++b) |
1732 | if (smask & (((uint32_t)1) << b)) |
1732 | if (smask & (((uint32_t)1) << b)) |
|
|
1733 | { |
|
|
1734 | int level = (w << 5) | b; |
|
|
1735 | HE *he; |
|
|
1736 | |
|
|
1737 | hv_iterinit (smooth); |
|
|
1738 | while ((he = hv_iternext (smooth))) |
1733 | { |
1739 | { |
1734 | int level = (w << 5) | b; |
1740 | smooth_key *skey = (smooth_key *)HeKEY (he); |
1735 | HE *he; |
1741 | IV bits = SvIVX (HeVAL (he)); |
1736 | |
1742 | |
1737 | hv_iterinit (smooth); |
1743 | if (!(bits & 0x1000) |
1738 | while ((he = hv_iternext (smooth))) |
1744 | && skey->level == level |
|
|
1745 | && level >= smooth_max [skey->x][skey->y]) |
1739 | { |
1746 | { |
1740 | smooth_key *skey = (smooth_key *)HeKEY (he); |
1747 | maptex tex = self->tex [skey->tile]; |
1741 | IV bits = SvIVX (HeVAL (he)); |
1748 | int px = (((int)skey->x) - 1) * T; |
1742 | |
1749 | int py = (((int)skey->y) - 1) * T; |
1743 | if (!(bits & 0x1000) |
1750 | int border = bits & 15; |
1744 | && skey->level == level |
1751 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1745 | && level >= smooth_max [skey->x][skey->y]) |
1752 | float dx = tex.s * .0625f; // 16 images/row |
|
|
1753 | float dy = tex.t * .5f ; // 2 images/column |
|
|
1754 | |
|
|
1755 | // this time naively avoiding texture state changes |
|
|
1756 | // save gobs of state changes. |
|
|
1757 | if (last_name != tex.name) |
1746 | { |
1758 | { |
1747 | maptex tex = self->tex [skey->tile]; |
|
|
1748 | int px = (((int)skey->x) - 1) * T; |
|
|
1749 | int py = (((int)skey->y) - 1) * T; |
|
|
1750 | int border = bits & 15; |
|
|
1751 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
1752 | float dx = tex.s * .0625f; // 16 images/row |
|
|
1753 | float dy = tex.t * .5f ; // 2 images/column |
|
|
1754 | |
|
|
1755 | // this time naively avoiding texture state changes |
|
|
1756 | // save gobs of state changes. |
|
|
1757 | if (last_name != tex.name) |
|
|
1758 | { |
|
|
1759 | if (!tex.name) |
1759 | if (!tex.name) |
1760 | continue; // smoothing not yet available |
1760 | continue; // smoothing not yet available |
1761 | |
1761 | |
1762 | glEnd (); |
1762 | glEnd (); |
1763 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1763 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1764 | glBegin (GL_QUADS); |
1764 | glBegin (GL_QUADS); |
1765 | } |
1765 | } |
1766 | |
1766 | |
1767 | if (border) |
1767 | if (border) |
1768 | { |
1768 | { |
1769 | float ox = border * dx; |
1769 | float ox = border * dx; |
1770 | |
1770 | |
1771 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
1771 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
1772 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
1772 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
1773 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
1773 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
1774 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
1774 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
1775 | } |
1775 | } |
1776 | |
1776 | |
1777 | if (corner) |
1777 | if (corner) |
1778 | { |
1778 | { |
1779 | float ox = corner * dx; |
1779 | float ox = corner * dx; |
1780 | |
1780 | |
1781 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
1781 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
1782 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
1782 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
1783 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
1783 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
1784 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
1784 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
1785 | } |
|
|
1786 | } |
1785 | } |
1787 | } |
1786 | } |
1788 | } |
1787 | } |
1789 | } |
1788 | } |
1790 | } |
1789 | } |
1791 | |
|
|
1792 | hv_clear (smooth); |
|
|
1793 | } |
1790 | } |
|
|
1791 | |
|
|
1792 | //hv_clear (smooth); |
1794 | |
1793 | |
1795 | glEnd (); |
1794 | glEnd (); |
1796 | |
1795 | |
1797 | glDisable (GL_TEXTURE_2D); |
1796 | glDisable (GL_TEXTURE_2D); |
1798 | glDisable (GL_BLEND); |
1797 | glDisable (GL_BLEND); |