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.142 by root, Fri Aug 18 01:27:15 2006 UTC vs.
Revision 1.159 by root, Sun Oct 8 21:22:29 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 {
175 uint32_t player;
176 mapface face[3];
174 uint16_t darkness; 177 uint16_t darkness;
175 mapface face[3]; 178 uint8_t stat_width, stat_hp, flags;
176 uint8_t stat_hp;
177} mapcell; 179} mapcell;
178 180
179typedef struct { 181typedef struct {
180 int32_t c0, c1; 182 int32_t c0, c1;
181 mapcell *col; 183 mapcell *col;
294static void 296static void
295map_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)
296{ 298{
297 int x, y; 299 int x, y;
298 maprow *row; 300 maprow *row;
301 mapcell *cell;
299 302
300 for (y = y0; y < y0 + h; y++) 303 for (y = y0; y < y0 + h; y++)
301 if (y >= 0) 304 if (y >= 0)
302 { 305 {
303 if (y >= self->rows) 306 if (y >= self->rows)
309 if (x >= row->c0) 312 if (x >= row->c0)
310 { 313 {
311 if (x >= row->c1) 314 if (x >= row->c1)
312 break; 315 break;
313 316
314 row->col[x - row->c0].darkness = 0; 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;
315 } 323 }
316 } 324 }
317} 325}
318 326
319static void 327static void
644#ifndef _WIN32 652#ifndef _WIN32
645 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 653 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
646#endif 654#endif
647 655
648void 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
649add_font (char *file) 686add_font (char *file)
650 CODE: 687 CODE:
651 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 688 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
652 689
653void 690void
755 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 792 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
756#endif 793#endif
757 _exit (1); 794 _exit (1);
758 795
759void 796void
760_exit (int retval) 797_exit (int retval = 0)
761 CODE: 798 CODE:
762 _exit (retval); 799 _exit (retval);
763 800
764MODULE = CFPlus PACKAGE = CFPlus::Font 801MODULE = CFPlus PACKAGE = CFPlus::Font
765 802
1239void 1276void
1240scroll (CFPlus::Map self, int dx, int dy) 1277scroll (CFPlus::Map self, int dx, int dy)
1241 CODE: 1278 CODE:
1242{ 1279{
1243 if (dx > 0) 1280 if (dx > 0)
1244 map_blank (self, self->x, self->y, dx - 1, self->h); 1281 map_blank (self, self->x, self->y, dx, self->h);
1245 else if (dx < 0) 1282 else if (dx < 0)
1246 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1283 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1247 1284
1248 if (dy > 0) 1285 if (dy > 0)
1249 map_blank (self, self->x, self->y, self->w, dy - 1); 1286 map_blank (self, self->x, self->y, self->w, dy);
1250 else if (dy < 0) 1287 else if (dy < 0)
1251 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1288 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1252 1289
1253 self->ox += dx; self->x += dx; 1290 self->ox += dx; self->x += dx;
1254 self->oy += dy; self->y += dy; 1291 self->oy += dy; self->y += dy;
1255 1292
1256 while (self->y < 0) 1293 while (self->y < 0)
1269 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1306 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1270 uint8_t *data_end = (uint8_t *)SvEND (data_); 1307 uint8_t *data_end = (uint8_t *)SvEND (data_);
1271 mapcell *cell; 1308 mapcell *cell;
1272 int x, y, flags; 1309 int x, y, flags;
1273 1310
1274 while (data < data_end) 1311 while (data < data_end - 1)
1275 { 1312 {
1276 flags = (data [0] << 8) + data [1]; data += 2; 1313 flags = (data [0] << 8) + data [1]; data += 2;
1277 1314
1278 x = self->x + ((flags >> 10) & 63); 1315 x = self->x + ((flags >> 10) & 63);
1279 y = self->y + ((flags >> 4) & 63); 1316 y = self->y + ((flags >> 4) & 63);
1282 1319
1283 if (flags & 15) 1320 if (flags & 15)
1284 { 1321 {
1285 if (!cell->darkness) 1322 if (!cell->darkness)
1286 { 1323 {
1324 memset (cell, 0, sizeof (*cell));
1287 cell->darkness = 256; 1325 cell->darkness = 256;
1288 cell->face [0] = 0;
1289 cell->face [1] = 0;
1290 cell->face [2] = 0;
1291 } 1326 }
1292 1327
1293 //TODO: don't trust server data to be in-range(!) 1328 //TODO: don't trust server data to be in-range(!)
1294 1329
1295 if (flags & 8) 1330 if (flags & 8)
1299 uint8_t ext, cmd; 1334 uint8_t ext, cmd;
1300 1335
1301 do 1336 do
1302 { 1337 {
1303 ext = *data++; 1338 ext = *data++;
1304 cmd = ext & 0x7f; 1339 cmd = ext & 0x3f;
1305 1340
1306 if (ext < 4) 1341 if (cmd < 4)
1307 cell->darkness = 255 - ext * 64 + 1; 1342 cell->darkness = 255 - ext * 64 + 1;
1308 else if (ext == 5) // health 1343 else if (cmd == 5) // health
1344 {
1345 cell->stat_width = 1;
1309 cell->stat_hp = *data++; 1346 cell->stat_hp = *data++;
1347 }
1348 else if (cmd == 6) // monster width
1349 cell->stat_width = *data++ + 1;
1350 else if (cmd == 0x47) // monster width
1351 {
1352 if (*data == 4)
1353 ; // decode player tag
1354
1355 data += *data + 1;
1356 }
1357 else if (cmd == 8) // cell flags
1358 cell->flags = *data++;
1359 else if (ext & 0x40) // unknown, multibyte => skip
1360 data += *data + 1;
1361 else
1362 data++;
1310 } 1363 }
1311 while (cmd & 0x80); 1364 while (ext & 0x80);
1312 } 1365 }
1313 else 1366 else
1314 cell->darkness = *data++ + 1; 1367 cell->darkness = *data++ + 1;
1315 } 1368 }
1316 1369
1438 { 1491 {
1439 mapcell *cell = row->col + (x + vx - row->c0); 1492 mapcell *cell = row->col + (x + vx - row->c0);
1440 1493
1441 face = cell->face [z]; 1494 face = cell->face [z];
1442 1495
1443 if (face) 1496 if (face && face < self->texs)
1444 { 1497 {
1445 maptex tex = self->tex [face]; 1498 maptex tex = self->tex [face];
1446
1447 int px = (x + 1) * 32 - tex.w; 1499 int px = (x + 1) * 32 - tex.w;
1448 int py = (y + 1) * 32 - tex.h; 1500 int py = (y + 1) * 32 - tex.h;
1449 1501
1450 if (last_name != tex.name) 1502 if (last_name != tex.name)
1451 { 1503 {
1452 glEnd (); 1504 glEnd ();
1453 last_name = tex.name;
1454 glBindTexture (GL_TEXTURE_2D, last_name); 1505 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1455 glBegin (GL_QUADS); 1506 glBegin (GL_QUADS);
1456 } 1507 }
1457 1508
1458 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1509 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1459 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1510 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1460 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1511 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1461 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1512 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1462 } 1513 }
1514
1515 if (cell->flags && z == 2)
1516 {
1517 if (cell->flags & 1)
1518 {
1519 maptex tex = self->tex [1];
1520 int px = (x + 1) * 32 - tex.w + 2;
1521 int py = (y + 1) * 32 - tex.h - 6;
1522
1523 glEnd ();
1524 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1525 glBegin (GL_QUADS);
1526
1527 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1528 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1529 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1530 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1531 }
1532 }
1463 } 1533 }
1464 } 1534 }
1465 1535
1466 glEnd (); 1536 glEnd ();
1467 1537
1468 glDisable (GL_TEXTURE_2D); 1538 glDisable (GL_TEXTURE_2D);
1469 glDisable (GL_BLEND); 1539 glDisable (GL_BLEND);
1540
1541 // top layer: overlays such as the health bar
1542 for (y = 0; y < sh; y++)
1543 if (0 <= y + vy && y + vy < self->rows)
1544 {
1545 maprow *row = self->row + (y + vy);
1546
1547 for (x = 0; x < sw; x++)
1548 if (row->c0 <= x + vx && x + vx < row->c1)
1549 {
1550 mapcell *cell = row->col + (x + vx - row->c0);
1551
1552 int px = x * 32;
1553 int py = y * 32;
1554
1555 if (cell->stat_hp)
1556 {
1557 int width = cell->stat_width * 32;
1558 int thick = sh / 28 + 1 + cell->stat_width;
1559
1560 glColor3ub (0, 0, 0);
1561 glRectf (px + 1, py - thick - 2,
1562 px + width - 1, py);
1563
1564 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1565 glRectf (px + 2,
1566 py - thick - 1,
1567 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1568 }
1569 }
1570 }
1470} 1571}
1471 1572
1472void 1573void
1473draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1574draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1474 CODE: 1575 CODE:
1555 if (row->c0 <= x + vx && x + vx < row->c1) 1656 if (row->c0 <= x + vx && x + vx < row->c1)
1556 { 1657 {
1557 mapcell *cell = row->col + (x + vx - row->c0); 1658 mapcell *cell = row->col + (x + vx - row->c0);
1558 1659
1559 darkness[y * sw4 + x] = cell->darkness 1660 darkness[y * sw4 + x] = cell->darkness
1560 ? 255 - cell->darkness + 1 1661 ? 255 - (cell->darkness - 1)
1561 : 255 - FOW_DARKNESS; 1662 : 255 - FOW_DARKNESS;
1562 } 1663 }
1563 } 1664 }
1564 1665
1565 EXTEND (SP, 3); 1666 EXTEND (SP, 3);
1681 1782
1682 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1783 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1683 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1784 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1684 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1785 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1685 1786
1686 if (cell->darkness <= 1) 1787 if (cell->darkness == 0)
1687 { 1788 {
1688 cell->darkness = 0; 1789 cell->darkness = 0;
1689 1790
1690 for (z = 0; z <= 2; z++) 1791 for (z = 0; z <= 2; z++)
1691 { 1792 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines