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.213 by root, Sun Jul 29 04:14:45 2007 UTC vs.
Revision 1.222 by root, Sat Aug 11 06:34:26 2007 UTC

17#include "perl.h" 17#include "perl.h"
18#include "XSUB.h" 18#include "XSUB.h"
19 19
20#ifdef _WIN32 20#ifdef _WIN32
21# undef pipe 21# undef pipe
22// microsoft vs. C
23# define sqrtf(x) sqrt(x)
24# define roundf(x) (int)(x)
25# define atan2f(x,y) atan2(x,y)
26# define M_PI 3.14159265f
22#endif 27#endif
23 28
24#include <assert.h> 29#include <assert.h>
25#include <math.h> 30#include <math.h>
26#include <string.h> 31#include <string.h>
804 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 809 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
805 } 810 }
806} 811}
807 812
808int 813int
809Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) 814Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024)
810 POSTCALL: 815 POSTCALL:
811 Mix_HookMusicFinished (music_finished); 816 Mix_HookMusicFinished (music_finished);
812 Mix_ChannelFinished (channel_finished); 817 Mix_ChannelFinished (channel_finished);
813 818
814void 819void
815Mix_CloseAudio () 820Mix_CloseAudio ()
816 821
817int 822int
818Mix_AllocateChannels (int numchans = -1) 823Mix_AllocateChannels (int numchans = -1)
824
825const char *
826Mix_GetError ()
819 827
820void 828void
821lowdelay (int fd, int val = 1) 829lowdelay (int fd, int val = 1)
822 CODE: 830 CODE:
823 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); 831 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val));
1347 HV *hv = (HV *)SvRV (self); 1355 HV *hv = (HV *)SvRV (self);
1348 float s = SvNV (*hv_fetch (hv, "s", 1, 1)); 1356 float s = SvNV (*hv_fetch (hv, "s", 1, 1));
1349 float t = SvNV (*hv_fetch (hv, "t", 1, 1)); 1357 float t = SvNV (*hv_fetch (hv, "t", 1, 1));
1350 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 1358 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
1351 1359
1360 if (name <= 0)
1361 XSRETURN_EMPTY;
1362
1352 if (items < 5) 1363 if (items < 5)
1353 { 1364 {
1354 w = SvNV (*hv_fetch (hv, "w", 1, 1)); 1365 w = SvNV (*hv_fetch (hv, "w", 1, 1));
1355 h = SvNV (*hv_fetch (hv, "h", 1, 1)); 1366 h = SvNV (*hv_fetch (hv, "h", 1, 1));
1356 } 1367 }
1544 self->rows += MAP_EXTEND_Y; 1555 self->rows += MAP_EXTEND_Y;
1545 self->y += MAP_EXTEND_Y; 1556 self->y += MAP_EXTEND_Y;
1546 } 1557 }
1547} 1558}
1548 1559
1549void 1560SV *
1550map1a_update (CFPlus::Map self, SV *data_, int extmap) 1561map1a_update (CFPlus::Map self, SV *data_, int extmap)
1551 CODE: 1562 CODE:
1552{ 1563{
1553 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1564 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1554 uint8_t *data_end = (uint8_t *)SvEND (data_); 1565 uint8_t *data_end = (uint8_t *)SvEND (data_);
1555 mapcell *cell; 1566 mapcell *cell;
1556 int x, y, flags; 1567 int x, y, z, flags;
1568 AV *missing = newAV ();
1569 RETVAL = newRV_noinc ((SV *)missing);
1557 1570
1558 while (data < data_end - 1) 1571 while (data < data_end - 1)
1559 { 1572 {
1560 flags = (data [0] << 8) + data [1]; data += 2; 1573 flags = (data [0] << 8) + data [1]; data += 2;
1561 1574
1612 } 1625 }
1613 else 1626 else
1614 cell->darkness = *data++ + 1; 1627 cell->darkness = *data++ + 1;
1615 } 1628 }
1616 1629
1630 for (z = 0; z <= 2; ++z)
1617 if (flags & 4) 1631 if (flags & (4 >> z))
1618 { 1632 {
1619 faceid face = (data [0] << 8) + data [1]; data += 2; 1633 faceid face = (data [0] << 8) + data [1]; data += 2;
1620 need_facenum (self, face); 1634 need_facenum (self, face);
1621 cell->tile [0] = self->face2tile [face]; 1635 cell->tile [z] = self->face2tile [face];
1636
1637 if (cell->tile [z])
1638 {
1639 maptex *tex = self->tex + cell->tile [z];
1640 if (!tex->name)
1641 av_push (missing, newSViv (cell->tile [z]));
1642
1643 if (tex->smoothtile)
1644 {
1645 maptex *smooth = self->tex + tex->smoothtile;
1646 if (!smooth->name)
1647 av_push (missing, newSViv (tex->smoothtile));
1648 }
1649 }
1622 } 1650 }
1623
1624 if (flags & 2)
1625 {
1626 faceid face = (data [0] << 8) + data [1]; data += 2;
1627 need_facenum (self, face);
1628 cell->tile [1] = self->face2tile [face];
1629 }
1630
1631 if (flags & 1)
1632 {
1633 faceid face = (data [0] << 8) + data [1]; data += 2;
1634 need_facenum (self, face);
1635 cell->tile [2] = self->face2tile [face];
1636 }
1637 } 1651 }
1638 else 1652 else
1639 cell->darkness = 0; 1653 cell->darkness = 0;
1640 } 1654 }
1641} 1655}
1656 OUTPUT:
1657 RETVAL
1642 1658
1643SV * 1659SV *
1644mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1660mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1645 CODE: 1661 CODE:
1646{ 1662{
1720 glEnable (GL_TEXTURE_2D); 1736 glEnable (GL_TEXTURE_2D);
1721 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1737 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1722 1738
1723 glBegin (GL_QUADS); 1739 glBegin (GL_QUADS);
1724 1740
1725 last_name = 0; 1741 last_name = -1;
1726 1742
1727 mx += self->x; 1743 mx += self->x;
1728 my += self->y; 1744 my += self->y;
1729 1745
1730 // first pass: determine smooth_max 1746 // first pass: determine smooth_max
1765 tileid tile = cell->tile [z]; 1781 tileid tile = cell->tile [z];
1766 1782
1767 if (tile) 1783 if (tile)
1768 { 1784 {
1769 maptex tex = self->tex [tile]; 1785 maptex tex = self->tex [tile];
1770 int px = (x + 1) * T - tex.w; 1786 int px, py;
1771 int py = (y + 1) * T - tex.h;
1772 1787
1773 // suppressing texture state switches here 1788 // suppressing texture state switches here
1774 // is only moderately effective, but worth the extra effort 1789 // is only moderately effective, but worth the extra effort
1775 if (last_name != tex.name) 1790 if (last_name != tex.name)
1776 { 1791 {
1779 1794
1780 glEnd (); 1795 glEnd ();
1781 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1796 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1782 glBegin (GL_QUADS); 1797 glBegin (GL_QUADS);
1783 } 1798 }
1799
1800 px = (x + 1) * T - tex.w;
1801 py = (y + 1) * T - tex.h;
1784 1802
1785 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1803 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1786 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1804 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1787 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1805 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1788 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1806 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
2257 CODE: 2275 CODE:
2258 RETVAL = SDL_RWFromFile (path, mode); 2276 RETVAL = SDL_RWFromFile (path, mode);
2259 OUTPUT: 2277 OUTPUT:
2260 RETVAL 2278 RETVAL
2261 2279
2280# fails on win32:
2281# CFPlus.xs(2268) : error C2059: syntax error : '('
2262void 2282#void
2263close (CFPlus::RW self) 2283#close (CFPlus::RW self)
2264 CODE: 2284# CODE:
2265 SDL_RWclose (self); 2285# (self->(close)) (self);
2266 2286
2267MODULE = CFPlus PACKAGE = CFPlus::Channel 2287MODULE = CFPlus PACKAGE = CFPlus::Channel
2268 2288
2269PROTOTYPES: DISABLE 2289PROTOTYPES: DISABLE
2290
2291CFPlus::Channel
2292find ()
2293 CODE:
2294{
2295 RETVAL = Mix_GroupAvailable (-1);
2296
2297 if (RETVAL < 0)
2298 {
2299 RETVAL = Mix_GroupOldest (-1);
2300
2301 if (RETVAL < 0)
2302 XSRETURN_UNDEF;
2303
2304 Mix_HaltChannel (RETVAL);
2305 }
2306
2307 Mix_UnregisterAllEffects (RETVAL);
2308 Mix_Volume (RETVAL, 128);
2309}
2310 OUTPUT:
2311 RETVAL
2270 2312
2271void 2313void
2272halt (CFPlus::Channel self) 2314halt (CFPlus::Channel self)
2273 CODE: 2315 CODE:
2274 Mix_HaltChannel (self); 2316 Mix_HaltChannel (self);
2284 Mix_FadeOutChannel (self, ticks); 2326 Mix_FadeOutChannel (self, ticks);
2285 2327
2286int 2328int
2287volume (CFPlus::Channel self, int volume) 2329volume (CFPlus::Channel self, int volume)
2288 CODE: 2330 CODE:
2289 RETVAL = Mix_Volume (self, volume); 2331 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128));
2290 OUTPUT: 2332 OUTPUT:
2291 RETVAL 2333 RETVAL
2292 2334
2293void 2335void
2294unregister_all_effects (CFPlus::Channel self) 2336unregister_all_effects (CFPlus::Channel self)
2296 Mix_UnregisterAllEffects (self); 2338 Mix_UnregisterAllEffects (self);
2297 2339
2298void 2340void
2299set_panning (CFPlus::Channel self, int left, int right) 2341set_panning (CFPlus::Channel self, int left, int right)
2300 CODE: 2342 CODE:
2343 left = CLAMP (left , 0, 255);
2344 right = CLAMP (right, 0, 255);
2301 Mix_SetPanning (self, left, right); 2345 Mix_SetPanning (self, left, right);
2302 2346
2303void 2347void
2304set_distance (CFPlus::Channel self, int distance) 2348set_distance (CFPlus::Channel self, int distance)
2305 CODE: 2349 CODE:
2306 Mix_SetDistance (self, distance); 2350 Mix_SetDistance (self, CLAMP (distance, 0, 255));
2307 2351
2308void 2352void
2309set_position (CFPlus::Channel self, int angle, int distance) 2353set_position (CFPlus::Channel self, int angle, int distance)
2310 CODE: 2354 CODE:
2355
2356void
2357set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance)
2358 CODE:
2359{
2360 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance));
2361 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI);
2311 Mix_SetPosition (self, angle, distance); 2362 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2363}
2312 2364
2313void 2365void
2314set_reverse_stereo (CFPlus::Channel self, int flip) 2366set_reverse_stereo (CFPlus::Channel self, int flip)
2315 CODE: 2367 CODE:
2316 Mix_SetReverseStereo (self, flip); 2368 Mix_SetReverseStereo (self, flip);
2332 Mix_FreeChunk (self); 2384 Mix_FreeChunk (self);
2333 2385
2334int 2386int
2335volume (CFPlus::MixChunk self, int volume = -1) 2387volume (CFPlus::MixChunk self, int volume = -1)
2336 CODE: 2388 CODE:
2389 if (items > 1)
2390 volume = CLAMP (volume, 0, 128);
2337 RETVAL = Mix_VolumeChunk (self, volume); 2391 RETVAL = Mix_VolumeChunk (self, volume);
2338 OUTPUT: 2392 OUTPUT:
2339 RETVAL 2393 RETVAL
2340 2394
2341CFPlus::Channel 2395CFPlus::Channel
2342play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) 2396play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1)
2343 CODE: 2397 CODE:
2398{
2344 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 2399 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
2400
2401 if (RETVAL < 0)
2402 XSRETURN_UNDEF;
2403
2404 if (channel < 0)
2405 {
2345 Mix_UnregisterAllEffects (RETVAL); 2406 Mix_UnregisterAllEffects (RETVAL);
2407 Mix_Volume (RETVAL, 128);
2408 }
2409}
2346 OUTPUT: 2410 OUTPUT:
2347 RETVAL 2411 RETVAL
2348 2412
2349MODULE = CFPlus PACKAGE = CFPlus::MixMusic 2413MODULE = CFPlus PACKAGE = CFPlus::MixMusic
2350 2414
2351int 2415int
2352volume (int volume = -1) 2416volume (int volume = -1)
2353 PROTOTYPE: ;$ 2417 PROTOTYPE: ;$
2354 CODE: 2418 CODE:
2419 if (items > 0)
2420 volume = CLAMP (volume, 0, 128);
2355 RETVAL = Mix_VolumeMusic (volume); 2421 RETVAL = Mix_VolumeMusic (volume);
2356 OUTPUT: 2422 OUTPUT:
2357 RETVAL 2423 RETVAL
2358 2424
2359void 2425void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines