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.156 by root, Thu Sep 21 14:47:51 2006 UTC vs.
Revision 1.167 by root, Sat Dec 9 02:21:25 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)
8# pragma warning(disable:4761)
7#endif 9#endif
8 10
9#include "EXTERN.h" 11#include "EXTERN.h"
10#include "perl.h" 12#include "perl.h"
11#include "XSUB.h" 13#include "XSUB.h"
36# include <sys/types.h> 38# include <sys/types.h>
37# include <sys/socket.h> 39# include <sys/socket.h>
38# include <netinet/in.h> 40# include <netinet/in.h>
39# include <netinet/tcp.h> 41# include <netinet/tcp.h>
40# include <inttypes.h> 42# include <inttypes.h>
41#else
42 typedef unsigned char uint8_t;
43 typedef unsigned short uint16_t;
44 typedef unsigned int uint32_t;
45 typedef signed char int8_t;
46 typedef signed short int16_t;
47 typedef signed int int32_t;
48#endif 43#endif
49 44
50#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ 45#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
51 46
52#define FOW_DARKNESS 32 47#define FOW_DARKNESS 32
53 48
54#define MAP_EXTEND_X 32 49#define MAP_EXTEND_X 32
55#define MAP_EXTEND_Y 512 50#define MAP_EXTEND_Y 512
364 n |= n >> 16; 359 n |= n >> 16;
365 360
366 return n + 1; 361 return n + 1;
367} 362}
368 363
364/* SDL should provide this, really. */
365#define SDLK_MODIFIER_MIN 300
366#define SDLK_MODIFIER_MAX 314
367
369MODULE = CFPlus PACKAGE = CFPlus 368MODULE = CFPlus PACKAGE = CFPlus
370 369
371PROTOTYPES: ENABLE 370PROTOTYPES: ENABLE
372 371
373BOOT: 372BOOT:
376 static const struct { 375 static const struct {
377 const char *name; 376 const char *name;
378 IV iv; 377 IV iv;
379 } *civ, const_iv[] = { 378 } *civ, const_iv[] = {
380# define const_iv(name) { # name, (IV)name } 379# define const_iv(name) { # name, (IV)name }
380 const_iv (SDLK_MODIFIER_MIN),
381 const_iv (SDLK_MODIFIER_MAX),
382
381 const_iv (SDL_ACTIVEEVENT), 383 const_iv (SDL_ACTIVEEVENT),
382 const_iv (SDL_KEYDOWN), 384 const_iv (SDL_KEYDOWN),
383 const_iv (SDL_KEYUP), 385 const_iv (SDL_KEYUP),
384 const_iv (SDL_MOUSEMOTION), 386 const_iv (SDL_MOUSEMOTION),
385 const_iv (SDL_MOUSEBUTTONDOWN), 387 const_iv (SDL_MOUSEBUTTONDOWN),
394 const_iv (SDL_EVENT_RESERVEDA), 396 const_iv (SDL_EVENT_RESERVEDA),
395 const_iv (SDL_EVENT_RESERVEDB), 397 const_iv (SDL_EVENT_RESERVEDB),
396 const_iv (SDL_VIDEORESIZE), 398 const_iv (SDL_VIDEORESIZE),
397 const_iv (SDL_VIDEOEXPOSE), 399 const_iv (SDL_VIDEOEXPOSE),
398 const_iv (SDL_USEREVENT), 400 const_iv (SDL_USEREVENT),
401
402 const_iv (SDL_APPINPUTFOCUS),
403 const_iv (SDL_APPMOUSEFOCUS),
404 const_iv (SDL_APPACTIVE),
405
399 const_iv (SDLK_KP0), 406 const_iv (SDLK_KP0),
400 const_iv (SDLK_KP1), 407 const_iv (SDLK_KP1),
401 const_iv (SDLK_KP2), 408 const_iv (SDLK_KP2),
402 const_iv (SDLK_KP3), 409 const_iv (SDLK_KP3),
403 const_iv (SDLK_KP4), 410 const_iv (SDLK_KP4),
458 const_iv (SDLK_BREAK), 465 const_iv (SDLK_BREAK),
459 const_iv (SDLK_MENU), 466 const_iv (SDLK_MENU),
460 const_iv (SDLK_POWER), 467 const_iv (SDLK_POWER),
461 const_iv (SDLK_EURO), 468 const_iv (SDLK_EURO),
462 const_iv (SDLK_UNDO), 469 const_iv (SDLK_UNDO),
470
463 const_iv (KMOD_NONE), 471 const_iv (KMOD_NONE),
472 const_iv (KMOD_SHIFT),
464 const_iv (KMOD_LSHIFT), 473 const_iv (KMOD_LSHIFT),
465 const_iv (KMOD_RSHIFT), 474 const_iv (KMOD_RSHIFT),
475 const_iv (KMOD_CTRL),
466 const_iv (KMOD_LCTRL), 476 const_iv (KMOD_LCTRL),
467 const_iv (KMOD_RCTRL), 477 const_iv (KMOD_RCTRL),
478 const_iv (KMOD_ALT),
468 const_iv (KMOD_LALT), 479 const_iv (KMOD_LALT),
469 const_iv (KMOD_RALT), 480 const_iv (KMOD_RALT),
481 const_iv (KMOD_META),
470 const_iv (KMOD_LMETA), 482 const_iv (KMOD_LMETA),
471 const_iv (KMOD_RMETA), 483 const_iv (KMOD_RMETA),
472 const_iv (KMOD_NUM), 484 const_iv (KMOD_NUM),
473 const_iv (KMOD_CAPS), 485 const_iv (KMOD_CAPS),
474 const_iv (KMOD_MODE), 486 const_iv (KMOD_MODE),
475 const_iv (KMOD_CTRL),
476 const_iv (KMOD_SHIFT),
477 const_iv (KMOD_ALT),
478 const_iv (KMOD_META)
479# undef const_iv 487# undef const_iv
480 }; 488 };
481 489
482 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 490 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
483 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 491 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
492
493 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
494 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
484} 495}
485 496
486int 497int
487in_destruct () 498in_destruct ()
488 CODE: 499 CODE:
592 case SDL_KEYDOWN: 603 case SDL_KEYDOWN:
593 case SDL_KEYUP: 604 case SDL_KEYUP:
594 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 605 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
595 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 606 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
596 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 607 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0);
608 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */
597 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 609 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
598 break; 610 break;
599 611
600 case SDL_ACTIVEEVENT: 612 case SDL_ACTIVEEVENT:
601 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 613 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
649lowdelay (int fd, int val = 1) 661lowdelay (int fd, int val = 1)
650 CODE: 662 CODE:
651#ifndef _WIN32 663#ifndef _WIN32
652 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 664 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
653#endif 665#endif
666
667void
668win32_proxy_info ()
669 PPCODE:
670{
671#ifdef _WIN32
672 char buffer[2048];
673 DWORD buflen;
674
675 EXTEND (SP, 3);
676
677 buflen = sizeof (buffer);
678 if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen))
679 if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
680 {
681 PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0));
682
683 buflen = sizeof (buffer);
684 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen))
685 {
686 PUSHs (newSVpv (buffer, 0));
687
688 buflen = sizeof (buffer);
689 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen))
690 PUSHs (newSVpv (buffer, 0));
691 }
692 }
693#endif
694}
654 695
655void 696void
656add_font (char *file) 697add_font (char *file)
657 CODE: 698 CODE:
658 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 699 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
762 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 803 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
763#endif 804#endif
764 _exit (1); 805 _exit (1);
765 806
766void 807void
767_exit (int retval) 808_exit (int retval = 0)
768 CODE: 809 CODE:
810#ifdef WIN32
811 ExitThread (retval); // unclean, please beam me up
812#else
769 _exit (retval); 813 _exit (retval);
814#endif
770 815
771MODULE = CFPlus PACKAGE = CFPlus::Font 816MODULE = CFPlus PACKAGE = CFPlus::Font
772 817
773CFPlus::Font 818CFPlus::Font
774new_from_file (SV *class, char *path, int id = 0) 819new_from_file (SV *class, char *path, int id = 0)
1021xy_to_index (CFPlus::Layout self, int x, int y) 1066xy_to_index (CFPlus::Layout self, int x, int y)
1022 CODE: 1067 CODE:
1023{ 1068{
1024 int index, trailing; 1069 int index, trailing;
1025 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1070 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1026 RETVAL = index; 1071 RETVAL = index + trailing;
1027} 1072}
1028 OUTPUT: 1073 OUTPUT:
1029 RETVAL 1074 RETVAL
1030 1075
1031void 1076void
1037 1082
1038 EXTEND (SP, 3); 1083 EXTEND (SP, 3);
1039 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1084 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
1040 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1085 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1041 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1086 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1087}
1088
1089void
1090index_to_line_x (CFPlus::Layout self, int index, int trailing = 0)
1091 PPCODE:
1092{
1093 int line, x;
1094
1095 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1096 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1097
1098 EXTEND (SP, 2);
1099 PUSHs (sv_2mortal (newSViv (line - 1)));
1100 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1101}
1102
1103void
1104line_x_to_index (CFPlus::Layout self, int line, int x)
1105 PPCODE:
1106{
1107 PangoLayoutLine *lp;
1108 int index, trailing;
1109
1110 if (line < 0)
1111 XSRETURN_EMPTY;
1112
1113 if (!(lp = pango_layout_get_line (self->pl, line)))
1114 XSRETURN_EMPTY; /* do better */
1115
1116 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1117
1118 EXTEND (SP, 2);
1119 if (GIMME_V == G_SCALAR)
1120 PUSHs (sv_2mortal (newSViv (index + trailing)));
1121 else
1122 {
1123 PUSHs (sv_2mortal (newSViv (index)));
1124 PUSHs (sv_2mortal (newSViv (trailing)));
1125 }
1042} 1126}
1043 1127
1044void 1128void
1045render (CFPlus::Layout self, float x, float y, int flags = 0) 1129render (CFPlus::Layout self, float x, float y, int flags = 0)
1046 PPCODE: 1130 PPCODE:
1140} 1224}
1141 1225
1142MODULE = CFPlus PACKAGE = CFPlus::Map 1226MODULE = CFPlus PACKAGE = CFPlus::Map
1143 1227
1144CFPlus::Map 1228CFPlus::Map
1145new (SV *class, int map_width, int map_height) 1229new (SV *class)
1146 CODE: 1230 CODE:
1147 New (0, RETVAL, 1, struct map); 1231 New (0, RETVAL, 1, struct map);
1148 RETVAL->x = 0; 1232 RETVAL->x = 0;
1149 RETVAL->y = 0; 1233 RETVAL->y = 0;
1150 RETVAL->w = map_width; 1234 RETVAL->w = 0;
1151 RETVAL->h = map_height; 1235 RETVAL->h = 0;
1152 RETVAL->ox = 0; 1236 RETVAL->ox = 0;
1153 RETVAL->oy = 0; 1237 RETVAL->oy = 0;
1154 RETVAL->faces = 8192; 1238 RETVAL->faces = 8192;
1155 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1239 Newz (0, RETVAL->face, RETVAL->faces, mapface);
1156 RETVAL->texs = 8192; 1240 RETVAL->texs = 8192;
1167 map_clear (self); 1251 map_clear (self);
1168 Safefree (self->face); 1252 Safefree (self->face);
1169 Safefree (self->tex); 1253 Safefree (self->tex);
1170 Safefree (self); 1254 Safefree (self);
1171} 1255}
1256
1257void
1258resize (CFPlus::Map self, int map_width, int map_height)
1259 CODE:
1260 self->w = map_width;
1261 self->h = map_height;
1172 1262
1173void 1263void
1174clear (CFPlus::Map self) 1264clear (CFPlus::Map self)
1175 CODE: 1265 CODE:
1176 map_clear (self); 1266 map_clear (self);
1416} 1506}
1417 OUTPUT: 1507 OUTPUT:
1418 RETVAL 1508 RETVAL
1419 1509
1420void 1510void
1421draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1511draw (CFPlus::Map self, int mx, int my, int sw, int sh)
1422 CODE: 1512 CODE:
1423{ 1513{
1424 int vx, vy;
1425 int x, y, z; 1514 int x, y, z;
1426 int last_name; 1515 int last_name;
1427 mapface face; 1516 mapface face;
1428
1429 vx = self->x + self->w / 2 - sw / 2 - shift_x;
1430 vy = self->y + self->h / 2 - sh / 2 - shift_y;
1431
1432 /*
1433 int vx = self->vx = self->w >= sw
1434 ? self->x + (self->w - sw) / 2
1435 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1436
1437 int vy = self->vy = self->h >= sh
1438 ? self->y + (self->h - sh) / 2
1439 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1440 */
1441 1517
1442 glColor4ub (255, 255, 255, 255); 1518 glColor4ub (255, 255, 255, 255);
1443 1519
1444 glEnable (GL_BLEND); 1520 glEnable (GL_BLEND);
1445 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1521 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1448 1524
1449 glBegin (GL_QUADS); 1525 glBegin (GL_QUADS);
1450 1526
1451 last_name = 0; 1527 last_name = 0;
1452 1528
1529 mx += self->x;
1530 my += self->y;
1531
1453 for (z = 0; z < 3; z++) 1532 for (z = 0; z < 3; z++)
1454 for (y = 0; y < sh; y++) 1533 for (y = 0; y < sh; y++)
1455 if (0 <= y + vy && y + vy < self->rows) 1534 if (0 <= y + my && y + my < self->rows)
1456 { 1535 {
1457 maprow *row = self->row + (y + vy); 1536 maprow *row = self->row + (y + my);
1458 1537
1459 for (x = 0; x < sw; x++) 1538 for (x = 0; x < sw; x++)
1460 if (row->c0 <= x + vx && x + vx < row->c1) 1539 if (row->c0 <= x + mx && x + mx < row->c1)
1461 { 1540 {
1462 mapcell *cell = row->col + (x + vx - row->c0); 1541 mapcell *cell = row->col + (x + mx - row->c0);
1463 1542
1464 face = cell->face [z]; 1543 face = cell->face [z];
1465 1544
1466 if (face && face < self->texs) 1545 if (face && face < self->texs)
1467 { 1546 {
1508 glDisable (GL_TEXTURE_2D); 1587 glDisable (GL_TEXTURE_2D);
1509 glDisable (GL_BLEND); 1588 glDisable (GL_BLEND);
1510 1589
1511 // top layer: overlays such as the health bar 1590 // top layer: overlays such as the health bar
1512 for (y = 0; y < sh; y++) 1591 for (y = 0; y < sh; y++)
1513 if (0 <= y + vy && y + vy < self->rows) 1592 if (0 <= y + my && y + my < self->rows)
1514 { 1593 {
1515 maprow *row = self->row + (y + vy); 1594 maprow *row = self->row + (y + my);
1516 1595
1517 for (x = 0; x < sw; x++) 1596 for (x = 0; x < sw; x++)
1518 if (row->c0 <= x + vx && x + vx < row->c1) 1597 if (row->c0 <= x + mx && x + mx < row->c1)
1519 { 1598 {
1520 mapcell *cell = row->col + (x + vx - row->c0); 1599 mapcell *cell = row->col + (x + mx - row->c0);
1521 1600
1522 int px = x * 32; 1601 int px = x * 32;
1523 int py = y * 32; 1602 int py = y * 32;
1524 1603
1525 if (cell->stat_hp) 1604 if (cell->stat_hp)
1599 glDisable (GL_BLEND); 1678 glDisable (GL_BLEND);
1600 glDisable (GL_TEXTURE_2D); 1679 glDisable (GL_TEXTURE_2D);
1601} 1680}
1602 1681
1603void 1682void
1604fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1683fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1605 PPCODE: 1684 PPCODE:
1606{ 1685{
1607 int vx, vy;
1608 int x, y; 1686 int x, y;
1609 int sw4 = (sw + 3) & ~3; 1687 int sw4 = (sw + 3) & ~3;
1610 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1688 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1611 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1689 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1612 1690
1613 memset (darkness, 255, sw4 * sh); 1691 memset (darkness, 255, sw4 * sh);
1614 SvPOK_only (darkness_sv); 1692 SvPOK_only (darkness_sv);
1615 SvCUR_set (darkness_sv, sw4 * sh); 1693 SvCUR_set (darkness_sv, sw4 * sh);
1616 1694
1617 vx = self->x + (self->w - sw + 1) / 2 - shift_x; 1695 mx += self->x;
1618 vy = self->y + (self->h - sh + 1) / 2 - shift_y; 1696 my += self->y;
1619 1697
1620 for (y = 0; y < sh; y++) 1698 for (y = 0; y < sh; y++)
1621 if (0 <= y + vy && y + vy < self->rows) 1699 if (0 <= y + my && y + my < self->rows)
1622 { 1700 {
1623 maprow *row = self->row + (y + vy); 1701 maprow *row = self->row + (y + my);
1624 1702
1625 for (x = 0; x < sw; x++) 1703 for (x = 0; x < sw; x++)
1626 if (row->c0 <= x + vx && x + vx < row->c1) 1704 if (row->c0 <= x + mx && x + mx < row->c1)
1627 { 1705 {
1628 mapcell *cell = row->col + (x + vx - row->c0); 1706 mapcell *cell = row->col + (x + mx - row->c0);
1629 1707
1630 darkness[y * sw4 + x] = cell->darkness 1708 darkness[y * sw4 + x] = cell->darkness
1631 ? 255 - (cell->darkness - 1) 1709 ? 255 - (cell->darkness - 1)
1632 : 255 - FOW_DARKNESS; 1710 : 255 - FOW_DARKNESS;
1633 } 1711 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines