--- deliantra/Deliantra-Client/Client.xs 2008/11/26 23:08:34 1.280 +++ deliantra/Deliantra-Client/Client.xs 2018/11/19 01:23:01 1.333 @@ -17,20 +17,24 @@ #include "perl.h" #include "XSUB.h" +#include "flat_hash_map.hpp" + #ifdef _WIN32 # undef pipe // microsoft vs. C # define sqrtf(x) sqrt(x) -# define roundf(x) (int)(x) # define atan2f(x,y) atan2(x,y) # define M_PI 3.14159265f #endif -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#include +#include #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW @@ -44,12 +48,14 @@ /* work around os x broken headers */ #ifdef __MACOSX__ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); #endif #define PANGO_ENABLE_BACKEND #define G_DISABLE_CAST_CHECKS -#include +#include #include @@ -72,18 +78,15 @@ # include #endif -#if __GNUC__ >= 4 -# define expect(expr,value) __builtin_expect ((expr),(value)) -#else -# define expect(expr,value) (expr) -#endif - -#define expect_false(expr) expect ((expr) != 0, 0) -#define expect_true(expr) expect ((expr) != 0, 1) +#include "ecb.h" +#include "salloc.h" #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ -#define FOW_DARKNESS 32 +/* this is used as fow flag as well, so has to have a different value */ +/* then anything that is computed by incoming darkness */ +#define FOW_DARKNESS 50 +#define DARKNESS_ADJUST(n) (n) #define MAP_EXTEND_X 32 #define MAP_EXTEND_Y 512 @@ -95,6 +98,28 @@ #define KMOD_LRAM 0x10000 // our extension +#define TEXID_SPEECH 1 +#define TEXID_NOFACE 2 + +static char * +fast_sv_grow (SV *sv, STRLEN need) +{ + STRLEN len = SvLEN (sv); + STRLEN want = SvCUR (sv) + need; + + if (ecb_expect_false (len < want)) + { + do + len *= 2; + while (len < want); + + sv_grow (sv, len); + } + + SvCUR_set (sv, want); + return SvEND (sv) - need; +} + static AV *texture_av; static struct @@ -160,7 +185,7 @@ while (attrs) { - PangoAttribute *attr = attrs->data; + PangoAttribute *attr = (PangoAttribute *)attrs->data; if (attr->klass->type == PANGO_ATTR_SHAPE) return 1; @@ -171,13 +196,15 @@ return 0; } -typedef struct cf_layout { +struct cf_layout { PangoLayout *pl; float r, g, b, a; // default color for rgba mode int base_height; DC__Font font; - rc_t *rc; -} *DC__Layout; + rc_t rc; +}; + +typedef cf_layout *DC__Layout; static DC__Font default_font; static PangoContext *opengl_context; @@ -188,7 +215,7 @@ { FcPatternAddBool (pattern, FC_HINTING, 1); #ifdef FC_HINT_STYLE - FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); + FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); #endif FcPatternAddBool (pattern, FC_AUTOHINT, 0); } @@ -225,10 +252,13 @@ *h = rect.height; } +///////////////////////////////////////////////////////////////////////////// + typedef uint16_t tileid; typedef uint16_t faceid; -typedef struct { +struct maptex +{ GLuint name; int w, h; float s, t; @@ -236,21 +266,23 @@ tileid smoothtile; uint8_t smoothlevel; uint8_t unused; /* set to zero on use */ -} maptex; +}; -typedef struct { +struct mapcell +{ uint32_t player; tileid tile[3]; uint16_t darkness; uint8_t stat_width, stat_hp, flags, smoothmax; -} mapcell; +}; -typedef struct { +struct maprow +{ int32_t c0, c1; mapcell *col; -} maprow; +}; -typedef struct map { +struct mapgrid { int x, y, w, h; int ox, oy; /* offset to virtual global coordinate system */ int faces; tileid *face2tile; // [faceid] @@ -258,60 +290,59 @@ int32_t rows; maprow *row; -} *DC__Map; +}; -static char * -prepend (char *ptr, int sze, int inc) +typedef mapgrid *DC__Map; + +template +static void +prepend (T *&ptr, int sze, int inc) { - char *p; + T *p; - New (0, p, sze + inc, char); - Zero (p, inc, char); - Move (ptr, p + inc, sze, char); + Newx (p, inc + sze, T); + Zero (p, inc, T); + Move (ptr, p + inc, sze, T); Safefree (ptr); - return p; + ptr = p; } -static char * -append (char *ptr, int sze, int inc) +template +static void +append (T *&ptr, int sze, int inc) { - Renew (ptr, sze + inc, char); - Zero (ptr + sze, inc, char); - - return ptr; + Renew (ptr, sze + inc, T); + Zero (ptr + sze, inc, T); } -#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) -#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) - static void -need_facenum (struct map *self, faceid face) +need_facenum (struct mapgrid *self, faceid face) { while (self->faces <= face) { - Append (tileid, self->face2tile, self->faces, self->faces); + append (self->face2tile, self->faces, self->faces); self->faces *= 2; } } static void -need_texid (struct map *self, int texid) +need_texid (struct mapgrid *self, int texid) { while (self->texs <= texid) { - Append (maptex, self->tex, self->texs, self->texs); + append (self->tex, self->texs, self->texs); self->texs *= 2; } } static maprow * -map_get_row (DC__Map self, int y) +map_get_row (mapgrid *self, int y) { if (0 > y) { int extend = - y + MAP_EXTEND_Y; - Prepend (maprow, self->row, self->rows, extend); + prepend (self->row, self->rows, extend); self->rows += extend; self->y += extend; @@ -320,7 +351,7 @@ else if (y >= self->rows) { int extend = y - self->rows + MAP_EXTEND_Y; - Append (maprow, self->row, self->rows, extend); + append (self->row, self->rows, extend); self->rows += extend; } @@ -340,13 +371,13 @@ if (row->c0 > x) { int extend = row->c0 - x + MAP_EXTEND_X; - Prepend (mapcell, row->col, row->c1 - row->c0, extend); + prepend (row->col, row->c1 - row->c0, extend); row->c0 -= extend; } else if (x >= row->c1) { int extend = x - row->c1 + MAP_EXTEND_X; - Append (mapcell, row->col, row->c1 - row->c0, extend); + append (row->col, row->c1 - row->c0, extend); row->c1 += extend; } @@ -354,13 +385,13 @@ } static mapcell * -map_get_cell (DC__Map self, int x, int y) +map_get_cell (mapgrid *self, int x, int y) { return row_get_cell (map_get_row (self, y), x); } static void -map_clear (DC__Map self) +map_clear (mapgrid *self) { int r; @@ -388,7 +419,7 @@ } while (0) static void -map_blank (DC__Map self, int x0, int y0, int w, int h) +map_blank (mapgrid *self, int x0, int y0, int w, int h) { int x, y; maprow *row; @@ -415,20 +446,39 @@ } } -typedef struct { +struct smooth_key +{ tileid tile; uint8_t x, y, level; -} smooth_key; + + bool operator == (const smooth_key &o) const + { + return tile == o.tile && x == o.x && y == o.y && level == o.level; + } +}; + +typedef ska::flat_hash_map smooth_hash; + +namespace std { + template <> + struct hash + { + size_t operator () (const smooth_key &v) const + { + return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); + } + }; +} static void -smooth_or_bits (HV *hv, smooth_key *key, IV bits) +smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) { - SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); + auto &&it = h.find (key); - if (SvIOK (*sv)) - SvIV_set (*sv, SvIVX (*sv) | bits); + if (it == h.end ()) + h.insert (std::make_pair (key, bits)); else - sv_setiv (*sv, bits); + it->second |= bits; } static void @@ -457,6 +507,13 @@ SDL_PushEvent ((SDL_Event *)&ev); } +// approximately divide by 255 +static unsigned int +div255 (unsigned int n) +{ + return (n + (n >> 8)) >> 8; +} + static unsigned int minpot (unsigned int n) { @@ -474,17 +531,6 @@ return n + 1; } -static unsigned int -popcount (unsigned int n) -{ - n -= (n >> 1) & 0x55555555U; - n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); - n = ((n >> 4) + n) & 0x0f0f0f0fU; - n *= 0x01010101U; - - return n >> 24; -} - /* SDL should provide this, really. */ #define SDLK_MODIFIER_MIN 300 #define SDLK_MODIFIER_MAX 314 @@ -547,23 +593,27 @@ } static void -deliantra_main () +deliantra_main (SV *real_main) { - char *argv[] = { 0 }; - call_argv ("::main", G_DISCARD | G_VOID, argv); + dSP; + + PUSHMARK (SP); + call_sv (real_main, G_DISCARD | G_VOID); } #ifdef __MACOSX__ + static SV *real_main; + /* to due surprising braindamage on the side of SDL design, we * do some mind-boggling hack here: SDL requires a custom main() * on OS X, so... we provide one and call the original main(), which, - * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, + * due to shared library magic, calls -lSDLmain's main, not perl's main, * and which calls our main (== SDL_main) back. */ extern C_LINKAGE int main (int argc, char *argv[]) { - deliantra_main (); + deliantra_main (real_main); } #undef main @@ -571,16 +621,18 @@ extern C_LINKAGE int main (int argc, char *argv[]); static void - SDL_braino (void) + SDL_main_hack (SV *real_main_) { + real_main = real_main_; + char *argv[] = { "deliantra client", 0 }; (main) (1, argv); } #else static void - SDL_braino (void) + SDL_main_hack (SV *real_main) { - deliantra_main (); + deliantra_main (real_main); } #endif @@ -791,8 +843,8 @@ # undef const_iv }; - for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) - newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); + for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) + newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); @@ -817,7 +869,23 @@ IV minpot (UV n) +UV ld32 (UV n) + CODE: + RETVAL = ecb_ld32 (n); + OUTPUT: + RETVAL + IV popcount (UV n) + CODE: + RETVAL = ecb_popcount32 (n); + OUTPUT: + RETVAL + +NV distance (NV dx, NV dy) + CODE: + RETVAL = pow (dx * dx + dy * dy, 0.5); + OUTPUT: + RETVAL void pango_init () @@ -835,7 +903,8 @@ char *SDL_GetError () -void SDL_braino () +void SDL_main_hack (SV *real_main) + PROTOTYPE: & int SDL_Init (U32 flags) @@ -846,10 +915,11 @@ void SDL_Quit () int SDL_GL_SetAttribute (int attr, int value) + C_ARGS: (SDL_GLattr)attr, value int SDL_GL_GetAttribute (int attr) CODE: - if (SDL_GL_GetAttribute (attr, &RETVAL)) + if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) XSRETURN_UNDEF; OUTPUT: RETVAL @@ -914,21 +984,25 @@ if (RETVAL) { av_clear (texture_av); - - SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra"); #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); #include "glfunc.h" #undef GL_FUNC + if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; + if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; } } OUTPUT: RETVAL void +SDL_WM_SetCaption (const char *title, const char *icon) + +void SDL_GL_SwapBuffers () char * SDL_GetKeyName (int sym) + C_ARGS: (SDLKey)sym int SDL_GetAppState () @@ -936,8 +1010,15 @@ int SDL_GetModState () +int +SDL_WaitEvent () + C_ARGS: 0 + +void +SDL_PumpEvents () + void -poll_events () +peep_events () PPCODE: { SDL_Event ev; @@ -1013,9 +1094,22 @@ } } +char * +SDL_AudioDriverName () + CODE: +{ + char buf [256]; + if (!SDL_AudioDriverName (buf, sizeof (buf))) + XSRETURN_UNDEF; + + RETVAL = buf; +} + OUTPUT: + RETVAL + int Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) - POSTCALL: + POSTCALL: Mix_HookMusicFinished (music_finished); Mix_ChannelFinished (channel_finished); @@ -1086,6 +1180,13 @@ RETVAL void +IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) + +# MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s +void +Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG) + +void load_image_inline (SV *image_) ALIAS: load_image_file = 1 @@ -1139,7 +1240,7 @@ EXTEND (SP, 6); PUSHs (sv_2mortal (newSViv (surface2->w))); PUSHs (sv_2mortal (newSViv (surface2->h))); - PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); + PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); PUSHs (sv_2mortal (newSViv (GL_RGBA))); PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); @@ -1221,7 +1322,7 @@ PROTOTYPES: DISABLE DC::Font -new_from_file (SV *class, char *path, int id = 0) +new_from_file (SV *klass, char *path, int id = 0) CODE: { int count; @@ -1260,9 +1361,9 @@ tc_restore (); DC::Layout -new (SV *class) +new (SV *klass) CODE: - New (0, RETVAL, 1, struct cf_layout); + RETVAL = new cf_layout; RETVAL->pl = pango_layout_new (opengl_context); RETVAL->r = 1.; @@ -1271,7 +1372,6 @@ RETVAL->a = 1.; RETVAL->base_height = MIN_FONT_HEIGHT; RETVAL->font = 0; - RETVAL->rc = rc_alloc (); pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); layout_update_font (RETVAL); @@ -1282,8 +1382,7 @@ DESTROY (DC::Layout self) CODE: g_object_unref (self->pl); - rc_free (self->rc); - Safefree (self); + delete self; void set_text (DC::Layout self, SV *text_) @@ -1419,7 +1518,7 @@ set_height (DC::Layout self, int base_height) CODE: if (self->base_height != base_height) - { + { self->base_height = base_height; layout_update_font (self); } @@ -1547,10 +1646,10 @@ void render (DC::Layout self, float x, float y, int flags = 0) CODE: - rc_clear (self->rc); + self->rc.clear (); pango_opengl_render_layout_subpixel ( self->pl, - self->rc, + &self->rc, x * PANGO_SCALE, y * PANGO_SCALE, self->r, self->g, self->b, self->a, flags @@ -1571,7 +1670,7 @@ glEnable (GL_ALPHA_TEST); glAlphaFunc (GL_GREATER, 7.f / 255.f); - rc_draw (self->rc); + self->rc.draw (); glDisable (GL_ALPHA_TEST); glDisable (GL_BLEND); @@ -1656,6 +1755,127 @@ } } +void +draw_fow_texture (float intensity, int hidden_tex, int name1, uint8_t *data1, float s, float t, int w, int h, float blend = 0.f, int dx = 0, int dy = 0, int name2 = 0, uint8_t *data2 = data1) + PROTOTYPE: @ + CODE: +{ + glEnable (GL_BLEND); + glBlendFunc (intensity ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_TEXTURE_2D); + glBindTexture (GL_TEXTURE_2D, name1); + + glColor3f (intensity, intensity, intensity); + glPushMatrix (); + glScalef (1./3, 1./3, 1.); + + if (blend > 0.f) + { + float dx3 = dx * -3.f / w; + float dy3 = dy * -3.f / h; + GLfloat env_color[4] = { 0., 0., 0., blend }; + + /* interpolate the two shadow textures */ + /* stage 0 == rgb(glcolor) + alpha(t0) */ + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */ + gl.ActiveTexture (GL_TEXTURE1); + glEnable (GL_TEXTURE_2D); + glBindTexture (GL_TEXTURE_2D, name2); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + + /* rgb == rgb(glcolor) */ + glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); + glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR); + glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); + + /* alpha = interpolate t0, t1 by env_alpha */ + glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color); + + glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE); + glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); + glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); + + glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); + glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); + + glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); + glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); + + glBegin (GL_QUADS); + gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0); + gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h); + gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h); + gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0); + glEnd (); + + glDisable (GL_TEXTURE_2D); + gl.ActiveTexture (GL_TEXTURE0); + } + else + { + /* simple blending of one texture, also opengl <1.3 path */ + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glBegin (GL_QUADS); + glTexCoord2f (0, 0); glVertex2f (0, 0); + glTexCoord2f (0, t); glVertex2f (0, h); + glTexCoord2f (s, t); glVertex2f (w, h); + glTexCoord2f (s, 0); glVertex2f (w, 0); + glEnd (); + } + + /* draw ?-marks or equivalent, this is very clumsy code :/ */ + { + int x, y; + int dx3 = dx * 3; + int dy3 = dy * 3; + + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glBindTexture (GL_TEXTURE_2D, hidden_tex); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glTranslatef (-1., -1., 0); + glBegin (GL_QUADS); + + for (y = 1; y < h; y += 3) + { + int y1 = y - dy3; + int y1valid = y1 >= 0 && y1 < h; + + for (x = 1; x < w; x += 3) + { + int x1 = x - dx3; + uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); + uint8_t h2; + + if (y1valid && x1 >= 0 && x1 < w) + h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); + else + h2 = 1; /* out of range == invisible */ + + if (h1 || h2) + { + float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend; + glColor4f (1., 1., 1., alpha); + + glTexCoord2f (0, 0.); glVertex2i (x , y ); + glTexCoord2f (0, 1.); glVertex2i (x , y + 3); + glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3); + glTexCoord2f (1, 0.); glVertex2i (x + 3, y ); + } + } + } + } + + glEnd (); + + glPopMatrix (); + + glDisable (GL_TEXTURE_2D); + glDisable (GL_BLEND); +} + IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) CODE: { @@ -1672,9 +1892,9 @@ PROTOTYPES: DISABLE DC::Map -new (SV *class) +new (SV *klass) CODE: - New (0, RETVAL, 1, struct map); + New (0, RETVAL, 1, mapgrid); RETVAL->x = 0; RETVAL->y = 0; RETVAL->w = 0; @@ -1721,7 +1941,7 @@ set_smooth (DC::Map self, int face, int smooth, int level) CODE: { - tileid texid; + tileid texid; maptex *tex; if (face < 0 || face >= self->faces) @@ -1730,7 +1950,7 @@ if (smooth < 0 || smooth >= self->faces) return; - texid = self->face2tile [face]; + texid = self->face2tile [face]; if (!texid) return; @@ -1773,7 +1993,7 @@ void expire_textures (DC::Map self, int texid, int count) PPCODE: - for (; texid < self->texs && count; ++texid, --count) + for (; texid < self->texs && count; ++texid, --count) { maptex *tex = self->tex + texid; @@ -1782,7 +2002,7 @@ if (tex->unused) { tex->name = 0; - tex->unused = 0, + tex->unused = 0; XPUSHs (sv_2mortal (newSViv (texid))); } else @@ -1830,7 +2050,7 @@ while (self->y < 0) { - Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); + prepend (self->row, self->rows, MAP_EXTEND_Y); self->rows += MAP_EXTEND_Y; self->y += MAP_EXTEND_Y; @@ -1838,7 +2058,7 @@ } SV * -map1a_update (DC::Map self, SV *data_, int extmap) +map1a_update (DC::Map self, SV *data_) CODE: { uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); @@ -1869,44 +2089,39 @@ if (flags & 8) { - if (extmap) + uint8_t ext, cmd; + + do { - uint8_t ext, cmd; + ext = *data++; + cmd = ext & 0x7f; - do + if (cmd < 4) + cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ + else if (cmd == 5) // health { - ext = *data++; - cmd = ext & 0x7f; - - if (cmd < 4) - cell->darkness = 255 - ext * 64 + 1; - else if (cmd == 5) // health - { - cell->stat_width = 1; - cell->stat_hp = *data++; - } - else if (cmd == 6) // monster width - cell->stat_width = *data++ + 1; - else if (cmd == 0x47) - { - if (*data == 1) cell->player = data [1]; - else if (*data == 2) cell->player = data [2] + (data [1] << 8); - else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); - else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); + cell->stat_width = 1; + cell->stat_hp = *data++; + } + else if (cmd == 6) // monster width + cell->stat_width = *data++ + 1; + else if (cmd == 0x47) + { + if (*data == 1) cell->player = data [1]; + else if (*data == 2) cell->player = data [2] + (data [1] << 8); + else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); + else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); - data += *data + 1; - } - else if (cmd == 8) // cell flags - cell->flags = *data++; - else if (ext & 0x40) // unknown, multibyte => skip - data += *data + 1; - else - data++; + data += *data + 1; } - while (ext & 0x80); + else if (cmd == 8) // cell flags + cell->flags = *data++; + else if (ext & 0x40) // unknown, multibyte => skip + data += *data + 1; + else + data++; } - else - cell->darkness = *data++ + 1; + while (ext & 0x80); } for (z = 0; z <= 2; ++z) @@ -1964,7 +2179,7 @@ for (x = x0; x < x1; x++) { - int r = 32, g = 32, b = 32, a = 192; + unsigned int r = 32, g = 32, b = 32, a = 192; if (row && row->c0 <= x && x < row->c1) { @@ -1976,10 +2191,10 @@ int a0 = 255 - tex.a; int a1 = tex.a; - r = (r * a0 + tex.r * a1) / 255; - g = (g * a0 + tex.g * a1) / 255; - b = (b * a0 + tex.b * a1) / 255; - a = (a * a0 + tex.a * a1) / 255; + r = div255 (r * a0 + tex.r * a1); + g = div255 (g * a0 + tex.g * a1); + b = div255 (b * a0 + tex.b * a1); + a = div255 (a * a0 + tex.a * a1); } } @@ -1990,36 +2205,31 @@ } } - RETVAL = map_sv; + RETVAL = map_sv; } OUTPUT: RETVAL void -draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) +draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) CODE: { int x, y, z; - HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); - uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level - static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) - smooth_key skey; + static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! int pl_x, pl_y; maptex pl_tex; - rc_t *rc = rc_alloc (); + rc_t rc; + rc_t rc_ov; rc_key_t key; - rc_array_t *arr; + rc_t::array_t *arr; pl_tex.name = 0; - // thats current max. sorry. + // that's current max. sorry. if (sw > 255) sw = 255; if (sh > 255) sh = 255; - // clear key, in case of extra padding - memset (&skey, 0, sizeof (skey)); - memset (&key, 0, sizeof (key)); key.r = 255; key.g = 255; @@ -2027,7 +2237,6 @@ key.a = 255; key.mode = GL_QUADS; key.format = GL_T2F_V3F; - key.texname = -1; mx += self->x; my += self->y; @@ -2035,7 +2244,7 @@ // first pass: determine smooth_max // rather ugly, if you ask me // could also be stored inside mapcell and updated on change - memset (smooth_max, 0, sizeof (smooth_max)); + memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1)); for (y = 0; y < sh; y++) if (0 <= y + my && y + my < self->rows) @@ -2060,7 +2269,10 @@ for (z = 0; z <= 2; z++) { - memset (smooth_level, 0, sizeof (smooth_level)); + std::bitset<256> smooth_level; // one bit for every possible smooth level + smooth_key skey; + smooth_hash smooth; + key.texname = -1; for (y = 0; y < sh; y++) if (0 <= y + my && y + my < self->rows) @@ -2076,21 +2288,23 @@ if (tile) { maptex tex = self->tex [tile]; - int px = (x + 1) * T - tex.w; - int py = (y + 1) * T - tex.h; + int px, py; if (key.texname != tex.name) { self->tex [tile].unused = 0; if (!tex.name) - tex = self->tex [2]; /* missing, replace by noface */ + tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ key.texname = tex.name; - arr = rc_array (rc, &key); + arr = &rc.array (key); } - if (expect_false (cell->player == player) && expect_false (z == 2)) + px = (x + 1) * Th - tex.w; + py = (y + 1) * Tw - tex.h; + + if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2)) { pl_x = px; pl_y = py; @@ -2098,35 +2312,10 @@ continue; } - rc_t2f_v3f (arr, 0 , 0 , px , py , 0); - rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); - rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); - rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); - - if (expect_false (cell->flags) && expect_false (z == 2)) - { - // overlays such as the speech bubble, probably more to come - if (cell->flags & 1) - { - maptex tex = self->tex [1]; - int px = x * T + T * 2 / 32; - int py = y * T - T * 6 / 32; - - if (tex.name) - { - if (key.texname != tex.name) - { - key.texname = tex.name; - arr = rc_array (rc, &key); - } - - rc_t2f_v3f (arr, 0 , 0 , px , py , 0); - rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); - rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); - rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); - } - } - } + arr->t2f_v3f (0 , 0 , px , py , 0); + arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0); + arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); + arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0); // update smooth hash if (tex.smoothtile) @@ -2134,7 +2323,7 @@ skey.tile = tex.smoothtile; skey.level = tex.smoothlevel; - smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); + smooth_level[tex.smoothlevel] = 1; // add bits to current tile and all neighbours. skey.x|y is // shifted +1|+1 so we always stay positive. @@ -2152,26 +2341,46 @@ // ·· ·· ·┏ ┓· // full tile - skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); + skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); // borders - skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); - skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); - skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); - skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); + skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); + skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); + skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); + skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); // corners - skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); - skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); - skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); - skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); + skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); + skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); + skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); + skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); + } + } + + if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags)) + { + // overlays such as the speech bubble, probably more to come + if (cell->flags & 1) + { + rc_key_t key_ov = key; + maptex tex = self->tex[TEXID_SPEECH]; + int px = x * Tw + Tw * 2 / 32; + int py = y * Th - Th * 6 / 32; + + key_ov.texname = tex.name; + rc_t::array_t &arr = rc_ov.array (key_ov); + + arr.t2f_v3f (0 , 0 , px , py , 0); + arr.t2f_v3f (0 , tex.t, px , py + Th, 0); + arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0); + arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0); } } } } - rc_draw (rc); - rc_clear (rc); + rc.draw (); + rc.clear (); // go through all smoothlevels, lowest to highest, then draw. // this is basically counting sort @@ -2180,78 +2389,65 @@ glEnable (GL_TEXTURE_2D); glBegin (GL_QUADS); - for (w = 0; w < 256 / 32; ++w) - { - uint32_t smask = smooth_level [w]; - if (smask) - for (b = 0; b < 32; ++b) - if (smask & (((uint32_t)1) << b)) + for (int level = 0; level < smooth_level.size (); ++level) + if (smooth_level[level]) + for (auto &&it = smooth.begin (); it != smooth.end (); ++it) + { + smooth_key &skey = it->first; + IV bits = it->second; + + if (!(bits & 0x1000) + && skey.level == level + && level > smooth_max [skey.x][skey.y]) { - int level = (w << 5) | b; - HE *he; + maptex tex = self->tex [skey.tile]; + int px = (((int)skey.x) - 1) * Tw; + int py = (((int)skey.y) - 1) * Th; + int border = bits & 15; + int corner = (bits >> 8) & ~(bits >> 4) & 15; + float dx = tex.s * .0625f; // 16 images/row + float dy = tex.t * .5f ; // 2 images/column - hv_iterinit (smooth); - while ((he = hv_iternext (smooth))) + if (tex.name) { - smooth_key *skey = (smooth_key *)HeKEY (he); - IV bits = SvIVX (HeVAL (he)); + // this time avoiding texture state changes + // save gobs of state changes. + if (key.texname != tex.name) + { + self->tex [skey.tile].unused = 0; + + glEnd (); + glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); + glBegin (GL_QUADS); + } - if (!(bits & 0x1000) - && skey->level == level - && level > smooth_max [skey->x][skey->y]) + if (border) { - maptex tex = self->tex [skey->tile]; - int px = (((int)skey->x) - 1) * T; - int py = (((int)skey->y) - 1) * T; - int border = bits & 15; - int corner = (bits >> 8) & ~(bits >> 4) & 15; - float dx = tex.s * .0625f; // 16 images/row - float dy = tex.t * .5f ; // 2 images/column - - if (tex.name) - { - // this time avoiding texture state changes - // save gobs of state changes. - if (key.texname != tex.name) - { - self->tex [skey->tile].unused = 0; - - glEnd (); - glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); - glBegin (GL_QUADS); - } - - if (border) - { - float ox = border * dx; - - glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); - glTexCoord2f (ox , dy ); glVertex2i (px , py + T); - glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); - glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); - } - - if (corner) - { - float ox = corner * dx; - - glTexCoord2f (ox , dy ); glVertex2i (px , py ); - glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); - glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); - glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); - } - } + float ox = border * dx; + + glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); + glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); + glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); + glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); + } + + if (corner) + { + float ox = corner * dx; + + glTexCoord2f (ox , dy ); glVertex2i (px , py ); + glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); + glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); + glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); } } } - } + } glEnd (); glDisable (GL_TEXTURE_2D); key.texname = -1; } - - hv_clear (smooth); } if (pl_tex.name) @@ -2261,18 +2457,20 @@ int py = pl_y + sdy; key.texname = tex.name; - arr = rc_array (rc, &key); + rc_t::array_t &arr = rc.array (key); - rc_t2f_v3f (arr, 0 , 0 , px , py , 0); - rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); - rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); - rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); + arr.t2f_v3f (0 , 0 , px , py , 0); + arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0); + arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); + arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0); - rc_draw (rc); + rc.draw (); } + rc_ov.draw (); + rc_ov.clear (); + glDisable (GL_BLEND); - rc_free (rc); // top layer: overlays such as the health bar for (y = 0; y < sh; y++) @@ -2285,10 +2483,10 @@ { mapcell *cell = row->col + (x + mx - row->c0); - int px = x * T; - int py = y * T; + int px = x * Tw; + int py = y * Th; - if (expect_false (cell->player == player)) + if (ecb_expect_false (cell->player == player)) { px += sdx; py += sdy; @@ -2296,8 +2494,8 @@ if (cell->stat_hp) { - int width = cell->stat_width * T; - int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; + int width = cell->stat_width * Tw; + int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; glColor3ub (0, 0, 0); glRectf (px + 1, py - thick - 2, @@ -2313,36 +2511,42 @@ } void -draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data) +draw_magicmap (DC::Map self, int w, int h, unsigned char *data) CODE: { static float color[16][3] = { - { 0.00F, 0.00F, 0.00F }, - { 1.00F, 1.00F, 1.00F }, - { 0.00F, 0.00F, 0.55F }, - { 1.00F, 0.00F, 0.00F }, - - { 1.00F, 0.54F, 0.00F }, - { 0.11F, 0.56F, 1.00F }, - { 0.93F, 0.46F, 0.00F }, - { 0.18F, 0.54F, 0.34F }, - - { 0.56F, 0.73F, 0.56F }, - { 0.80F, 0.80F, 0.80F }, - { 0.55F, 0.41F, 0.13F }, - { 0.99F, 0.77F, 0.26F }, - - { 0.74F, 0.65F, 0.41F }, - - { 0.00F, 1.00F, 1.00F }, - { 1.00F, 0.00F, 1.00F }, - { 1.00F, 1.00F, 0.00F }, + { 0.00f, 0.00f, 0.00f }, + { 1.00f, 1.00f, 1.00f }, + { 0.00f, 0.00f, 0.55f }, + { 1.00f, 0.00f, 0.00f }, + + { 1.00f, 0.54f, 0.00f }, + { 0.11f, 0.56f, 1.00f }, + { 0.93f, 0.46f, 0.00f }, + { 0.18f, 0.54f, 0.34f }, + + { 0.56f, 0.73f, 0.56f }, + { 0.80f, 0.80f, 0.80f }, + { 0.55f, 0.41f, 0.13f }, + { 0.99f, 0.77f, 0.26f }, + + { 0.74f, 0.65f, 0.41f }, + + { 0.00f, 1.00f, 1.00f }, + { 1.00f, 0.00f, 1.00f }, + { 1.00f, 1.00f, 0.00f }, }; int x, y; glEnable (GL_TEXTURE_2D); - glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + /* GL_REPLACE would be correct, as we don't need to modulate alpha, + * but the nvidia driver (185.18.14) mishandles alpha textures + * and takes the colour from god knows where instead of using + * Cp. MODULATE results in the same colour, but slightly different + * alpha, but atcually gives us the correct colour with nvidia. + */ + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin (GL_QUADS); @@ -2356,10 +2560,10 @@ { float *c = color [m & 15]; - float tx1 = m & 0x40 ? 0.5 : 0.; - float tx2 = tx1 + 0.5; + float tx1 = m & 0x40 ? 0.5f : 0.f; + float tx2 = tx1 + 0.5f; - glColor4f (c[0], c[1], c[2], 0.75); + glColor4f (c[0], c[1], c[2], 1); glTexCoord2f (tx1, 0.); glVertex2i (x , y ); glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); @@ -2377,22 +2581,21 @@ PPCODE: { int x, y; - int sw1 = sw + 2; - int sh1 = sh + 2; - int sh3 = sh * 3; - int sw34 = (sw * 3 + 3) & ~3; - uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); - SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); + int sw1 = sw + 2; + int sh1 = sh + 2; + int sh3 = sh * 3; + int sw3 = sw * 3; + SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); + uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); + memset (darkness1, 0, sw1*sh1); SvPOK_only (darkness3_sv); - SvCUR_set (darkness3_sv, sw34 * sh3); + SvCUR_set (darkness3_sv, sw3 * sh3); mx += self->x - 1; my += self->y - 1; - memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); - for (y = 0; y < sh1; y++) if (0 <= y + my && y + my < self->rows) { @@ -2404,8 +2607,8 @@ mapcell *cell = row->col + (x + mx - row->c0); darkness1 [y * sw1 + x] = cell->darkness - ? 255 - (cell->darkness - 1) - : 255 - FOW_DARKNESS; + ? DARKNESS_ADJUST (255 - (cell->darkness - 1)) + : DARKNESS_ADJUST (255 - FOW_DARKNESS); } } @@ -2434,21 +2637,21 @@ uint8_t r23 = d23; uint8_t r33 = (d23 + d33 + d32) / 3; - darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); - darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); - darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); - darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); - darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); - darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); - darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); - darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); - darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); + darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11); + darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21); + darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31); + darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12); + darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */ + darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32); + darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13); + darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23); + darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33); } free (darkness1); EXTEND (SP, 3); - PUSHs (sv_2mortal (newSViv (sw34))); + PUSHs (sv_2mortal (newSViv (sw3))); PUSHs (sv_2mortal (newSViv (sh3))); PUSHs (darkness3_sv); } @@ -2521,14 +2724,14 @@ } } - /* if size is w*h + 5 then no data has been found */ + /* if size is w*h + 5 then no data has been found */ if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) { SvPOK_only (data_sv); SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); } - RETVAL = data_sv; + RETVAL = data_sv; } OUTPUT: RETVAL @@ -2545,7 +2748,7 @@ len = SvLEN (data_sv); SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more - data = SvPVbyte_nolen (data_sv); + data = (uint8_t *)SvPVbyte_nolen (data_sv); end = data + len + 8; if (len < 5) @@ -2616,7 +2819,7 @@ MODULE = Deliantra::Client PACKAGE = DC::RW DC::RW -new (SV *class, SV *data_sv) +new (SV *klass, SV *data_sv) CODE: { STRLEN datalen; @@ -2628,7 +2831,7 @@ RETVAL DC::RW -new_from_file (SV *class, const char *path, const char *mode = "rb") +new_from_file (SV *klass, const char *path, const char *mode = "rb") CODE: RETVAL = SDL_RWFromFile (path, mode); OUTPUT: @@ -2656,9 +2859,15 @@ RETVAL = Mix_GroupOldest (-1); if (RETVAL < 0) - XSRETURN_UNDEF; + { + // happens sometimes, maybe it just stopped playing(?) + RETVAL = Mix_GroupAvailable (-1); - Mix_HaltChannel (RETVAL); + if (RETVAL < 0) + XSRETURN_UNDEF; + } + else + Mix_HaltChannel (RETVAL); } Mix_UnregisterAllEffects (RETVAL); @@ -2715,7 +2924,7 @@ 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); + int angle = atan2f (dx, -dy) * 180.f / (float)M_PI + 360.f; Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); } @@ -2728,8 +2937,20 @@ PROTOTYPES: DISABLE +void +decoders () + PPCODE: +#if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 + int i, num = Mix_GetNumChunkDecoders (); + EXTEND (SP, num); + for (i = 0; i < num; ++i) + PUSHs (sv_2mortal (newSVpv (Mix_GetChunkDecoder (i), 0))); +#else + XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); +#endif + DC::MixChunk -new (SV *class, DC::RW rwops) +new (SV *klass, DC::RW rwops) CODE: RETVAL = Mix_LoadWAV_RW (rwops, 1); OUTPUT: @@ -2769,6 +2990,18 @@ MODULE = Deliantra::Client PACKAGE = DC::MixMusic +void +decoders () + PPCODE: +#if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 + int i, num = Mix_GetNumMusicDecoders (); + EXTEND (SP, num); + for (i = 0; i < num; ++i) + PUSHs (sv_2mortal (newSVpv (Mix_GetMusicDecoder (i), 0))); +#else + XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); +#endif + int volume (int volume = -1) PROTOTYPE: ;$ @@ -2789,8 +3022,15 @@ CODE: Mix_HaltMusic (); +int +playing () + CODE: + RETVAL = Mix_PlayingMusic (); + OUTPUT: + RETVAL + DC::MixMusic -new (SV *class, DC::RW rwops) +new (SV *klass, DC::RW rwops) CODE: RETVAL = Mix_LoadMUS_RW (rwops); OUTPUT: @@ -2828,6 +3068,7 @@ const_iv (GL_VENDOR), const_iv (GL_VERSION), const_iv (GL_EXTENSIONS), + const_iv (GL_MAX_TEXTURE_UNITS), const_iv (GL_COLOR_MATERIAL), const_iv (GL_SMOOTH), const_iv (GL_FLAT), @@ -2849,6 +3090,10 @@ const_iv (GL_DST_ALPHA), const_iv (GL_ONE_MINUS_SRC_ALPHA), const_iv (GL_ONE_MINUS_DST_ALPHA), + const_iv (GL_SRC_COLOR), + const_iv (GL_DST_COLOR), + const_iv (GL_ONE_MINUS_SRC_COLOR), + const_iv (GL_ONE_MINUS_DST_COLOR), const_iv (GL_SRC_ALPHA_SATURATE), const_iv (GL_RGB), const_iv (GL_RGBA), @@ -2926,11 +3171,14 @@ const_iv (GL_V3F), const_iv (GL_T2F_V3F), const_iv (GL_T2F_N3F_V3F), + const_iv (GL_FUNC_ADD), + const_iv (GL_FUNC_SUBTRACT), + const_iv (GL_FUNC_REVERSE_SUBTRACT), # undef const_iv }; - for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) - newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); + for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) + newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); texture_av = newAV (); AvREAL_off (texture_av); @@ -2942,28 +3190,35 @@ gl.BlendFuncSeparate = 0; gl.BlendFuncSeparateEXT = 0; -char * +void +apple_nvidia_bug (int enable) + +const char * gl_vendor () CODE: - RETVAL = (char *)glGetString (GL_VENDOR); + RETVAL = (const char *)glGetString (GL_VENDOR); OUTPUT: RETVAL -char * +const char * gl_version () CODE: - RETVAL = (char *)glGetString (GL_VERSION); + RETVAL = (const char *)glGetString (GL_VERSION); OUTPUT: RETVAL -char * +const char * gl_extensions () CODE: - RETVAL = (char *)glGetString (GL_EXTENSIONS); + RETVAL = (const char *)glGetString (GL_EXTENSIONS); OUTPUT: RETVAL const char *glGetString (GLenum pname) + CODE: + RETVAL = (const char *)glGetString (pname); + OUTPUT: + RETVAL GLint glGetInteger (GLenum pname) CODE: @@ -2981,6 +3236,8 @@ void glFinish () +void glFlush () + void glClear (int mask) void glClearColor (float r, float g, float b, float a = 1.0) @@ -3000,6 +3257,8 @@ CODE: gl_BlendFuncSeparate (sa, da, saa, daa); +# void glBlendEquation (int se) + void glDepthMask (int flag) void glLogicOp (int opcode) @@ -3159,6 +3418,11 @@ void glCallList (int list) +void c_init () + CODE: + glPixelStorei (GL_PACK_ALIGNMENT , 1); + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + MODULE = Deliantra::Client PACKAGE = DC::UI::Base PROTOTYPES: DISABLE @@ -3167,7 +3431,7 @@ find_widget (SV *self, NV x, NV y) PPCODE: { - if (within_widget (self, x, y)) + if (within_widget (self, x, y)) XPUSHs (self); } @@ -3185,8 +3449,8 @@ draw (SV *self) CODE: { - HV *hv; - SV **svp; + HV *hv; + SV **svp; NV x, y, w, h; SV *draw_x_sv = GvSV (draw_x_gv); SV *draw_y_sv = GvSV (draw_y_gv);