--- deliantra/Deliantra-Client/Client.xs 2007/04/04 02:43:29 1.173 +++ deliantra/Deliantra-Client/Client.xs 2007/04/06 07:45:34 1.174 @@ -157,10 +157,11 @@ *h = rect.height; } -typedef uint16_t mapface; +typedef uint16_t tileid; +typedef uint16_t faceid; typedef struct { - GLint name; + int name; int w, h; float s, t; uint8_t r, g, b, a; @@ -168,7 +169,7 @@ typedef struct { uint32_t player; - mapface face[3]; + tileid tile[3]; uint16_t darkness; uint8_t stat_width, stat_hp, flags; } mapcell; @@ -181,11 +182,8 @@ typedef struct map { int x, y, w, h; int ox, oy; /* offset to virtual global coordinate system */ - int faces; - mapface *face; - - int texs; - maptex *tex; + int faces; tileid *face2tile; // [faceid] + int texs; maptex *tex; // [tileid] int32_t rows; maprow *row; @@ -216,6 +214,26 @@ #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) +{ + while (self->faces <= face) + { + Append (tileid, self->face2tile, self->faces, self->faces); + self->faces *= 2; + } +} + +static void +need_texid (struct map *self, int texid) +{ + while (self->texs <= texid) + { + Append (maptex, self->tex, self->texs, self->texs); + self->texs *= 2; + } +} + static maprow * map_get_row (CFPlus__Map self, int y) { @@ -1242,10 +1260,8 @@ RETVAL->h = 0; RETVAL->ox = 0; RETVAL->oy = 0; - RETVAL->faces = 8192; - Newz (0, RETVAL->face, RETVAL->faces, mapface); - RETVAL->texs = 8192; - Newz (0, RETVAL->tex, RETVAL->texs, maptex); + RETVAL->faces = 8192; Newz (0, RETVAL->face2tile, RETVAL->faces, tileid); + RETVAL->texs = 8192; Newz (0, RETVAL->tex , RETVAL->texs , maptex); RETVAL->rows = 0; RETVAL->row = 0; OUTPUT: @@ -1256,7 +1272,7 @@ CODE: { map_clear (self); - Safefree (self->face); + Safefree (self->face2tile); Safefree (self->tex); Safefree (self); } @@ -1273,27 +1289,18 @@ map_clear (self); void -set_face (CFPlus::Map self, int face, int texid) +set_tileid (CFPlus::Map self, int face, int tile) CODE: { - while (self->faces <= face) - { - Append (mapface, self->face, self->faces, self->faces); - self->faces *= 2; - } - - self->face [face] = texid; + need_facenum (self, face); self->face2tile [face] = tile; + need_texid (self, tile); } void 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) - { - Append (maptex, self->tex, self->texs, self->texs); - self->texs *= 2; - } + need_texid (self, texid); { maptex *tex = self->tex + texid; @@ -1436,17 +1443,23 @@ if (flags & 4) { - cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; + faceid face = (data [0] << 8) + data [1]; data += 2; + need_facenum (self, face); + cell->tile [0] = self->face2tile [face]; } if (flags & 2) { - cell->face [1] = self->face [(data [0] << 8) + data [1]]; data += 2; + faceid face = (data [0] << 8) + data [1]; data += 2; + need_facenum (self, face); + cell->tile [1] = self->face2tile [face]; } if (flags & 1) { - cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; + faceid face = (data [0] << 8) + data [1]; data += 2; + need_facenum (self, face); + cell->tile [2] = self->face2tile [face]; } } else @@ -1486,19 +1499,14 @@ for (z = 0; z <= 0; z++) { - mapface face = cell->face [z]; - - if (face > 0 && face < self->texs) - { - maptex tex = self->tex [face]; - 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; - } + maptex tex = self->tex [cell->tile [z]]; + 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; } } @@ -1520,7 +1528,6 @@ { int x, y, z; int last_name; - mapface face; glColor4ub (255, 255, 255, 255); @@ -1546,17 +1553,19 @@ if (row->c0 <= x + mx && x + mx < row->c1) { mapcell *cell = row->col + (x + mx - row->c0); - - face = cell->face [z]; - - if (face > 0 && face < self->texs) + tileid tile = cell->tile [z]; + + if (tile) { - maptex tex = self->tex [face]; + maptex tex = self->tex [tile]; int px = (x + 1) * T - tex.w; int py = (y + 1) * T - tex.h; if (last_name != tex.name) { + if (!tex.name) + tex = self->tex [2]; /* missing, replace by noface */ + glEnd (); glBindTexture (GL_TEXTURE_2D, last_name = tex.name); glBegin (GL_QUADS); @@ -1566,24 +1575,24 @@ 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 ); - } - if (cell->flags && z == 2) - { - if (cell->flags & 1) + if (cell->flags && z == 2) { - maptex tex = self->tex [1]; - int px = (x + 1) * T - tex.w + 2; - int py = (y + 1) * T - 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 ); + if (cell->flags & 1) + { + maptex tex = self->tex [1]; + int px = x * T + T * 2 / 32; + int py = y * T - T * 6 / 32; + + 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 + T); + glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); + glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); + } } } } @@ -1611,7 +1620,7 @@ if (cell->stat_hp) { int width = cell->stat_width * T; - int thick = (sh * T / 32) / 28 + 1 + cell->stat_width; + int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; glColor3ub (0, 0, 0); glRectf (px + 1, py - thick - 2, @@ -1760,28 +1769,31 @@ mapcell *cell = row->col + (x - row->c0); uint8_t flags = 0; - if (cell->face [0]) flags |= 1; - if (cell->face [1]) flags |= 2; - if (cell->face [2]) flags |= 4; + if (cell->tile [0]) flags |= 1; + if (cell->tile [1]) flags |= 2; + if (cell->tile [2]) flags |= 4; *data++ = flags; if (flags & 1) { - *data++ = cell->face [0] >> 8; - *data++ = cell->face [0]; + tileid tile = cell->tile [0]; + *data++ = tile >> 8; + *data++ = tile; } if (flags & 2) { - *data++ = cell->face [1] >> 8; - *data++ = cell->face [1]; + tileid tile = cell->tile [1]; + *data++ = tile >> 8; + *data++ = tile; } if (flags & 4) { - *data++ = cell->face [2] >> 8; - *data++ = cell->face [2]; + tileid tile = cell->tile [2]; + *data++ = tile >> 8; + *data++ = tile; } } else @@ -1831,13 +1843,12 @@ if (flags) { - mapface face[3] = { 0, 0, 0 }; - mapcell *cell = row_get_cell (row, x); + tileid tile[3] = { 0, 0, 0 }; - if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } - if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } - if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } + if (flags & 1) { tile[0] = *data++ << 8; tile[0] |= *data++; } + if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } + if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } if (cell->darkness == 0) { @@ -1845,10 +1856,15 @@ for (z = 0; z <= 2; z++) { - cell->face[z] = face[z]; + tileid t = tile [z]; + + if (t >= self->texs || !self->tex [t].name) + { + XPUSHs (sv_2mortal (newSViv (t))); + need_texid (self, t); + } - if (face[z] && (face[z] >= self->texs || !self->tex[face [z]].name)) - XPUSHs (sv_2mortal (newSViv (face[z]))); + cell->tile [z] = t; } } }