--- deliantra/Deliantra-Client/Client.xs 2006/04/11 22:49:13 1.19 +++ deliantra/Deliantra-Client/Client.xs 2006/04/13 00:25:28 1.28 @@ -3,8 +3,10 @@ #include "XSUB.h" #include +#include #include +#include #include #include @@ -16,6 +18,8 @@ #include #include +#include + static PangoContext *context; static PangoFontMap *fontmap; @@ -27,8 +31,8 @@ static void substitute_func (FcPattern *pattern, gpointer data) { - //FcPatternAddBool (pattern, FC_HINTING, 1); - //FcPatternAddBool (pattern, FC_AUTOHINT, 1); + FcPatternAddBool (pattern, FC_HINTING , 1); + FcPatternAddBool (pattern, FC_AUTOHINT, 1); } static void @@ -53,6 +57,26 @@ if (!*h) *h = 1; } +typedef struct { + uint16_t face[3]; + uint8_t darkness; + uint8_t padding; +} mapcell; + +typedef struct { + uint32_t cols; + mapcell *col; +} maprow; + +typedef struct map { + int x, y, w, h; + int faces; + GLint *face; + + uint32_t rows; + maprow *row; +} *CFClient__Map; + MODULE = CFClient PACKAGE = CFClient PROTOTYPES: ENABLE @@ -99,6 +123,71 @@ pango_context_set_font_description (context, font); } +void +load_image_inline (SV *image_) + ALIAS: + load_image_file = 1 + PPCODE: +{ + STRLEN image_len; + char *image = (char *)SvPVbyte (image_, image_len); + SDL_Surface *surface, *surface2; + SDL_PixelFormat fmt; + SDL_RWops *rw = ix + ? SDL_RWFromFile (image, "r") + : SDL_RWFromConstMem (image, image_len); + + if (!rw) + croak ("load_image: unable to open file"); + + surface = IMG_Load_RW (rw, 1); + if (!surface) + croak ("load_image: unable to read file"); + + fmt.palette = NULL; + fmt.BitsPerPixel = 32; + fmt.BytesPerPixel = 4; + fmt.Rmask = 0x000000ff; + fmt.Gmask = 0x0000ff00; + fmt.Bmask = 0x00ff0000; + fmt.Amask = 0xff000000; + fmt.Rloss = 0; + fmt.Gloss = 0; + fmt.Bloss = 0; + fmt.Aloss = 0; + fmt.Rshift = 0; + fmt.Gshift = 8; + fmt.Bshift = 16; + fmt.Ashift = 24; + fmt.colorkey = 0; + fmt.alpha = 0; + + surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); + + EXTEND (SP, 5); + 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_INT_8_8_8_8_REV))); + + SDL_FreeSurface (surface); + SDL_FreeSurface (surface2); +} + +void +fatal (char *message) + CODE: +#ifdef WIN32 + MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); +#else + fprintf (stderr, "%s\n", message); +#endif + exit (1); + MODULE = CFClient PACKAGE = CFClient::Layout CFClient::Layout @@ -236,3 +325,42 @@ glTexCoord2d (s, 0); glVertex2d (x + w, y ); glEnd (); } + +MODULE = CFClient PACKAGE = CFClient::Map + +CFClient::Map +new (SV *class, int map_width, int map_height) + CODE: + New (0, RETVAL, 1, struct map); + RETVAL->x = 0; + RETVAL->y = 0; + RETVAL->w = map_width; + RETVAL->h = map_height; + RETVAL->faces = 0; + RETVAL->face = 0; + + RETVAL->rows = 0; + RETVAL->row = 0; + OUTPUT: + RETVAL + +void +DESTROY (CFClient::Map self) + CODE: +{ + int r, c; + + Safefree (self->face); + for (r = 0; r < self->rows; r++) + { + maprow *row = self->row + r; + if (!row) + continue; + + Safefree (row->col); + } + + Safefree (self->row); + Safefree (self); +} +