ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.185 by root, Sat Apr 21 09:21:03 2007 UTC vs.
Revision 1.190 by root, Thu Apr 26 17:41:23 2007 UTC

55#if 0 55#if 0
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
61static AV *texture_av;
60 62
61static struct 63static 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"
400 402
401/* SDL should provide this, really. */ 403/* SDL should provide this, really. */
402#define SDLK_MODIFIER_MIN 300 404#define SDLK_MODIFIER_MIN 300
403#define SDLK_MODIFIER_MAX 314 405#define SDLK_MODIFIER_MAX 314
404 406
405static AV *texture_av;
406
407MODULE = CFPlus PACKAGE = CFPlus 407MODULE = CFPlus PACKAGE = CFPlus
408 408
409PROTOTYPES: ENABLE 409PROTOTYPES: ENABLE
410 410
411BOOT: 411BOOT:
412{ 412{
413 texture_av = newAV ();
414 AvREAL_off (texture_av);
415
416 HV *stash = gv_stashpv ("CFPlus", 1); 413 HV *stash = gv_stashpv ("CFPlus", 1);
417 static const struct { 414 static const struct {
418 const char *name; 415 const char *name;
419 IV iv; 416 IV iv;
420 } *civ, const_iv[] = { 417 } *civ, const_iv[] = {
619 RETVAL = !!SDL_SetVideoMode ( 616 RETVAL = !!SDL_SetVideoMode (
620 w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0) 617 w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)
621 ); 618 );
622 if (RETVAL) 619 if (RETVAL)
623 { 620 {
621 av_clear (texture_av);
622
624 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 623 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+");
625# define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 624# define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
626# include "glfunc.h" 625# include "glfunc.h"
627# undef GL_FUNC 626# undef GL_FUNC
627
628 } 628 }
629 OUTPUT: 629 OUTPUT:
630 RETVAL 630 RETVAL
631 631
632void 632void
1396 CODE: 1396 CODE:
1397{ 1397{
1398 if (dx > 0) 1398 if (dx > 0)
1399 map_blank (self, self->x, self->y, dx, self->h); 1399 map_blank (self, self->x, self->y, dx, self->h);
1400 else if (dx < 0) 1400 else if (dx < 0)
1401 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); 1401 map_blank (self, self->x + self->w + dx, self->y, -dx, self->h);
1402 1402
1403 if (dy > 0) 1403 if (dy > 0)
1404 map_blank (self, self->x, self->y, self->w, dy); 1404 map_blank (self, self->x, self->y, self->w, dy);
1405 else if (dy < 0) 1405 else if (dy < 0)
1406 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); 1406 map_blank (self, self->x, self->y + self->h + dy, self->w, -dy);
1407 1407
1408 self->ox += dx; self->x += dx; 1408 self->ox += dx; self->x += dx;
1409 self->oy += dy; self->y += dy; 1409 self->oy += dy; self->y += dy;
1410 1410
1411 while (self->y < 0) 1411 while (self->y < 0)
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));
1606 1605
1607 for (y = 0; y < sh; y++) 1606 for (y = 0; y < sh; y++)
1608 if (0 <= y + my && y + my < self->rows) 1607 if (0 <= y + my && y + my < self->rows)
1609 { 1608 {
1610 maprow *row = self->row + (y + my); 1609 maprow *row = self->row + (y + my);
1621 } 1620 }
1622 } 1621 }
1623 1622
1624 for (z = 0; z <= 2; z++) 1623 for (z = 0; z <= 2; z++)
1625 { 1624 {
1625 memset (smooth_level, 0, sizeof (smooth_level));
1626
1626 for (y = 0; y < sh; y++) 1627 for (y = 0; y < sh; y++)
1627 if (0 <= y + my && y + my < self->rows) 1628 if (0 <= y + my && y + my < self->rows)
1628 { 1629 {
1629 maprow *row = self->row + (y + my); 1630 maprow *row = self->row + (y + my);
1630 1631
1715 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 1716 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800);
1716 } 1717 }
1717 } 1718 }
1718 } 1719 }
1719 } 1720 }
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)
1728 { 1724 {
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)))
1739 { 1733 {
1740 smooth_key *skey = (smooth_key *)HeKEY (he); 1734 int level = (w << 5) | b;
1741 IV bits = SvIVX (HeVAL (he)); 1735 HE *he;
1742 1736
1743 if (!(bits & 0x1000) 1737 hv_iterinit (smooth);
1744 && skey->level == level 1738 while ((he = hv_iternext (smooth)))
1745 && level >= smooth_max [skey->x][skey->y])
1746 { 1739 {
1747 maptex tex = self->tex [skey->tile]; 1740 smooth_key *skey = (smooth_key *)HeKEY (he);
1748 int px = (((int)skey->x) - 1) * T; 1741 IV bits = SvIVX (HeVAL (he));
1749 int py = (((int)skey->y) - 1) * T; 1742
1750 int border = bits & 15; 1743 if (!(bits & 0x1000)
1751 int corner = (bits >> 8) & ~(bits >> 4) & 15; 1744 && skey->level == level
1752 float dx = tex.s * .0625f; // 16 images/row 1745 && 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 { 1746 {
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 }
1785 } 1786 }
1786 } 1787 }
1787 } 1788 }
1788 } 1789 }
1789 } 1790 }
1791
1792 hv_clear (smooth);
1790 } 1793 }
1791
1792 //hv_clear (smooth);
1793 1794
1794 glEnd (); 1795 glEnd ();
1795 1796
1796 glDisable (GL_TEXTURE_2D); 1797 glDisable (GL_TEXTURE_2D);
1797 glDisable (GL_BLEND); 1798 glDisable (GL_BLEND);
2214# undef const_iv 2215# undef const_iv
2215 }; 2216 };
2216 2217
2217 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 2218 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
2218 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 2219 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
2220
2221 texture_av = newAV ();
2222 AvREAL_off (texture_av);
2219} 2223}
2220 2224
2221char * 2225char *
2222gl_vendor () 2226gl_vendor ()
2223 CODE: 2227 CODE:
2375int glGenTexture () 2379int glGenTexture ()
2376 CODE: 2380 CODE:
2377{ 2381{
2378 GLuint name; 2382 GLuint name;
2379 if (AvFILL (texture_av) >= 0) 2383 if (AvFILL (texture_av) >= 0)
2380 name = (GLuint)av_pop (texture_av); 2384 name = (GLuint)(size_t)av_pop (texture_av);
2381 else 2385 else
2382 glGenTextures (1, &name); 2386 glGenTextures (1, &name);
2383 RETVAL = name; 2387 RETVAL = name;
2384} 2388}
2385 OUTPUT: 2389 OUTPUT:
2388void glDeleteTexture (int name) 2392void glDeleteTexture (int name)
2389 CODE: 2393 CODE:
2390{ 2394{
2391 /* make a half-assed attempt at returning the memory used by the texture */ 2395 /* make a half-assed attempt at returning the memory used by the texture */
2392 /* textures are frequently being reused by cfplus anyway */ 2396 /* textures are frequently being reused by cfplus anyway */
2393 glBindTexture (GL_TEXTURE_2D, name); 2397 /*glBindTexture (GL_TEXTURE_2D, name);*/
2394 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0); 2398 /*glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0);*/
2395 av_push (texture_av, (SV *)name); 2399 av_push (texture_av, (SV *)(size_t)name);
2396 /*glDeleteTextures (1, &name_);*/ 2400 /*{ GLuint name_ = name; glDeleteTextures (1, &name_); }*/
2397} 2401}
2398 2402
2399int glGenList () 2403int glGenList ()
2400 CODE: 2404 CODE:
2401 RETVAL = glGenLists (1); 2405 RETVAL = glGenLists (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines