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.178 by root, Tue Apr 10 11:12:53 2007 UTC vs.
Revision 1.185 by root, Sat Apr 21 09:21:03 2007 UTC

345} smooth_key; 345} smooth_key;
346 346
347static void 347static void
348smooth_or_bits (HV *hv, smooth_key *key, IV bits) 348smooth_or_bits (HV *hv, smooth_key *key, IV bits)
349{ 349{
350 SV **sv = hv_fetch (hv, (char *)key, sizeof (key), 1); 350 SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1);
351 351
352 if (SvIOK (*sv)) 352 if (SvIOK (*sv))
353 SvIV_set (*sv, SvIVX (*sv) | bits); 353 SvIV_set (*sv, SvIVX (*sv) | bits);
354 else 354 else
355 sv_setiv (*sv, bits); 355 sv_setiv (*sv, bits);
400 400
401/* SDL should provide this, really. */ 401/* SDL should provide this, really. */
402#define SDLK_MODIFIER_MIN 300 402#define SDLK_MODIFIER_MIN 300
403#define SDLK_MODIFIER_MAX 314 403#define SDLK_MODIFIER_MAX 314
404 404
405static AV *texture_av;
406
405MODULE = CFPlus PACKAGE = CFPlus 407MODULE = CFPlus PACKAGE = CFPlus
406 408
407PROTOTYPES: ENABLE 409PROTOTYPES: ENABLE
408 410
409BOOT: 411BOOT:
410{ 412{
413 texture_av = newAV ();
414 AvREAL_off (texture_av);
415
411 HV *stash = gv_stashpv ("CFPlus", 1); 416 HV *stash = gv_stashpv ("CFPlus", 1);
412 static const struct { 417 static const struct {
413 const char *name; 418 const char *name;
414 IV iv; 419 IV iv;
415 } *civ, const_iv[] = { 420 } *civ, const_iv[] = {
701Mix_AllocateChannels (int numchans = -1) 706Mix_AllocateChannels (int numchans = -1)
702 707
703void 708void
704lowdelay (int fd, int val = 1) 709lowdelay (int fd, int val = 1)
705 CODE: 710 CODE:
706#ifndef _WIN32
707 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 711 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val));
708#endif
709 712
710void 713void
711win32_proxy_info () 714win32_proxy_info ()
712 PPCODE: 715 PPCODE:
713{ 716{
1462 } 1465 }
1463 else if (cmd == 6) // monster width 1466 else if (cmd == 6) // monster width
1464 cell->stat_width = *data++ + 1; 1467 cell->stat_width = *data++ + 1;
1465 else if (cmd == 0x47) 1468 else if (cmd == 0x47)
1466 { 1469 {
1467 if (*data == 8) 1470 if (*data == 4)
1468 ; // decode player uuid 1471 ; // decode player count
1469 1472
1470 data += *data + 1; 1473 data += *data + 1;
1471 } 1474 }
1472 else if (cmd == 8) // cell flags 1475 else if (cmd == 8) // cell flags
1473 cell->flags = *data++; 1476 cell->flags = *data++;
1597 1600
1598 // first pass: determine smooth_max 1601 // first pass: determine smooth_max
1599 // rather ugly, if you ask me 1602 // rather ugly, if you ask me
1600 // could also be stored inside mapcell and updated on change 1603 // could also be stored inside mapcell and updated on change
1601 memset (smooth_max, 0, sizeof (smooth_max)); 1604 memset (smooth_max, 0, sizeof (smooth_max));
1605 memset (smooth_level, 0, sizeof (smooth_level));
1602 1606
1603 for (y = 0; y < sh; y++) 1607 for (y = 0; y < sh; y++)
1604 if (0 <= y + my && y + my < self->rows) 1608 if (0 <= y + my && y + my < self->rows)
1605 { 1609 {
1606 maprow *row = self->row + (y + my); 1610 maprow *row = self->row + (y + my);
1617 } 1621 }
1618 } 1622 }
1619 1623
1620 for (z = 0; z <= 2; z++) 1624 for (z = 0; z <= 2; z++)
1621 { 1625 {
1622 memset (smooth_level, 0, sizeof (smooth_level));
1623
1624 for (y = 0; y < sh; y++) 1626 for (y = 0; y < sh; y++)
1625 if (0 <= y + my && y + my < self->rows) 1627 if (0 <= y + my && y + my < self->rows)
1626 { 1628 {
1627 maprow *row = self->row + (y + my); 1629 maprow *row = self->row + (y + my);
1628 1630
1683 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 1685 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31);
1684 1686
1685 // add bits to current tile and all neighbours. skey.x|y is 1687 // add bits to current tile and all neighbours. skey.x|y is
1686 // shifted +1|+1 so we always stay positive. 1688 // shifted +1|+1 so we always stay positive.
1687 1689
1690 // bits is ___n cccc CCCC bbbb
1691 // n do not draw borders&corners
1692 // c draw these corners, but...
1693 // C ... not these
1694 // b draw these borders
1695
1696 // borders: 1 ┃· 2 ━━ 4 ·┃ 8 ··
1697 // ┃· ·· ·┃ ━━
1698
1699 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ··
1700 // ·· ·· ·┏ ┓·
1701
1688 // full tile 1702 // full tile
1689 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); 1703 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000);
1690 1704
1691 // borders 1705 // borders
1692 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0031); 1706 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091);
1693 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0092); 1707 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032);
1694 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); 1708 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064);
1695 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); 1709 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8);
1696 1710
1697 // corners 1711 // corners
1698 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 1712 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100);
1701 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);
1702 } 1716 }
1703 } 1717 }
1704 } 1718 }
1705 } 1719 }
1720 }
1706 1721
1707 // go through all smoothlevels, lowest to highest, then draw 1722 // go through all smoothlevels, lowest to highest, then draw.
1708 // 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)
1709 { 1728 {
1710 int w, b;
1711
1712 for (w = 0; w < 256 / 32; ++w)
1713 {
1714 uint32_t smask = smooth_level [w]; 1729 uint32_t smask = smooth_level [w];
1715 if (smask) 1730 if (smask)
1716 for (b = 0; b < 32; ++b) 1731 for (b = 0; b < 32; ++b)
1717 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)))
1718 { 1739 {
1719 int level = (w << 5) | b; 1740 smooth_key *skey = (smooth_key *)HeKEY (he);
1720 HE *he; 1741 IV bits = SvIVX (HeVAL (he));
1721 1742
1722 hv_iterinit (smooth); 1743 if (!(bits & 0x1000)
1723 while ((he = hv_iternext (smooth))) 1744 && skey->level == level
1745 && level >= smooth_max [skey->x][skey->y])
1724 { 1746 {
1725 smooth_key *skey = (smooth_key *)HeKEY (he); 1747 maptex tex = self->tex [skey->tile];
1726 IV bits = SvIVX (HeVAL (he)); 1748 int px = (((int)skey->x) - 1) * T;
1727 1749 int py = (((int)skey->y) - 1) * T;
1728 // bits is ___n cccc CCCC bbbb
1729 // n do not draw borders&corners
1730 // c draw these corners, but...
1731 // C ... not these
1732 // b draw these borders
1733
1734 if (!(bits & 0x1000) 1750 int border = bits & 15;
1735 && skey->level == level 1751 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1736 && 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)
1737 { 1758 {
1738 maptex tex = self->tex [skey->tile];
1739 int px = (((int)skey->x) - 1) * T;
1740 int py = (((int)skey->y) - 1) * T;
1741 int border = bits & 15;
1742 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1743 float dx = tex.s * .0625f; // 16 images/row
1744 float dy = tex.t * .5f ; // 2 images/column
1745
1746 // this time naively avoiding texture state changes
1747 // save gobs of state changes.
1748 if (last_name != tex.name)
1749 {
1750 if (!tex.name) 1759 if (!tex.name)
1751 continue; // smoothing not yet available 1760 continue; // smoothing not yet available
1752 1761
1753 glEnd (); 1762 glEnd ();
1754 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1763 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1755 glBegin (GL_QUADS); 1764 glBegin (GL_QUADS);
1756 } 1765 }
1757 1766
1758 if (border) 1767 if (border)
1759 { 1768 {
1760 float ox = border * dx; 1769 float ox = border * dx;
1761 1770
1762 glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); 1771 glTexCoord2f (ox , 0.f ); glVertex2f (px , py );
1763 glTexCoord2f (ox , dy ); glVertex2f (px , py + T); 1772 glTexCoord2f (ox , dy ); glVertex2f (px , py + T);
1764 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); 1773 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T);
1765 glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); 1774 glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py );
1766 } 1775 }
1767 1776
1768 if (corner) 1777 if (corner)
1769 { 1778 {
1770 float ox = corner * dx; 1779 float ox = corner * dx;
1771 1780
1772 glTexCoord2f (ox , dy ); glVertex2f (px , py ); 1781 glTexCoord2f (ox , dy ); glVertex2f (px , py );
1773 glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); 1782 glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T);
1774 glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); 1783 glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T);
1775 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); 1784 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py );
1776 }
1777 } 1785 }
1778 } 1786 }
1779 } 1787 }
1780 } 1788 }
1781 } 1789 }
1782
1783 hv_clear (smooth);
1784 } 1790 }
1791
1792 //hv_clear (smooth);
1785 1793
1786 glEnd (); 1794 glEnd ();
1787 1795
1788 glDisable (GL_TEXTURE_2D); 1796 glDisable (GL_TEXTURE_2D);
1789 glDisable (GL_BLEND); 1797 glDisable (GL_BLEND);
2366 2374
2367int glGenTexture () 2375int glGenTexture ()
2368 CODE: 2376 CODE:
2369{ 2377{
2370 GLuint name; 2378 GLuint name;
2379 if (AvFILL (texture_av) >= 0)
2380 name = (GLuint)av_pop (texture_av);
2381 else
2371 glGenTextures (1, &name); 2382 glGenTextures (1, &name);
2372 RETVAL = name; 2383 RETVAL = name;
2373} 2384}
2374 OUTPUT: 2385 OUTPUT:
2375 RETVAL 2386 RETVAL
2376 2387
2377void glDeleteTexture (int name) 2388void glDeleteTexture (int name)
2378 CODE: 2389 CODE:
2379{ 2390{
2380 GLuint name_ = name; 2391 /* make a half-assed attempt at returning the memory used by the texture */
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);
2381 glDeleteTextures (1, &name_); 2396 /*glDeleteTextures (1, &name_);*/
2382} 2397}
2383 2398
2384int glGenList () 2399int glGenList ()
2385 CODE: 2400 CODE:
2386 RETVAL = glGenLists (1); 2401 RETVAL = glGenLists (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines