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.157 by root, Sun Oct 1 14:48:50 2006 UTC vs.
Revision 1.166 by root, Fri Dec 8 15:07:08 2006 UTC

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# include <wininet.h>
7# pragma warning(disable:4244) 7# pragma warning(disable:4244)
8# pragma warning(disable:4761)
8#endif 9#endif
9 10
10#include "EXTERN.h" 11#include "EXTERN.h"
11#include "perl.h" 12#include "perl.h"
12#include "XSUB.h" 13#include "XSUB.h"
37# include <sys/types.h> 38# include <sys/types.h>
38# include <sys/socket.h> 39# include <sys/socket.h>
39# include <netinet/in.h> 40# include <netinet/in.h>
40# include <netinet/tcp.h> 41# include <netinet/tcp.h>
41# include <inttypes.h> 42# include <inttypes.h>
42#else
43 typedef unsigned char uint8_t;
44 typedef unsigned short uint16_t;
45 typedef unsigned int uint32_t;
46 typedef signed char int8_t;
47 typedef signed short int16_t;
48 typedef signed int int32_t;
49#endif 43#endif
50 44
51#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ 45#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
52 46
53#define FOW_DARKNESS 32 47#define FOW_DARKNESS 32
54 48
55#define MAP_EXTEND_X 32 49#define MAP_EXTEND_X 32
56#define MAP_EXTEND_Y 512 50#define MAP_EXTEND_Y 512
656void 650void
657win32_proxy_info () 651win32_proxy_info ()
658 PPCODE: 652 PPCODE:
659{ 653{
660#ifdef _WIN32 654#ifdef _WIN32
661 INTERNET_PROXY_INFO proxyinfo;
662 char buffer[2048]; 655 char buffer[2048];
663 DWORD buflen; 656 DWORD buflen;
664 657
665 EXTEND (SP, 3); 658 EXTEND (SP, 3);
666 659
793 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 786 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
794#endif 787#endif
795 _exit (1); 788 _exit (1);
796 789
797void 790void
798_exit (int retval) 791_exit (int retval = 0)
799 CODE: 792 CODE:
793#ifdef WIN32
794 ExitThread (retval); // unclean, please beam me up
795#else
800 _exit (retval); 796 _exit (retval);
797#endif
801 798
802MODULE = CFPlus PACKAGE = CFPlus::Font 799MODULE = CFPlus PACKAGE = CFPlus::Font
803 800
804CFPlus::Font 801CFPlus::Font
805new_from_file (SV *class, char *path, int id = 0) 802new_from_file (SV *class, char *path, int id = 0)
1052xy_to_index (CFPlus::Layout self, int x, int y) 1049xy_to_index (CFPlus::Layout self, int x, int y)
1053 CODE: 1050 CODE:
1054{ 1051{
1055 int index, trailing; 1052 int index, trailing;
1056 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1053 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1057 RETVAL = index; 1054 RETVAL = index + trailing;
1058} 1055}
1059 OUTPUT: 1056 OUTPUT:
1060 RETVAL 1057 RETVAL
1061 1058
1062void 1059void
1068 1065
1069 EXTEND (SP, 3); 1066 EXTEND (SP, 3);
1070 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1067 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
1071 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1068 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1072 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1069 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1070}
1071
1072void
1073index_to_line_x (CFPlus::Layout self, int index, int trailing = 0)
1074 PPCODE:
1075{
1076 int line, x;
1077
1078 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1079 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1080
1081 EXTEND (SP, 2);
1082 PUSHs (sv_2mortal (newSViv (line - 1)));
1083 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1084}
1085
1086void
1087line_x_to_index (CFPlus::Layout self, int line, int x)
1088 PPCODE:
1089{
1090 PangoLayoutLine *lp;
1091 int index, trailing;
1092
1093 if (line < 0)
1094 XSRETURN_EMPTY;
1095
1096 if (!(lp = pango_layout_get_line (self->pl, line)))
1097 XSRETURN_EMPTY; /* do better */
1098
1099 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1100
1101 EXTEND (SP, 2);
1102 if (GIMME_V == G_SCALAR)
1103 PUSHs (sv_2mortal (newSViv (index + trailing)));
1104 else
1105 {
1106 PUSHs (sv_2mortal (newSViv (index)));
1107 PUSHs (sv_2mortal (newSViv (trailing)));
1108 }
1073} 1109}
1074 1110
1075void 1111void
1076render (CFPlus::Layout self, float x, float y, int flags = 0) 1112render (CFPlus::Layout self, float x, float y, int flags = 0)
1077 PPCODE: 1113 PPCODE:
1171} 1207}
1172 1208
1173MODULE = CFPlus PACKAGE = CFPlus::Map 1209MODULE = CFPlus PACKAGE = CFPlus::Map
1174 1210
1175CFPlus::Map 1211CFPlus::Map
1176new (SV *class, int map_width, int map_height) 1212new (SV *class)
1177 CODE: 1213 CODE:
1178 New (0, RETVAL, 1, struct map); 1214 New (0, RETVAL, 1, struct map);
1179 RETVAL->x = 0; 1215 RETVAL->x = 0;
1180 RETVAL->y = 0; 1216 RETVAL->y = 0;
1181 RETVAL->w = map_width; 1217 RETVAL->w = 0;
1182 RETVAL->h = map_height; 1218 RETVAL->h = 0;
1183 RETVAL->ox = 0; 1219 RETVAL->ox = 0;
1184 RETVAL->oy = 0; 1220 RETVAL->oy = 0;
1185 RETVAL->faces = 8192; 1221 RETVAL->faces = 8192;
1186 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1222 Newz (0, RETVAL->face, RETVAL->faces, mapface);
1187 RETVAL->texs = 8192; 1223 RETVAL->texs = 8192;
1198 map_clear (self); 1234 map_clear (self);
1199 Safefree (self->face); 1235 Safefree (self->face);
1200 Safefree (self->tex); 1236 Safefree (self->tex);
1201 Safefree (self); 1237 Safefree (self);
1202} 1238}
1239
1240void
1241resize (CFPlus::Map self, int map_width, int map_height)
1242 CODE:
1243 self->w = map_width;
1244 self->h = map_height;
1203 1245
1204void 1246void
1205clear (CFPlus::Map self) 1247clear (CFPlus::Map self)
1206 CODE: 1248 CODE:
1207 map_clear (self); 1249 map_clear (self);
1447} 1489}
1448 OUTPUT: 1490 OUTPUT:
1449 RETVAL 1491 RETVAL
1450 1492
1451void 1493void
1452draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1494draw (CFPlus::Map self, int mx, int my, int sw, int sh)
1453 CODE: 1495 CODE:
1454{ 1496{
1455 int vx, vy;
1456 int x, y, z; 1497 int x, y, z;
1457 int last_name; 1498 int last_name;
1458 mapface face; 1499 mapface face;
1459
1460 vx = self->x + self->w / 2 - sw / 2 - shift_x;
1461 vy = self->y + self->h / 2 - sh / 2 - shift_y;
1462
1463 /*
1464 int vx = self->vx = self->w >= sw
1465 ? self->x + (self->w - sw) / 2
1466 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1467
1468 int vy = self->vy = self->h >= sh
1469 ? self->y + (self->h - sh) / 2
1470 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1471 */
1472 1500
1473 glColor4ub (255, 255, 255, 255); 1501 glColor4ub (255, 255, 255, 255);
1474 1502
1475 glEnable (GL_BLEND); 1503 glEnable (GL_BLEND);
1476 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1504 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1479 1507
1480 glBegin (GL_QUADS); 1508 glBegin (GL_QUADS);
1481 1509
1482 last_name = 0; 1510 last_name = 0;
1483 1511
1512 mx += self->x;
1513 my += self->y;
1514
1484 for (z = 0; z < 3; z++) 1515 for (z = 0; z < 3; z++)
1485 for (y = 0; y < sh; y++) 1516 for (y = 0; y < sh; y++)
1486 if (0 <= y + vy && y + vy < self->rows) 1517 if (0 <= y + my && y + my < self->rows)
1487 { 1518 {
1488 maprow *row = self->row + (y + vy); 1519 maprow *row = self->row + (y + my);
1489 1520
1490 for (x = 0; x < sw; x++) 1521 for (x = 0; x < sw; x++)
1491 if (row->c0 <= x + vx && x + vx < row->c1) 1522 if (row->c0 <= x + mx && x + mx < row->c1)
1492 { 1523 {
1493 mapcell *cell = row->col + (x + vx - row->c0); 1524 mapcell *cell = row->col + (x + mx - row->c0);
1494 1525
1495 face = cell->face [z]; 1526 face = cell->face [z];
1496 1527
1497 if (face && face < self->texs) 1528 if (face && face < self->texs)
1498 { 1529 {
1539 glDisable (GL_TEXTURE_2D); 1570 glDisable (GL_TEXTURE_2D);
1540 glDisable (GL_BLEND); 1571 glDisable (GL_BLEND);
1541 1572
1542 // top layer: overlays such as the health bar 1573 // top layer: overlays such as the health bar
1543 for (y = 0; y < sh; y++) 1574 for (y = 0; y < sh; y++)
1544 if (0 <= y + vy && y + vy < self->rows) 1575 if (0 <= y + my && y + my < self->rows)
1545 { 1576 {
1546 maprow *row = self->row + (y + vy); 1577 maprow *row = self->row + (y + my);
1547 1578
1548 for (x = 0; x < sw; x++) 1579 for (x = 0; x < sw; x++)
1549 if (row->c0 <= x + vx && x + vx < row->c1) 1580 if (row->c0 <= x + mx && x + mx < row->c1)
1550 { 1581 {
1551 mapcell *cell = row->col + (x + vx - row->c0); 1582 mapcell *cell = row->col + (x + mx - row->c0);
1552 1583
1553 int px = x * 32; 1584 int px = x * 32;
1554 int py = y * 32; 1585 int py = y * 32;
1555 1586
1556 if (cell->stat_hp) 1587 if (cell->stat_hp)
1630 glDisable (GL_BLEND); 1661 glDisable (GL_BLEND);
1631 glDisable (GL_TEXTURE_2D); 1662 glDisable (GL_TEXTURE_2D);
1632} 1663}
1633 1664
1634void 1665void
1635fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1666fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1636 PPCODE: 1667 PPCODE:
1637{ 1668{
1638 int vx, vy;
1639 int x, y; 1669 int x, y;
1640 int sw4 = (sw + 3) & ~3; 1670 int sw4 = (sw + 3) & ~3;
1641 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1671 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1642 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1672 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1643 1673
1644 memset (darkness, 255, sw4 * sh); 1674 memset (darkness, 255, sw4 * sh);
1645 SvPOK_only (darkness_sv); 1675 SvPOK_only (darkness_sv);
1646 SvCUR_set (darkness_sv, sw4 * sh); 1676 SvCUR_set (darkness_sv, sw4 * sh);
1647 1677
1648 vx = self->x + (self->w - sw + 1) / 2 - shift_x; 1678 mx += self->x;
1649 vy = self->y + (self->h - sh + 1) / 2 - shift_y; 1679 my += self->y;
1650 1680
1651 for (y = 0; y < sh; y++) 1681 for (y = 0; y < sh; y++)
1652 if (0 <= y + vy && y + vy < self->rows) 1682 if (0 <= y + my && y + my < self->rows)
1653 { 1683 {
1654 maprow *row = self->row + (y + vy); 1684 maprow *row = self->row + (y + my);
1655 1685
1656 for (x = 0; x < sw; x++) 1686 for (x = 0; x < sw; x++)
1657 if (row->c0 <= x + vx && x + vx < row->c1) 1687 if (row->c0 <= x + mx && x + mx < row->c1)
1658 { 1688 {
1659 mapcell *cell = row->col + (x + vx - row->c0); 1689 mapcell *cell = row->col + (x + mx - row->c0);
1660 1690
1661 darkness[y * sw4 + x] = cell->darkness 1691 darkness[y * sw4 + x] = cell->darkness
1662 ? 255 - (cell->darkness - 1) 1692 ? 255 - (cell->darkness - 1)
1663 : 255 - FOW_DARKNESS; 1693 : 255 - FOW_DARKNESS;
1664 } 1694 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines