… | |
… | |
17 | #include "perl.h" |
17 | #include "perl.h" |
18 | #include "XSUB.h" |
18 | #include "XSUB.h" |
19 | |
19 | |
20 | #ifdef _WIN32 |
20 | #ifdef _WIN32 |
21 | # undef pipe |
21 | # undef pipe |
|
|
22 | // microsoft vs. C |
|
|
23 | # define sqrtf(x) sqrt(x) |
|
|
24 | # define roundf(x) (int)(x) |
|
|
25 | # define atan2f(x,y) atan2(x,y) |
|
|
26 | # define M_PI 3.14159265f |
22 | #endif |
27 | #endif |
23 | |
28 | |
24 | #include <assert.h> |
29 | #include <assert.h> |
25 | #include <math.h> |
30 | #include <math.h> |
26 | #include <string.h> |
31 | #include <string.h> |
… | |
… | |
109 | av_push (texture_av, (SV *)(size_t)name); |
114 | av_push (texture_av, (SV *)(size_t)name); |
110 | glDeleteTextures (1, &name); |
115 | glDeleteTextures (1, &name); |
111 | } |
116 | } |
112 | |
117 | |
113 | #include "texcache.c" |
118 | #include "texcache.c" |
|
|
119 | #include "rendercache.c" |
114 | |
120 | |
115 | #include "pango-font.c" |
121 | #include "pango-font.c" |
116 | #include "pango-fontmap.c" |
122 | #include "pango-fontmap.c" |
117 | #include "pango-render.c" |
123 | #include "pango-render.c" |
118 | |
124 | |
… | |
… | |
144 | typedef struct cf_layout { |
150 | typedef struct cf_layout { |
145 | PangoLayout *pl; |
151 | PangoLayout *pl; |
146 | float r, g, b, a; // default color for rgba mode |
152 | float r, g, b, a; // default color for rgba mode |
147 | int base_height; |
153 | int base_height; |
148 | CFPlus__Font font; |
154 | CFPlus__Font font; |
|
|
155 | rc_t *rc; |
149 | } *CFPlus__Layout; |
156 | } *CFPlus__Layout; |
150 | |
157 | |
151 | static CFPlus__Font default_font; |
158 | static CFPlus__Font default_font; |
152 | static PangoContext *opengl_context; |
159 | static PangoContext *opengl_context; |
153 | static PangoFontMap *opengl_fontmap; |
160 | static PangoFontMap *opengl_fontmap; |
… | |
… | |
196 | |
203 | |
197 | typedef uint16_t tileid; |
204 | typedef uint16_t tileid; |
198 | typedef uint16_t faceid; |
205 | typedef uint16_t faceid; |
199 | |
206 | |
200 | typedef struct { |
207 | typedef struct { |
201 | int name; |
208 | GLuint name; |
202 | int w, h; |
209 | int w, h; |
203 | float s, t; |
210 | float s, t; |
204 | uint8_t r, g, b, a; |
211 | uint8_t r, g, b, a; |
205 | tileid smoothtile; |
212 | tileid smoothtile; |
206 | uint8_t smoothlevel; |
213 | uint8_t smoothlevel; |
… | |
… | |
708 | |
715 | |
709 | if (RETVAL) |
716 | if (RETVAL) |
710 | { |
717 | { |
711 | av_clear (texture_av); |
718 | av_clear (texture_av); |
712 | |
719 | |
713 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
720 | SDL_WM_SetCaption ("Crossfire TRT Client " VERSION, "Crossfire TRT"); |
714 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
721 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
715 | #include "glfunc.h" |
722 | #include "glfunc.h" |
716 | #undef GL_FUNC |
723 | #undef GL_FUNC |
717 | } |
724 | } |
718 | } |
725 | } |
… | |
… | |
804 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
811 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
805 | } |
812 | } |
806 | } |
813 | } |
807 | |
814 | |
808 | int |
815 | int |
809 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
816 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) |
810 | POSTCALL: |
817 | POSTCALL: |
811 | Mix_HookMusicFinished (music_finished); |
818 | Mix_HookMusicFinished (music_finished); |
812 | Mix_ChannelFinished (channel_finished); |
819 | Mix_ChannelFinished (channel_finished); |
813 | |
820 | |
814 | void |
821 | void |
… | |
… | |
1030 | RETVAL->g = 1.; |
1037 | RETVAL->g = 1.; |
1031 | RETVAL->b = 1.; |
1038 | RETVAL->b = 1.; |
1032 | RETVAL->a = 1.; |
1039 | RETVAL->a = 1.; |
1033 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1040 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1034 | RETVAL->font = 0; |
1041 | RETVAL->font = 0; |
|
|
1042 | RETVAL->rc = rc_alloc (); |
1035 | |
1043 | |
1036 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1044 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1037 | layout_update_font (RETVAL); |
1045 | layout_update_font (RETVAL); |
1038 | OUTPUT: |
1046 | OUTPUT: |
1039 | RETVAL |
1047 | RETVAL |
1040 | |
1048 | |
1041 | void |
1049 | void |
1042 | DESTROY (CFPlus::Layout self) |
1050 | DESTROY (CFPlus::Layout self) |
1043 | CODE: |
1051 | CODE: |
1044 | g_object_unref (self->pl); |
1052 | g_object_unref (self->pl); |
|
|
1053 | rc_free (self->rc); |
1045 | Safefree (self); |
1054 | Safefree (self); |
1046 | |
1055 | |
1047 | void |
1056 | void |
1048 | set_text (CFPlus::Layout self, SV *text_) |
1057 | set_text (CFPlus::Layout self, SV *text_) |
1049 | CODE: |
1058 | CODE: |
… | |
… | |
1301 | } |
1310 | } |
1302 | } |
1311 | } |
1303 | |
1312 | |
1304 | void |
1313 | void |
1305 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1314 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1306 | PPCODE: |
1315 | CODE: |
|
|
1316 | rc_clear (self->rc); |
1307 | pango_opengl_render_layout_subpixel ( |
1317 | pango_opengl_render_layout_subpixel ( |
1308 | self->pl, |
1318 | self->pl, |
|
|
1319 | self->rc, |
1309 | x * PANGO_SCALE, y * PANGO_SCALE, |
1320 | x * PANGO_SCALE, y * PANGO_SCALE, |
1310 | self->r, self->g, self->b, self->a, |
1321 | self->r, self->g, self->b, self->a, |
1311 | flags |
1322 | flags |
1312 | ); |
1323 | ); |
|
|
1324 | // we assume that context_change actually clears/frees stuff |
|
|
1325 | // and does not do any recomputation... |
|
|
1326 | pango_layout_context_changed (self->pl); |
|
|
1327 | |
|
|
1328 | void |
|
|
1329 | draw (CFPlus::Layout self) |
|
|
1330 | CODE: |
|
|
1331 | { |
|
|
1332 | glEnable (GL_TEXTURE_2D); |
|
|
1333 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1334 | glEnable (GL_BLEND); |
|
|
1335 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1336 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1337 | glEnable (GL_ALPHA_TEST); |
|
|
1338 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1339 | |
|
|
1340 | rc_draw (self->rc); |
|
|
1341 | |
|
|
1342 | glDisable (GL_ALPHA_TEST); |
|
|
1343 | glDisable (GL_BLEND); |
|
|
1344 | glDisable (GL_TEXTURE_2D); |
|
|
1345 | } |
1313 | |
1346 | |
1314 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1347 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1315 | |
1348 | |
1316 | PROTOTYPES: ENABLE |
1349 | PROTOTYPES: ENABLE |
1317 | |
1350 | |
… | |
… | |
1349 | { |
1382 | { |
1350 | HV *hv = (HV *)SvRV (self); |
1383 | HV *hv = (HV *)SvRV (self); |
1351 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1384 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1352 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1385 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1353 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1386 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
|
|
1387 | |
|
|
1388 | if (name <= 0) |
|
|
1389 | XSRETURN_EMPTY; |
1354 | |
1390 | |
1355 | if (items < 5) |
1391 | if (items < 5) |
1356 | { |
1392 | { |
1357 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1393 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1358 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1394 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
… | |
… | |
1547 | self->rows += MAP_EXTEND_Y; |
1583 | self->rows += MAP_EXTEND_Y; |
1548 | self->y += MAP_EXTEND_Y; |
1584 | self->y += MAP_EXTEND_Y; |
1549 | } |
1585 | } |
1550 | } |
1586 | } |
1551 | |
1587 | |
1552 | void |
1588 | SV * |
1553 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1589 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1554 | CODE: |
1590 | CODE: |
1555 | { |
1591 | { |
1556 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1592 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1557 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1593 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1558 | mapcell *cell; |
1594 | mapcell *cell; |
1559 | int x, y, flags; |
1595 | int x, y, z, flags; |
|
|
1596 | AV *missing = newAV (); |
|
|
1597 | RETVAL = newRV_noinc ((SV *)missing); |
1560 | |
1598 | |
1561 | while (data < data_end - 1) |
1599 | while (data < data_end - 1) |
1562 | { |
1600 | { |
1563 | flags = (data [0] << 8) + data [1]; data += 2; |
1601 | flags = (data [0] << 8) + data [1]; data += 2; |
1564 | |
1602 | |
… | |
… | |
1615 | } |
1653 | } |
1616 | else |
1654 | else |
1617 | cell->darkness = *data++ + 1; |
1655 | cell->darkness = *data++ + 1; |
1618 | } |
1656 | } |
1619 | |
1657 | |
|
|
1658 | for (z = 0; z <= 2; ++z) |
1620 | if (flags & 4) |
1659 | if (flags & (4 >> z)) |
1621 | { |
1660 | { |
1622 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1661 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1623 | need_facenum (self, face); |
1662 | need_facenum (self, face); |
1624 | cell->tile [0] = self->face2tile [face]; |
1663 | cell->tile [z] = self->face2tile [face]; |
|
|
1664 | |
|
|
1665 | if (cell->tile [z]) |
|
|
1666 | { |
|
|
1667 | maptex *tex = self->tex + cell->tile [z]; |
|
|
1668 | if (!tex->name) |
|
|
1669 | av_push (missing, newSViv (cell->tile [z])); |
|
|
1670 | |
|
|
1671 | if (tex->smoothtile) |
|
|
1672 | { |
|
|
1673 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
1674 | if (!smooth->name) |
|
|
1675 | av_push (missing, newSViv (tex->smoothtile)); |
|
|
1676 | } |
|
|
1677 | } |
1625 | } |
1678 | } |
1626 | |
|
|
1627 | if (flags & 2) |
|
|
1628 | { |
|
|
1629 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1630 | need_facenum (self, face); |
|
|
1631 | cell->tile [1] = self->face2tile [face]; |
|
|
1632 | } |
|
|
1633 | |
|
|
1634 | if (flags & 1) |
|
|
1635 | { |
|
|
1636 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1637 | need_facenum (self, face); |
|
|
1638 | cell->tile [2] = self->face2tile [face]; |
|
|
1639 | } |
|
|
1640 | } |
1679 | } |
1641 | else |
1680 | else |
1642 | cell->darkness = 0; |
1681 | cell->darkness = 0; |
1643 | } |
1682 | } |
1644 | } |
1683 | } |
|
|
1684 | OUTPUT: |
|
|
1685 | RETVAL |
1645 | |
1686 | |
1646 | SV * |
1687 | SV * |
1647 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1688 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1648 | CODE: |
1689 | CODE: |
1649 | { |
1690 | { |
… | |
… | |
1700 | |
1741 | |
1701 | void |
1742 | void |
1702 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1743 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1703 | CODE: |
1744 | CODE: |
1704 | { |
1745 | { |
|
|
1746 | int x, y, z; |
|
|
1747 | |
1705 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1748 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1706 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1749 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1707 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1750 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1708 | smooth_key skey; |
1751 | smooth_key skey; |
1709 | int x, y, z; |
1752 | |
1710 | int last_name; |
1753 | rc_t *rc = rc_alloc (); |
|
|
1754 | rc_key_t key; |
|
|
1755 | rc_array_t *arr; |
1711 | |
1756 | |
1712 | // thats current max. sorry. |
1757 | // thats current max. sorry. |
1713 | if (sw > 255) sw = 255; |
1758 | if (sw > 255) sw = 255; |
1714 | if (sh > 255) sh = 255; |
1759 | if (sh > 255) sh = 255; |
1715 | |
1760 | |
1716 | // clear key, in case of extra padding |
1761 | // clear key, in case of extra padding |
1717 | memset (&skey, 0, sizeof (skey)); |
1762 | memset (&skey, 0, sizeof (skey)); |
1718 | |
1763 | |
1719 | glColor4ub (255, 255, 255, 255); |
1764 | memset (&key, 0, sizeof (key)); |
1720 | |
1765 | key.r = 255; |
1721 | glEnable (GL_BLEND); |
1766 | key.g = 255; |
1722 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1767 | key.b = 255; |
1723 | glEnable (GL_TEXTURE_2D); |
1768 | key.a = 255; |
1724 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1769 | key.mode = GL_QUADS; |
1725 | |
1770 | key.format = GL_T2F_V3F; |
1726 | glBegin (GL_QUADS); |
1771 | key.texname = -1; |
1727 | |
|
|
1728 | last_name = 0; |
|
|
1729 | |
1772 | |
1730 | mx += self->x; |
1773 | mx += self->x; |
1731 | my += self->y; |
1774 | my += self->y; |
1732 | |
1775 | |
1733 | // first pass: determine smooth_max |
1776 | // first pass: determine smooth_max |
… | |
… | |
1749 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1792 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1750 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1793 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1751 | self->tex [cell->tile [2]].smoothlevel)); |
1794 | self->tex [cell->tile [2]].smoothlevel)); |
1752 | } |
1795 | } |
1753 | } |
1796 | } |
|
|
1797 | |
|
|
1798 | glEnable (GL_BLEND); |
|
|
1799 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1800 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1754 | |
1801 | |
1755 | for (z = 0; z <= 2; z++) |
1802 | for (z = 0; z <= 2; z++) |
1756 | { |
1803 | { |
1757 | memset (smooth_level, 0, sizeof (smooth_level)); |
1804 | memset (smooth_level, 0, sizeof (smooth_level)); |
1758 | |
1805 | |
… | |
… | |
1768 | tileid tile = cell->tile [z]; |
1815 | tileid tile = cell->tile [z]; |
1769 | |
1816 | |
1770 | if (tile) |
1817 | if (tile) |
1771 | { |
1818 | { |
1772 | maptex tex = self->tex [tile]; |
1819 | maptex tex = self->tex [tile]; |
1773 | int px = (x + 1) * T - tex.w; |
1820 | int px, py; |
1774 | int py = (y + 1) * T - tex.h; |
|
|
1775 | |
1821 | |
1776 | // suppressing texture state switches here |
|
|
1777 | // is only moderately effective, but worth the extra effort |
|
|
1778 | if (last_name != tex.name) |
1822 | if (key.texname != tex.name) |
1779 | { |
1823 | { |
1780 | if (!tex.name) |
1824 | if (!tex.name) |
1781 | tex = self->tex [2]; /* missing, replace by noface */ |
1825 | tex = self->tex [2]; /* missing, replace by noface */ |
1782 | |
1826 | |
1783 | glEnd (); |
1827 | key.texname = tex.name; |
1784 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1828 | arr = rc_array (rc, &key); |
1785 | glBegin (GL_QUADS); |
|
|
1786 | } |
1829 | } |
1787 | |
1830 | |
1788 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1831 | px = (x + 1) * T - tex.w; |
|
|
1832 | py = (y + 1) * T - tex.h; |
|
|
1833 | |
|
|
1834 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
1789 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1835 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
1790 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1836 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
1791 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1837 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1792 | |
1838 | |
1793 | if (cell->flags && z == 2) |
1839 | if (cell->flags && z == 2) |
1794 | { |
1840 | { |
|
|
1841 | // overlays such as the speech bubble, probably more to come |
1795 | if (cell->flags & 1) |
1842 | if (cell->flags & 1) |
1796 | { |
1843 | { |
1797 | maptex tex = self->tex [1]; |
1844 | maptex tex = self->tex [1]; |
1798 | int px = x * T + T * 2 / 32; |
1845 | int px = x * T + T * 2 / 32; |
1799 | int py = y * T - T * 6 / 32; |
1846 | int py = y * T - T * 6 / 32; |
1800 | |
1847 | |
|
|
1848 | if (tex.name) |
1801 | glEnd (); |
1849 | { |
1802 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1850 | if (key.texname != tex.name) |
|
|
1851 | { |
|
|
1852 | key.texname = tex.name; |
|
|
1853 | arr = rc_array (rc, &key); |
|
|
1854 | } |
|
|
1855 | |
|
|
1856 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1857 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1858 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1859 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
1803 | glBegin (GL_QUADS); |
1860 | } |
1804 | |
|
|
1805 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1806 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + T); |
|
|
1807 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); |
|
|
1808 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); |
|
|
1809 | } |
1861 | } |
1810 | } |
1862 | } |
1811 | |
1863 | |
1812 | // update smooth hash |
1864 | // update smooth hash |
1813 | if (tex.smoothtile) |
1865 | if (tex.smoothtile) |
… | |
… | |
1849 | } |
1901 | } |
1850 | } |
1902 | } |
1851 | } |
1903 | } |
1852 | } |
1904 | } |
1853 | |
1905 | |
|
|
1906 | rc_draw (rc); |
|
|
1907 | rc_clear (rc); |
|
|
1908 | |
1854 | // go through all smoothlevels, lowest to highest, then draw. |
1909 | // go through all smoothlevels, lowest to highest, then draw. |
1855 | // this is basically counting sort |
1910 | // this is basically counting sort |
1856 | { |
1911 | { |
1857 | int w, b; |
1912 | int w, b; |
1858 | |
1913 | |
|
|
1914 | glEnable (GL_TEXTURE_2D); |
|
|
1915 | glBegin (GL_QUADS); |
1859 | for (w = 0; w < 256 / 32; ++w) |
1916 | for (w = 0; w < 256 / 32; ++w) |
1860 | { |
1917 | { |
1861 | uint32_t smask = smooth_level [w]; |
1918 | uint32_t smask = smooth_level [w]; |
1862 | if (smask) |
1919 | if (smask) |
1863 | for (b = 0; b < 32; ++b) |
1920 | for (b = 0; b < 32; ++b) |
… | |
… | |
1882 | int border = bits & 15; |
1939 | int border = bits & 15; |
1883 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1940 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1884 | float dx = tex.s * .0625f; // 16 images/row |
1941 | float dx = tex.s * .0625f; // 16 images/row |
1885 | float dy = tex.t * .5f ; // 2 images/column |
1942 | float dy = tex.t * .5f ; // 2 images/column |
1886 | |
1943 | |
1887 | // this time naively avoiding texture state changes |
|
|
1888 | // save gobs of state changes. |
|
|
1889 | if (last_name != tex.name) |
1944 | if (tex.name) |
1890 | { |
1945 | { |
|
|
1946 | // this time avoiding texture state changes |
|
|
1947 | // save gobs of state changes. |
1891 | if (!tex.name) |
1948 | if (key.texname != tex.name) |
1892 | continue; // smoothing not yet available |
1949 | { |
1893 | |
|
|
1894 | glEnd (); |
1950 | glEnd (); |
1895 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1951 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1896 | glBegin (GL_QUADS); |
1952 | glBegin (GL_QUADS); |
1897 | } |
1953 | } |
1898 | |
1954 | |
1899 | if (border) |
1955 | if (border) |
1900 | { |
1956 | { |
1901 | float ox = border * dx; |
1957 | float ox = border * dx; |
1902 | |
1958 | |
1903 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
1959 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1904 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
1960 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
1905 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
1961 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
1906 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
1962 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
1907 | } |
1963 | } |
1908 | |
1964 | |
1909 | if (corner) |
1965 | if (corner) |
1910 | { |
1966 | { |
1911 | float ox = corner * dx; |
1967 | float ox = corner * dx; |
1912 | |
1968 | |
1913 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
1969 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1914 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
1970 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
1915 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
1971 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
1916 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
1972 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
|
|
1973 | } |
1917 | } |
1974 | } |
1918 | } |
1975 | } |
1919 | } |
1976 | } |
1920 | } |
1977 | } |
1921 | } |
1978 | } |
|
|
1979 | |
|
|
1980 | glEnd (); |
|
|
1981 | glDisable (GL_TEXTURE_2D); |
|
|
1982 | key.texname = -1; |
1922 | } |
1983 | } |
1923 | |
1984 | |
1924 | hv_clear (smooth); |
1985 | hv_clear (smooth); |
1925 | } |
1986 | } |
1926 | |
1987 | |
1927 | glEnd (); |
|
|
1928 | |
|
|
1929 | glDisable (GL_TEXTURE_2D); |
|
|
1930 | glDisable (GL_BLEND); |
1988 | glDisable (GL_BLEND); |
|
|
1989 | rc_free (rc); |
1931 | |
1990 | |
1932 | // top layer: overlays such as the health bar |
1991 | // top layer: overlays such as the health bar |
1933 | for (y = 0; y < sh; y++) |
1992 | for (y = 0; y < sh; y++) |
1934 | if (0 <= y + my && y + my < self->rows) |
1993 | if (0 <= y + my && y + my < self->rows) |
1935 | { |
1994 | { |
… | |
… | |
2184 | int x, y, z; |
2243 | int x, y, z; |
2185 | int w, h; |
2244 | int w, h; |
2186 | int x1, y1; |
2245 | int x1, y1; |
2187 | |
2246 | |
2188 | if (*data++ != 0) |
2247 | if (*data++ != 0) |
2189 | return; /* version mismatch */ |
2248 | XSRETURN_EMPTY; /* version mismatch */ |
2190 | |
2249 | |
2191 | w = *data++ << 8; w |= *data++; |
2250 | w = *data++ << 8; w |= *data++; |
2192 | h = *data++ << 8; h |= *data++; |
2251 | h = *data++ << 8; h |= *data++; |
2193 | |
2252 | |
2194 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2253 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2260 | CODE: |
2319 | CODE: |
2261 | RETVAL = SDL_RWFromFile (path, mode); |
2320 | RETVAL = SDL_RWFromFile (path, mode); |
2262 | OUTPUT: |
2321 | OUTPUT: |
2263 | RETVAL |
2322 | RETVAL |
2264 | |
2323 | |
|
|
2324 | # fails on win32: |
|
|
2325 | # CFPlus.xs(2268) : error C2059: syntax error : '(' |
2265 | void |
2326 | #void |
2266 | close (CFPlus::RW self) |
2327 | #close (CFPlus::RW self) |
2267 | CODE: |
2328 | # CODE: |
2268 | SDL_RWclose (self); |
2329 | # (self->(close)) (self); |
2269 | |
2330 | |
2270 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
2331 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
2271 | |
2332 | |
2272 | PROTOTYPES: DISABLE |
2333 | PROTOTYPES: DISABLE |
2273 | |
2334 | |
… | |
… | |
2309 | Mix_FadeOutChannel (self, ticks); |
2370 | Mix_FadeOutChannel (self, ticks); |
2310 | |
2371 | |
2311 | int |
2372 | int |
2312 | volume (CFPlus::Channel self, int volume) |
2373 | volume (CFPlus::Channel self, int volume) |
2313 | CODE: |
2374 | CODE: |
2314 | RETVAL = Mix_Volume (self, volume); |
2375 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2315 | OUTPUT: |
2376 | OUTPUT: |
2316 | RETVAL |
2377 | RETVAL |
2317 | |
2378 | |
2318 | void |
2379 | void |
2319 | unregister_all_effects (CFPlus::Channel self) |
2380 | unregister_all_effects (CFPlus::Channel self) |
… | |
… | |
2321 | Mix_UnregisterAllEffects (self); |
2382 | Mix_UnregisterAllEffects (self); |
2322 | |
2383 | |
2323 | void |
2384 | void |
2324 | set_panning (CFPlus::Channel self, int left, int right) |
2385 | set_panning (CFPlus::Channel self, int left, int right) |
2325 | CODE: |
2386 | CODE: |
|
|
2387 | left = CLAMP (left , 0, 255); |
|
|
2388 | right = CLAMP (right, 0, 255); |
2326 | Mix_SetPanning (self, left, right); |
2389 | Mix_SetPanning (self, left, right); |
2327 | |
2390 | |
2328 | void |
2391 | void |
2329 | set_distance (CFPlus::Channel self, int distance) |
2392 | set_distance (CFPlus::Channel self, int distance) |
2330 | CODE: |
2393 | CODE: |
2331 | Mix_SetDistance (self, distance); |
2394 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2332 | |
2395 | |
2333 | void |
2396 | void |
2334 | set_position (CFPlus::Channel self, int angle, int distance) |
2397 | set_position (CFPlus::Channel self, int angle, int distance) |
2335 | CODE: |
2398 | CODE: |
|
|
2399 | |
|
|
2400 | void |
|
|
2401 | set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) |
|
|
2402 | CODE: |
|
|
2403 | { |
|
|
2404 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
|
|
2405 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2336 | Mix_SetPosition (self, angle, distance); |
2406 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
|
|
2407 | } |
2337 | |
2408 | |
2338 | void |
2409 | void |
2339 | set_reverse_stereo (CFPlus::Channel self, int flip) |
2410 | set_reverse_stereo (CFPlus::Channel self, int flip) |
2340 | CODE: |
2411 | CODE: |
2341 | Mix_SetReverseStereo (self, flip); |
2412 | Mix_SetReverseStereo (self, flip); |
… | |
… | |
2357 | Mix_FreeChunk (self); |
2428 | Mix_FreeChunk (self); |
2358 | |
2429 | |
2359 | int |
2430 | int |
2360 | volume (CFPlus::MixChunk self, int volume = -1) |
2431 | volume (CFPlus::MixChunk self, int volume = -1) |
2361 | CODE: |
2432 | CODE: |
|
|
2433 | if (items > 1) |
|
|
2434 | volume = CLAMP (volume, 0, 128); |
2362 | RETVAL = Mix_VolumeChunk (self, volume); |
2435 | RETVAL = Mix_VolumeChunk (self, volume); |
2363 | OUTPUT: |
2436 | OUTPUT: |
2364 | RETVAL |
2437 | RETVAL |
2365 | |
2438 | |
2366 | CFPlus::Channel |
2439 | CFPlus::Channel |
… | |
… | |
2385 | |
2458 | |
2386 | int |
2459 | int |
2387 | volume (int volume = -1) |
2460 | volume (int volume = -1) |
2388 | PROTOTYPE: ;$ |
2461 | PROTOTYPE: ;$ |
2389 | CODE: |
2462 | CODE: |
|
|
2463 | if (items > 0) |
|
|
2464 | volume = CLAMP (volume, 0, 128); |
2390 | RETVAL = Mix_VolumeMusic (volume); |
2465 | RETVAL = Mix_VolumeMusic (volume); |
2391 | OUTPUT: |
2466 | OUTPUT: |
2392 | RETVAL |
2467 | RETVAL |
2393 | |
2468 | |
2394 | void |
2469 | void |
… | |
… | |
2474 | const_iv (GL_INTENSITY), |
2549 | const_iv (GL_INTENSITY), |
2475 | const_iv (GL_LUMINANCE), |
2550 | const_iv (GL_LUMINANCE), |
2476 | const_iv (GL_LUMINANCE_ALPHA), |
2551 | const_iv (GL_LUMINANCE_ALPHA), |
2477 | const_iv (GL_FLOAT), |
2552 | const_iv (GL_FLOAT), |
2478 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
2553 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
2554 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
2555 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
2556 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
2557 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
2558 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
2559 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2479 | const_iv (GL_COMPILE), |
2560 | const_iv (GL_COMPILE), |
2480 | const_iv (GL_PROXY_TEXTURE_1D), |
2561 | const_iv (GL_PROXY_TEXTURE_1D), |
2481 | const_iv (GL_PROXY_TEXTURE_2D), |
2562 | const_iv (GL_PROXY_TEXTURE_2D), |
2482 | const_iv (GL_TEXTURE_1D), |
2563 | const_iv (GL_TEXTURE_1D), |
2483 | const_iv (GL_TEXTURE_2D), |
2564 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2522 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2603 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2523 | const_iv (GL_POINT_SMOOTH_HINT), |
2604 | const_iv (GL_POINT_SMOOTH_HINT), |
2524 | const_iv (GL_LINE_SMOOTH_HINT), |
2605 | const_iv (GL_LINE_SMOOTH_HINT), |
2525 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2606 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2526 | const_iv (GL_GENERATE_MIPMAP_HINT), |
2607 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
2608 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2527 | const_iv (GL_FASTEST), |
2609 | const_iv (GL_FASTEST), |
2528 | const_iv (GL_DONT_CARE), |
2610 | const_iv (GL_DONT_CARE), |
2529 | const_iv (GL_NICEST), |
2611 | const_iv (GL_NICEST), |
2530 | const_iv (GL_V2F), |
2612 | const_iv (GL_V2F), |
2531 | const_iv (GL_V3F), |
2613 | const_iv (GL_V3F), |
… | |
… | |
2539 | |
2621 | |
2540 | texture_av = newAV (); |
2622 | texture_av = newAV (); |
2541 | AvREAL_off (texture_av); |
2623 | AvREAL_off (texture_av); |
2542 | } |
2624 | } |
2543 | |
2625 | |
|
|
2626 | void |
|
|
2627 | disable_GL_EXT_blend_func_separate () |
|
|
2628 | CODE: |
|
|
2629 | gl.BlendFuncSeparate = 0; |
|
|
2630 | gl.BlendFuncSeparateEXT = 0; |
|
|
2631 | |
2544 | char * |
2632 | char * |
2545 | gl_vendor () |
2633 | gl_vendor () |
2546 | CODE: |
2634 | CODE: |
2547 | RETVAL = (char *)glGetString (GL_VENDOR); |
2635 | RETVAL = (char *)glGetString (GL_VENDOR); |
2548 | OUTPUT: |
2636 | OUTPUT: |
… | |
… | |
2669 | |
2757 | |
2670 | void glRect (float x1, float y1, float x2, float y2) |
2758 | void glRect (float x1, float y1, float x2, float y2) |
2671 | CODE: |
2759 | CODE: |
2672 | glRectf (x1, y1, x2, y2); |
2760 | glRectf (x1, y1, x2, y2); |
2673 | |
2761 | |
|
|
2762 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
2763 | CODE: |
|
|
2764 | glBegin (GL_LINE_LOOP); |
|
|
2765 | glVertex2f (x1, y1); |
|
|
2766 | glVertex2f (x2, y1); |
|
|
2767 | glVertex2f (x2, y2); |
|
|
2768 | glVertex2f (x1, y2); |
|
|
2769 | glEnd (); |
|
|
2770 | |
2674 | PROTOTYPES: ENABLE |
2771 | PROTOTYPES: ENABLE |
2675 | |
2772 | |
2676 | void glBegin (int mode) |
2773 | void glBegin (int mode) |
2677 | |
2774 | |
2678 | void glEnd () |
2775 | void glEnd () |
… | |
… | |
2779 | NV x, y, w, h; |
2876 | NV x, y, w, h; |
2780 | SV *draw_x_sv = GvSV (draw_x_gv); |
2877 | SV *draw_x_sv = GvSV (draw_x_gv); |
2781 | SV *draw_y_sv = GvSV (draw_y_gv); |
2878 | SV *draw_y_sv = GvSV (draw_y_gv); |
2782 | SV *draw_w_sv = GvSV (draw_w_gv); |
2879 | SV *draw_w_sv = GvSV (draw_w_gv); |
2783 | SV *draw_h_sv = GvSV (draw_h_gv); |
2880 | SV *draw_h_sv = GvSV (draw_h_gv); |
2784 | SV *hover; |
|
|
2785 | double draw_x, draw_y, draw_w, draw_h; |
2881 | double draw_x, draw_y; |
2786 | |
2882 | |
2787 | if (!SvROK (self)) |
2883 | if (!SvROK (self)) |
2788 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
2884 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
2789 | |
2885 | |
2790 | hv = (HV *)SvRV (self); |
2886 | hv = (HV *)SvRV (self); |
… | |
… | |
2818 | { |
2914 | { |
2819 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2915 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2820 | |
2916 | |
2821 | if (svp && SvTRUE (*svp)) |
2917 | if (svp && SvTRUE (*svp)) |
2822 | { |
2918 | { |
2823 | glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); |
2919 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
2824 | glEnable (GL_BLEND); |
2920 | glEnable (GL_BLEND); |
2825 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2921 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2826 | glBegin (GL_QUADS); |
2922 | glBegin (GL_QUADS); |
2827 | glVertex2f (0, 0); |
2923 | glVertex2f (0, 0); |
2828 | glVertex2f (w, 0); |
2924 | glVertex2f (w, 0); |
… | |
… | |
2831 | glEnd (); |
2927 | glEnd (); |
2832 | glDisable (GL_BLEND); |
2928 | glDisable (GL_BLEND); |
2833 | } |
2929 | } |
2834 | } |
2930 | } |
2835 | #if 0 |
2931 | #if 0 |
2836 | if ($ENV{CFPLUS_DEBUG} & 1) { |
2932 | // draw borders, for debugging |
2837 | glPushMatrix; |
2933 | glPushMatrix (); |
2838 | glColor 1, 1, 0, 1; |
2934 | glColor4f (1., 1., 0., 1.); |
2839 | glTranslate 0.375, 0.375; |
2935 | glTranslatef (.5, .5, 0.); |
2840 | glBegin GL_LINE_LOOP; |
2936 | glBegin (GL_LINE_LOOP); |
2841 | glVertex 0 , 0; |
2937 | glVertex2f (0 , 0); |
2842 | glVertex $self->{w} - 1, 0; |
2938 | glVertex2f (w - 1, 0); |
2843 | glVertex $self->{w} - 1, $self->{h} - 1; |
2939 | glVertex2f (w - 1, h - 1); |
2844 | glVertex 0 , $self->{h} - 1; |
2940 | glVertex2f (0 , h - 1); |
2845 | glEnd; |
2941 | glEnd (); |
2846 | glPopMatrix; |
2942 | glPopMatrix (); |
2847 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2848 | } |
|
|
2849 | #endif |
2943 | #endif |
2850 | PUSHMARK (SP); |
2944 | PUSHMARK (SP); |
2851 | XPUSHs (self); |
2945 | XPUSHs (self); |
2852 | PUTBACK; |
2946 | PUTBACK; |
2853 | call_method ("_draw", G_VOID | G_DISCARD); |
2947 | call_method ("_draw", G_VOID | G_DISCARD); |