--- deliantra/Deliantra-Client/Client.xs 2007/07/21 22:54:52 1.209 +++ deliantra/Deliantra-Client/Client.xs 2007/08/10 04:02:13 1.221 @@ -27,6 +27,8 @@ #include #include +#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW + #include #include #include @@ -114,6 +116,8 @@ #include "pango-fontmap.c" #include "pango-render.c" +typedef IV CFPlus__Channel; +typedef SDL_RWops *CFPlus__RW; typedef Mix_Chunk *CFPlus__MixChunk; typedef Mix_Music *CFPlus__MixMusic; @@ -802,7 +806,7 @@ } int -Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) +Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) POSTCALL: Mix_HookMusicFinished (music_finished); Mix_ChannelFinished (channel_finished); @@ -813,6 +817,9 @@ int Mix_AllocateChannels (int numchans = -1) +const char * +Mix_GetError () + void lowdelay (int fd, int val = 1) CODE: @@ -863,7 +870,7 @@ SDL_Surface *surface, *surface2; SDL_PixelFormat fmt; SDL_RWops *rw = ix - ? SDL_RWFromFile (image, "r") + ? SDL_RWFromFile (image, "rb") : SDL_RWFromConstMem (image, image_len); if (!rw) @@ -1345,6 +1352,9 @@ float t = SvNV (*hv_fetch (hv, "t", 1, 1)); int name = SvIV (*hv_fetch (hv, "name", 4, 1)); + if (name <= 0) + XSRETURN_EMPTY; + if (items < 5) { w = SvNV (*hv_fetch (hv, "w", 1, 1)); @@ -1542,14 +1552,16 @@ } } -void +SV * map1a_update (CFPlus::Map self, SV *data_, int extmap) CODE: { uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); uint8_t *data_end = (uint8_t *)SvEND (data_); mapcell *cell; - int x, y, flags; + int x, y, z, flags; + AV *missing = newAV (); + RETVAL = newRV_noinc ((SV *)missing); while (data < data_end - 1) { @@ -1610,31 +1622,34 @@ cell->darkness = *data++ + 1; } - if (flags & 4) - { - faceid face = (data [0] << 8) + data [1]; data += 2; - need_facenum (self, face); - cell->tile [0] = self->face2tile [face]; - } + for (z = 0; z <= 2; ++z) + if (flags & (4 >> z)) + { + faceid face = (data [0] << 8) + data [1]; data += 2; + need_facenum (self, face); + cell->tile [z] = self->face2tile [face]; - if (flags & 2) - { - faceid face = (data [0] << 8) + data [1]; data += 2; - need_facenum (self, face); - cell->tile [1] = self->face2tile [face]; - } + if (cell->tile [z]) + { + maptex *tex = self->tex + cell->tile [z]; + if (!tex->name) + av_push (missing, newSViv (cell->tile [z])); - if (flags & 1) - { - faceid face = (data [0] << 8) + data [1]; data += 2; - need_facenum (self, face); - cell->tile [2] = self->face2tile [face]; - } + if (tex->smoothtile) + { + maptex *smooth = self->tex + tex->smoothtile; + if (!smooth->name) + av_push (missing, newSViv (tex->smoothtile)); + } + } + } } else cell->darkness = 0; } } + OUTPUT: + RETVAL SV * mapmap (CFPlus::Map self, int x0, int y0, int w, int h) @@ -1718,7 +1733,7 @@ glBegin (GL_QUADS); - last_name = 0; + last_name = -1; mx += self->x; my += self->y; @@ -1763,8 +1778,7 @@ if (tile) { maptex tex = self->tex [tile]; - int px = (x + 1) * T - tex.w; - int py = (y + 1) * T - tex.h; + int px, py; // suppressing texture state switches here // is only moderately effective, but worth the extra effort @@ -1778,6 +1792,9 @@ glBegin (GL_QUADS); } + px = (x + 1) * T - tex.w; + py = (y + 1) * T - tex.h; + glTexCoord2f (0 , 0 ); glVertex2f (px , py ); glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); @@ -2234,14 +2251,125 @@ } } +MODULE = CFPlus PACKAGE = CFPlus::RW + +CFPlus::RW +new (SV *class, SV *data_sv) + CODE: +{ + STRLEN datalen; + char *data = SvPVbyte (data_sv, datalen); + + RETVAL = SDL_RWFromConstMem (data, datalen); +} + OUTPUT: + RETVAL + +CFPlus::RW +new_from_file (SV *class, const char *path, const char *mode = "rb") + CODE: + RETVAL = SDL_RWFromFile (path, mode); + OUTPUT: + RETVAL + +# fails on win32: +# CFPlus.xs(2268) : error C2059: syntax error : '(' +#void +#close (CFPlus::RW self) +# CODE: +# (self->(close)) (self); + +MODULE = CFPlus PACKAGE = CFPlus::Channel + +PROTOTYPES: DISABLE + +CFPlus::Channel +find () + CODE: +{ + RETVAL = Mix_GroupAvailable (-1); + + if (RETVAL < 0) + { + RETVAL = Mix_GroupOldest (-1); + + if (RETVAL < 0) + XSRETURN_UNDEF; + + Mix_HaltChannel (RETVAL); + } + + Mix_UnregisterAllEffects (RETVAL); + Mix_Volume (RETVAL, 128); +} + OUTPUT: + RETVAL + +void +halt (CFPlus::Channel self) + CODE: + Mix_HaltChannel (self); + +void +expire (CFPlus::Channel self, int ticks = -1) + CODE: + Mix_ExpireChannel (self, ticks); + +void +fade_out (CFPlus::Channel self, int ticks = -1) + CODE: + Mix_FadeOutChannel (self, ticks); + +int +volume (CFPlus::Channel self, int volume) + CODE: + RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); + OUTPUT: + RETVAL + +void +unregister_all_effects (CFPlus::Channel self) + CODE: + Mix_UnregisterAllEffects (self); + +void +set_panning (CFPlus::Channel self, int left, int right) + CODE: + left = CLAMP (left , 0, 255); + right = CLAMP (right, 0, 255); + Mix_SetPanning (self, left, right); + +void +set_distance (CFPlus::Channel self, int distance) + CODE: + Mix_SetDistance (self, CLAMP (distance, 0, 255)); + +void +set_position (CFPlus::Channel self, int angle, int distance) + CODE: + +void +set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) + CODE: +{ + int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); + int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); + Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); +} + +void +set_reverse_stereo (CFPlus::Channel self, int flip) + CODE: + Mix_SetReverseStereo (self, flip); + MODULE = CFPlus PACKAGE = CFPlus::MixChunk PROTOTYPES: DISABLE CFPlus::MixChunk -new_from_file (SV *class, char *path) +new (SV *class, CFPlus::RW rwops) CODE: - RETVAL = Mix_LoadWAV (path); + RETVAL = Mix_LoadWAV_RW (rwops, 1); OUTPUT: RETVAL @@ -2253,14 +2381,27 @@ int volume (CFPlus::MixChunk self, int volume = -1) CODE: + if (items > 1) + volume = CLAMP (volume, 0, 128); RETVAL = Mix_VolumeChunk (self, volume); OUTPUT: RETVAL -int -play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) +CFPlus::Channel +play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) CODE: +{ RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); + + if (RETVAL < 0) + XSRETURN_UNDEF; + + if (channel < 0) + { + Mix_UnregisterAllEffects (RETVAL); + Mix_Volume (RETVAL, 128); + } +} OUTPUT: RETVAL @@ -2270,21 +2411,26 @@ volume (int volume = -1) PROTOTYPE: ;$ CODE: + if (items > 0) + volume = CLAMP (volume, 0, 128); RETVAL = Mix_VolumeMusic (volume); OUTPUT: RETVAL -int +void fade_out (int ms) CODE: - RETVAL = Mix_FadeOutMusic (ms); - OUTPUT: - RETVAL + Mix_FadeOutMusic (ms); + +void +halt () + CODE: + Mix_HaltMusic (); CFPlus::MixMusic -new_from_file (SV *class, char *path) +new (SV *class, CFPlus::RW rwops) CODE: - RETVAL = Mix_LoadMUS (path); + RETVAL = Mix_LoadMUS_RW (rwops); OUTPUT: RETVAL @@ -2300,12 +2446,10 @@ OUTPUT: RETVAL -int +void fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) CODE: - RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); - OUTPUT: - RETVAL + Mix_FadeInMusicPos (self, loops, ms, position); MODULE = CFPlus PACKAGE = CFPlus::OpenGL @@ -2549,6 +2693,10 @@ CODE: glTexCoord2f (s, t); +void glRect (float x1, float y1, float x2, float y2) + CODE: + glRectf (x1, y1, x2, y2); + PROTOTYPES: ENABLE void glBegin (int mode)