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.176 by root, Tue Apr 10 09:39:48 2007 UTC vs.
Revision 1.188 by root, Sat Apr 21 23:47:50 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"
345} smooth_key; 347} smooth_key;
346 348
347static void 349static void
348smooth_or_bits (HV *hv, smooth_key *key, IV bits) 350smooth_or_bits (HV *hv, smooth_key *key, IV bits)
349{ 351{
350 SV **sv = hv_fetch (hv, (char *)key, sizeof (key), 1); 352 SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1);
351 353
352 if (SvIOK (*sv)) 354 if (SvIOK (*sv))
353 SvIV_set (*sv, SvIVX (*sv) | bits); 355 SvIV_set (*sv, SvIVX (*sv) | bits);
354 else 356 else
355 sv_setiv (*sv, bits); 357 sv_setiv (*sv, bits);
614 RETVAL = !!SDL_SetVideoMode ( 616 RETVAL = !!SDL_SetVideoMode (
615 w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0) 617 w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)
616 ); 618 );
617 if (RETVAL) 619 if (RETVAL)
618 { 620 {
621 av_clear (texture_av);
622
619 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 623 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+");
620# 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);
621# include "glfunc.h" 625# include "glfunc.h"
622# undef GL_FUNC 626# undef GL_FUNC
627
623 } 628 }
624 OUTPUT: 629 OUTPUT:
625 RETVAL 630 RETVAL
626 631
627void 632void
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{
1393 CODE: 1396 CODE:
1394{ 1397{
1395 if (dx > 0) 1398 if (dx > 0)
1396 map_blank (self, self->x, self->y, dx, self->h); 1399 map_blank (self, self->x, self->y, dx, self->h);
1397 else if (dx < 0) 1400 else if (dx < 0)
1398 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);
1399 1402
1400 if (dy > 0) 1403 if (dy > 0)
1401 map_blank (self, self->x, self->y, self->w, dy); 1404 map_blank (self, self->x, self->y, self->w, dy);
1402 else if (dy < 0) 1405 else if (dy < 0)
1403 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);
1404 1407
1405 self->ox += dx; self->x += dx; 1408 self->ox += dx; self->x += dx;
1406 self->oy += dy; self->y += dy; 1409 self->oy += dy; self->y += dy;
1407 1410
1408 while (self->y < 0) 1411 while (self->y < 0)
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++;
1567draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 1570draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T)
1568 CODE: 1571 CODE:
1569{ 1572{
1570 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1573 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1571 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1574 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1572 uint8_t smooth_max[256][256]; 1575 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k)
1573 smooth_key skey; 1576 smooth_key skey;
1574 int x, y, z; 1577 int x, y, z;
1575 int last_name; 1578 int last_name;
1576 1579
1577 // thats current max. sorry. 1580 // thats current max. sorry.
1608 for (x = 0; x < sw; x++) 1611 for (x = 0; x < sw; x++)
1609 if (row->c0 <= x + mx && x + mx < row->c1) 1612 if (row->c0 <= x + mx && x + mx < row->c1)
1610 { 1613 {
1611 mapcell *cell = row->col + (x + mx - row->c0); 1614 mapcell *cell = row->col + (x + mx - row->c0);
1612 1615
1613 for (z = 0; z <= 2; z++)
1614 {
1615 uint8_t level = self->tex [cell->tile [z]].smoothlevel;
1616 if (level > smooth_max [x + 1][y + 1])
1617 smooth_max [x + 1][y + 1] = level; 1616 smooth_max[x + 1][y + 1] =
1618 } 1617 MAX (self->tex [cell->tile [0]].smoothlevel,
1618 MAX (self->tex [cell->tile [1]].smoothlevel,
1619 self->tex [cell->tile [2]].smoothlevel));
1619 } 1620 }
1620 } 1621 }
1621 1622
1622 for (z = 0; z <= 2; z++) 1623 for (z = 0; z <= 2; z++)
1623 { 1624 {
1685 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 1686 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31);
1686 1687
1687 // add bits to current tile and all neighbours. skey.x|y is 1688 // add bits to current tile and all neighbours. skey.x|y is
1688 // shifted +1|+1 so we always stay positive. 1689 // shifted +1|+1 so we always stay positive.
1689 1690
1691 // bits is ___n cccc CCCC bbbb
1692 // n do not draw borders&corners
1693 // c draw these corners, but...
1694 // C ... not these
1695 // b draw these borders
1696
1697 // borders: 1 ┃· 2 ━━ 4 ·┃ 8 ··
1698 // ┃· ·· ·┃ ━━
1699
1700 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ··
1701 // ·· ·· ·┏ ┓·
1702
1690 // full tile 1703 // full tile
1691 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); 1704 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000);
1692 1705
1693 // borders 1706 // borders
1694 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0031); 1707 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091);
1695 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0092); 1708 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032);
1696 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); 1709 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064);
1697 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); 1710 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8);
1698 1711
1699 // corners 1712 // corners
1700 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 1713 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100);
1704 } 1717 }
1705 } 1718 }
1706 } 1719 }
1707 } 1720 }
1708 1721
1709 // go through all smoothlevels, lowest to highest, then draw 1722 // go through all smoothlevels, lowest to highest, then draw.
1710 // this is basically counting sort 1723 // this is basically counting sort
1711 { 1724 {
1712 int w, b; 1725 int w, b;
1713 1726
1714 for (w = 0; w < 256 / 32; ++w) 1727 for (w = 0; w < 256 / 32; ++w)
1724 hv_iterinit (smooth); 1737 hv_iterinit (smooth);
1725 while ((he = hv_iternext (smooth))) 1738 while ((he = hv_iternext (smooth)))
1726 { 1739 {
1727 smooth_key *skey = (smooth_key *)HeKEY (he); 1740 smooth_key *skey = (smooth_key *)HeKEY (he);
1728 IV bits = SvIVX (HeVAL (he)); 1741 IV bits = SvIVX (HeVAL (he));
1729
1730 // bits is ___n cccc CCCC bbbb
1731 // n do not draw borders&corners
1732 // c draw these corners, but...
1733 // C ... not these
1734 // b draw these borders
1735 1742
1736 if (!(bits & 0x1000) 1743 if (!(bits & 0x1000)
1737 && skey->level == level 1744 && skey->level == level
1738 && level >= smooth_max [skey->x][skey->y]) 1745 && level >= smooth_max [skey->x][skey->y])
1739 { 1746 {
2208# undef const_iv 2215# undef const_iv
2209 }; 2216 };
2210 2217
2211 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; )
2212 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);
2213} 2223}
2214 2224
2215char * 2225char *
2216gl_vendor () 2226gl_vendor ()
2217 CODE: 2227 CODE:
2368 2378
2369int glGenTexture () 2379int glGenTexture ()
2370 CODE: 2380 CODE:
2371{ 2381{
2372 GLuint name; 2382 GLuint name;
2383 if (AvFILL (texture_av) >= 0)
2384 name = (GLuint)av_pop (texture_av);
2385 else
2373 glGenTextures (1, &name); 2386 glGenTextures (1, &name);
2374 RETVAL = name; 2387 RETVAL = name;
2375} 2388}
2376 OUTPUT: 2389 OUTPUT:
2377 RETVAL 2390 RETVAL
2378 2391
2379void glDeleteTexture (int name) 2392void glDeleteTexture (int name)
2380 CODE: 2393 CODE:
2381{ 2394{
2382 GLuint name_ = name; 2395 /* make a half-assed attempt at returning the memory used by the texture */
2396 /* textures are frequently being reused by cfplus anyway */
2397 glBindTexture (GL_TEXTURE_2D, name);
2398 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0);
2399 av_push (texture_av, (SV *)name);
2383 glDeleteTextures (1, &name_); 2400 /*glDeleteTextures (1, &name_);*/
2384} 2401}
2385 2402
2386int glGenList () 2403int glGenList ()
2387 CODE: 2404 CODE:
2388 RETVAL = glGenLists (1); 2405 RETVAL = glGenLists (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines