--- deliantra/Deliantra-Client/Client.xs 2008/08/20 17:50:47 1.274 +++ deliantra/Deliantra-Client/Client.xs 2010/10/14 00:02:39 1.306 @@ -21,7 +21,6 @@ # 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 @@ -44,6 +43,8 @@ /* 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 @@ -83,7 +84,10 @@ #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 @@ -93,6 +97,30 @@ /* mask out modifiers we are not interested in */ #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) +#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 (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 @@ -233,6 +261,7 @@ uint8_t r, g, b, a; tileid smoothtile; uint8_t smoothlevel; + uint8_t unused; /* set to zero on use */ } maptex; typedef struct { @@ -455,6 +484,12 @@ } static unsigned int +div255 (unsigned int n) +{ + return (n + (n >> 8)) >> 8; +} + +static unsigned int minpot (unsigned int n) { if (!n) @@ -529,6 +564,20 @@ return 1; } +/******************************************************************************/ + +/* process keyboard modifiers */ +static int +mod_munge (int mod) +{ + mod &= MOD_MASK; + + if (mod & (KMOD_META | KMOD_ALT)) + mod |= KMOD_LRAM; + + return mod; +} + static void deliantra_main () { @@ -605,6 +654,56 @@ const_iv (SDL_APPMOUSEFOCUS), const_iv (SDL_APPACTIVE), + + const_iv (SDLK_UNKNOWN), + const_iv (SDLK_FIRST), + const_iv (SDLK_BACKSPACE), + const_iv (SDLK_TAB), + const_iv (SDLK_CLEAR), + const_iv (SDLK_RETURN), + const_iv (SDLK_PAUSE), + const_iv (SDLK_ESCAPE), + const_iv (SDLK_SPACE), + const_iv (SDLK_EXCLAIM), + const_iv (SDLK_QUOTEDBL), + const_iv (SDLK_HASH), + const_iv (SDLK_DOLLAR), + const_iv (SDLK_AMPERSAND), + const_iv (SDLK_QUOTE), + const_iv (SDLK_LEFTPAREN), + const_iv (SDLK_RIGHTPAREN), + const_iv (SDLK_ASTERISK), + const_iv (SDLK_PLUS), + const_iv (SDLK_COMMA), + const_iv (SDLK_MINUS), + const_iv (SDLK_PERIOD), + const_iv (SDLK_SLASH), + const_iv (SDLK_0), + const_iv (SDLK_1), + const_iv (SDLK_2), + const_iv (SDLK_3), + const_iv (SDLK_4), + const_iv (SDLK_5), + const_iv (SDLK_6), + const_iv (SDLK_7), + const_iv (SDLK_8), + const_iv (SDLK_9), + const_iv (SDLK_COLON), + const_iv (SDLK_SEMICOLON), + const_iv (SDLK_LESS), + const_iv (SDLK_EQUALS), + const_iv (SDLK_GREATER), + const_iv (SDLK_QUESTION), + const_iv (SDLK_AT), + + const_iv (SDLK_LEFTBRACKET), + const_iv (SDLK_BACKSLASH), + const_iv (SDLK_RIGHTBRACKET), + const_iv (SDLK_CARET), + const_iv (SDLK_UNDERSCORE), + const_iv (SDLK_BACKQUOTE), + const_iv (SDLK_DELETE), + const_iv (SDLK_FIRST), const_iv (SDLK_LAST), const_iv (SDLK_KP0), @@ -689,6 +788,8 @@ const_iv (KMOD_CAPS), const_iv (KMOD_MODE), + const_iv (KMOD_LRAM), + const_iv (MIX_DEFAULT_FORMAT), const_iv (SDL_INIT_TIMER), @@ -750,6 +851,12 @@ IV popcount (UV n) +NV distance (NV dx, NV dy) + CODE: + RETVAL = pow (dx * dx + dy * dy, 0.5); + OUTPUT: + RETVAL + void pango_init () CODE: @@ -850,6 +957,9 @@ #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: @@ -885,8 +995,8 @@ case SDL_KEYUP: hv_store (hv, "state", 5, newSViv (ev.key.state), 0); hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); - hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); - hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ + hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0); + hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */ hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); break; @@ -914,7 +1024,7 @@ SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); } - hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); + hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0); hv_store (hv, "state", 5, newSViv (state), 0); hv_store (hv, "x", 1, newSViv (x), 0); hv_store (hv, "y", 1, newSViv (y), 0); @@ -944,6 +1054,19 @@ } } +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: @@ -1017,6 +1140,9 @@ RETVAL void +IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) + +void load_image_inline (SV *image_) ALIAS: load_image_file = 1 @@ -1140,6 +1266,13 @@ #endif } +int +SvREFCNT (SV *sv) + CODE: + RETVAL = SvREFCNT (sv); + OUTPUT: + RETVAL + MODULE = Deliantra::Client PACKAGE = DC::Font PROTOTYPES: DISABLE @@ -1580,6 +1713,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: { @@ -1694,6 +1948,26 @@ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } +void +expire_textures (DC::Map self, int texid, int count) + PPCODE: + for (; texid < self->texs && count; ++texid, --count) + { + maptex *tex = self->tex + texid; + + if (tex->name) + { + if (tex->unused) + { + tex->name = 0; + tex->unused = 0; + XPUSHs (sv_2mortal (newSViv (texid))); + } + else + tex->unused = 1; + } + } + int ox (DC::Map self) ALIAS: @@ -1783,7 +2057,7 @@ cmd = ext & 0x7f; if (cmd < 4) - cell->darkness = 255 - ext * 64 + 1; + cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ else if (cmd == 5) // health { cell->stat_width = 1; @@ -1823,12 +2097,14 @@ if (cell->tile [z]) { maptex *tex = self->tex + cell->tile [z]; + tex->unused = 0; if (!tex->name) av_push (missing, newSViv (cell->tile [z])); if (tex->smoothtile) { maptex *smooth = self->tex + tex->smoothtile; + smooth->unused = 0; if (!smooth->name) av_push (missing, newSViv (tex->smoothtile)); } @@ -1866,7 +2142,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) { @@ -1878,10 +2154,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); } } @@ -1898,7 +2174,7 @@ 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; @@ -1909,13 +2185,14 @@ smooth_key skey; int pl_x, pl_y; maptex pl_tex; - rc_t *rc = rc_alloc (); + rc_t *rc = rc_alloc (); + rc_t *rc_ov = rc_alloc (); rc_key_t key; rc_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; @@ -1929,7 +2206,6 @@ key.a = 255; key.mode = GL_QUADS; key.format = GL_T2F_V3F; - key.texname = -1; mx += self->x; my += self->y; @@ -1963,6 +2239,7 @@ for (z = 0; z <= 2; z++) { memset (smooth_level, 0, sizeof (smooth_level)); + key.texname = -1; for (y = 0; y < sh; y++) if (0 <= y + my && y + my < self->rows) @@ -1978,18 +2255,22 @@ 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); } + px = (x + 1) * Th - tex.w; + py = (y + 1) * Tw - tex.h; + if (expect_false (cell->player == player) && expect_false (z == 2)) { pl_x = px; @@ -2003,31 +2284,6 @@ 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); - } - } - } - // update smooth hash if (tex.smoothtile) { @@ -2067,6 +2323,27 @@ skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); } } + + if (expect_false (z == 2) && 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; + 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_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); + } + } } } @@ -2101,8 +2378,8 @@ && level > smooth_max [skey->x][skey->y]) { maptex tex = self->tex [skey->tile]; - int px = (((int)skey->x) - 1) * T; - int py = (((int)skey->y) - 1) * T; + 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 @@ -2114,6 +2391,8 @@ // 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); @@ -2123,20 +2402,20 @@ { 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 ); + 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 + T); - glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); - glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); + 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 ); } } } @@ -2169,8 +2448,12 @@ rc_draw (rc); } + rc_draw (rc_ov); + rc_clear (rc_ov); + glDisable (GL_BLEND); rc_free (rc); + rc_free (rc_ov); // top layer: overlays such as the health bar for (y = 0; y < sh; y++) @@ -2183,13 +2466,19 @@ { 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)) + { + px += sdx; + py += sdy; + } 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, @@ -2205,36 +2494,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); @@ -2248,10 +2543,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); @@ -2269,22 +2564,20 @@ PPCODE: { int x, y; - int sw1 = sw + 2; - int sh1 = sh + 2; - int sh3 = sh * 3; - int sw34 = (sw * 3 + 3) & ~3; + int sw1 = sw + 2; + int sh1 = sh + 2; + int sh3 = sh * 3; + int sw3 = sw * 3; uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); - SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); + SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); 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) { @@ -2296,8 +2589,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); } } @@ -2326,21 +2619,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); } @@ -2548,9 +2841,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); @@ -2607,7 +2906,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)); } @@ -2620,6 +2919,18 @@ 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) CODE: @@ -2661,6 +2972,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: ;$ @@ -2681,6 +3004,13 @@ CODE: Mix_HaltMusic (); +int +playing () + CODE: + RETVAL = Mix_PlayingMusic (); + OUTPUT: + RETVAL + DC::MixMusic new (SV *class, DC::RW rwops) CODE: @@ -2720,6 +3050,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), @@ -2741,6 +3072,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), @@ -2818,6 +3153,9 @@ 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 }; @@ -2834,6 +3172,9 @@ gl.BlendFuncSeparate = 0; gl.BlendFuncSeparateEXT = 0; +void +apple_nvidia_bug (int enable) + char * gl_vendor () CODE: @@ -2873,6 +3214,8 @@ void glFinish () +void glFlush () + void glClear (int mask) void glClearColor (float r, float g, float b, float a = 1.0) @@ -2892,6 +3235,8 @@ CODE: gl_BlendFuncSeparate (sa, da, saa, daa); +# void glBlendEquation (int se) + void glDepthMask (int flag) void glLogicOp (int opcode) @@ -2935,6 +3280,7 @@ glRotatef (angle, x, y, z); void glColor (float r, float g, float b, float a = 1.0) + PROTOTYPE: @ ALIAS: glColor_premultiply = 1 CODE: @@ -3050,6 +3396,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