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.160 by root, Mon Oct 9 01:06:36 2006 UTC vs.
Revision 1.166 by root, Fri Dec 8 15:07:08 2006 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2long _ftol (double); /* defined by VC6 C libs */
3long _ftol2 (double dblSource) { return _ftol (dblSource); }
4# define WIN32_LEAN_AND_MEAN 2# define WIN32_LEAN_AND_MEAN
5# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls
6# include <malloc.h> 4# include <malloc.h>
7# include <windows.h> 5# include <windows.h>
8# include <wininet.h> 6# include <wininet.h>
9# pragma warning(disable:4244) 7# pragma warning(disable:4244)
8# pragma warning(disable:4761)
10#endif 9#endif
11 10
12#include "EXTERN.h" 11#include "EXTERN.h"
13#include "perl.h" 12#include "perl.h"
14#include "XSUB.h" 13#include "XSUB.h"
39# include <sys/types.h> 38# include <sys/types.h>
40# include <sys/socket.h> 39# include <sys/socket.h>
41# include <netinet/in.h> 40# include <netinet/in.h>
42# include <netinet/tcp.h> 41# include <netinet/tcp.h>
43# include <inttypes.h> 42# include <inttypes.h>
44#else
45 typedef unsigned char uint8_t;
46 typedef unsigned short uint16_t;
47 typedef unsigned int uint32_t;
48 typedef signed char int8_t;
49 typedef signed short int16_t;
50 typedef signed int int32_t;
51#endif 43#endif
52 44
53#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ 45#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
54 46
55#define FOW_DARKNESS 32 47#define FOW_DARKNESS 32
56 48
57#define MAP_EXTEND_X 32 49#define MAP_EXTEND_X 32
58#define MAP_EXTEND_Y 512 50#define MAP_EXTEND_Y 512
796 _exit (1); 788 _exit (1);
797 789
798void 790void
799_exit (int retval = 0) 791_exit (int retval = 0)
800 CODE: 792 CODE:
793#ifdef WIN32
794 ExitThread (retval); // unclean, please beam me up
795#else
801 _exit (retval); 796 _exit (retval);
797#endif
802 798
803MODULE = CFPlus PACKAGE = CFPlus::Font 799MODULE = CFPlus PACKAGE = CFPlus::Font
804 800
805CFPlus::Font 801CFPlus::Font
806new_from_file (SV *class, char *path, int id = 0) 802new_from_file (SV *class, char *path, int id = 0)
1053xy_to_index (CFPlus::Layout self, int x, int y) 1049xy_to_index (CFPlus::Layout self, int x, int y)
1054 CODE: 1050 CODE:
1055{ 1051{
1056 int index, trailing; 1052 int index, trailing;
1057 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);
1058 RETVAL = index; 1054 RETVAL = index + trailing;
1059} 1055}
1060 OUTPUT: 1056 OUTPUT:
1061 RETVAL 1057 RETVAL
1062 1058
1063void 1059void
1069 1065
1070 EXTEND (SP, 3); 1066 EXTEND (SP, 3);
1071 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1067 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
1072 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1068 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1073 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 }
1074} 1109}
1075 1110
1076void 1111void
1077render (CFPlus::Layout self, float x, float y, int flags = 0) 1112render (CFPlus::Layout self, float x, float y, int flags = 0)
1078 PPCODE: 1113 PPCODE:
1172} 1207}
1173 1208
1174MODULE = CFPlus PACKAGE = CFPlus::Map 1209MODULE = CFPlus PACKAGE = CFPlus::Map
1175 1210
1176CFPlus::Map 1211CFPlus::Map
1177new (SV *class, int map_width, int map_height) 1212new (SV *class)
1178 CODE: 1213 CODE:
1179 New (0, RETVAL, 1, struct map); 1214 New (0, RETVAL, 1, struct map);
1180 RETVAL->x = 0; 1215 RETVAL->x = 0;
1181 RETVAL->y = 0; 1216 RETVAL->y = 0;
1182 RETVAL->w = map_width; 1217 RETVAL->w = 0;
1183 RETVAL->h = map_height; 1218 RETVAL->h = 0;
1184 RETVAL->ox = 0; 1219 RETVAL->ox = 0;
1185 RETVAL->oy = 0; 1220 RETVAL->oy = 0;
1186 RETVAL->faces = 8192; 1221 RETVAL->faces = 8192;
1187 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1222 Newz (0, RETVAL->face, RETVAL->faces, mapface);
1188 RETVAL->texs = 8192; 1223 RETVAL->texs = 8192;
1199 map_clear (self); 1234 map_clear (self);
1200 Safefree (self->face); 1235 Safefree (self->face);
1201 Safefree (self->tex); 1236 Safefree (self->tex);
1202 Safefree (self); 1237 Safefree (self);
1203} 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;
1204 1245
1205void 1246void
1206clear (CFPlus::Map self) 1247clear (CFPlus::Map self)
1207 CODE: 1248 CODE:
1208 map_clear (self); 1249 map_clear (self);
1448} 1489}
1449 OUTPUT: 1490 OUTPUT:
1450 RETVAL 1491 RETVAL
1451 1492
1452void 1493void
1453draw (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)
1454 CODE: 1495 CODE:
1455{ 1496{
1456 int vx, vy;
1457 int x, y, z; 1497 int x, y, z;
1458 int last_name; 1498 int last_name;
1459 mapface face; 1499 mapface face;
1460
1461 vx = self->x + self->w / 2 - sw / 2 - shift_x;
1462 vy = self->y + self->h / 2 - sh / 2 - shift_y;
1463
1464 /*
1465 int vx = self->vx = self->w >= sw
1466 ? self->x + (self->w - sw) / 2
1467 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1468
1469 int vy = self->vy = self->h >= sh
1470 ? self->y + (self->h - sh) / 2
1471 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1472 */
1473 1500
1474 glColor4ub (255, 255, 255, 255); 1501 glColor4ub (255, 255, 255, 255);
1475 1502
1476 glEnable (GL_BLEND); 1503 glEnable (GL_BLEND);
1477 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1504 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1480 1507
1481 glBegin (GL_QUADS); 1508 glBegin (GL_QUADS);
1482 1509
1483 last_name = 0; 1510 last_name = 0;
1484 1511
1512 mx += self->x;
1513 my += self->y;
1514
1485 for (z = 0; z < 3; z++) 1515 for (z = 0; z < 3; z++)
1486 for (y = 0; y < sh; y++) 1516 for (y = 0; y < sh; y++)
1487 if (0 <= y + vy && y + vy < self->rows) 1517 if (0 <= y + my && y + my < self->rows)
1488 { 1518 {
1489 maprow *row = self->row + (y + vy); 1519 maprow *row = self->row + (y + my);
1490 1520
1491 for (x = 0; x < sw; x++) 1521 for (x = 0; x < sw; x++)
1492 if (row->c0 <= x + vx && x + vx < row->c1) 1522 if (row->c0 <= x + mx && x + mx < row->c1)
1493 { 1523 {
1494 mapcell *cell = row->col + (x + vx - row->c0); 1524 mapcell *cell = row->col + (x + mx - row->c0);
1495 1525
1496 face = cell->face [z]; 1526 face = cell->face [z];
1497 1527
1498 if (face && face < self->texs) 1528 if (face && face < self->texs)
1499 { 1529 {
1540 glDisable (GL_TEXTURE_2D); 1570 glDisable (GL_TEXTURE_2D);
1541 glDisable (GL_BLEND); 1571 glDisable (GL_BLEND);
1542 1572
1543 // top layer: overlays such as the health bar 1573 // top layer: overlays such as the health bar
1544 for (y = 0; y < sh; y++) 1574 for (y = 0; y < sh; y++)
1545 if (0 <= y + vy && y + vy < self->rows) 1575 if (0 <= y + my && y + my < self->rows)
1546 { 1576 {
1547 maprow *row = self->row + (y + vy); 1577 maprow *row = self->row + (y + my);
1548 1578
1549 for (x = 0; x < sw; x++) 1579 for (x = 0; x < sw; x++)
1550 if (row->c0 <= x + vx && x + vx < row->c1) 1580 if (row->c0 <= x + mx && x + mx < row->c1)
1551 { 1581 {
1552 mapcell *cell = row->col + (x + vx - row->c0); 1582 mapcell *cell = row->col + (x + mx - row->c0);
1553 1583
1554 int px = x * 32; 1584 int px = x * 32;
1555 int py = y * 32; 1585 int py = y * 32;
1556 1586
1557 if (cell->stat_hp) 1587 if (cell->stat_hp)
1631 glDisable (GL_BLEND); 1661 glDisable (GL_BLEND);
1632 glDisable (GL_TEXTURE_2D); 1662 glDisable (GL_TEXTURE_2D);
1633} 1663}
1634 1664
1635void 1665void
1636fow_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)
1637 PPCODE: 1667 PPCODE:
1638{ 1668{
1639 int vx, vy;
1640 int x, y; 1669 int x, y;
1641 int sw4 = (sw + 3) & ~3; 1670 int sw4 = (sw + 3) & ~3;
1642 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1671 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1643 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1672 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1644 1673
1645 memset (darkness, 255, sw4 * sh); 1674 memset (darkness, 255, sw4 * sh);
1646 SvPOK_only (darkness_sv); 1675 SvPOK_only (darkness_sv);
1647 SvCUR_set (darkness_sv, sw4 * sh); 1676 SvCUR_set (darkness_sv, sw4 * sh);
1648 1677
1649 vx = self->x + (self->w - sw + 1) / 2 - shift_x; 1678 mx += self->x;
1650 vy = self->y + (self->h - sh + 1) / 2 - shift_y; 1679 my += self->y;
1651 1680
1652 for (y = 0; y < sh; y++) 1681 for (y = 0; y < sh; y++)
1653 if (0 <= y + vy && y + vy < self->rows) 1682 if (0 <= y + my && y + my < self->rows)
1654 { 1683 {
1655 maprow *row = self->row + (y + vy); 1684 maprow *row = self->row + (y + my);
1656 1685
1657 for (x = 0; x < sw; x++) 1686 for (x = 0; x < sw; x++)
1658 if (row->c0 <= x + vx && x + vx < row->c1) 1687 if (row->c0 <= x + mx && x + mx < row->c1)
1659 { 1688 {
1660 mapcell *cell = row->col + (x + vx - row->c0); 1689 mapcell *cell = row->col + (x + mx - row->c0);
1661 1690
1662 darkness[y * sw4 + x] = cell->darkness 1691 darkness[y * sw4 + x] = cell->darkness
1663 ? 255 - (cell->darkness - 1) 1692 ? 255 - (cell->darkness - 1)
1664 : 255 - FOW_DARKNESS; 1693 : 255 - FOW_DARKNESS;
1665 } 1694 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines