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.141 by root, Fri Aug 18 01:01:00 2006 UTC vs.
Revision 1.152 by root, Sat Aug 19 18:18:36 2006 UTC

169 float s, t; 169 float s, t;
170 uint8_t r, g, b, a; 170 uint8_t r, g, b, a;
171} maptex; 171} maptex;
172 172
173typedef struct { 173typedef struct {
174 int16_t darkness; 174 uint16_t darkness;
175 mapface face[3]; 175 mapface face[3];
176 uint8_t stat_width, stat_hp;
176} mapcell; 177} mapcell;
177 178
178typedef struct { 179typedef struct {
179 int32_t c0, c1; 180 int32_t c0, c1;
180 mapcell *col; 181 mapcell *col;
293static void 294static void
294map_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)
295{ 296{
296 int x, y; 297 int x, y;
297 maprow *row; 298 maprow *row;
299 mapcell *cell;
298 300
299 for (y = y0; y < y0 + h; y++) 301 for (y = y0; y < y0 + h; y++)
300 if (y >= 0) 302 if (y >= 0)
301 { 303 {
302 if (y >= self->rows) 304 if (y >= self->rows)
308 if (x >= row->c0) 310 if (x >= row->c0)
309 { 311 {
310 if (x >= row->c1) 312 if (x >= row->c1)
311 break; 313 break;
312 314
313 row->col[x - row->c0].darkness = -1; 315 cell = row->col + x - row->c0;
316
317 cell->darkness = 0;
318 cell->stat_hp = 0;
314 } 319 }
315 } 320 }
316} 321}
317 322
318static void 323static void
1268 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1273 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1269 uint8_t *data_end = (uint8_t *)SvEND (data_); 1274 uint8_t *data_end = (uint8_t *)SvEND (data_);
1270 mapcell *cell; 1275 mapcell *cell;
1271 int x, y, flags; 1276 int x, y, flags;
1272 1277
1273 while (data < data_end) 1278 while (data < data_end - 1)
1274 { 1279 {
1275 flags = (data [0] << 8) + data [1]; data += 2; 1280 flags = (data [0] << 8) + data [1]; data += 2;
1276 1281
1277 x = self->x + ((flags >> 10) & 63); 1282 x = self->x + ((flags >> 10) & 63);
1278 y = self->y + ((flags >> 4) & 63); 1283 y = self->y + ((flags >> 4) & 63);
1279 1284
1280 cell = map_get_cell (self, x, y); 1285 cell = map_get_cell (self, x, y);
1281 1286
1282 if (flags & 15) 1287 if (flags & 15)
1283 { 1288 {
1284 if (cell->darkness < 0) 1289 if (!cell->darkness)
1285 { 1290 {
1286 cell->darkness = 0; 1291 cell->darkness = 256;
1287 cell->face [0] = 0; 1292 cell->face [0] = 0;
1288 cell->face [1] = 0; 1293 cell->face [1] = 0;
1289 cell->face [2] = 0; 1294 cell->face [2] = 0;
1290 } 1295 }
1291 1296
1297 //TODO: don't trust server data to be in-range(!)
1298
1292 if (flags & 8) 1299 if (flags & 8)
1293 { 1300 {
1294 fprintf (stderr, "oi\n");//D
1295 if (extmap) 1301 if (extmap)
1296 { 1302 {
1297 uint8_t ext, cmd; 1303 uint8_t ext, cmd;
1298 1304
1299 do 1305 do
1300 { 1306 {
1301
1302 ext = *data++; 1307 ext = *data++;
1303 cmd = ext & 0x7f; 1308 cmd = ext & 0x3f;
1304 1309
1305 fprintf (stderr, "extcmd = %x\n", ext);//D
1306
1307 if (ext < 4) 1310 if (cmd < 4)
1308 cell->darkness = 255 - ext * 64; 1311 cell->darkness = 255 - ext * 64 + 1;
1312 else if (cmd == 5) // health
1313 {
1314 cell->stat_width = 1;
1315 cell->stat_hp = *data++;
1316 }
1317 else if (cmd == 6) // monster width
1318 cell->stat_width = *data++ + 1;
1319 else if (ext & 0x40) // unknown, multibyte => skip
1320 data += *data + 1;
1321 else
1322 data++;
1309 } 1323 }
1310 while (cmd & 0x80); 1324 while (ext & 0x80);
1311 } 1325 }
1312 else 1326 else
1313 cell->darkness = flags & 8 ? *data++ : 255; 1327 cell->darkness = *data++ + 1;
1314 } 1328 }
1315
1316 //TODO: don't trust server data to be in-range(!)
1317 1329
1318 if (flags & 4) 1330 if (flags & 4)
1319 { 1331 {
1320 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1332 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1321 } 1333 }
1329 { 1341 {
1330 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1342 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1331 } 1343 }
1332 } 1344 }
1333 else 1345 else
1346 {
1334 cell->darkness = -1; 1347 cell->darkness = 0;
1348 cell->stat_hp = 0;
1349 }
1335 } 1350 }
1336} 1351}
1337 1352
1338SV * 1353SV *
1339mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1354mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1439 { 1454 {
1440 mapcell *cell = row->col + (x + vx - row->c0); 1455 mapcell *cell = row->col + (x + vx - row->c0);
1441 1456
1442 face = cell->face [z]; 1457 face = cell->face [z];
1443 1458
1444 if (face) 1459 if (face && face < self->texs)
1445 { 1460 {
1446 maptex tex = self->tex [face]; 1461 maptex tex = self->tex [face];
1447 1462
1448 int px = (x + 1) * 32 - tex.w; 1463 int px = (x + 1) * 32 - tex.w;
1449 int py = (y + 1) * 32 - tex.h; 1464 int py = (y + 1) * 32 - tex.h;
1466 1481
1467 glEnd (); 1482 glEnd ();
1468 1483
1469 glDisable (GL_TEXTURE_2D); 1484 glDisable (GL_TEXTURE_2D);
1470 glDisable (GL_BLEND); 1485 glDisable (GL_BLEND);
1486
1487 // top layer: overlays such as the health bar
1488 for (y = 0; y < sh; y++)
1489 if (0 <= y + vy && y + vy < self->rows)
1490 {
1491 maprow *row = self->row + (y + vy);
1492
1493 for (x = 0; x < sw; x++)
1494 if (row->c0 <= x + vx && x + vx < row->c1)
1495 {
1496 mapcell *cell = row->col + (x + vx - row->c0);
1497
1498 int px = x * 32;
1499 int py = y * 32;
1500
1501 if (cell->stat_hp)
1502 {
1503 int width = cell->stat_width * 32;
1504 int thick = sh / 28 + 1 + cell->stat_width;
1505
1506 glColor3ub (0, 0, 0);
1507 glRectf (px + 1, py - thick - 2,
1508 px + width - 1, py);
1509
1510 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1511 glRectf (px + 2,
1512 py - thick - 1,
1513 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1514 }
1515 }
1516 }
1471} 1517}
1472 1518
1473void 1519void
1474draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1520draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1475 CODE: 1521 CODE:
1555 for (x = 0; x < sw; x++) 1601 for (x = 0; x < sw; x++)
1556 if (row->c0 <= x + vx && x + vx < row->c1) 1602 if (row->c0 <= x + vx && x + vx < row->c1)
1557 { 1603 {
1558 mapcell *cell = row->col + (x + vx - row->c0); 1604 mapcell *cell = row->col + (x + vx - row->c0);
1559 1605
1560 darkness[y * sw4 + x] = cell->darkness < 0 1606 darkness[y * sw4 + x] = cell->darkness
1607 ? 255 - (cell->darkness - 1)
1561 ? 255 - FOW_DARKNESS 1608 : 255 - FOW_DARKNESS;
1562 : 255 - cell->darkness;
1563 } 1609 }
1564 } 1610 }
1565 1611
1566 EXTEND (SP, 3); 1612 EXTEND (SP, 3);
1567 PUSHs (sv_2mortal (newSViv (sw4))); 1613 PUSHs (sv_2mortal (newSViv (sw4)));
1682 1728
1683 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1729 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1684 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1730 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1685 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1731 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1686 1732
1687 if (cell->darkness <= 0) 1733 if (cell->darkness == 0)
1688 { 1734 {
1689 cell->darkness = -1; 1735 cell->darkness = 0;
1690 1736
1691 for (z = 0; z <= 2; z++) 1737 for (z = 0; z <= 2; z++)
1692 { 1738 {
1693 cell->face[z] = face[z]; 1739 cell->face[z] = face[z];
1694 1740

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines