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.144 by root, Fri Aug 18 02:25:12 2006 UTC vs.
Revision 1.160 by root, Mon Oct 9 01:06:36 2006 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2long _ftol (double); /* defined by VC6 C libs */
3long _ftol2 (double dblSource) { return _ftol (dblSource); }
2# define WIN32_LEAN_AND_MEAN 4# define WIN32_LEAN_AND_MEAN
3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 5# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls
4# include <malloc.h> 6# include <malloc.h>
5# include <windows.h> 7# include <windows.h>
8# include <wininet.h>
6# pragma warning(disable:4244) 9# pragma warning(disable:4244)
7#endif 10#endif
8 11
9#include "EXTERN.h" 12#include "EXTERN.h"
10#include "perl.h" 13#include "perl.h"
169 float s, t; 172 float s, t;
170 uint8_t r, g, b, a; 173 uint8_t r, g, b, a;
171} maptex; 174} maptex;
172 175
173typedef struct { 176typedef struct {
177 uint32_t player;
178 mapface face[3];
174 uint16_t darkness; 179 uint16_t darkness;
175 mapface face[3]; 180 uint8_t stat_width, stat_hp, flags;
176 uint8_t stat_hp;
177} mapcell; 181} mapcell;
178 182
179typedef struct { 183typedef struct {
180 int32_t c0, c1; 184 int32_t c0, c1;
181 mapcell *col; 185 mapcell *col;
294static void 298static void
295map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 299map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
296{ 300{
297 int x, y; 301 int x, y;
298 maprow *row; 302 maprow *row;
303 mapcell *cell;
299 304
300 for (y = y0; y < y0 + h; y++) 305 for (y = y0; y < y0 + h; y++)
301 if (y >= 0) 306 if (y >= 0)
302 { 307 {
303 if (y >= self->rows) 308 if (y >= self->rows)
309 if (x >= row->c0) 314 if (x >= row->c0)
310 { 315 {
311 if (x >= row->c1) 316 if (x >= row->c1)
312 break; 317 break;
313 318
314 row->col[x - row->c0].darkness = 0; 319 cell = row->col + x - row->c0;
320
321 cell->darkness = 0;
322 cell->stat_hp = 0;
323 cell->flags = 0;
324 cell->player = 0;
315 } 325 }
316 } 326 }
317} 327}
318 328
319static void 329static void
644#ifndef _WIN32 654#ifndef _WIN32
645 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 655 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
646#endif 656#endif
647 657
648void 658void
659win32_proxy_info ()
660 PPCODE:
661{
662#ifdef _WIN32
663 char buffer[2048];
664 DWORD buflen;
665
666 EXTEND (SP, 3);
667
668 buflen = sizeof (buffer);
669 if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen))
670 if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
671 {
672 PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0));
673
674 buflen = sizeof (buffer);
675 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen))
676 {
677 PUSHs (newSVpv (buffer, 0));
678
679 buflen = sizeof (buffer);
680 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen))
681 PUSHs (newSVpv (buffer, 0));
682 }
683 }
684#endif
685}
686
687void
649add_font (char *file) 688add_font (char *file)
650 CODE: 689 CODE:
651 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 690 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
652 691
653void 692void
755 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 794 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
756#endif 795#endif
757 _exit (1); 796 _exit (1);
758 797
759void 798void
760_exit (int retval) 799_exit (int retval = 0)
761 CODE: 800 CODE:
762 _exit (retval); 801 _exit (retval);
763 802
764MODULE = CFPlus PACKAGE = CFPlus::Font 803MODULE = CFPlus PACKAGE = CFPlus::Font
765 804
1239void 1278void
1240scroll (CFPlus::Map self, int dx, int dy) 1279scroll (CFPlus::Map self, int dx, int dy)
1241 CODE: 1280 CODE:
1242{ 1281{
1243 if (dx > 0) 1282 if (dx > 0)
1244 map_blank (self, self->x, self->y, dx - 1, self->h); 1283 map_blank (self, self->x, self->y, dx, self->h);
1245 else if (dx < 0) 1284 else if (dx < 0)
1246 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1285 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1247 1286
1248 if (dy > 0) 1287 if (dy > 0)
1249 map_blank (self, self->x, self->y, self->w, dy - 1); 1288 map_blank (self, self->x, self->y, self->w, dy);
1250 else if (dy < 0) 1289 else if (dy < 0)
1251 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1290 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1252 1291
1253 self->ox += dx; self->x += dx; 1292 self->ox += dx; self->x += dx;
1254 self->oy += dy; self->y += dy; 1293 self->oy += dy; self->y += dy;
1255 1294
1256 while (self->y < 0) 1295 while (self->y < 0)
1269 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1308 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1270 uint8_t *data_end = (uint8_t *)SvEND (data_); 1309 uint8_t *data_end = (uint8_t *)SvEND (data_);
1271 mapcell *cell; 1310 mapcell *cell;
1272 int x, y, flags; 1311 int x, y, flags;
1273 1312
1274 while (data < data_end) 1313 while (data < data_end - 1)
1275 { 1314 {
1276 flags = (data [0] << 8) + data [1]; data += 2; 1315 flags = (data [0] << 8) + data [1]; data += 2;
1277 1316
1278 x = self->x + ((flags >> 10) & 63); 1317 x = self->x + ((flags >> 10) & 63);
1279 y = self->y + ((flags >> 4) & 63); 1318 y = self->y + ((flags >> 4) & 63);
1282 1321
1283 if (flags & 15) 1322 if (flags & 15)
1284 { 1323 {
1285 if (!cell->darkness) 1324 if (!cell->darkness)
1286 { 1325 {
1326 memset (cell, 0, sizeof (*cell));
1287 cell->darkness = 256; 1327 cell->darkness = 256;
1288 cell->face [0] = 0;
1289 cell->face [1] = 0;
1290 cell->face [2] = 0;
1291 cell->stat_hp = 0;
1292 } 1328 }
1293 1329
1294 //TODO: don't trust server data to be in-range(!) 1330 //TODO: don't trust server data to be in-range(!)
1295 1331
1296 if (flags & 8) 1332 if (flags & 8)
1302 do 1338 do
1303 { 1339 {
1304 ext = *data++; 1340 ext = *data++;
1305 cmd = ext & 0x3f; 1341 cmd = ext & 0x3f;
1306 1342
1307 if (ext < 4) 1343 if (cmd < 4)
1308 cell->darkness = 255 - ext * 64 + 1; 1344 cell->darkness = 255 - ext * 64 + 1;
1309 else if (ext == 5) // health 1345 else if (cmd == 5) // health
1346 {
1347 cell->stat_width = 1;
1310 cell->stat_hp = *data++; 1348 cell->stat_hp = *data++;
1349 }
1350 else if (cmd == 6) // monster width
1351 cell->stat_width = *data++ + 1;
1352 else if (cmd == 0x47) // monster width
1353 {
1354 if (*data == 4)
1355 ; // decode player tag
1356
1357 data += *data + 1;
1358 }
1359 else if (cmd == 8) // cell flags
1360 cell->flags = *data++;
1311 else if (ext & 0x40) // unknown, multibyte => skip 1361 else if (ext & 0x40) // unknown, multibyte => skip
1312 data += *data + 1; 1362 data += *data + 1;
1363 else
1364 data++;
1313 } 1365 }
1314 while (cmd & 0x80); 1366 while (ext & 0x80);
1315 } 1367 }
1316 else 1368 else
1317 cell->darkness = *data++ + 1; 1369 cell->darkness = *data++ + 1;
1318 } 1370 }
1319 1371
1441 { 1493 {
1442 mapcell *cell = row->col + (x + vx - row->c0); 1494 mapcell *cell = row->col + (x + vx - row->c0);
1443 1495
1444 face = cell->face [z]; 1496 face = cell->face [z];
1445 1497
1446 if (face) 1498 if (face && face < self->texs)
1447 { 1499 {
1448 maptex tex = self->tex [face]; 1500 maptex tex = self->tex [face];
1449
1450 int px = (x + 1) * 32 - tex.w; 1501 int px = (x + 1) * 32 - tex.w;
1451 int py = (y + 1) * 32 - tex.h; 1502 int py = (y + 1) * 32 - tex.h;
1452 1503
1453 if (last_name != tex.name) 1504 if (last_name != tex.name)
1454 { 1505 {
1455 glEnd (); 1506 glEnd ();
1456 last_name = tex.name;
1457 glBindTexture (GL_TEXTURE_2D, last_name); 1507 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1458 glBegin (GL_QUADS); 1508 glBegin (GL_QUADS);
1459 } 1509 }
1460 1510
1461 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1511 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1462 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1512 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1463 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1513 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1464 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1514 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1465 } 1515 }
1516
1517 if (cell->flags && z == 2)
1518 {
1519 if (cell->flags & 1)
1520 {
1521 maptex tex = self->tex [1];
1522 int px = (x + 1) * 32 - tex.w + 2;
1523 int py = (y + 1) * 32 - tex.h - 6;
1524
1525 glEnd ();
1526 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1527 glBegin (GL_QUADS);
1528
1529 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1530 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1531 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1532 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1533 }
1534 }
1466 } 1535 }
1467 } 1536 }
1468 1537
1469 glEnd (); 1538 glEnd ();
1470 1539
1471 glDisable (GL_TEXTURE_2D); 1540 glDisable (GL_TEXTURE_2D);
1472 glDisable (GL_BLEND); 1541 glDisable (GL_BLEND);
1473 1542
1543 // top layer: overlays such as the health bar
1474 for (y = 0; y < sh; y++) 1544 for (y = 0; y < sh; y++)
1475 if (0 <= y + vy && y + vy < self->rows) 1545 if (0 <= y + vy && y + vy < self->rows)
1476 { 1546 {
1477 maprow *row = self->row + (y + vy); 1547 maprow *row = self->row + (y + vy);
1478 1548
1484 int px = x * 32; 1554 int px = x * 32;
1485 int py = y * 32; 1555 int py = y * 32;
1486 1556
1487 if (cell->stat_hp) 1557 if (cell->stat_hp)
1488 { 1558 {
1559 int width = cell->stat_width * 32;
1560 int thick = sh / 28 + 1 + cell->stat_width;
1561
1489 glColor3ub (0, 0, 0); 1562 glColor3ub (0, 0, 0);
1490 glRectf (px + 1, py + 1, px + 31, py + 4); 1563 glRectf (px + 1, py - thick - 2,
1564 px + width - 1, py);
1491 1565
1492 glColor3ub (0, 255, 0); 1566 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1493 glBegin (GL_LINES);
1494 glVertex2f (px + 2, py + 2.5f); 1567 glRectf (px + 2,
1495 glVertex2f (px + 29.f - cell->stat_hp * (28.f / 255.f), py + 2.5f); 1568 py - thick - 1,
1496 glEnd (); 1569 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1497 } 1570 }
1498 } 1571 }
1499 } 1572 }
1500} 1573}
1501 1574

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines