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.161 by root, Mon Oct 9 23:30:44 2006 UTC vs.
Revision 1.165 by root, Fri Dec 8 14:59:54 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
1055xy_to_index (CFPlus::Layout self, int x, int y) 1049xy_to_index (CFPlus::Layout self, int x, int y)
1056 CODE: 1050 CODE:
1057{ 1051{
1058 int index, trailing; 1052 int index, trailing;
1059 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);
1060 RETVAL = index; 1054 RETVAL = index + trailing;
1061} 1055}
1062 OUTPUT: 1056 OUTPUT:
1063 RETVAL 1057 RETVAL
1064 1058
1065void 1059void
1071 1065
1072 EXTEND (SP, 3); 1066 EXTEND (SP, 3);
1073 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1067 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
1074 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1068 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1075 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 if (!pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing))
1100 XSRETURN_EMPTY; /* do better */
1101
1102 EXTEND (SP, 2);
1103 if (GIMME_V == G_SCALAR)
1104 PUSHs (sv_2mortal (newSViv (index + trailing)));
1105 else
1106 {
1107 PUSHs (sv_2mortal (newSViv (index)));
1108 PUSHs (sv_2mortal (newSViv (trailing)));
1109 }
1076} 1110}
1077 1111
1078void 1112void
1079render (CFPlus::Layout self, float x, float y, int flags = 0) 1113render (CFPlus::Layout self, float x, float y, int flags = 0)
1080 PPCODE: 1114 PPCODE:
1174} 1208}
1175 1209
1176MODULE = CFPlus PACKAGE = CFPlus::Map 1210MODULE = CFPlus PACKAGE = CFPlus::Map
1177 1211
1178CFPlus::Map 1212CFPlus::Map
1179new (SV *class, int map_width, int map_height) 1213new (SV *class)
1180 CODE: 1214 CODE:
1181 New (0, RETVAL, 1, struct map); 1215 New (0, RETVAL, 1, struct map);
1182 RETVAL->x = 0; 1216 RETVAL->x = 0;
1183 RETVAL->y = 0; 1217 RETVAL->y = 0;
1184 RETVAL->w = map_width; 1218 RETVAL->w = 0;
1185 RETVAL->h = map_height; 1219 RETVAL->h = 0;
1186 RETVAL->ox = 0; 1220 RETVAL->ox = 0;
1187 RETVAL->oy = 0; 1221 RETVAL->oy = 0;
1188 RETVAL->faces = 8192; 1222 RETVAL->faces = 8192;
1189 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1223 Newz (0, RETVAL->face, RETVAL->faces, mapface);
1190 RETVAL->texs = 8192; 1224 RETVAL->texs = 8192;
1201 map_clear (self); 1235 map_clear (self);
1202 Safefree (self->face); 1236 Safefree (self->face);
1203 Safefree (self->tex); 1237 Safefree (self->tex);
1204 Safefree (self); 1238 Safefree (self);
1205} 1239}
1240
1241void
1242resize (CFPlus::Map self, int map_width, int map_height)
1243 CODE:
1244 self->w = map_width;
1245 self->h = map_height;
1206 1246
1207void 1247void
1208clear (CFPlus::Map self) 1248clear (CFPlus::Map self)
1209 CODE: 1249 CODE:
1210 map_clear (self); 1250 map_clear (self);
1450} 1490}
1451 OUTPUT: 1491 OUTPUT:
1452 RETVAL 1492 RETVAL
1453 1493
1454void 1494void
1455draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1495draw (CFPlus::Map self, int mx, int my, int sw, int sh)
1456 CODE: 1496 CODE:
1457{ 1497{
1458 int vx, vy;
1459 int x, y, z; 1498 int x, y, z;
1460 int last_name; 1499 int last_name;
1461 mapface face; 1500 mapface face;
1462
1463 vx = self->x + self->w / 2 - sw / 2 - shift_x;
1464 vy = self->y + self->h / 2 - sh / 2 - shift_y;
1465
1466 /*
1467 int vx = self->vx = self->w >= sw
1468 ? self->x + (self->w - sw) / 2
1469 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1470
1471 int vy = self->vy = self->h >= sh
1472 ? self->y + (self->h - sh) / 2
1473 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1474 */
1475 1501
1476 glColor4ub (255, 255, 255, 255); 1502 glColor4ub (255, 255, 255, 255);
1477 1503
1478 glEnable (GL_BLEND); 1504 glEnable (GL_BLEND);
1479 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1505 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1482 1508
1483 glBegin (GL_QUADS); 1509 glBegin (GL_QUADS);
1484 1510
1485 last_name = 0; 1511 last_name = 0;
1486 1512
1513 mx += self->x;
1514 my += self->y;
1515
1487 for (z = 0; z < 3; z++) 1516 for (z = 0; z < 3; z++)
1488 for (y = 0; y < sh; y++) 1517 for (y = 0; y < sh; y++)
1489 if (0 <= y + vy && y + vy < self->rows) 1518 if (0 <= y + my && y + my < self->rows)
1490 { 1519 {
1491 maprow *row = self->row + (y + vy); 1520 maprow *row = self->row + (y + my);
1492 1521
1493 for (x = 0; x < sw; x++) 1522 for (x = 0; x < sw; x++)
1494 if (row->c0 <= x + vx && x + vx < row->c1) 1523 if (row->c0 <= x + mx && x + mx < row->c1)
1495 { 1524 {
1496 mapcell *cell = row->col + (x + vx - row->c0); 1525 mapcell *cell = row->col + (x + mx - row->c0);
1497 1526
1498 face = cell->face [z]; 1527 face = cell->face [z];
1499 1528
1500 if (face && face < self->texs) 1529 if (face && face < self->texs)
1501 { 1530 {
1542 glDisable (GL_TEXTURE_2D); 1571 glDisable (GL_TEXTURE_2D);
1543 glDisable (GL_BLEND); 1572 glDisable (GL_BLEND);
1544 1573
1545 // top layer: overlays such as the health bar 1574 // top layer: overlays such as the health bar
1546 for (y = 0; y < sh; y++) 1575 for (y = 0; y < sh; y++)
1547 if (0 <= y + vy && y + vy < self->rows) 1576 if (0 <= y + my && y + my < self->rows)
1548 { 1577 {
1549 maprow *row = self->row + (y + vy); 1578 maprow *row = self->row + (y + my);
1550 1579
1551 for (x = 0; x < sw; x++) 1580 for (x = 0; x < sw; x++)
1552 if (row->c0 <= x + vx && x + vx < row->c1) 1581 if (row->c0 <= x + mx && x + mx < row->c1)
1553 { 1582 {
1554 mapcell *cell = row->col + (x + vx - row->c0); 1583 mapcell *cell = row->col + (x + mx - row->c0);
1555 1584
1556 int px = x * 32; 1585 int px = x * 32;
1557 int py = y * 32; 1586 int py = y * 32;
1558 1587
1559 if (cell->stat_hp) 1588 if (cell->stat_hp)
1633 glDisable (GL_BLEND); 1662 glDisable (GL_BLEND);
1634 glDisable (GL_TEXTURE_2D); 1663 glDisable (GL_TEXTURE_2D);
1635} 1664}
1636 1665
1637void 1666void
1638fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1667fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1639 PPCODE: 1668 PPCODE:
1640{ 1669{
1641 int vx, vy;
1642 int x, y; 1670 int x, y;
1643 int sw4 = (sw + 3) & ~3; 1671 int sw4 = (sw + 3) & ~3;
1644 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1672 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1645 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1673 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1646 1674
1647 memset (darkness, 255, sw4 * sh); 1675 memset (darkness, 255, sw4 * sh);
1648 SvPOK_only (darkness_sv); 1676 SvPOK_only (darkness_sv);
1649 SvCUR_set (darkness_sv, sw4 * sh); 1677 SvCUR_set (darkness_sv, sw4 * sh);
1650 1678
1651 vx = self->x + (self->w - sw + 1) / 2 - shift_x; 1679 mx += self->x;
1652 vy = self->y + (self->h - sh + 1) / 2 - shift_y; 1680 my += self->y;
1653 1681
1654 for (y = 0; y < sh; y++) 1682 for (y = 0; y < sh; y++)
1655 if (0 <= y + vy && y + vy < self->rows) 1683 if (0 <= y + my && y + my < self->rows)
1656 { 1684 {
1657 maprow *row = self->row + (y + vy); 1685 maprow *row = self->row + (y + my);
1658 1686
1659 for (x = 0; x < sw; x++) 1687 for (x = 0; x < sw; x++)
1660 if (row->c0 <= x + vx && x + vx < row->c1) 1688 if (row->c0 <= x + mx && x + mx < row->c1)
1661 { 1689 {
1662 mapcell *cell = row->col + (x + vx - row->c0); 1690 mapcell *cell = row->col + (x + mx - row->c0);
1663 1691
1664 darkness[y * sw4 + x] = cell->darkness 1692 darkness[y * sw4 + x] = cell->darkness
1665 ? 255 - (cell->darkness - 1) 1693 ? 255 - (cell->darkness - 1)
1666 : 255 - FOW_DARKNESS; 1694 : 255 - FOW_DARKNESS;
1667 } 1695 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines