… | |
… | |
56 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
56 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
57 | #else |
57 | #else |
58 | # define PARACHUTE 0 |
58 | # define PARACHUTE 0 |
59 | #endif |
59 | #endif |
60 | |
60 | |
|
|
61 | static AV *texture_av; |
|
|
62 | |
61 | static struct |
63 | static struct |
62 | { |
64 | { |
63 | #define GL_FUNC(ptr,name) ptr name; |
65 | #define GL_FUNC(ptr,name) ptr name; |
64 | #include "glfunc.h" |
66 | #include "glfunc.h" |
65 | #undef GL_FUNC |
67 | #undef GL_FUNC |
66 | } gl; |
68 | } gl; |
67 | |
69 | |
|
|
70 | static void |
68 | static void gl_BlendFuncSeparate (GLenum sa, GLenum da, GLenum saa, GLenum daa) |
71 | gl_BlendFuncSeparate (GLenum sa, GLenum da, GLenum saa, GLenum daa) |
69 | { |
72 | { |
70 | if (gl.BlendFuncSeparate) |
73 | if (gl.BlendFuncSeparate) |
71 | gl.BlendFuncSeparate (sa, da, saa, daa); |
74 | gl.BlendFuncSeparate (sa, da, saa, daa); |
72 | else if (gl.BlendFuncSeparateEXT) |
75 | else if (gl.BlendFuncSeparateEXT) |
73 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
76 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
74 | else |
77 | else |
75 | glBlendFunc (sa, da); |
78 | glBlendFunc (sa, da); |
|
|
79 | } |
|
|
80 | |
|
|
81 | static GLuint |
|
|
82 | gen_texture () |
|
|
83 | { |
|
|
84 | GLuint name; |
|
|
85 | |
|
|
86 | if (AvFILL (texture_av) >= 0) |
|
|
87 | name = (GLuint)(size_t)av_pop (texture_av); |
|
|
88 | else |
|
|
89 | glGenTextures (1, &name); |
|
|
90 | |
|
|
91 | return name; |
|
|
92 | } |
|
|
93 | |
|
|
94 | static void |
|
|
95 | del_texture (GLuint name) |
|
|
96 | { |
|
|
97 | /* make a half-assed attempt at returning the memory used by the texture */ |
|
|
98 | /* textures are frequently being reused by cfplus anyway */ |
|
|
99 | /*glBindTexture (GL_TEXTURE_2D, name);*/ |
|
|
100 | /*glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0);*/ |
|
|
101 | av_push (texture_av, (SV *)(size_t)name); |
|
|
102 | glDeleteTextures (1, &name); |
76 | } |
103 | } |
77 | |
104 | |
78 | #include "texcache.c" |
105 | #include "texcache.c" |
79 | |
106 | |
80 | #include "pango-font.c" |
107 | #include "pango-font.c" |
… | |
… | |
400 | |
427 | |
401 | /* SDL should provide this, really. */ |
428 | /* SDL should provide this, really. */ |
402 | #define SDLK_MODIFIER_MIN 300 |
429 | #define SDLK_MODIFIER_MIN 300 |
403 | #define SDLK_MODIFIER_MAX 314 |
430 | #define SDLK_MODIFIER_MAX 314 |
404 | |
431 | |
405 | static AV *texture_av; |
|
|
406 | |
|
|
407 | MODULE = CFPlus PACKAGE = CFPlus |
432 | MODULE = CFPlus PACKAGE = CFPlus |
408 | |
433 | |
409 | PROTOTYPES: ENABLE |
434 | PROTOTYPES: ENABLE |
410 | |
435 | |
411 | BOOT: |
436 | BOOT: |
412 | { |
437 | { |
413 | texture_av = newAV (); |
|
|
414 | AvREAL_off (texture_av); |
|
|
415 | |
|
|
416 | HV *stash = gv_stashpv ("CFPlus", 1); |
438 | HV *stash = gv_stashpv ("CFPlus", 1); |
417 | static const struct { |
439 | static const struct { |
418 | const char *name; |
440 | const char *name; |
419 | IV iv; |
441 | IV iv; |
420 | } *civ, const_iv[] = { |
442 | } *civ, const_iv[] = { |
… | |
… | |
619 | RETVAL = !!SDL_SetVideoMode ( |
641 | RETVAL = !!SDL_SetVideoMode ( |
620 | w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0) |
642 | w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0) |
621 | ); |
643 | ); |
622 | if (RETVAL) |
644 | if (RETVAL) |
623 | { |
645 | { |
|
|
646 | av_clear (texture_av); |
|
|
647 | |
624 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
648 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
625 | # define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
649 | # define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
626 | # include "glfunc.h" |
650 | # include "glfunc.h" |
627 | # undef GL_FUNC |
651 | # undef GL_FUNC |
|
|
652 | |
628 | } |
653 | } |
629 | OUTPUT: |
654 | OUTPUT: |
630 | RETVAL |
655 | RETVAL |
631 | |
656 | |
632 | void |
657 | void |
… | |
… | |
1396 | CODE: |
1421 | CODE: |
1397 | { |
1422 | { |
1398 | if (dx > 0) |
1423 | if (dx > 0) |
1399 | map_blank (self, self->x, self->y, dx, self->h); |
1424 | map_blank (self, self->x, self->y, dx, self->h); |
1400 | else if (dx < 0) |
1425 | else if (dx < 0) |
1401 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1426 | map_blank (self, self->x + self->w + dx, self->y, -dx, self->h); |
1402 | |
1427 | |
1403 | if (dy > 0) |
1428 | if (dy > 0) |
1404 | map_blank (self, self->x, self->y, self->w, dy); |
1429 | map_blank (self, self->x, self->y, self->w, dy); |
1405 | else if (dy < 0) |
1430 | else if (dy < 0) |
1406 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1431 | map_blank (self, self->x, self->y + self->h + dy, self->w, -dy); |
1407 | |
1432 | |
1408 | self->ox += dx; self->x += dx; |
1433 | self->ox += dx; self->x += dx; |
1409 | self->oy += dy; self->y += dy; |
1434 | self->oy += dy; self->y += dy; |
1410 | |
1435 | |
1411 | while (self->y < 0) |
1436 | while (self->y < 0) |
… | |
… | |
1600 | |
1625 | |
1601 | // first pass: determine smooth_max |
1626 | // first pass: determine smooth_max |
1602 | // rather ugly, if you ask me |
1627 | // rather ugly, if you ask me |
1603 | // could also be stored inside mapcell and updated on change |
1628 | // could also be stored inside mapcell and updated on change |
1604 | memset (smooth_max, 0, sizeof (smooth_max)); |
1629 | memset (smooth_max, 0, sizeof (smooth_max)); |
1605 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
1606 | |
1630 | |
1607 | for (y = 0; y < sh; y++) |
1631 | for (y = 0; y < sh; y++) |
1608 | if (0 <= y + my && y + my < self->rows) |
1632 | if (0 <= y + my && y + my < self->rows) |
1609 | { |
1633 | { |
1610 | maprow *row = self->row + (y + my); |
1634 | maprow *row = self->row + (y + my); |
… | |
… | |
1621 | } |
1645 | } |
1622 | } |
1646 | } |
1623 | |
1647 | |
1624 | for (z = 0; z <= 2; z++) |
1648 | for (z = 0; z <= 2; z++) |
1625 | { |
1649 | { |
|
|
1650 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
1651 | |
1626 | for (y = 0; y < sh; y++) |
1652 | for (y = 0; y < sh; y++) |
1627 | if (0 <= y + my && y + my < self->rows) |
1653 | if (0 <= y + my && y + my < self->rows) |
1628 | { |
1654 | { |
1629 | maprow *row = self->row + (y + my); |
1655 | maprow *row = self->row + (y + my); |
1630 | |
1656 | |
… | |
… | |
1715 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
1741 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
1716 | } |
1742 | } |
1717 | } |
1743 | } |
1718 | } |
1744 | } |
1719 | } |
1745 | } |
1720 | } |
|
|
1721 | |
1746 | |
1722 | // go through all smoothlevels, lowest to highest, then draw. |
1747 | // go through all smoothlevels, lowest to highest, then draw. |
1723 | // this is basically counting sort |
1748 | // this is basically counting sort |
1724 | { |
|
|
1725 | int w, b; |
|
|
1726 | |
|
|
1727 | for (w = 0; w < 256 / 32; ++w) |
|
|
1728 | { |
1749 | { |
|
|
1750 | int w, b; |
|
|
1751 | |
|
|
1752 | for (w = 0; w < 256 / 32; ++w) |
|
|
1753 | { |
1729 | uint32_t smask = smooth_level [w]; |
1754 | uint32_t smask = smooth_level [w]; |
1730 | if (smask) |
1755 | if (smask) |
1731 | for (b = 0; b < 32; ++b) |
1756 | for (b = 0; b < 32; ++b) |
1732 | if (smask & (((uint32_t)1) << b)) |
1757 | 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))) |
|
|
1739 | { |
1758 | { |
1740 | smooth_key *skey = (smooth_key *)HeKEY (he); |
1759 | int level = (w << 5) | b; |
1741 | IV bits = SvIVX (HeVAL (he)); |
1760 | HE *he; |
1742 | |
1761 | |
1743 | if (!(bits & 0x1000) |
1762 | hv_iterinit (smooth); |
1744 | && skey->level == level |
1763 | while ((he = hv_iternext (smooth))) |
1745 | && level >= smooth_max [skey->x][skey->y]) |
|
|
1746 | { |
1764 | { |
1747 | maptex tex = self->tex [skey->tile]; |
1765 | smooth_key *skey = (smooth_key *)HeKEY (he); |
1748 | int px = (((int)skey->x) - 1) * T; |
1766 | IV bits = SvIVX (HeVAL (he)); |
1749 | int py = (((int)skey->y) - 1) * T; |
1767 | |
1750 | int border = bits & 15; |
1768 | if (!(bits & 0x1000) |
1751 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1769 | && skey->level == level |
1752 | float dx = tex.s * .0625f; // 16 images/row |
1770 | && level > smooth_max [skey->x][skey->y]) |
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 | { |
1771 | { |
|
|
1772 | maptex tex = self->tex [skey->tile]; |
|
|
1773 | int px = (((int)skey->x) - 1) * T; |
|
|
1774 | int py = (((int)skey->y) - 1) * T; |
|
|
1775 | int border = bits & 15; |
|
|
1776 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
1777 | float dx = tex.s * .0625f; // 16 images/row |
|
|
1778 | float dy = tex.t * .5f ; // 2 images/column |
|
|
1779 | |
|
|
1780 | // this time naively avoiding texture state changes |
|
|
1781 | // save gobs of state changes. |
|
|
1782 | if (last_name != tex.name) |
|
|
1783 | { |
1759 | if (!tex.name) |
1784 | if (!tex.name) |
1760 | continue; // smoothing not yet available |
1785 | continue; // smoothing not yet available |
1761 | |
1786 | |
1762 | glEnd (); |
1787 | glEnd (); |
1763 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1788 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1764 | glBegin (GL_QUADS); |
1789 | glBegin (GL_QUADS); |
1765 | } |
1790 | } |
1766 | |
1791 | |
1767 | if (border) |
1792 | if (border) |
1768 | { |
1793 | { |
1769 | float ox = border * dx; |
1794 | float ox = border * dx; |
1770 | |
1795 | |
1771 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
1796 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
1772 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
1797 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
1773 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
1798 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
1774 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
1799 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
1775 | } |
1800 | } |
1776 | |
1801 | |
1777 | if (corner) |
1802 | if (corner) |
1778 | { |
1803 | { |
1779 | float ox = corner * dx; |
1804 | float ox = corner * dx; |
1780 | |
1805 | |
1781 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
1806 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
1782 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
1807 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
1783 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
1808 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
1784 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
1809 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
|
|
1810 | } |
1785 | } |
1811 | } |
1786 | } |
1812 | } |
1787 | } |
1813 | } |
1788 | } |
1814 | } |
1789 | } |
1815 | } |
|
|
1816 | |
|
|
1817 | hv_clear (smooth); |
1790 | } |
1818 | } |
1791 | |
|
|
1792 | //hv_clear (smooth); |
|
|
1793 | |
1819 | |
1794 | glEnd (); |
1820 | glEnd (); |
1795 | |
1821 | |
1796 | glDisable (GL_TEXTURE_2D); |
1822 | glDisable (GL_TEXTURE_2D); |
1797 | glDisable (GL_BLEND); |
1823 | glDisable (GL_BLEND); |
… | |
… | |
2214 | # undef const_iv |
2240 | # undef const_iv |
2215 | }; |
2241 | }; |
2216 | |
2242 | |
2217 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
2243 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
2218 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
2244 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
2245 | |
|
|
2246 | texture_av = newAV (); |
|
|
2247 | AvREAL_off (texture_av); |
2219 | } |
2248 | } |
2220 | |
2249 | |
2221 | char * |
2250 | char * |
2222 | gl_vendor () |
2251 | gl_vendor () |
2223 | CODE: |
2252 | CODE: |
… | |
… | |
2372 | |
2401 | |
2373 | void glCopyPixels (int x, int y, int width, int height, int type = GL_COLOR) |
2402 | void glCopyPixels (int x, int y, int width, int height, int type = GL_COLOR) |
2374 | |
2403 | |
2375 | int glGenTexture () |
2404 | int glGenTexture () |
2376 | CODE: |
2405 | CODE: |
2377 | { |
2406 | RETVAL = gen_texture (); |
2378 | GLuint name; |
|
|
2379 | if (AvFILL (texture_av) >= 0) |
|
|
2380 | name = (GLuint)av_pop (texture_av); |
|
|
2381 | else |
|
|
2382 | glGenTextures (1, &name); |
|
|
2383 | RETVAL = name; |
|
|
2384 | } |
|
|
2385 | OUTPUT: |
2407 | OUTPUT: |
2386 | RETVAL |
2408 | RETVAL |
2387 | |
2409 | |
2388 | void glDeleteTexture (int name) |
2410 | void glDeleteTexture (int name) |
2389 | CODE: |
2411 | CODE: |
2390 | { |
2412 | del_texture (name); |
2391 | /* make a half-assed attempt at returning the memory used by the texture */ |
2413 | |
2392 | /* textures are frequently being reused by cfplus anyway */ |
|
|
2393 | glBindTexture (GL_TEXTURE_2D, name); |
|
|
2394 | glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0); |
|
|
2395 | av_push (texture_av, (SV *)name); |
|
|
2396 | /*glDeleteTextures (1, &name_);*/ |
|
|
2397 | } |
|
|
2398 | |
|
|
2399 | int glGenList () |
2414 | int glGenList () |
2400 | CODE: |
2415 | CODE: |
2401 | RETVAL = glGenLists (1); |
2416 | RETVAL = glGenLists (1); |
2402 | OUTPUT: |
2417 | OUTPUT: |
2403 | RETVAL |
2418 | RETVAL |