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.161 by root, Mon Oct 9 23:30:44 2006 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2# define WIN32_LEAN_AND_MEAN 2# define WIN32_LEAN_AND_MEAN
3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls
4# include <malloc.h> 4# include <malloc.h>
5# include <windows.h> 5# include <windows.h>
6# include <wininet.h>
6# pragma warning(disable:4244) 7# pragma warning(disable:4244)
7#endif 8#endif
8 9
9#include "EXTERN.h" 10#include "EXTERN.h"
10#include "perl.h" 11#include "perl.h"
169 float s, t; 170 float s, t;
170 uint8_t r, g, b, a; 171 uint8_t r, g, b, a;
171} maptex; 172} maptex;
172 173
173typedef struct { 174typedef struct {
174 int16_t darkness; 175 uint32_t player;
175 mapface face[3]; 176 mapface face[3];
177 uint16_t darkness;
178 uint8_t stat_width, stat_hp, flags;
176} mapcell; 179} mapcell;
177 180
178typedef struct { 181typedef struct {
179 int32_t c0, c1; 182 int32_t c0, c1;
180 mapcell *col; 183 mapcell *col;
293static void 296static void
294map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 297map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
295{ 298{
296 int x, y; 299 int x, y;
297 maprow *row; 300 maprow *row;
301 mapcell *cell;
298 302
299 for (y = y0; y < y0 + h; y++) 303 for (y = y0; y < y0 + h; y++)
300 if (y >= 0) 304 if (y >= 0)
301 { 305 {
302 if (y >= self->rows) 306 if (y >= self->rows)
308 if (x >= row->c0) 312 if (x >= row->c0)
309 { 313 {
310 if (x >= row->c1) 314 if (x >= row->c1)
311 break; 315 break;
312 316
313 row->col[x - row->c0].darkness = -1; 317 cell = row->col + x - row->c0;
318
319 cell->darkness = 0;
320 cell->stat_hp = 0;
321 cell->flags = 0;
322 cell->player = 0;
314 } 323 }
315 } 324 }
316} 325}
317 326
318static void 327static void
643#ifndef _WIN32 652#ifndef _WIN32
644 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 653 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
645#endif 654#endif
646 655
647void 656void
657win32_proxy_info ()
658 PPCODE:
659{
660#ifdef _WIN32
661 char buffer[2048];
662 DWORD buflen;
663
664 EXTEND (SP, 3);
665
666 buflen = sizeof (buffer);
667 if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen))
668 if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
669 {
670 PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0));
671
672 buflen = sizeof (buffer);
673 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen))
674 {
675 PUSHs (newSVpv (buffer, 0));
676
677 buflen = sizeof (buffer);
678 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen))
679 PUSHs (newSVpv (buffer, 0));
680 }
681 }
682#endif
683}
684
685void
648add_font (char *file) 686add_font (char *file)
649 CODE: 687 CODE:
650 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 688 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
651 689
652void 690void
754 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 792 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
755#endif 793#endif
756 _exit (1); 794 _exit (1);
757 795
758void 796void
759_exit (int retval) 797_exit (int retval = 0)
760 CODE: 798 CODE:
799#ifdef WIN32
800 ExitThread (retval); // unclean, please beam me up
801#else
761 _exit (retval); 802 _exit (retval);
803#endif
762 804
763MODULE = CFPlus PACKAGE = CFPlus::Font 805MODULE = CFPlus PACKAGE = CFPlus::Font
764 806
765CFPlus::Font 807CFPlus::Font
766new_from_file (SV *class, char *path, int id = 0) 808new_from_file (SV *class, char *path, int id = 0)
1238void 1280void
1239scroll (CFPlus::Map self, int dx, int dy) 1281scroll (CFPlus::Map self, int dx, int dy)
1240 CODE: 1282 CODE:
1241{ 1283{
1242 if (dx > 0) 1284 if (dx > 0)
1243 map_blank (self, self->x, self->y, dx - 1, self->h); 1285 map_blank (self, self->x, self->y, dx, self->h);
1244 else if (dx < 0) 1286 else if (dx < 0)
1245 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1287 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1246 1288
1247 if (dy > 0) 1289 if (dy > 0)
1248 map_blank (self, self->x, self->y, self->w, dy - 1); 1290 map_blank (self, self->x, self->y, self->w, dy);
1249 else if (dy < 0) 1291 else if (dy < 0)
1250 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1292 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1251 1293
1252 self->ox += dx; self->x += dx; 1294 self->ox += dx; self->x += dx;
1253 self->oy += dy; self->y += dy; 1295 self->oy += dy; self->y += dy;
1254 1296
1255 while (self->y < 0) 1297 while (self->y < 0)
1268 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1310 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1269 uint8_t *data_end = (uint8_t *)SvEND (data_); 1311 uint8_t *data_end = (uint8_t *)SvEND (data_);
1270 mapcell *cell; 1312 mapcell *cell;
1271 int x, y, flags; 1313 int x, y, flags;
1272 1314
1273 while (data < data_end) 1315 while (data < data_end - 1)
1274 { 1316 {
1275 flags = (data [0] << 8) + data [1]; data += 2; 1317 flags = (data [0] << 8) + data [1]; data += 2;
1276 1318
1277 x = self->x + ((flags >> 10) & 63); 1319 x = self->x + ((flags >> 10) & 63);
1278 y = self->y + ((flags >> 4) & 63); 1320 y = self->y + ((flags >> 4) & 63);
1279 1321
1280 cell = map_get_cell (self, x, y); 1322 cell = map_get_cell (self, x, y);
1281 1323
1282 if (flags & 15) 1324 if (flags & 15)
1283 { 1325 {
1284 if (cell->darkness < 0) 1326 if (!cell->darkness)
1285 { 1327 {
1328 memset (cell, 0, sizeof (*cell));
1286 cell->darkness = 0; 1329 cell->darkness = 256;
1287 cell->face [0] = 0;
1288 cell->face [1] = 0;
1289 cell->face [2] = 0;
1290 } 1330 }
1331
1332 //TODO: don't trust server data to be in-range(!)
1291 1333
1292 if (flags & 8) 1334 if (flags & 8)
1293 { 1335 {
1294 fprintf (stderr, "oi\n");//D
1295 if (extmap) 1336 if (extmap)
1296 { 1337 {
1297 uint8_t ext, cmd; 1338 uint8_t ext, cmd;
1298 1339
1299 do 1340 do
1300 { 1341 {
1301
1302 ext = *data++; 1342 ext = *data++;
1303 cmd = ext & 0x7f; 1343 cmd = ext & 0x3f;
1304 1344
1305 fprintf (stderr, "extcmd = %x\n", ext);//D
1306
1307 if (ext < 4) 1345 if (cmd < 4)
1308 cell->darkness = 255 - ext * 64; 1346 cell->darkness = 255 - ext * 64 + 1;
1347 else if (cmd == 5) // health
1348 {
1349 cell->stat_width = 1;
1350 cell->stat_hp = *data++;
1351 }
1352 else if (cmd == 6) // monster width
1353 cell->stat_width = *data++ + 1;
1354 else if (cmd == 0x47) // monster width
1355 {
1356 if (*data == 4)
1357 ; // decode player tag
1358
1359 data += *data + 1;
1360 }
1361 else if (cmd == 8) // cell flags
1362 cell->flags = *data++;
1363 else if (ext & 0x40) // unknown, multibyte => skip
1364 data += *data + 1;
1365 else
1366 data++;
1309 } 1367 }
1310 while (cmd & 0x80); 1368 while (ext & 0x80);
1311 } 1369 }
1312 else 1370 else
1313 cell->darkness = flags & 8 ? *data++ : 255; 1371 cell->darkness = *data++ + 1;
1314 } 1372 }
1315
1316 //TODO: don't trust server data to be in-range(!)
1317 1373
1318 if (flags & 4) 1374 if (flags & 4)
1319 { 1375 {
1320 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1376 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1321 } 1377 }
1329 { 1385 {
1330 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1386 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1331 } 1387 }
1332 } 1388 }
1333 else 1389 else
1334 cell->darkness = -1; 1390 cell->darkness = 0;
1335 } 1391 }
1336} 1392}
1337 1393
1338SV * 1394SV *
1339mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1395mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1439 { 1495 {
1440 mapcell *cell = row->col + (x + vx - row->c0); 1496 mapcell *cell = row->col + (x + vx - row->c0);
1441 1497
1442 face = cell->face [z]; 1498 face = cell->face [z];
1443 1499
1444 if (face) 1500 if (face && face < self->texs)
1445 { 1501 {
1446 maptex tex = self->tex [face]; 1502 maptex tex = self->tex [face];
1447
1448 int px = (x + 1) * 32 - tex.w; 1503 int px = (x + 1) * 32 - tex.w;
1449 int py = (y + 1) * 32 - tex.h; 1504 int py = (y + 1) * 32 - tex.h;
1450 1505
1451 if (last_name != tex.name) 1506 if (last_name != tex.name)
1452 { 1507 {
1453 glEnd (); 1508 glEnd ();
1454 last_name = tex.name;
1455 glBindTexture (GL_TEXTURE_2D, last_name); 1509 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1456 glBegin (GL_QUADS); 1510 glBegin (GL_QUADS);
1457 } 1511 }
1458 1512
1459 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1513 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1460 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1514 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1461 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1515 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1462 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1516 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1463 } 1517 }
1518
1519 if (cell->flags && z == 2)
1520 {
1521 if (cell->flags & 1)
1522 {
1523 maptex tex = self->tex [1];
1524 int px = (x + 1) * 32 - tex.w + 2;
1525 int py = (y + 1) * 32 - tex.h - 6;
1526
1527 glEnd ();
1528 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1529 glBegin (GL_QUADS);
1530
1531 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1532 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1533 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1534 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1535 }
1536 }
1464 } 1537 }
1465 } 1538 }
1466 1539
1467 glEnd (); 1540 glEnd ();
1468 1541
1469 glDisable (GL_TEXTURE_2D); 1542 glDisable (GL_TEXTURE_2D);
1470 glDisable (GL_BLEND); 1543 glDisable (GL_BLEND);
1544
1545 // top layer: overlays such as the health bar
1546 for (y = 0; y < sh; y++)
1547 if (0 <= y + vy && y + vy < self->rows)
1548 {
1549 maprow *row = self->row + (y + vy);
1550
1551 for (x = 0; x < sw; x++)
1552 if (row->c0 <= x + vx && x + vx < row->c1)
1553 {
1554 mapcell *cell = row->col + (x + vx - row->c0);
1555
1556 int px = x * 32;
1557 int py = y * 32;
1558
1559 if (cell->stat_hp)
1560 {
1561 int width = cell->stat_width * 32;
1562 int thick = sh / 28 + 1 + cell->stat_width;
1563
1564 glColor3ub (0, 0, 0);
1565 glRectf (px + 1, py - thick - 2,
1566 px + width - 1, py);
1567
1568 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1569 glRectf (px + 2,
1570 py - thick - 1,
1571 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1572 }
1573 }
1574 }
1471} 1575}
1472 1576
1473void 1577void
1474draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1578draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1475 CODE: 1579 CODE:
1555 for (x = 0; x < sw; x++) 1659 for (x = 0; x < sw; x++)
1556 if (row->c0 <= x + vx && x + vx < row->c1) 1660 if (row->c0 <= x + vx && x + vx < row->c1)
1557 { 1661 {
1558 mapcell *cell = row->col + (x + vx - row->c0); 1662 mapcell *cell = row->col + (x + vx - row->c0);
1559 1663
1560 darkness[y * sw4 + x] = cell->darkness < 0 1664 darkness[y * sw4 + x] = cell->darkness
1665 ? 255 - (cell->darkness - 1)
1561 ? 255 - FOW_DARKNESS 1666 : 255 - FOW_DARKNESS;
1562 : 255 - cell->darkness;
1563 } 1667 }
1564 } 1668 }
1565 1669
1566 EXTEND (SP, 3); 1670 EXTEND (SP, 3);
1567 PUSHs (sv_2mortal (newSViv (sw4))); 1671 PUSHs (sv_2mortal (newSViv (sw4)));
1682 1786
1683 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1787 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1684 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1788 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1685 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1789 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1686 1790
1687 if (cell->darkness <= 0) 1791 if (cell->darkness == 0)
1688 { 1792 {
1689 cell->darkness = -1; 1793 cell->darkness = 0;
1690 1794
1691 for (z = 0; z <= 2; z++) 1795 for (z = 0; z <= 2; z++)
1692 { 1796 {
1693 cell->face[z] = face[z]; 1797 cell->face[z] = face[z];
1694 1798

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines