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.145 by root, Fri Aug 18 03:19:58 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 {
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:
799#ifdef WIN32
800 ExitThread (retval); // unclean, please beam me up
801#else
762 _exit (retval); 802 _exit (retval);
803#endif
763 804
764MODULE = CFPlus PACKAGE = CFPlus::Font 805MODULE = CFPlus PACKAGE = CFPlus::Font
765 806
766CFPlus::Font 807CFPlus::Font
767new_from_file (SV *class, char *path, int id = 0) 808new_from_file (SV *class, char *path, int id = 0)
1239void 1280void
1240scroll (CFPlus::Map self, int dx, int dy) 1281scroll (CFPlus::Map self, int dx, int dy)
1241 CODE: 1282 CODE:
1242{ 1283{
1243 if (dx > 0) 1284 if (dx > 0)
1244 map_blank (self, self->x, self->y, dx - 1, self->h); 1285 map_blank (self, self->x, self->y, dx, self->h);
1245 else if (dx < 0) 1286 else if (dx < 0)
1246 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);
1247 1288
1248 if (dy > 0) 1289 if (dy > 0)
1249 map_blank (self, self->x, self->y, self->w, dy - 1); 1290 map_blank (self, self->x, self->y, self->w, dy);
1250 else if (dy < 0) 1291 else if (dy < 0)
1251 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);
1252 1293
1253 self->ox += dx; self->x += dx; 1294 self->ox += dx; self->x += dx;
1254 self->oy += dy; self->y += dy; 1295 self->oy += dy; self->y += dy;
1255 1296
1256 while (self->y < 0) 1297 while (self->y < 0)
1269 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1310 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1270 uint8_t *data_end = (uint8_t *)SvEND (data_); 1311 uint8_t *data_end = (uint8_t *)SvEND (data_);
1271 mapcell *cell; 1312 mapcell *cell;
1272 int x, y, flags; 1313 int x, y, flags;
1273 1314
1274 while (data < data_end) 1315 while (data < data_end - 1)
1275 { 1316 {
1276 flags = (data [0] << 8) + data [1]; data += 2; 1317 flags = (data [0] << 8) + data [1]; data += 2;
1277 1318
1278 x = self->x + ((flags >> 10) & 63); 1319 x = self->x + ((flags >> 10) & 63);
1279 y = self->y + ((flags >> 4) & 63); 1320 y = self->y + ((flags >> 4) & 63);
1282 1323
1283 if (flags & 15) 1324 if (flags & 15)
1284 { 1325 {
1285 if (!cell->darkness) 1326 if (!cell->darkness)
1286 { 1327 {
1328 memset (cell, 0, sizeof (*cell));
1287 cell->darkness = 256; 1329 cell->darkness = 256;
1288 cell->face [0] = 0;
1289 cell->face [1] = 0;
1290 cell->face [2] = 0;
1291 cell->stat_hp = 0;
1292 } 1330 }
1293 1331
1294 //TODO: don't trust server data to be in-range(!) 1332 //TODO: don't trust server data to be in-range(!)
1295 1333
1296 if (flags & 8) 1334 if (flags & 8)
1302 do 1340 do
1303 { 1341 {
1304 ext = *data++; 1342 ext = *data++;
1305 cmd = ext & 0x3f; 1343 cmd = ext & 0x3f;
1306 1344
1307 if (ext < 4) 1345 if (cmd < 4)
1308 cell->darkness = 255 - ext * 64 + 1; 1346 cell->darkness = 255 - ext * 64 + 1;
1309 else if (ext == 5) // health 1347 else if (cmd == 5) // health
1348 {
1349 cell->stat_width = 1;
1310 cell->stat_hp = *data++; 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++;
1311 else if (ext & 0x40) // unknown, multibyte => skip 1363 else if (ext & 0x40) // unknown, multibyte => skip
1312 data += *data + 1; 1364 data += *data + 1;
1365 else
1366 data++;
1313 } 1367 }
1314 while (cmd & 0x80); 1368 while (ext & 0x80);
1315 } 1369 }
1316 else 1370 else
1317 cell->darkness = *data++ + 1; 1371 cell->darkness = *data++ + 1;
1318 } 1372 }
1319 1373
1444 face = cell->face [z]; 1498 face = cell->face [z];
1445 1499
1446 if (face && face < self->texs) 1500 if (face && face < self->texs)
1447 { 1501 {
1448 maptex tex = self->tex [face]; 1502 maptex tex = self->tex [face];
1449
1450 int px = (x + 1) * 32 - tex.w; 1503 int px = (x + 1) * 32 - tex.w;
1451 int py = (y + 1) * 32 - tex.h; 1504 int py = (y + 1) * 32 - tex.h;
1452 1505
1453 if (last_name != tex.name) 1506 if (last_name != tex.name)
1454 { 1507 {
1455 glEnd (); 1508 glEnd ();
1456 last_name = tex.name;
1457 glBindTexture (GL_TEXTURE_2D, last_name); 1509 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1458 glBegin (GL_QUADS); 1510 glBegin (GL_QUADS);
1459 } 1511 }
1460 1512
1461 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1513 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1462 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1514 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1463 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);
1464 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1516 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1465 } 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 }
1466 } 1537 }
1467 } 1538 }
1468 1539
1469 glEnd (); 1540 glEnd ();
1470 1541
1485 int px = x * 32; 1556 int px = x * 32;
1486 int py = y * 32; 1557 int py = y * 32;
1487 1558
1488 if (cell->stat_hp) 1559 if (cell->stat_hp)
1489 { 1560 {
1490 int width = sh / 28 + 1; 1561 int width = cell->stat_width * 32;
1562 int thick = sh / 28 + 1 + cell->stat_width;
1491 1563
1492 glColor3ub (0, 0, 0); 1564 glColor3ub (0, 0, 0);
1493 glRectf (px + 1, py, px + 31, py + width + 2); 1565 glRectf (px + 1, py - thick - 2,
1566 px + width - 1, py);
1494 1567
1495 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); 1568 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1496 glRectf (px + 2, py + 1, px + 30 - cell->stat_hp * 28 / 255, py + width + 1); 1569 glRectf (px + 2,
1570 py - thick - 1,
1571 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1497 } 1572 }
1498 } 1573 }
1499 } 1574 }
1500} 1575}
1501 1576

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines