--- deliantra/Deliantra-Client/Client.xs 2007/04/10 09:39:48 1.176 +++ deliantra/Deliantra-Client/Client.xs 2007/07/17 13:53:02 1.199 @@ -8,6 +8,11 @@ # pragma warning(disable:4761) #endif +//#define DEBUG 1 +#if DEBUG +# include +#endif + #include "EXTERN.h" #include "perl.h" #include "XSUB.h" @@ -58,6 +63,8 @@ # define PARACHUTE 0 #endif +static AV *texture_av; + static struct { #define GL_FUNC(ptr,name) ptr name; @@ -65,7 +72,8 @@ #undef GL_FUNC } gl; -static void gl_BlendFuncSeparate (GLenum sa, GLenum da, GLenum saa, GLenum daa) +static void +gl_BlendFuncSeparate (GLenum sa, GLenum da, GLenum saa, GLenum daa) { if (gl.BlendFuncSeparate) gl.BlendFuncSeparate (sa, da, saa, daa); @@ -75,6 +83,30 @@ glBlendFunc (sa, da); } +static GLuint +gen_texture () +{ + GLuint name; + + if (AvFILL (texture_av) >= 0) + name = (GLuint)(size_t)av_pop (texture_av); + else + glGenTextures (1, &name); + + return name; +} + +static void +del_texture (GLuint name) +{ + /* make a half-assed attempt at returning the memory used by the texture */ + /* textures are frequently being reused by cfplus anyway */ + /*glBindTexture (GL_TEXTURE_2D, name);*/ + /*glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0);*/ + av_push (texture_av, (SV *)(size_t)name); + glDeleteTextures (1, &name); +} + #include "texcache.c" #include "pango-font.c" @@ -347,7 +379,7 @@ static void smooth_or_bits (HV *hv, smooth_key *key, IV bits) { - SV **sv = hv_fetch (hv, (char *)key, sizeof (key), 1); + SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); if (SvIOK (*sv)) SvIV_set (*sv, SvIVX (*sv) | bits); @@ -616,10 +648,13 @@ ); if (RETVAL) { + av_clear (texture_av); + SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); # define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); # include "glfunc.h" # undef GL_FUNC + } OUTPUT: RETVAL @@ -630,13 +665,17 @@ char * SDL_GetKeyName (int sym) +int +SDL_GetAppState () + void -SDL_PollEvent () +poll_events () PPCODE: { SDL_Event ev; - while (SDL_PollEvent (&ev)) + SDL_PumpEvents (); + while (SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_ALLEVENTS) > 0) { HV *hv = newHV (); hv_store (hv, "type", 4, newSViv (ev.type), 0); @@ -658,13 +697,31 @@ break; case SDL_MOUSEMOTION: - hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); + { + int state = ev.motion.state; + int x = ev.motion.x; + int y = ev.motion.y; + int xrel = ev.motion.xrel; + int yrel = ev.motion.yrel; + + /* do simplistic event compression */ + while (SDL_PeepEvents (&ev, 1, SDL_PEEKEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)) > 0 + && state == ev.motion.state) + { + xrel += ev.motion.xrel; + yrel += ev.motion.yrel; + x = ev.motion.x; + y = ev.motion.y; + SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); + } - hv_store (hv, "state", 5, newSViv (ev.motion.state), 0); - hv_store (hv, "x", 1, newSViv (ev.motion.x), 0); - hv_store (hv, "y", 1, newSViv (ev.motion.y), 0); - hv_store (hv, "xrel", 4, newSViv (ev.motion.xrel), 0); - hv_store (hv, "yrel", 4, newSViv (ev.motion.yrel), 0); + hv_store (hv, "mod", 3, newSViv (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); + hv_store (hv, "xrel", 4, newSViv (xrel), 0); + hv_store (hv, "yrel", 4, newSViv (yrel), 0); + } break; case SDL_MOUSEBUTTONDOWN: @@ -703,9 +760,7 @@ void lowdelay (int fd, int val = 1) CODE: -#ifndef _WIN32 - setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); -#endif + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); void win32_proxy_info () @@ -856,6 +911,15 @@ _exit (retval); #endif +void +debug () + CODE: +{ +#if DEBUG + VALGRIND_DO_LEAK_CHECK; +#endif +} + MODULE = CFPlus PACKAGE = CFPlus::Font CFPlus::Font @@ -1180,6 +1244,8 @@ MODULE = CFPlus PACKAGE = CFPlus::Texture +int minpot (int n) + void pad2pot (SV *data_, SV *w_, SV *h_) CODE: @@ -1266,6 +1332,17 @@ } } +IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) + CODE: +{ + GLint width; + glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); + glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + RETVAL = width > 0; +} + OUTPUT: + RETVAL + MODULE = CFPlus PACKAGE = CFPlus::Map CFPlus::Map @@ -1395,12 +1472,12 @@ if (dx > 0) map_blank (self, self->x, self->y, dx, self->h); else if (dx < 0) - map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); + map_blank (self, self->x + self->w + dx, self->y, -dx, self->h); if (dy > 0) map_blank (self, self->x, self->y, self->w, dy); else if (dy < 0) - map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); + map_blank (self, self->x, self->y + self->h + dy, self->w, -dy); self->ox += dx; self->x += dx; self->oy += dy; self->y += dy; @@ -1464,8 +1541,8 @@ cell->stat_width = *data++ + 1; else if (cmd == 0x47) { - if (*data == 8) - ; // decode player uuid + if (*data == 4) + ; // decode player count data += *data + 1; } @@ -1569,7 +1646,7 @@ { HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level - uint8_t smooth_max[256][256]; + static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) smooth_key skey; int x, y, z; int last_name; @@ -1610,12 +1687,10 @@ { mapcell *cell = row->col + (x + mx - row->c0); - for (z = 0; z <= 2; z++) - { - uint8_t level = self->tex [cell->tile [z]].smoothlevel; - if (level > smooth_max [x + 1][y + 1]) - smooth_max [x + 1][y + 1] = level; - } + smooth_max[x + 1][y + 1] = + MAX (self->tex [cell->tile [0]].smoothlevel, + MAX (self->tex [cell->tile [1]].smoothlevel, + self->tex [cell->tile [2]].smoothlevel)); } } @@ -1687,12 +1762,24 @@ // add bits to current tile and all neighbours. skey.x|y is // shifted +1|+1 so we always stay positive. + // bits is ___n cccc CCCC bbbb + // n do not draw borders&corners + // c draw these corners, but... + // C ... not these + // b draw these borders + + // borders: 1 ┃· 2 ━━ 4 ·┃ 8 ·· + // ┃· ·· ·┃ ━━ + + // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· + // ·· ·· ·┏ ┓· + // full tile 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, 0x0031); - skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0092); + 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); @@ -1706,7 +1793,7 @@ } } - // go through all smoothlevels, lowest to highest, then draw + // go through all smoothlevels, lowest to highest, then draw. // this is basically counting sort { int w, b; @@ -1727,15 +1814,9 @@ smooth_key *skey = (smooth_key *)HeKEY (he); IV bits = SvIVX (HeVAL (he)); - // bits is ___n cccc CCCC bbbb - // n do not draw borders&corners - // c draw these corners, but... - // C ... not these - // b draw these borders - if (!(bits & 0x1000) && skey->level == level - && level >= smooth_max [skey->x][skey->y]) + && level > smooth_max [skey->x][skey->y]) { maptex tex = self->tex [skey->tile]; int px = (((int)skey->x) - 1) * T; @@ -2096,6 +2177,13 @@ OUTPUT: RETVAL +int +fade_out (int ms) + CODE: + RETVAL = Mix_FadeOutMusic (ms); + OUTPUT: + RETVAL + CFPlus::MixMusic new_from_file (SV *class, char *path) CODE: @@ -2115,6 +2203,13 @@ OUTPUT: RETVAL +int +fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) + CODE: + RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); + OUTPUT: + RETVAL + MODULE = CFPlus PACKAGE = CFPlus::OpenGL BOOT: @@ -2125,6 +2220,9 @@ IV iv; } *civ, const_iv[] = { # define const_iv(name) { # name, (IV)name } + const_iv (GL_VENDOR), + const_iv (GL_VERSION), + const_iv (GL_EXTENSIONS), const_iv (GL_COLOR_MATERIAL), const_iv (GL_SMOOTH), const_iv (GL_FLAT), @@ -2161,6 +2259,8 @@ const_iv (GL_FLOAT), const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), const_iv (GL_COMPILE), + const_iv (GL_PROXY_TEXTURE_1D), + const_iv (GL_PROXY_TEXTURE_2D), const_iv (GL_TEXTURE_1D), const_iv (GL_TEXTURE_2D), const_iv (GL_TEXTURE_ENV), @@ -2210,6 +2310,9 @@ for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); + + texture_av = newAV (); + AvREAL_off (texture_av); } char * @@ -2233,6 +2336,20 @@ OUTPUT: RETVAL +char *glGetString (GLenum pname) + +GLint glGetInteger (GLenum pname) + CODE: + glGetIntegerv (pname, &RETVAL); + OUTPUT: + RETVAL + +GLdouble glGetDouble (GLenum pname) + CODE: + glGetDoublev (pname, &RETVAL); + OUTPUT: + RETVAL + int glGetError () void glFinish () @@ -2364,25 +2481,20 @@ void glDrawPixels (int width, int height, int format, int type, char *pixels) +void glPixelZoom (float x, float y) + void glCopyPixels (int x, int y, int width, int height, int type = GL_COLOR) int glGenTexture () CODE: -{ - GLuint name; - glGenTextures (1, &name); - RETVAL = name; -} + RETVAL = gen_texture (); OUTPUT: RETVAL void glDeleteTexture (int name) CODE: -{ - GLuint name_ = name; - glDeleteTextures (1, &name_); -} - + del_texture (name); + int glGenList () CODE: RETVAL = glGenLists (1);