--- deliantra/Deliantra-Client/Client.xs 2006/06/15 08:29:16 1.116 +++ deliantra/Deliantra-Client/Client.xs 2006/09/21 00:16:42 1.155 @@ -1,4 +1,5 @@ #ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls # include # include @@ -9,6 +10,10 @@ #include "perl.h" #include "XSUB.h" +#ifdef _WIN32 +# undef pipe +#endif + #include #include #include @@ -20,12 +25,12 @@ #include #include +#define PANGO_ENABLE_BACKEND +#define G_DISABLE_CAST_CHECKS + #include #include -#include -#include -#include #ifndef _WIN32 # include @@ -42,7 +47,7 @@ typedef signed int int32_t; #endif -#include "glext.h" +#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ #define FOW_DARKNESS 32 @@ -51,6 +56,12 @@ #define MIN_FONT_HEIGHT 10 +#if 0 +# define PARACHUTE SDL_INIT_NOPARACHUTE +#else +# define PARACHUTE 0 +#endif + static struct { #define GL_FUNC(ptr,name) ptr name; @@ -68,22 +79,45 @@ glBlendFunc (sa, da); } -typedef Mix_Chunk *CFClient__MixChunk; -typedef Mix_Music *CFClient__MixMusic; +#include "texcache.c" + +#include "pango-font.c" +#include "pango-fontmap.c" +#include "pango-render.c" + +typedef Mix_Chunk *CFPlus__MixChunk; +typedef Mix_Music *CFPlus__MixMusic; + +typedef PangoFontDescription *CFPlus__Font; + +static int +shape_attr_p (PangoLayoutRun *run) +{ + GSList *attrs = run->item->analysis.extra_attrs; + + while (attrs) + { + PangoAttribute *attr = attrs->data; + + if (attr->klass->type == PANGO_ATTR_SHAPE) + return 1; + + attrs = attrs->next; + } -typedef PangoFontDescription *CFClient__Font; + return 0; +} typedef struct cf_layout { - PangoLayout *pl; // either derived from a cairo or ft2 context - int rgba; // wether we use rgba (cairo) or grayscale (ft2) + PangoLayout *pl; float r, g, b, a; // default color for rgba mode int base_height; - CFClient__Font font; -} *CFClient__Layout; + CFPlus__Font font; +} *CFPlus__Layout; -static CFClient__Font default_font; -static PangoContext *ft2_context, *cairo_context; -static PangoFontMap *ft2_fontmap, *cairo_fontmap; +static CFPlus__Font default_font; +static PangoContext *opengl_context; +static PangoFontMap *opengl_fontmap; static void substitute_func (FcPattern *pattern, gpointer data) @@ -92,15 +126,11 @@ #ifdef FC_HINT_STYLE FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); #endif -#ifdef _WIN32 - FcPatternAddBool (pattern, FC_AUTOHINT, 1); -#else FcPatternAddBool (pattern, FC_AUTOHINT, 0); -#endif } static void -layout_update_font (CFClient__Layout self) +layout_update_font (CFPlus__Layout self) { /* use a random scale factor to account for unknown descenders, 0.8 works * reasonably well with bitstream vera @@ -114,14 +144,21 @@ } static void -layout_get_pixel_size (CFClient__Layout self, int *w, int *h) +layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) { - pango_layout_get_pixel_size (self->pl, w, h); + PangoRectangle rect; + + // get_pixel_* wrongly rounds down + pango_layout_get_extents (self->pl, 0, &rect); + + rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; + rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; - if (!*w) *w = 1; - if (!*h) *h = 1; + if (!rect.width) rect.width = 1; + if (!rect.height) rect.height = 1; - *w = (*w + 3) & ~3; + *w = rect.width; + *h = rect.height; } typedef uint16_t mapface; @@ -134,8 +171,10 @@ } maptex; typedef struct { - int16_t darkness; + uint32_t player; mapface face[3]; + uint16_t darkness; + uint8_t stat_width, stat_hp, flags; } mapcell; typedef struct { @@ -154,7 +193,7 @@ int32_t rows; maprow *row; -} *CFClient__Map; +} *CFPlus__Map; static char * prepend (char *ptr, int sze, int inc) @@ -182,7 +221,7 @@ #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) static maprow * -map_get_row (CFClient__Map self, int y) +map_get_row (CFPlus__Map self, int y) { if (0 > y) { @@ -230,13 +269,13 @@ } static mapcell * -map_get_cell (CFClient__Map self, int x, int y) +map_get_cell (CFPlus__Map self, int x, int y) { return row_get_cell (map_get_row (self, y), x); } static void -map_clear (CFClient__Map self) +map_clear (CFPlus__Map self) { int r; @@ -254,10 +293,11 @@ } static void -map_blank (CFClient__Map self, int x0, int y0, int w, int h) +map_blank (CFPlus__Map self, int x0, int y0, int w, int h) { int x, y; maprow *row; + mapcell *cell; for (y = y0; y < y0 + h; y++) if (y >= 0) @@ -273,7 +313,12 @@ if (x >= row->c1) break; - row->col[x - row->c0].darkness = -1; + cell = row->col + x - row->c0; + + cell->darkness = 0; + cell->stat_hp = 0; + cell->flags = 0; + cell->player = 0; } } } @@ -321,13 +366,13 @@ return n + 1; } -MODULE = CFClient PACKAGE = CFClient +MODULE = CFPlus PACKAGE = CFPlus PROTOTYPES: ENABLE BOOT: { - HV *stash = gv_stashpv ("CFClient", 1); + HV *stash = gv_stashpv ("CFPlus", 1); static const struct { const char *name; IV iv; @@ -438,6 +483,13 @@ newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); } +int +in_destruct () + CODE: + RETVAL = PL_main_cv == Nullcv; + OUTPUT: + RETVAL + NV floor (NV x) NV ceil (NV x) @@ -445,32 +497,14 @@ void pango_init () CODE: - // delayed, so it can pick up new fonts added by AddFontResourceEx { - { - ft2_fontmap = pango_ft2_font_map_new (); - pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); - ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); - } - { - cairo_font_options_t *fopt = cairo_font_options_create (); - cairo_fontmap = pango_cairo_font_map_get_default (); - cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); -#ifdef _WIN32 - // cairo looks like shit eaten twice on windows - cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); -#else - cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); -#endif - cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); - cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); - pango_cairo_context_set_font_options (cairo_context, fopt); - cairo_font_options_destroy (fopt); - } + opengl_fontmap = pango_opengl_font_map_new (); + pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); + opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); } int -SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) +SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) void SDL_Quit () @@ -495,6 +529,10 @@ SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); +#if SDL_VERSION_ATLEAST(1,2,10) + SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); + SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); +#endif SDL_EnableUNICODE (1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); @@ -591,7 +629,7 @@ break; } - XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); + XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); } } @@ -617,11 +655,7 @@ void add_font (char *file) CODE: - FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ -#ifdef _WIN32 - // cairo... sigh... requires win2000 - AddFontResourceEx (file, FR_PRIVATE, 0); -#endif + FcConfigAppFontAddFile (0, (const FcChar8 *)file); void load_image_inline (SV *image_) @@ -673,15 +707,15 @@ assert (surface2->pitch == surface2->w * 4); - EXTEND (SP, 5); + SDL_LockSurface (surface2); + EXTEND (SP, 6); PUSHs (sv_2mortal (newSViv (surface2->w))); PUSHs (sv_2mortal (newSViv (surface2->h))); - SDL_LockSurface (surface2); PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); - SDL_UnlockSurface (surface2); 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))); + SDL_UnlockSurface (surface2); SDL_FreeSurface (surface); SDL_FreeSurface (surface2); @@ -734,9 +768,9 @@ CODE: _exit (retval); -MODULE = CFClient PACKAGE = CFClient::Font +MODULE = CFPlus PACKAGE = CFPlus::Font -CFClient::Font +CFPlus::Font new_from_file (SV *class, char *path, int id = 0) CODE: { @@ -749,24 +783,28 @@ RETVAL void -DESTROY (CFClient::Font self) +DESTROY (CFPlus::Font self) CODE: pango_font_description_free (self); void -make_default (CFClient::Font self) +make_default (CFPlus::Font self) CODE: default_font = self; -MODULE = CFClient PACKAGE = CFClient::Layout +MODULE = CFPlus PACKAGE = CFPlus::Layout -CFClient::Layout -new (SV *class, int rgba = 0) +void +reset_glyph_cache () + CODE: + tc_clear (); + +CFPlus::Layout +new (SV *class) CODE: New (0, RETVAL, 1, struct cf_layout); - RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); - RETVAL->rgba = rgba; + RETVAL->pl = pango_layout_new (opengl_context); RETVAL->r = 1.; RETVAL->g = 1.; RETVAL->b = 1.; @@ -780,20 +818,13 @@ RETVAL void -DESTROY (CFClient::Layout self) +DESTROY (CFPlus::Layout self) CODE: g_object_unref (self->pl); Safefree (self); -int -is_rgba (CFClient::Layout self) - CODE: - RETVAL = self->rgba; - OUTPUT: - RETVAL - void -set_text (CFClient::Layout self, SV *text_) +set_text (CFPlus::Layout self, SV *text_) CODE: { STRLEN textlen; @@ -803,7 +834,7 @@ } void -set_markup (CFClient::Layout self, SV *text_) +set_markup (CFPlus::Layout self, SV *text_) CODE: { STRLEN textlen; @@ -812,8 +843,93 @@ pango_layout_set_markup (self->pl, text, textlen); } +void +set_shapes (CFPlus::Layout self, ...) + CODE: +{ + PangoAttrList *attrs = 0; + const char *text = pango_layout_get_text (self->pl); + const char *pos = text; + int arg = 4; + + while (arg < items && (pos = strstr (pos, OBJ_STR))) + { + PangoRectangle inkrect, rect; + PangoAttribute *attr; + + int x = SvIV (ST (arg - 3)); + int y = SvIV (ST (arg - 2)); + int w = SvIV (ST (arg - 1)); + int h = SvIV (ST (arg )); + + inkrect.x = 0; + inkrect.y = 0; + inkrect.width = 0; + inkrect.height = 0; + + rect.x = x * PANGO_SCALE; + rect.y = y * PANGO_SCALE; + rect.width = w * PANGO_SCALE; + rect.height = h * PANGO_SCALE; + + if (!attrs) + attrs = pango_layout_get_attributes (self->pl); + + attr = pango_attr_shape_new (&inkrect, &rect); + attr->start_index = pos - text; + attr->end_index = attr->start_index + sizeof (OBJ_STR) - 1; + pango_attr_list_insert (attrs, attr); + + arg += 4; + pos += sizeof (OBJ_STR) - 1; + } + + if (attrs) + pango_layout_set_attributes (self->pl, attrs); +} + +void +get_shapes (CFPlus::Layout self) + PPCODE: +{ + PangoLayoutIter *iter = pango_layout_get_iter (self->pl); + + do + { + PangoLayoutRun *run = pango_layout_iter_get_run (iter); + + if (run && shape_attr_p (run)) + { + PangoRectangle extents; + pango_layout_iter_get_run_extents (iter, 0, &extents); + + EXTEND (SP, 2); + PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); + PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); + } + } + while (pango_layout_iter_next_run (iter)); + + pango_layout_iter_free (iter); +} + +int +has_wrapped (CFPlus::Layout self) + CODE: +{ + int lines = 1; + const char *text = pango_layout_get_text (self->pl); + + while (*text) + lines += *text++ == '\n'; + + RETVAL = lines < pango_layout_get_line_count (self->pl); +} + OUTPUT: + RETVAL + SV * -get_text (CFClient::Layout self) +get_text (CFPlus::Layout self) CODE: RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); sv_utf8_decode (RETVAL); @@ -821,7 +937,7 @@ RETVAL void -set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) +set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) CODE: self->r = r; self->g = g; @@ -829,7 +945,7 @@ self->a = a; void -set_font (CFClient::Layout self, CFClient::Font font = 0) +set_font (CFPlus::Layout self, CFPlus::Font font = 0) CODE: if (self->font != font) { @@ -838,7 +954,7 @@ } void -set_height (CFClient::Layout self, int base_height) +set_height (CFPlus::Layout self, int base_height) CODE: if (self->base_height != base_height) { @@ -847,22 +963,22 @@ } void -set_width (CFClient::Layout self, int max_width = -1) +set_width (CFPlus::Layout self, int max_width = -1) CODE: pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); void -set_indent (CFClient::Layout self, int indent) +set_indent (CFPlus::Layout self, int indent) CODE: pango_layout_set_indent (self->pl, indent * PANGO_SCALE); void -set_spacing (CFClient::Layout self, int spacing) +set_spacing (CFPlus::Layout self, int spacing) CODE: pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); void -set_ellipsise (CFClient::Layout self, int ellipsise) +set_ellipsise (CFPlus::Layout self, int ellipsise) CODE: pango_layout_set_ellipsize (self->pl, ellipsise == 1 ? PANGO_ELLIPSIZE_START @@ -872,12 +988,12 @@ ); void -set_single_paragraph_mode (CFClient::Layout self, int spm) +set_single_paragraph_mode (CFPlus::Layout self, int spm) CODE: pango_layout_set_single_paragraph_mode (self->pl, !!spm); void -size (CFClient::Layout self) +size (CFPlus::Layout self) PPCODE: { int w, h; @@ -890,7 +1006,19 @@ } int -xy_to_index (CFClient::Layout self, int x, int y) +descent (CFPlus::Layout self) + CODE: +{ + PangoRectangle rect; + PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); + pango_layout_line_get_pixel_extents (line, 0, &rect); + RETVAL = PANGO_DESCENT (rect); +} + OUTPUT: + RETVAL + +int +xy_to_index (CFPlus::Layout self, int x, int y) CODE: { int index, trailing; @@ -901,7 +1029,7 @@ RETVAL void -cursor_pos (CFClient::Layout self, int index) +cursor_pos (CFPlus::Layout self, int index) PPCODE: { PangoRectangle strong_pos; @@ -914,97 +1042,16 @@ } void -render (CFClient::Layout self) +render (CFPlus::Layout self, float x, float y, int flags = 0) PPCODE: -{ - SV *retval; - int w, h; - - layout_get_pixel_size (self, &w, &h); - - if (self->rgba) - { - cairo_surface_t *surface; - cairo_t *cairo; - - retval = newSV (w * h * 4); - SvPOK_only (retval); - SvCUR_set (retval, w * h * 4); - - memset (SvPVX (retval), 0, w * h * 4); - - surface = cairo_image_surface_create_for_data ( - (void*)SvPVX (retval), CAIRO_FORMAT_ARGB32, w, h, w * 4); - cairo = cairo_create (surface); - cairo_set_source_rgba (cairo, self->r, self->g, self->b, self->a); - - pango_cairo_show_layout (cairo, self->pl); - - cairo_destroy (cairo); - cairo_surface_destroy (surface); - - // what a mess, and its premultiplied, too :( - { - uint32_t *p = (uint32_t *)SvPVX (retval); - uint32_t *e = p + w * h; - - while (p < e) - { - uint32_t rgba = *p; - rgba = (rgba >> 24) | (rgba << 8); -#if 0 -#ifdef _WIN32 - {//D - uint8_t r = rgba >> 24; - uint8_t g = rgba >> 16; - uint8_t b = rgba >> 8; - uint8_t a = rgba >> 0; - - rgba = (rgba & 0xffffff00) | a; - } -#endif -#endif - rgba = SDL_SwapBE32 (rgba); - *p++ = rgba; - } - } - - EXTEND (SP, 5); - PUSHs (sv_2mortal (newSViv (w))); - PUSHs (sv_2mortal (newSViv (h))); - PUSHs (sv_2mortal (retval)); - PUSHs (sv_2mortal (newSViv (GL_RGBA))); - PUSHs (sv_2mortal (newSViv (GL_RGBA))); - } - else - { - FT_Bitmap bitmap; - - retval = newSV (w * h); - SvPOK_only (retval); - SvCUR_set (retval, w * h); - - bitmap.rows = h; - bitmap.width = w; - bitmap.pitch = w; - bitmap.buffer = (unsigned char*)SvPVX (retval); - bitmap.num_grays = 256; - bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; - - memset (bitmap.buffer, 0, w * h); - - pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); - - EXTEND (SP, 5); - PUSHs (sv_2mortal (newSViv (w))); - PUSHs (sv_2mortal (newSViv (h))); - PUSHs (sv_2mortal (retval)); - PUSHs (sv_2mortal (newSViv (GL_ALPHA))); - PUSHs (sv_2mortal (newSViv (GL_ALPHA))); - } -} + pango_opengl_render_layout_subpixel ( + self->pl, + x * PANGO_SCALE, y * PANGO_SCALE, + self->r, self->g, self->b, self->a, + flags + ); -MODULE = CFClient PACKAGE = CFClient::Texture +MODULE = CFPlus PACKAGE = CFPlus::Texture void pad2pot (SV *data_, SV *w_, SV *h_) @@ -1092,9 +1139,9 @@ } } -MODULE = CFClient PACKAGE = CFClient::Map +MODULE = CFPlus PACKAGE = CFPlus::Map -CFClient::Map +CFPlus::Map new (SV *class, int map_width, int map_height) CODE: New (0, RETVAL, 1, struct map); @@ -1114,7 +1161,7 @@ RETVAL void -DESTROY (CFClient::Map self) +DESTROY (CFPlus::Map self) CODE: { map_clear (self); @@ -1124,12 +1171,12 @@ } void -clear (CFClient::Map self) +clear (CFPlus::Map self) CODE: map_clear (self); void -set_face (CFClient::Map self, int face, int texid) +set_face (CFPlus::Map self, int face, int texid) CODE: { while (self->faces <= face) @@ -1142,7 +1189,7 @@ } void -set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) +set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) CODE: { while (self->texs <= texid) @@ -1176,7 +1223,7 @@ } int -ox (CFClient::Map self) +ox (CFPlus::Map self) ALIAS: oy = 1 x = 2 @@ -1197,18 +1244,18 @@ RETVAL void -scroll (CFClient::Map self, int dx, int dy) +scroll (CFPlus::Map self, int dx, int dy) CODE: { if (dx > 0) - map_blank (self, self->x, self->y, dx - 1, self->h); + 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, 1 - dx, self->h); + map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); if (dy > 0) - map_blank (self, self->x, self->y, self->w, dy - 1); + 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, 1 - dy); + map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); self->ox += dx; self->x += dx; self->oy += dy; self->y += dy; @@ -1223,7 +1270,7 @@ } void -map1a_update (CFClient::Map self, SV *data_) +map1a_update (CFPlus::Map self, SV *data_, int extmap) CODE: { uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); @@ -1231,29 +1278,66 @@ mapcell *cell; int x, y, flags; - while (data < data_end) + while (data < data_end - 1) { flags = (data [0] << 8) + data [1]; data += 2; - x = ((flags >> 10) & 63) + self->x; - y = ((flags >> 4) & 63) + self->y; + x = self->x + ((flags >> 10) & 63); + y = self->y + ((flags >> 4) & 63); cell = map_get_cell (self, x, y); if (flags & 15) { - if (cell->darkness < 0) + if (!cell->darkness) { - cell->darkness = 0; - cell->face [0] = 0; - cell->face [1] = 0; - cell->face [2] = 0; + memset (cell, 0, sizeof (*cell)); + cell->darkness = 256; } - cell->darkness = flags & 8 ? *data++ : 255; - //TODO: don't trust server data to be in-range(!) + if (flags & 8) + { + if (extmap) + { + uint8_t ext, cmd; + + do + { + ext = *data++; + cmd = ext & 0x3f; + + 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) // monster width + { + if (*data == 4) + ; // decode player tag + + data += *data + 1; + } + else if (cmd == 8) // cell flags + cell->flags = *data++; + else if (ext & 0x40) // unknown, multibyte => skip + data += *data + 1; + else + data++; + } + while (ext & 0x80); + } + else + cell->darkness = *data++ + 1; + + } + if (flags & 4) { cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; @@ -1270,12 +1354,12 @@ } } else - cell->darkness = -1; + cell->darkness = 0; } } SV * -mapmap (CFClient::Map self, int x0, int y0, int w, int h) +mapmap (CFPlus::Map self, int x0, int y0, int w, int h) CODE: { int x1, x; @@ -1335,7 +1419,7 @@ RETVAL void -draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) +draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) CODE: { int vx, vy; @@ -1343,8 +1427,8 @@ int last_name; mapface face; - vx = self->x + (self->w - sw + 1) / 2 - shift_x; - vy = self->y + (self->h - sh + 1) / 2 - shift_y; + vx = self->x + self->w / 2 - sw / 2 - shift_x; + vy = self->y + self->h / 2 - sh / 2 - shift_y; /* int vx = self->vx = self->w >= sw @@ -1358,8 +1442,8 @@ glColor4ub (255, 255, 255, 255); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_TEXTURE_2D); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); @@ -1380,18 +1464,16 @@ face = cell->face [z]; - if (face) + if (face && face < self->texs) { maptex tex = self->tex [face]; - int px = (x + 1) * 32 - tex.w; int py = (y + 1) * 32 - tex.h; if (last_name != tex.name) { glEnd (); - last_name = tex.name; - glBindTexture (GL_TEXTURE_2D, last_name); + glBindTexture (GL_TEXTURE_2D, last_name = tex.name); glBegin (GL_QUADS); } @@ -1400,6 +1482,25 @@ glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); } + + if (cell->flags && z == 2) + { + if (cell->flags & 1) + { + maptex tex = self->tex [1]; + int px = (x + 1) * 32 - tex.w + 2; + int py = (y + 1) * 32 - tex.h - 6; + + glEnd (); + glBindTexture (GL_TEXTURE_2D, last_name = tex.name); + glBegin (GL_QUADS); + + glTexCoord2f (0 , 0 ); glVertex2f (px , py ); + glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); + glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); + glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); + } + } } } @@ -1407,10 +1508,101 @@ glDisable (GL_TEXTURE_2D); glDisable (GL_BLEND); + + // top layer: overlays such as the health bar + for (y = 0; y < sh; y++) + if (0 <= y + vy && y + vy < self->rows) + { + maprow *row = self->row + (y + vy); + + for (x = 0; x < sw; x++) + if (row->c0 <= x + vx && x + vx < row->c1) + { + mapcell *cell = row->col + (x + vx - row->c0); + + int px = x * 32; + int py = y * 32; + + if (cell->stat_hp) + { + int width = cell->stat_width * 32; + int thick = sh / 28 + 1 + cell->stat_width; + + glColor3ub (0, 0, 0); + glRectf (px + 1, py - thick - 2, + px + width - 1, py); + + glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); + glRectf (px + 2, + py - thick - 1, + px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); + } + } + } } void -fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) +draw_magicmap (CFPlus::Map self, int dx, int dy, 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 }, + }; + + int x, y; + + glEnable (GL_TEXTURE_2D); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBegin (GL_QUADS); + + for (y = 0; y < h; y++) + for (x = 0; x < w; x++) + { + unsigned char m = data [x + y * w]; + + if (m) + { + float *c = color [m & 15]; + + float tx1 = m & 0x40 ? 0.5 : 0.; + float tx2 = tx1 + 0.5; + + glColor4f (c[0], c[1], c[2], 0.75); + glTexCoord2f (tx1, 0.); glVertex2i (x , y ); + glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); + glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); + glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); + } + } + + glEnd (); + glDisable (GL_BLEND); + glDisable (GL_TEXTURE_2D); +} + +void +fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) PPCODE: { int vx, vy; @@ -1436,9 +1628,9 @@ { mapcell *cell = row->col + (x + vx - row->c0); - darkness[y * sw4 + x] = cell->darkness < 0 - ? 255 - FOW_DARKNESS - : 255 - cell->darkness; + darkness[y * sw4 + x] = cell->darkness + ? 255 - (cell->darkness - 1) + : 255 - FOW_DARKNESS; } } @@ -1449,7 +1641,7 @@ } SV * -get_rect (CFClient::Map self, int x0, int y0, int w, int h) +get_rect (CFPlus::Map self, int x0, int y0, int w, int h) CODE: { int x, y, x1, y1; @@ -1521,7 +1713,7 @@ RETVAL void -set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) +set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) PPCODE: { int x, y, z; @@ -1563,9 +1755,9 @@ if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } - if (cell->darkness <= 0) + if (cell->darkness == 0) { - cell->darkness = -1; + cell->darkness = 0; for (z = 0; z <= 2; z++) { @@ -1580,9 +1772,9 @@ } } -MODULE = CFClient PACKAGE = CFClient::MixChunk +MODULE = CFPlus PACKAGE = CFPlus::MixChunk -CFClient::MixChunk +CFPlus::MixChunk new_from_file (SV *class, char *path) CODE: RETVAL = Mix_LoadWAV (path); @@ -1590,25 +1782,25 @@ RETVAL void -DESTROY (CFClient::MixChunk self) +DESTROY (CFPlus::MixChunk self) CODE: Mix_FreeChunk (self); int -volume (CFClient::MixChunk self, int volume = -1) +volume (CFPlus::MixChunk self, int volume = -1) CODE: RETVAL = Mix_VolumeChunk (self, volume); OUTPUT: RETVAL int -play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) +play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) CODE: RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); OUTPUT: RETVAL -MODULE = CFClient PACKAGE = CFClient::MixMusic +MODULE = CFPlus PACKAGE = CFPlus::MixMusic int volume (int volume = -1) @@ -1617,7 +1809,7 @@ OUTPUT: RETVAL -CFClient::MixMusic +CFPlus::MixMusic new_from_file (SV *class, char *path) CODE: RETVAL = Mix_LoadMUS (path); @@ -1625,22 +1817,22 @@ RETVAL void -DESTROY (CFClient::MixMusic self) +DESTROY (CFPlus::MixMusic self) CODE: Mix_FreeMusic (self); int -play (CFClient::MixMusic self, int loops = -1) +play (CFPlus::MixMusic self, int loops = -1) CODE: RETVAL = Mix_PlayMusic (self, loops); OUTPUT: RETVAL -MODULE = CFClient PACKAGE = CFClient::OpenGL +MODULE = CFPlus PACKAGE = CFPlus::OpenGL BOOT: { - HV *stash = gv_stashpv ("CFClient::OpenGL", 1); + HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); static const struct { const char *name; IV iv; @@ -1657,6 +1849,8 @@ const_iv (GL_ALPHA_TEST), const_iv (GL_NORMALIZE), const_iv (GL_RESCALE_NORMAL), + const_iv (GL_FRONT), + const_iv (GL_BACK), const_iv (GL_AND), const_iv (GL_ONE), const_iv (GL_ZERO), @@ -1711,6 +1905,7 @@ const_iv (GL_CONVOLUTION_BORDER_MODE), const_iv (GL_CONSTANT_BORDER), const_iv (GL_LINES), + const_iv (GL_LINE_STRIP), const_iv (GL_LINE_LOOP), const_iv (GL_QUADS), const_iv (GL_QUAD_STRIP), @@ -1788,6 +1983,10 @@ void glLoadIdentity () +void glDrawBuffer (int buffer) + +void glReadBuffer (int buffer) + # near_ and far_ are due to microsofts buggy "c" compiler void glFrustum (double left, double right, double bottom, double top, double near_, double far_) @@ -1826,10 +2025,7 @@ b *= a; } // microsoft visual "c" rounds instead of truncating... - glColor4ub (MIN ((int)(r * 256.f), 255), - MIN ((int)(g * 256.f), 255), - MIN ((int)(b * 256.f), 255), - MIN ((int)(a * 256.f), 255)); + glColor4f (r, g, b, a); void glInterleavedArrays (int format, int stride, char *data) @@ -1916,4 +2112,3 @@ void glCallList (int list) -