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.181 by root, Mon Apr 16 21:06:36 2007 UTC vs.
Revision 1.185 by root, Sat Apr 21 09:21:03 2007 UTC

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[] = {
1460 } 1465 }
1461 else if (cmd == 6) // monster width 1466 else if (cmd == 6) // monster width
1462 cell->stat_width = *data++ + 1; 1467 cell->stat_width = *data++ + 1;
1463 else if (cmd == 0x47) 1468 else if (cmd == 0x47)
1464 { 1469 {
1465 if (*data == 8) 1470 if (*data == 4)
1466 ; // decode player uuid 1471 ; // decode player count
1467 1472
1468 data += *data + 1; 1473 data += *data + 1;
1469 } 1474 }
1470 else if (cmd == 8) // cell flags 1475 else if (cmd == 8) // cell flags
1471 cell->flags = *data++; 1476 cell->flags = *data++;
1595 1600
1596 // first pass: determine smooth_max 1601 // first pass: determine smooth_max
1597 // rather ugly, if you ask me 1602 // rather ugly, if you ask me
1598 // could also be stored inside mapcell and updated on change 1603 // could also be stored inside mapcell and updated on change
1599 memset (smooth_max, 0, sizeof (smooth_max)); 1604 memset (smooth_max, 0, sizeof (smooth_max));
1605 memset (smooth_level, 0, sizeof (smooth_level));
1600 1606
1601 for (y = 0; y < sh; y++) 1607 for (y = 0; y < sh; y++)
1602 if (0 <= y + my && y + my < self->rows) 1608 if (0 <= y + my && y + my < self->rows)
1603 { 1609 {
1604 maprow *row = self->row + (y + my); 1610 maprow *row = self->row + (y + my);
1615 } 1621 }
1616 } 1622 }
1617 1623
1618 for (z = 0; z <= 2; z++) 1624 for (z = 0; z <= 2; z++)
1619 { 1625 {
1620 memset (smooth_level, 0, sizeof (smooth_level));
1621
1622 for (y = 0; y < sh; y++) 1626 for (y = 0; y < sh; y++)
1623 if (0 <= y + my && y + my < self->rows) 1627 if (0 <= y + my && y + my < self->rows)
1624 { 1628 {
1625 maprow *row = self->row + (y + my); 1629 maprow *row = self->row + (y + my);
1626 1630
1711 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);
1712 } 1716 }
1713 } 1717 }
1714 } 1718 }
1715 } 1719 }
1720 }
1716 1721
1717 // go through all smoothlevels, lowest to highest, then draw. 1722 // go through all smoothlevels, lowest to highest, then draw.
1718 // 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)
1719 { 1728 {
1720 int w, b;
1721
1722 for (w = 0; w < 256 / 32; ++w)
1723 {
1724 uint32_t smask = smooth_level [w]; 1729 uint32_t smask = smooth_level [w];
1725 if (smask) 1730 if (smask)
1726 for (b = 0; b < 32; ++b) 1731 for (b = 0; b < 32; ++b)
1727 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)))
1728 { 1739 {
1729 int level = (w << 5) | b; 1740 smooth_key *skey = (smooth_key *)HeKEY (he);
1730 HE *he; 1741 IV bits = SvIVX (HeVAL (he));
1731 1742
1732 hv_iterinit (smooth); 1743 if (!(bits & 0x1000)
1733 while ((he = hv_iternext (smooth))) 1744 && skey->level == level
1745 && level >= smooth_max [skey->x][skey->y])
1734 { 1746 {
1735 smooth_key *skey = (smooth_key *)HeKEY (he); 1747 maptex tex = self->tex [skey->tile];
1736 IV bits = SvIVX (HeVAL (he)); 1748 int px = (((int)skey->x) - 1) * T;
1737 1749 int py = (((int)skey->y) - 1) * T;
1738 if (!(bits & 0x1000) 1750 int border = bits & 15;
1739 && skey->level == level 1751 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1740 && 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)
1741 { 1758 {
1742 maptex tex = self->tex [skey->tile];
1743 int px = (((int)skey->x) - 1) * T;
1744 int py = (((int)skey->y) - 1) * T;
1745 int border = bits & 15;
1746 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1747 float dx = tex.s * .0625f; // 16 images/row
1748 float dy = tex.t * .5f ; // 2 images/column
1749
1750 // this time naively avoiding texture state changes
1751 // save gobs of state changes.
1752 if (last_name != tex.name)
1753 {
1754 if (!tex.name) 1759 if (!tex.name)
1755 continue; // smoothing not yet available 1760 continue; // smoothing not yet available
1756 1761
1757 glEnd (); 1762 glEnd ();
1758 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1763 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1759 glBegin (GL_QUADS); 1764 glBegin (GL_QUADS);
1760 } 1765 }
1761 1766
1762 if (border) 1767 if (border)
1763 { 1768 {
1764 float ox = border * dx; 1769 float ox = border * dx;
1765 1770
1766 glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); 1771 glTexCoord2f (ox , 0.f ); glVertex2f (px , py );
1767 glTexCoord2f (ox , dy ); glVertex2f (px , py + T); 1772 glTexCoord2f (ox , dy ); glVertex2f (px , py + T);
1768 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); 1773 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T);
1769 glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); 1774 glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py );
1770 } 1775 }
1771 1776
1772 if (corner) 1777 if (corner)
1773 { 1778 {
1774 float ox = corner * dx; 1779 float ox = corner * dx;
1775 1780
1776 glTexCoord2f (ox , dy ); glVertex2f (px , py ); 1781 glTexCoord2f (ox , dy ); glVertex2f (px , py );
1777 glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); 1782 glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T);
1778 glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); 1783 glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T);
1779 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); 1784 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py );
1780 }
1781 } 1785 }
1782 } 1786 }
1783 } 1787 }
1784 } 1788 }
1785 } 1789 }
1786
1787 hv_clear (smooth);
1788 } 1790 }
1791
1792 //hv_clear (smooth);
1789 1793
1790 glEnd (); 1794 glEnd ();
1791 1795
1792 glDisable (GL_TEXTURE_2D); 1796 glDisable (GL_TEXTURE_2D);
1793 glDisable (GL_BLEND); 1797 glDisable (GL_BLEND);
2370 2374
2371int glGenTexture () 2375int glGenTexture ()
2372 CODE: 2376 CODE:
2373{ 2377{
2374 GLuint name; 2378 GLuint name;
2379 if (AvFILL (texture_av) >= 0)
2380 name = (GLuint)av_pop (texture_av);
2381 else
2375 glGenTextures (1, &name); 2382 glGenTextures (1, &name);
2376 RETVAL = name; 2383 RETVAL = name;
2377} 2384}
2378 OUTPUT: 2385 OUTPUT:
2379 RETVAL 2386 RETVAL
2380 2387
2381void glDeleteTexture (int name) 2388void glDeleteTexture (int name)
2382 CODE: 2389 CODE:
2383{ 2390{
2384 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);
2385 glDeleteTextures (1, &name_); 2396 /*glDeleteTextures (1, &name_);*/
2386} 2397}
2387 2398
2388int glGenList () 2399int glGenList ()
2389 CODE: 2400 CODE:
2390 RETVAL = glGenLists (1); 2401 RETVAL = glGenLists (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines