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.214 by root, Sun Jul 29 18:56:02 2007 UTC vs.
Revision 1.220 by root, Thu Aug 9 11:02:08 2007 UTC

804 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 804 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
805 } 805 }
806} 806}
807 807
808int 808int
809Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) 809Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024)
810 POSTCALL: 810 POSTCALL:
811 Mix_HookMusicFinished (music_finished); 811 Mix_HookMusicFinished (music_finished);
812 Mix_ChannelFinished (channel_finished); 812 Mix_ChannelFinished (channel_finished);
813 813
814void 814void
1350 HV *hv = (HV *)SvRV (self); 1350 HV *hv = (HV *)SvRV (self);
1351 float s = SvNV (*hv_fetch (hv, "s", 1, 1)); 1351 float s = SvNV (*hv_fetch (hv, "s", 1, 1));
1352 float t = SvNV (*hv_fetch (hv, "t", 1, 1)); 1352 float t = SvNV (*hv_fetch (hv, "t", 1, 1));
1353 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 1353 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
1354 1354
1355 if (name <= 0)
1356 XSRETURN_EMPTY;
1357
1355 if (items < 5) 1358 if (items < 5)
1356 { 1359 {
1357 w = SvNV (*hv_fetch (hv, "w", 1, 1)); 1360 w = SvNV (*hv_fetch (hv, "w", 1, 1));
1358 h = SvNV (*hv_fetch (hv, "h", 1, 1)); 1361 h = SvNV (*hv_fetch (hv, "h", 1, 1));
1359 } 1362 }
1696 RETVAL = map_sv; 1699 RETVAL = map_sv;
1697} 1700}
1698 OUTPUT: 1701 OUTPUT:
1699 RETVAL 1702 RETVAL
1700 1703
1701void 1704SV *
1702draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 1705draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T)
1703 CODE: 1706 CODE:
1704{ 1707{
1705 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1708 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1706 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1709 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1707 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 1710 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k)
1708 smooth_key skey; 1711 smooth_key skey;
1709 int x, y, z; 1712 int x, y, z;
1710 int last_name; 1713 int last_name;
1714 AV *missing = newAV ();
1715 RETVAL = newRV_noinc ((SV *)missing);
1711 1716
1712 // thats current max. sorry. 1717 // thats current max. sorry.
1713 if (sw > 255) sw = 255; 1718 if (sw > 255) sw = 255;
1714 if (sh > 255) sh = 255; 1719 if (sh > 255) sh = 255;
1715 1720
1723 glEnable (GL_TEXTURE_2D); 1728 glEnable (GL_TEXTURE_2D);
1724 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1729 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1725 1730
1726 glBegin (GL_QUADS); 1731 glBegin (GL_QUADS);
1727 1732
1728 last_name = 0; 1733 last_name = -1;
1729 1734
1730 mx += self->x; 1735 mx += self->x;
1731 my += self->y; 1736 my += self->y;
1732 1737
1733 // first pass: determine smooth_max 1738 // first pass: determine smooth_max
1768 tileid tile = cell->tile [z]; 1773 tileid tile = cell->tile [z];
1769 1774
1770 if (tile) 1775 if (tile)
1771 { 1776 {
1772 maptex tex = self->tex [tile]; 1777 maptex tex = self->tex [tile];
1773 int px = (x + 1) * T - tex.w; 1778 int px, py;
1774 int py = (y + 1) * T - tex.h;
1775 1779
1776 // suppressing texture state switches here 1780 // suppressing texture state switches here
1777 // is only moderately effective, but worth the extra effort 1781 // is only moderately effective, but worth the extra effort
1778 if (last_name != tex.name) 1782 if (last_name != tex.name)
1779 { 1783 {
1780 if (!tex.name) 1784 if (!tex.name)
1785 {
1786 av_push (missing, newSViv (tile));
1781 tex = self->tex [2]; /* missing, replace by noface */ 1787 tex = self->tex [2]; /* missing, replace by noface */
1788 }
1782 1789
1783 glEnd (); 1790 glEnd ();
1784 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1791 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1785 glBegin (GL_QUADS); 1792 glBegin (GL_QUADS);
1786 } 1793 }
1794
1795 px = (x + 1) * T - tex.w;
1796 py = (y + 1) * T - tex.h;
1787 1797
1788 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1798 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1789 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1799 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1790 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1800 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1791 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1801 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1887 // this time naively avoiding texture state changes 1897 // this time naively avoiding texture state changes
1888 // save gobs of state changes. 1898 // save gobs of state changes.
1889 if (last_name != tex.name) 1899 if (last_name != tex.name)
1890 { 1900 {
1891 if (!tex.name) 1901 if (!tex.name)
1902 {
1903 av_push (missing, newSViv (skey->tile));
1892 continue; // smoothing not yet available 1904 continue; // smoothing not yet available
1905 }
1893 1906
1894 glEnd (); 1907 glEnd ();
1895 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1908 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1896 glBegin (GL_QUADS); 1909 glBegin (GL_QUADS);
1897 } 1910 }
1958 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); 1971 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1959 } 1972 }
1960 } 1973 }
1961 } 1974 }
1962} 1975}
1976 OUTPUT:
1977 RETVAL
1963 1978
1964void 1979void
1965draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1980draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1966 CODE: 1981 CODE:
1967{ 1982{
2260 CODE: 2275 CODE:
2261 RETVAL = SDL_RWFromFile (path, mode); 2276 RETVAL = SDL_RWFromFile (path, mode);
2262 OUTPUT: 2277 OUTPUT:
2263 RETVAL 2278 RETVAL
2264 2279
2280# fails on win32:
2281# CFPlus.xs(2268) : error C2059: syntax error : '('
2265void 2282#void
2266close (CFPlus::RW self) 2283#close (CFPlus::RW self)
2267 CODE: 2284# CODE:
2268 SDL_RWclose (self); 2285# (self->(close)) (self);
2269 2286
2270MODULE = CFPlus PACKAGE = CFPlus::Channel 2287MODULE = CFPlus PACKAGE = CFPlus::Channel
2271 2288
2272PROTOTYPES: 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
2273 2312
2274void 2313void
2275halt (CFPlus::Channel self) 2314halt (CFPlus::Channel self)
2276 CODE: 2315 CODE:
2277 Mix_HaltChannel (self); 2316 Mix_HaltChannel (self);
2287 Mix_FadeOutChannel (self, ticks); 2326 Mix_FadeOutChannel (self, ticks);
2288 2327
2289int 2328int
2290volume (CFPlus::Channel self, int volume) 2329volume (CFPlus::Channel self, int volume)
2291 CODE: 2330 CODE:
2292 RETVAL = Mix_Volume (self, volume); 2331 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128));
2293 OUTPUT: 2332 OUTPUT:
2294 RETVAL 2333 RETVAL
2295 2334
2296void 2335void
2297unregister_all_effects (CFPlus::Channel self) 2336unregister_all_effects (CFPlus::Channel self)
2299 Mix_UnregisterAllEffects (self); 2338 Mix_UnregisterAllEffects (self);
2300 2339
2301void 2340void
2302set_panning (CFPlus::Channel self, int left, int right) 2341set_panning (CFPlus::Channel self, int left, int right)
2303 CODE: 2342 CODE:
2343 left = CLAMP (left , 0, 255);
2344 right = CLAMP (right, 0, 255);
2304 Mix_SetPanning (self, left, right); 2345 Mix_SetPanning (self, left, right);
2305 2346
2306void 2347void
2307set_distance (CFPlus::Channel self, int distance) 2348set_distance (CFPlus::Channel self, int distance)
2308 CODE: 2349 CODE:
2309 Mix_SetDistance (self, distance); 2350 Mix_SetDistance (self, CLAMP (distance, 0, 255));
2310 2351
2311void 2352void
2312set_position (CFPlus::Channel self, int angle, int distance) 2353set_position (CFPlus::Channel self, int angle, int distance)
2313 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);
2314 Mix_SetPosition (self, angle, distance); 2362 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2363}
2315 2364
2316void 2365void
2317set_reverse_stereo (CFPlus::Channel self, int flip) 2366set_reverse_stereo (CFPlus::Channel self, int flip)
2318 CODE: 2367 CODE:
2319 Mix_SetReverseStereo (self, flip); 2368 Mix_SetReverseStereo (self, flip);
2335 Mix_FreeChunk (self); 2384 Mix_FreeChunk (self);
2336 2385
2337int 2386int
2338volume (CFPlus::MixChunk self, int volume = -1) 2387volume (CFPlus::MixChunk self, int volume = -1)
2339 CODE: 2388 CODE:
2389 if (items > 1)
2390 volume = CLAMP (volume, 0, 128);
2340 RETVAL = Mix_VolumeChunk (self, volume); 2391 RETVAL = Mix_VolumeChunk (self, volume);
2341 OUTPUT: 2392 OUTPUT:
2342 RETVAL 2393 RETVAL
2343 2394
2344CFPlus::Channel 2395CFPlus::Channel
2345play (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)
2346 CODE: 2397 CODE:
2398{
2347 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 {
2348 Mix_UnregisterAllEffects (RETVAL); 2406 Mix_UnregisterAllEffects (RETVAL);
2407 Mix_Volume (RETVAL, 128);
2408 }
2409}
2349 OUTPUT: 2410 OUTPUT:
2350 RETVAL 2411 RETVAL
2351 2412
2352MODULE = CFPlus PACKAGE = CFPlus::MixMusic 2413MODULE = CFPlus PACKAGE = CFPlus::MixMusic
2353 2414
2354int 2415int
2355volume (int volume = -1) 2416volume (int volume = -1)
2356 PROTOTYPE: ;$ 2417 PROTOTYPE: ;$
2357 CODE: 2418 CODE:
2419 if (items > 0)
2420 volume = CLAMP (volume, 0, 128);
2358 RETVAL = Mix_VolumeMusic (volume); 2421 RETVAL = Mix_VolumeMusic (volume);
2359 OUTPUT: 2422 OUTPUT:
2360 RETVAL 2423 RETVAL
2361 2424
2362void 2425void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines