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.140 by root, Mon Aug 14 03:41:25 2006 UTC vs.
Revision 1.154 by root, Tue Sep 19 22:23:30 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)
1260 self->y += MAP_EXTEND_Y; 1268 self->y += MAP_EXTEND_Y;
1261 } 1269 }
1262} 1270}
1263 1271
1264void 1272void
1265map1a_update (CFPlus::Map self, SV *data_) 1273map1a_update (CFPlus::Map self, SV *data_, int extmap)
1266 CODE: 1274 CODE:
1267{ 1275{
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 }
1291 1297
1292 cell->darkness = flags & 8 ? *data++ : 255;
1293
1294 //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
1339 }
1295 1340
1296 if (flags & 4) 1341 if (flags & 4)
1297 { 1342 {
1298 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1343 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1299 } 1344 }
1307 { 1352 {
1308 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1353 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1309 } 1354 }
1310 } 1355 }
1311 else 1356 else
1357 {
1312 cell->darkness = -1; 1358 cell->darkness = 0;
1359 cell->stat_hp = 0;
1360 cell->flags = 0;
1361 cell->player = 0;
1362 }
1313 } 1363 }
1314} 1364}
1315 1365
1316SV * 1366SV *
1317mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1367mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1417 { 1467 {
1418 mapcell *cell = row->col + (x + vx - row->c0); 1468 mapcell *cell = row->col + (x + vx - row->c0);
1419 1469
1420 face = cell->face [z]; 1470 face = cell->face [z];
1421 1471
1422 if (face) 1472 if (face && face < self->texs)
1423 { 1473 {
1424 maptex tex = self->tex [face]; 1474 maptex tex = self->tex [face];
1425
1426 int px = (x + 1) * 32 - tex.w; 1475 int px = (x + 1) * 32 - tex.w;
1427 int py = (y + 1) * 32 - tex.h; 1476 int py = (y + 1) * 32 - tex.h;
1428 1477
1429 if (last_name != tex.name) 1478 if (last_name != tex.name)
1430 { 1479 {
1431 glEnd (); 1480 glEnd ();
1432 last_name = tex.name;
1433 glBindTexture (GL_TEXTURE_2D, last_name); 1481 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1434 glBegin (GL_QUADS); 1482 glBegin (GL_QUADS);
1435 } 1483 }
1436 1484
1437 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1485 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1438 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1486 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1439 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1487 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1440 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1488 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1441 } 1489 }
1490
1491 if (cell->flags && z == 2)
1492 {
1493 if (cell->flags & 1)
1494 {
1495 maptex tex = self->tex [1];
1496 int px = (x + 1) * 32 - tex.w + 2;
1497 int py = (y + 1) * 32 - tex.h - 6;
1498
1499 glEnd ();
1500 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1501 glBegin (GL_QUADS);
1502
1503 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1504 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1505 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1506 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1507 }
1508 }
1442 } 1509 }
1443 } 1510 }
1444 1511
1445 glEnd (); 1512 glEnd ();
1446 1513
1447 glDisable (GL_TEXTURE_2D); 1514 glDisable (GL_TEXTURE_2D);
1448 glDisable (GL_BLEND); 1515 glDisable (GL_BLEND);
1516
1517 // top layer: overlays such as the health bar
1518 for (y = 0; y < sh; y++)
1519 if (0 <= y + vy && y + vy < self->rows)
1520 {
1521 maprow *row = self->row + (y + vy);
1522
1523 for (x = 0; x < sw; x++)
1524 if (row->c0 <= x + vx && x + vx < row->c1)
1525 {
1526 mapcell *cell = row->col + (x + vx - row->c0);
1527
1528 int px = x * 32;
1529 int py = y * 32;
1530
1531 if (cell->stat_hp)
1532 {
1533 int width = cell->stat_width * 32;
1534 int thick = sh / 28 + 1 + cell->stat_width;
1535
1536 glColor3ub (0, 0, 0);
1537 glRectf (px + 1, py - thick - 2,
1538 px + width - 1, py);
1539
1540 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1541 glRectf (px + 2,
1542 py - thick - 1,
1543 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1544 }
1545 }
1546 }
1449} 1547}
1450 1548
1451void 1549void
1452draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1550draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1453 CODE: 1551 CODE:
1533 for (x = 0; x < sw; x++) 1631 for (x = 0; x < sw; x++)
1534 if (row->c0 <= x + vx && x + vx < row->c1) 1632 if (row->c0 <= x + vx && x + vx < row->c1)
1535 { 1633 {
1536 mapcell *cell = row->col + (x + vx - row->c0); 1634 mapcell *cell = row->col + (x + vx - row->c0);
1537 1635
1538 darkness[y * sw4 + x] = cell->darkness < 0 1636 darkness[y * sw4 + x] = cell->darkness
1637 ? 255 - (cell->darkness - 1)
1539 ? 255 - FOW_DARKNESS 1638 : 255 - FOW_DARKNESS;
1540 : 255 - cell->darkness;
1541 } 1639 }
1542 } 1640 }
1543 1641
1544 EXTEND (SP, 3); 1642 EXTEND (SP, 3);
1545 PUSHs (sv_2mortal (newSViv (sw4))); 1643 PUSHs (sv_2mortal (newSViv (sw4)));
1660 1758
1661 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1759 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1662 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1760 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1663 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1761 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1664 1762
1665 if (cell->darkness <= 0) 1763 if (cell->darkness == 0)
1666 { 1764 {
1667 cell->darkness = -1; 1765 cell->darkness = 0;
1668 1766
1669 for (z = 0; z <= 2; z++) 1767 for (z = 0; z <= 2; z++)
1670 { 1768 {
1671 cell->face[z] = face[z]; 1769 cell->face[z] = face[z];
1672 1770

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines