ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.137 by root, Sun Aug 13 19:47:05 2006 UTC vs.
Revision 1.146 by root, Sat Aug 19 02:49:53 2006 UTC

144} 144}
145 145
146static void 146static void
147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) 147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
148{ 148{
149 PangoRectangle rect;
150
151 // get_pixel_* wrongly rounds down
149 pango_layout_get_pixel_size (self->pl, w, h); 152 pango_layout_get_extents (self->pl, 0, &rect);
150 153
151 if (!*w) *w = 1; 154 rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE;
152 if (!*h) *h = 1; 155 rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE;
153 156
154 *w = (*w + 3) & ~3; 157 if (!rect.width) rect.width = 1;
158 if (!rect.height) rect.height = 1;
159
160 *w = rect.width;
161 *h = rect.height;
155} 162}
156 163
157typedef uint16_t mapface; 164typedef uint16_t mapface;
158 165
159typedef struct { 166typedef struct {
162 float s, t; 169 float s, t;
163 uint8_t r, g, b, a; 170 uint8_t r, g, b, a;
164} maptex; 171} maptex;
165 172
166typedef struct { 173typedef struct {
167 int16_t darkness; 174 uint16_t darkness;
168 mapface face[3]; 175 mapface face[3];
176 uint8_t stat_hp;
169} mapcell; 177} mapcell;
170 178
171typedef struct { 179typedef struct {
172 int32_t c0, c1; 180 int32_t c0, c1;
173 mapcell *col; 181 mapcell *col;
286static void 294static void
287map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 295map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
288{ 296{
289 int x, y; 297 int x, y;
290 maprow *row; 298 maprow *row;
299 mapcell *cell;
291 300
292 for (y = y0; y < y0 + h; y++) 301 for (y = y0; y < y0 + h; y++)
293 if (y >= 0) 302 if (y >= 0)
294 { 303 {
295 if (y >= self->rows) 304 if (y >= self->rows)
301 if (x >= row->c0) 310 if (x >= row->c0)
302 { 311 {
303 if (x >= row->c1) 312 if (x >= row->c1)
304 break; 313 break;
305 314
306 row->col[x - row->c0].darkness = -1; 315 cell = row->col + x - row->c0;
316
317 cell->darkness = 0;
318 cell->stat_hp = 0;
307 } 319 }
308 } 320 }
309} 321}
310 322
311static void 323static void
1253 self->y += MAP_EXTEND_Y; 1265 self->y += MAP_EXTEND_Y;
1254 } 1266 }
1255} 1267}
1256 1268
1257void 1269void
1258map1a_update (CFPlus::Map self, SV *data_) 1270map1a_update (CFPlus::Map self, SV *data_, int extmap)
1259 CODE: 1271 CODE:
1260{ 1272{
1261 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1273 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1262 uint8_t *data_end = (uint8_t *)SvEND (data_); 1274 uint8_t *data_end = (uint8_t *)SvEND (data_);
1263 mapcell *cell; 1275 mapcell *cell;
1272 1284
1273 cell = map_get_cell (self, x, y); 1285 cell = map_get_cell (self, x, y);
1274 1286
1275 if (flags & 15) 1287 if (flags & 15)
1276 { 1288 {
1277 if (cell->darkness < 0) 1289 if (!cell->darkness)
1278 { 1290 {
1279 cell->darkness = 0; 1291 cell->darkness = 256;
1280 cell->face [0] = 0; 1292 cell->face [0] = 0;
1281 cell->face [1] = 0; 1293 cell->face [1] = 0;
1282 cell->face [2] = 0; 1294 cell->face [2] = 0;
1283 } 1295 }
1284 1296
1285 cell->darkness = flags & 8 ? *data++ : 255;
1286
1287 //TODO: don't trust server data to be in-range(!) 1297 //TODO: don't trust server data to be in-range(!)
1298
1299 if (flags & 8)
1300 {
1301 if (extmap)
1302 {
1303 uint8_t ext, cmd;
1304
1305 do
1306 {
1307 ext = *data++;
1308 cmd = ext & 0x3f;
1309
1310 if (ext < 4)
1311 cell->darkness = 255 - ext * 64 + 1;
1312 else if (ext == 5) // health
1313 cell->stat_hp = *data++;
1314 else if (ext & 0x40) // unknown, multibyte => skip
1315 data += *data + 1;
1316 }
1317 while (cmd & 0x80);
1318 }
1319 else
1320 cell->darkness = *data++ + 1;
1321 }
1288 1322
1289 if (flags & 4) 1323 if (flags & 4)
1290 { 1324 {
1291 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1325 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1292 } 1326 }
1300 { 1334 {
1301 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1335 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1302 } 1336 }
1303 } 1337 }
1304 else 1338 else
1339 {
1305 cell->darkness = -1; 1340 cell->darkness = 0;
1341 cell->stat_hp = 0;
1342 }
1306 } 1343 }
1307} 1344}
1308 1345
1309SV * 1346SV *
1310mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1347mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1410 { 1447 {
1411 mapcell *cell = row->col + (x + vx - row->c0); 1448 mapcell *cell = row->col + (x + vx - row->c0);
1412 1449
1413 face = cell->face [z]; 1450 face = cell->face [z];
1414 1451
1415 if (face) 1452 if (face && face < self->texs)
1416 { 1453 {
1417 maptex tex = self->tex [face]; 1454 maptex tex = self->tex [face];
1418 1455
1419 int px = (x + 1) * 32 - tex.w; 1456 int px = (x + 1) * 32 - tex.w;
1420 int py = (y + 1) * 32 - tex.h; 1457 int py = (y + 1) * 32 - tex.h;
1437 1474
1438 glEnd (); 1475 glEnd ();
1439 1476
1440 glDisable (GL_TEXTURE_2D); 1477 glDisable (GL_TEXTURE_2D);
1441 glDisable (GL_BLEND); 1478 glDisable (GL_BLEND);
1479
1480 // top layer: overlays such as the health bar
1481 for (y = 0; y < sh; y++)
1482 if (0 <= y + vy && y + vy < self->rows)
1483 {
1484 maprow *row = self->row + (y + vy);
1485
1486 for (x = 0; x < sw; x++)
1487 if (row->c0 <= x + vx && x + vx < row->c1)
1488 {
1489 mapcell *cell = row->col + (x + vx - row->c0);
1490
1491 int px = x * 32;
1492 int py = y * 32;
1493
1494 if (cell->stat_hp)
1495 {
1496 int width = sh / 28 + 1;
1497
1498 glColor3ub (0, 0, 0);
1499 glRectf (px + 1, py, px + 31, py + width + 2);
1500
1501 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1502 glRectf (px + 2, py + 1, px + 30 - cell->stat_hp * 28 / 255, py + width + 1);
1503 }
1504 }
1505 }
1442} 1506}
1443 1507
1444void 1508void
1445draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1509draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1446 CODE: 1510 CODE:
1526 for (x = 0; x < sw; x++) 1590 for (x = 0; x < sw; x++)
1527 if (row->c0 <= x + vx && x + vx < row->c1) 1591 if (row->c0 <= x + vx && x + vx < row->c1)
1528 { 1592 {
1529 mapcell *cell = row->col + (x + vx - row->c0); 1593 mapcell *cell = row->col + (x + vx - row->c0);
1530 1594
1531 darkness[y * sw4 + x] = cell->darkness < 0 1595 darkness[y * sw4 + x] = cell->darkness
1596 ? 255 - (cell->darkness - 1)
1532 ? 255 - FOW_DARKNESS 1597 : 255 - FOW_DARKNESS;
1533 : 255 - cell->darkness;
1534 } 1598 }
1535 } 1599 }
1536 1600
1537 EXTEND (SP, 3); 1601 EXTEND (SP, 3);
1538 PUSHs (sv_2mortal (newSViv (sw4))); 1602 PUSHs (sv_2mortal (newSViv (sw4)));
1653 1717
1654 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1718 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1655 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1719 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1656 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1720 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1657 1721
1658 if (cell->darkness <= 0) 1722 if (cell->darkness == 0)
1659 { 1723 {
1660 cell->darkness = -1; 1724 cell->darkness = 0;
1661 1725
1662 for (z = 0; z <= 2; z++) 1726 for (z = 0; z <= 2; z++)
1663 { 1727 {
1664 cell->face[z] = face[z]; 1728 cell->face[z] = face[z];
1665 1729
1803 const_iv (GL_SEPARABLE_2D), 1867 const_iv (GL_SEPARABLE_2D),
1804 const_iv (GL_CONVOLUTION_2D), 1868 const_iv (GL_CONVOLUTION_2D),
1805 const_iv (GL_CONVOLUTION_BORDER_MODE), 1869 const_iv (GL_CONVOLUTION_BORDER_MODE),
1806 const_iv (GL_CONSTANT_BORDER), 1870 const_iv (GL_CONSTANT_BORDER),
1807 const_iv (GL_LINES), 1871 const_iv (GL_LINES),
1872 const_iv (GL_LINE_STRIP),
1808 const_iv (GL_LINE_LOOP), 1873 const_iv (GL_LINE_LOOP),
1809 const_iv (GL_QUADS), 1874 const_iv (GL_QUADS),
1810 const_iv (GL_QUAD_STRIP), 1875 const_iv (GL_QUAD_STRIP),
1811 const_iv (GL_TRIANGLES), 1876 const_iv (GL_TRIANGLES),
1812 const_iv (GL_TRIANGLE_STRIP), 1877 const_iv (GL_TRIANGLE_STRIP),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines