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.156 by root, Thu Sep 21 14:47:51 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 uint32_t player;
175 mapface face[3]; 175 mapface face[3];
176 uint16_t darkness;
177 uint8_t stat_width, stat_hp, flags;
176} mapcell; 178} mapcell;
177 179
178typedef struct { 180typedef struct {
179 int32_t c0, c1; 181 int32_t c0, c1;
180 mapcell *col; 182 mapcell *col;
293static void 295static void
294map_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)
295{ 297{
296 int x, y; 298 int x, y;
297 maprow *row; 299 maprow *row;
300 mapcell *cell;
298 301
299 for (y = y0; y < y0 + h; y++) 302 for (y = y0; y < y0 + h; y++)
300 if (y >= 0) 303 if (y >= 0)
301 { 304 {
302 if (y >= self->rows) 305 if (y >= self->rows)
308 if (x >= row->c0) 311 if (x >= row->c0)
309 { 312 {
310 if (x >= row->c1) 313 if (x >= row->c1)
311 break; 314 break;
312 315
313 row->col[x - row->c0].darkness = -1; 316 cell = row->col + x - row->c0;
317
318 cell->darkness = 0;
319 cell->stat_hp = 0;
320 cell->flags = 0;
321 cell->player = 0;
314 } 322 }
315 } 323 }
316} 324}
317 325
318static void 326static void
1238void 1246void
1239scroll (CFPlus::Map self, int dx, int dy) 1247scroll (CFPlus::Map self, int dx, int dy)
1240 CODE: 1248 CODE:
1241{ 1249{
1242 if (dx > 0) 1250 if (dx > 0)
1243 map_blank (self, self->x, self->y, dx - 1, self->h); 1251 map_blank (self, self->x, self->y, dx, self->h);
1244 else if (dx < 0) 1252 else if (dx < 0)
1245 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1253 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1246 1254
1247 if (dy > 0) 1255 if (dy > 0)
1248 map_blank (self, self->x, self->y, self->w, dy - 1); 1256 map_blank (self, self->x, self->y, self->w, dy);
1249 else if (dy < 0) 1257 else if (dy < 0)
1250 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1258 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1251 1259
1252 self->ox += dx; self->x += dx; 1260 self->ox += dx; self->x += dx;
1253 self->oy += dy; self->y += dy; 1261 self->oy += dy; self->y += dy;
1254 1262
1255 while (self->y < 0) 1263 while (self->y < 0)
1268 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1276 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1269 uint8_t *data_end = (uint8_t *)SvEND (data_); 1277 uint8_t *data_end = (uint8_t *)SvEND (data_);
1270 mapcell *cell; 1278 mapcell *cell;
1271 int x, y, flags; 1279 int x, y, flags;
1272 1280
1273 while (data < data_end) 1281 while (data < data_end - 1)
1274 { 1282 {
1275 flags = (data [0] << 8) + data [1]; data += 2; 1283 flags = (data [0] << 8) + data [1]; data += 2;
1276 1284
1277 x = self->x + ((flags >> 10) & 63); 1285 x = self->x + ((flags >> 10) & 63);
1278 y = self->y + ((flags >> 4) & 63); 1286 y = self->y + ((flags >> 4) & 63);
1279 1287
1280 cell = map_get_cell (self, x, y); 1288 cell = map_get_cell (self, x, y);
1281 1289
1282 if (flags & 15) 1290 if (flags & 15)
1283 { 1291 {
1284 if (cell->darkness < 0) 1292 if (!cell->darkness)
1285 { 1293 {
1294 memset (cell, 0, sizeof (*cell));
1286 cell->darkness = 0; 1295 cell->darkness = 256;
1287 cell->face [0] = 0;
1288 cell->face [1] = 0;
1289 cell->face [2] = 0;
1290 } 1296 }
1297
1298 //TODO: don't trust server data to be in-range(!)
1291 1299
1292 if (flags & 8) 1300 if (flags & 8)
1293 { 1301 {
1294 fprintf (stderr, "oi\n");//D
1295 if (extmap) 1302 if (extmap)
1296 { 1303 {
1297 uint8_t ext, cmd; 1304 uint8_t ext, cmd;
1298 1305
1299 do 1306 do
1300 { 1307 {
1301
1302 ext = *data++; 1308 ext = *data++;
1303 cmd = ext & 0x7f; 1309 cmd = ext & 0x3f;
1304 1310
1305 fprintf (stderr, "extcmd = %x\n", ext);//D
1306
1307 if (ext < 4) 1311 if (cmd < 4)
1308 cell->darkness = 255 - ext * 64; 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++;
1309 } 1333 }
1310 while (cmd & 0x80); 1334 while (ext & 0x80);
1311 } 1335 }
1312 else 1336 else
1313 cell->darkness = flags & 8 ? *data++ : 255; 1337 cell->darkness = *data++ + 1;
1314 } 1338 }
1315
1316 //TODO: don't trust server data to be in-range(!)
1317 1339
1318 if (flags & 4) 1340 if (flags & 4)
1319 { 1341 {
1320 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;
1321 } 1343 }
1329 { 1351 {
1330 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;
1331 } 1353 }
1332 } 1354 }
1333 else 1355 else
1334 cell->darkness = -1; 1356 cell->darkness = 0;
1335 } 1357 }
1336} 1358}
1337 1359
1338SV * 1360SV *
1339mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1361mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1439 { 1461 {
1440 mapcell *cell = row->col + (x + vx - row->c0); 1462 mapcell *cell = row->col + (x + vx - row->c0);
1441 1463
1442 face = cell->face [z]; 1464 face = cell->face [z];
1443 1465
1444 if (face) 1466 if (face && face < self->texs)
1445 { 1467 {
1446 maptex tex = self->tex [face]; 1468 maptex tex = self->tex [face];
1447
1448 int px = (x + 1) * 32 - tex.w; 1469 int px = (x + 1) * 32 - tex.w;
1449 int py = (y + 1) * 32 - tex.h; 1470 int py = (y + 1) * 32 - tex.h;
1450 1471
1451 if (last_name != tex.name) 1472 if (last_name != tex.name)
1452 { 1473 {
1453 glEnd (); 1474 glEnd ();
1454 last_name = tex.name;
1455 glBindTexture (GL_TEXTURE_2D, last_name); 1475 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1456 glBegin (GL_QUADS); 1476 glBegin (GL_QUADS);
1457 } 1477 }
1458 1478
1459 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1479 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1460 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1480 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1461 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1481 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1462 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1482 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1463 } 1483 }
1484
1485 if (cell->flags && z == 2)
1486 {
1487 if (cell->flags & 1)
1488 {
1489 maptex tex = self->tex [1];
1490 int px = (x + 1) * 32 - tex.w + 2;
1491 int py = (y + 1) * 32 - tex.h - 6;
1492
1493 glEnd ();
1494 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1495 glBegin (GL_QUADS);
1496
1497 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1498 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1499 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1500 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1501 }
1502 }
1464 } 1503 }
1465 } 1504 }
1466 1505
1467 glEnd (); 1506 glEnd ();
1468 1507
1469 glDisable (GL_TEXTURE_2D); 1508 glDisable (GL_TEXTURE_2D);
1470 glDisable (GL_BLEND); 1509 glDisable (GL_BLEND);
1510
1511 // top layer: overlays such as the health bar
1512 for (y = 0; y < sh; y++)
1513 if (0 <= y + vy && y + vy < self->rows)
1514 {
1515 maprow *row = self->row + (y + vy);
1516
1517 for (x = 0; x < sw; x++)
1518 if (row->c0 <= x + vx && x + vx < row->c1)
1519 {
1520 mapcell *cell = row->col + (x + vx - row->c0);
1521
1522 int px = x * 32;
1523 int py = y * 32;
1524
1525 if (cell->stat_hp)
1526 {
1527 int width = cell->stat_width * 32;
1528 int thick = sh / 28 + 1 + cell->stat_width;
1529
1530 glColor3ub (0, 0, 0);
1531 glRectf (px + 1, py - thick - 2,
1532 px + width - 1, py);
1533
1534 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1535 glRectf (px + 2,
1536 py - thick - 1,
1537 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1538 }
1539 }
1540 }
1471} 1541}
1472 1542
1473void 1543void
1474draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1544draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1475 CODE: 1545 CODE:
1555 for (x = 0; x < sw; x++) 1625 for (x = 0; x < sw; x++)
1556 if (row->c0 <= x + vx && x + vx < row->c1) 1626 if (row->c0 <= x + vx && x + vx < row->c1)
1557 { 1627 {
1558 mapcell *cell = row->col + (x + vx - row->c0); 1628 mapcell *cell = row->col + (x + vx - row->c0);
1559 1629
1560 darkness[y * sw4 + x] = cell->darkness < 0 1630 darkness[y * sw4 + x] = cell->darkness
1631 ? 255 - (cell->darkness - 1)
1561 ? 255 - FOW_DARKNESS 1632 : 255 - FOW_DARKNESS;
1562 : 255 - cell->darkness;
1563 } 1633 }
1564 } 1634 }
1565 1635
1566 EXTEND (SP, 3); 1636 EXTEND (SP, 3);
1567 PUSHs (sv_2mortal (newSViv (sw4))); 1637 PUSHs (sv_2mortal (newSViv (sw4)));
1682 1752
1683 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1753 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1684 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1754 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1685 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1755 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1686 1756
1687 if (cell->darkness <= 0) 1757 if (cell->darkness == 0)
1688 { 1758 {
1689 cell->darkness = -1; 1759 cell->darkness = 0;
1690 1760
1691 for (z = 0; z <= 2; z++) 1761 for (z = 0; z <= 2; z++)
1692 { 1762 {
1693 cell->face[z] = face[z]; 1763 cell->face[z] = face[z];
1694 1764

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines