--- deliantra/Deliantra-Client/Client.xs 2011/12/29 07:13:44 1.312 +++ deliantra/Deliantra-Client/Client.xs 2018/11/19 00:10:34 1.331 @@ -17,6 +17,8 @@ #include "perl.h" #include "XSUB.h" +#include "flat_hash_map.hpp" + #ifdef _WIN32 # undef pipe // microsoft vs. C @@ -25,11 +27,14 @@ # 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 @@ -50,7 +55,7 @@ #define PANGO_ENABLE_BACKEND #define G_DISABLE_CAST_CHECKS -#include +#include #include @@ -73,14 +78,7 @@ # 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" #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ @@ -108,7 +106,7 @@ STRLEN len = SvLEN (sv); STRLEN want = SvCUR (sv) + need; - if (expect_false (len < want)) + if (ecb_expect_false (len < want)) { do len *= 2; @@ -186,7 +184,7 @@ while (attrs) { - PangoAttribute *attr = attrs->data; + PangoAttribute *attr = (PangoAttribute *)attrs->data; if (attr->klass->type == PANGO_ATTR_SHAPE) return 1; @@ -197,13 +195,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; @@ -214,7 +214,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); } @@ -251,10 +251,13 @@ *h = rect.height; } +///////////////////////////////////////////////////////////////////////////// + typedef uint16_t tileid; typedef uint16_t faceid; -typedef struct { +struct maptex +{ GLuint name; int w, h; float s, t; @@ -262,21 +265,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] @@ -284,60 +289,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; @@ -346,7 +350,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; } @@ -366,13 +370,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; } @@ -380,13 +384,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; @@ -414,7 +418,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; @@ -441,20 +445,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 @@ -483,6 +506,7 @@ SDL_PushEvent ((SDL_Event *)&ev); } +// approximately divide by 255 static unsigned int div255 (unsigned int n) { @@ -506,17 +530,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 @@ -579,13 +592,17 @@ } static void -deliantra_main () +deliantra_main (SV *real_main) { - char *argv[] = { 0 }; - call_argv ("DC::Main::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, @@ -595,7 +612,7 @@ extern C_LINKAGE int main (int argc, char *argv[]) { - deliantra_main (); + deliantra_main (real_main); } #undef main @@ -603,16 +620,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 @@ -850,6 +869,10 @@ IV minpot (UV n) IV popcount (UV n) + CODE: + RETVAL = ecb_popcount32 (n); + OUTPUT: + RETVAL NV distance (NV dx, NV dy) CODE: @@ -873,7 +896,8 @@ char *SDL_GetError () -void SDL_braino () +void SDL_main_hack (SV *real_main) + PROTOTYPE: & int SDL_Init (U32 flags) @@ -884,10 +908,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 @@ -952,12 +977,9 @@ 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; } @@ -966,10 +988,14 @@ 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 () @@ -1076,7 +1102,7 @@ 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); @@ -1207,7 +1233,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))); @@ -1289,7 +1315,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; @@ -1328,9 +1354,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.; @@ -1339,7 +1365,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); @@ -1350,8 +1375,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_) @@ -1487,7 +1511,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); } @@ -1615,10 +1639,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 @@ -1639,7 +1663,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); @@ -1861,9 +1885,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; @@ -1910,7 +1934,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) @@ -1919,7 +1943,7 @@ if (smooth < 0 || smooth >= self->faces) return; - texid = self->face2tile [face]; + texid = self->face2tile [face]; if (!texid) return; @@ -1962,7 +1986,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; @@ -2019,7 +2043,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; @@ -2027,7 +2051,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_); @@ -2058,44 +2082,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; /* make sure this doesn't collide with FOW_DARKNESS */ - 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) @@ -2179,7 +2198,7 @@ } } - RETVAL = map_sv; + RETVAL = map_sv; } OUTPUT: RETVAL @@ -2190,16 +2209,13 @@ { 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_ov = 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; @@ -2207,9 +2223,6 @@ 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; @@ -2224,7 +2237,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) @@ -2249,7 +2262,9 @@ 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++) @@ -2276,13 +2291,13 @@ tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ key.texname = tex.name; - arr = rc_array (rc, &key); + arr = &rc.array (key); } px = (x + 1) * Th - tex.w; py = (y + 1) * Tw - tex.h; - if (expect_false (cell->player == player) && expect_false (z == 2)) + if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2)) { pl_x = px; pl_y = py; @@ -2290,10 +2305,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); + 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) @@ -2301,7 +2316,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. @@ -2319,47 +2334,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 (expect_false (z == 2) && expect_false (cell->flags)) + 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]; - rc_array_t *arr; + 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; - arr = rc_array (rc_ov, &key_ov); + rc_t::array_t &arr = rc_ov.array (key_ov); - rc_t2f_v3f (arr, 0 , 0 , px , py , 0); - rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); - rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); - rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); + 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 @@ -2368,78 +2382,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; - if (!(bits & 0x1000) - && skey->level == level - && level > smooth_max [skey->x][skey->y]) + 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 + Th); + glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); + glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); + } + + if (corner) { - 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 - - 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 + 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 ); - } - } + 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) @@ -2449,22 +2450,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_draw (rc_ov); - rc_clear (rc_ov); + rc_ov.draw (); + rc_ov.clear (); glDisable (GL_BLEND); - rc_free (rc); - rc_free (rc_ov); // top layer: overlays such as the health bar for (y = 0; y < sh; y++) @@ -2480,7 +2479,7 @@ 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; @@ -2718,14 +2717,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 @@ -2742,7 +2741,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) @@ -2813,7 +2812,7 @@ MODULE = Deliantra::Client PACKAGE = DC::RW DC::RW -new (SV *class, SV *data_sv) +new (SV *klass, SV *data_sv) CODE: { STRLEN datalen; @@ -2825,7 +2824,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: @@ -2944,7 +2943,7 @@ #endif DC::MixChunk -new (SV *class, DC::RW rwops) +new (SV *klass, DC::RW rwops) CODE: RETVAL = Mix_LoadWAV_RW (rwops, 1); OUTPUT: @@ -3024,7 +3023,7 @@ RETVAL DC::MixMusic -new (SV *class, DC::RW rwops) +new (SV *klass, DC::RW rwops) CODE: RETVAL = Mix_LoadMUS_RW (rwops); OUTPUT: @@ -3187,28 +3186,32 @@ void apple_nvidia_bug (int enable) -char * +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: @@ -3421,7 +3424,7 @@ find_widget (SV *self, NV x, NV y) PPCODE: { - if (within_widget (self, x, y)) + if (within_widget (self, x, y)) XPUSHs (self); } @@ -3439,8 +3442,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);