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.153 by root, Tue Sep 19 22:02:38 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 uint32_t player;
168 mapface face[3]; 175 mapface face[3];
176 uint16_t darkness;
177 uint8_t stat_width, stat_hp, flags;
169} mapcell; 178} mapcell;
170 179
171typedef struct { 180typedef struct {
172 int32_t c0, c1; 181 int32_t c0, c1;
173 mapcell *col; 182 mapcell *col;
286static void 295static void
287map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 296map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
288{ 297{
289 int x, y; 298 int x, y;
290 maprow *row; 299 maprow *row;
300 mapcell *cell;
291 301
292 for (y = y0; y < y0 + h; y++) 302 for (y = y0; y < y0 + h; y++)
293 if (y >= 0) 303 if (y >= 0)
294 { 304 {
295 if (y >= self->rows) 305 if (y >= self->rows)
301 if (x >= row->c0) 311 if (x >= row->c0)
302 { 312 {
303 if (x >= row->c1) 313 if (x >= row->c1)
304 break; 314 break;
305 315
306 row->col[x - row->c0].darkness = -1; 316 cell = row->col + x - row->c0;
317
318 cell->darkness = 0;
319 cell->stat_hp = 0;
307 } 320 }
308 } 321 }
309} 322}
310 323
311static void 324static void
1253 self->y += MAP_EXTEND_Y; 1266 self->y += MAP_EXTEND_Y;
1254 } 1267 }
1255} 1268}
1256 1269
1257void 1270void
1258map1a_update (CFPlus::Map self, SV *data_) 1271map1a_update (CFPlus::Map self, SV *data_, int extmap)
1259 CODE: 1272 CODE:
1260{ 1273{
1261 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1274 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1262 uint8_t *data_end = (uint8_t *)SvEND (data_); 1275 uint8_t *data_end = (uint8_t *)SvEND (data_);
1263 mapcell *cell; 1276 mapcell *cell;
1264 int x, y, flags; 1277 int x, y, flags;
1265 1278
1266 while (data < data_end) 1279 while (data < data_end - 1)
1267 { 1280 {
1268 flags = (data [0] << 8) + data [1]; data += 2; 1281 flags = (data [0] << 8) + data [1]; data += 2;
1269 1282
1270 x = self->x + ((flags >> 10) & 63); 1283 x = self->x + ((flags >> 10) & 63);
1271 y = self->y + ((flags >> 4) & 63); 1284 y = self->y + ((flags >> 4) & 63);
1272 1285
1273 cell = map_get_cell (self, x, y); 1286 cell = map_get_cell (self, x, y);
1274 1287
1275 if (flags & 15) 1288 if (flags & 15)
1276 { 1289 {
1277 if (cell->darkness < 0) 1290 if (!cell->darkness)
1278 { 1291 {
1279 cell->darkness = 0; 1292 cell->darkness = 256;
1280 cell->face [0] = 0; 1293 cell->face [0] = 0;
1281 cell->face [1] = 0; 1294 cell->face [1] = 0;
1282 cell->face [2] = 0; 1295 cell->face [2] = 0;
1283 } 1296 }
1284 1297
1285 cell->darkness = flags & 8 ? *data++ : 255;
1286
1287 //TODO: don't trust server data to be in-range(!) 1298 //TODO: don't trust server data to be in-range(!)
1299
1300 if (flags & 8)
1301 {
1302 if (extmap)
1303 {
1304 uint8_t ext, cmd;
1305
1306 do
1307 {
1308 ext = *data++;
1309 cmd = ext & 0x3f;
1310
1311 if (cmd < 4)
1312 cell->darkness = 255 - ext * 64 + 1;
1313 else if (cmd == 5) // health
1314 {
1315 cell->stat_width = 1;
1316 cell->stat_hp = *data++;
1317 }
1318 else if (cmd == 6) // monster width
1319 cell->stat_width = *data++ + 1;
1320 else if (cmd == 0x47) // monster width
1321 {
1322 if (*data == 4)
1323 ; // decode player tag
1324
1325 data += *data + 1;
1326 }
1327 else if (cmd == 8) // cell flags
1328 cell->flags = *data++;
1329 else if (ext & 0x40) // unknown, multibyte => skip
1330 data += *data + 1;
1331 else
1332 data++;
1333 }
1334 while (ext & 0x80);
1335 }
1336 else
1337 cell->darkness = *data++ + 1;
1338 }
1288 1339
1289 if (flags & 4) 1340 if (flags & 4)
1290 { 1341 {
1291 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1342 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1292 } 1343 }
1300 { 1351 {
1301 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1352 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1302 } 1353 }
1303 } 1354 }
1304 else 1355 else
1356 {
1305 cell->darkness = -1; 1357 cell->darkness = 0;
1358 cell->stat_hp = 0;
1359 }
1306 } 1360 }
1307} 1361}
1308 1362
1309SV * 1363SV *
1310mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1364mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1410 { 1464 {
1411 mapcell *cell = row->col + (x + vx - row->c0); 1465 mapcell *cell = row->col + (x + vx - row->c0);
1412 1466
1413 face = cell->face [z]; 1467 face = cell->face [z];
1414 1468
1415 if (face) 1469 if (face && face < self->texs)
1416 { 1470 {
1417 maptex tex = self->tex [face]; 1471 maptex tex = self->tex [face];
1418
1419 int px = (x + 1) * 32 - tex.w; 1472 int px = (x + 1) * 32 - tex.w;
1420 int py = (y + 1) * 32 - tex.h; 1473 int py = (y + 1) * 32 - tex.h;
1421 1474
1422 if (last_name != tex.name) 1475 if (last_name != tex.name)
1423 { 1476 {
1424 glEnd (); 1477 glEnd ();
1425 last_name = tex.name;
1426 glBindTexture (GL_TEXTURE_2D, last_name); 1478 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1427 glBegin (GL_QUADS); 1479 glBegin (GL_QUADS);
1428 } 1480 }
1429 1481
1430 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1482 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1431 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1483 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1432 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1484 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1433 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1485 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1434 } 1486 }
1487
1488 if (cell->flags && z == 2)
1489 {
1490 if (cell->flags & 1)
1491 {
1492 maptex tex = self->tex [1];
1493 int px = (x + 1) * 32 - tex.w + 2;
1494 int py = (y + 1) * 32 - tex.h - 6;
1495
1496 glEnd ();
1497 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1498 glBegin (GL_QUADS);
1499
1500 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1501 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1502 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1503 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1504 }
1505 }
1435 } 1506 }
1436 } 1507 }
1437 1508
1438 glEnd (); 1509 glEnd ();
1439 1510
1440 glDisable (GL_TEXTURE_2D); 1511 glDisable (GL_TEXTURE_2D);
1441 glDisable (GL_BLEND); 1512 glDisable (GL_BLEND);
1513
1514 // top layer: overlays such as the health bar
1515 for (y = 0; y < sh; y++)
1516 if (0 <= y + vy && y + vy < self->rows)
1517 {
1518 maprow *row = self->row + (y + vy);
1519
1520 for (x = 0; x < sw; x++)
1521 if (row->c0 <= x + vx && x + vx < row->c1)
1522 {
1523 mapcell *cell = row->col + (x + vx - row->c0);
1524
1525 int px = x * 32;
1526 int py = y * 32;
1527
1528 if (cell->stat_hp)
1529 {
1530 int width = cell->stat_width * 32;
1531 int thick = sh / 28 + 1 + cell->stat_width;
1532
1533 glColor3ub (0, 0, 0);
1534 glRectf (px + 1, py - thick - 2,
1535 px + width - 1, py);
1536
1537 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1538 glRectf (px + 2,
1539 py - thick - 1,
1540 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1541 }
1542 }
1543 }
1442} 1544}
1443 1545
1444void 1546void
1445draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1547draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1446 CODE: 1548 CODE:
1526 for (x = 0; x < sw; x++) 1628 for (x = 0; x < sw; x++)
1527 if (row->c0 <= x + vx && x + vx < row->c1) 1629 if (row->c0 <= x + vx && x + vx < row->c1)
1528 { 1630 {
1529 mapcell *cell = row->col + (x + vx - row->c0); 1631 mapcell *cell = row->col + (x + vx - row->c0);
1530 1632
1531 darkness[y * sw4 + x] = cell->darkness < 0 1633 darkness[y * sw4 + x] = cell->darkness
1634 ? 255 - (cell->darkness - 1)
1532 ? 255 - FOW_DARKNESS 1635 : 255 - FOW_DARKNESS;
1533 : 255 - cell->darkness;
1534 } 1636 }
1535 } 1637 }
1536 1638
1537 EXTEND (SP, 3); 1639 EXTEND (SP, 3);
1538 PUSHs (sv_2mortal (newSViv (sw4))); 1640 PUSHs (sv_2mortal (newSViv (sw4)));
1653 1755
1654 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1756 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1655 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1757 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1656 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1758 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1657 1759
1658 if (cell->darkness <= 0) 1760 if (cell->darkness == 0)
1659 { 1761 {
1660 cell->darkness = -1; 1762 cell->darkness = 0;
1661 1763
1662 for (z = 0; z <= 2; z++) 1764 for (z = 0; z <= 2; z++)
1663 { 1765 {
1664 cell->face[z] = face[z]; 1766 cell->face[z] = face[z];
1665 1767
1803 const_iv (GL_SEPARABLE_2D), 1905 const_iv (GL_SEPARABLE_2D),
1804 const_iv (GL_CONVOLUTION_2D), 1906 const_iv (GL_CONVOLUTION_2D),
1805 const_iv (GL_CONVOLUTION_BORDER_MODE), 1907 const_iv (GL_CONVOLUTION_BORDER_MODE),
1806 const_iv (GL_CONSTANT_BORDER), 1908 const_iv (GL_CONSTANT_BORDER),
1807 const_iv (GL_LINES), 1909 const_iv (GL_LINES),
1910 const_iv (GL_LINE_STRIP),
1808 const_iv (GL_LINE_LOOP), 1911 const_iv (GL_LINE_LOOP),
1809 const_iv (GL_QUADS), 1912 const_iv (GL_QUADS),
1810 const_iv (GL_QUAD_STRIP), 1913 const_iv (GL_QUAD_STRIP),
1811 const_iv (GL_TRIANGLES), 1914 const_iv (GL_TRIANGLES),
1812 const_iv (GL_TRIANGLE_STRIP), 1915 const_iv (GL_TRIANGLE_STRIP),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines