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 |
… | |
… | |
315 | |
310 | |
316 | cell = row->col + x - row->c0; |
311 | cell = row->col + x - row->c0; |
317 | |
312 | |
318 | cell->darkness = 0; |
313 | cell->darkness = 0; |
319 | cell->stat_hp = 0; |
314 | cell->stat_hp = 0; |
|
|
315 | cell->flags = 0; |
|
|
316 | cell->player = 0; |
320 | } |
317 | } |
321 | } |
318 | } |
322 | } |
319 | } |
323 | |
320 | |
324 | static void |
321 | static void |
… | |
… | |
649 | #ifndef _WIN32 |
646 | #ifndef _WIN32 |
650 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
647 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
651 | #endif |
648 | #endif |
652 | |
649 | |
653 | void |
650 | void |
|
|
651 | win32_proxy_info () |
|
|
652 | PPCODE: |
|
|
653 | { |
|
|
654 | #ifdef _WIN32 |
|
|
655 | char buffer[2048]; |
|
|
656 | DWORD buflen; |
|
|
657 | |
|
|
658 | EXTEND (SP, 3); |
|
|
659 | |
|
|
660 | buflen = sizeof (buffer); |
|
|
661 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
662 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
663 | { |
|
|
664 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
665 | |
|
|
666 | buflen = sizeof (buffer); |
|
|
667 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
668 | { |
|
|
669 | PUSHs (newSVpv (buffer, 0)); |
|
|
670 | |
|
|
671 | buflen = sizeof (buffer); |
|
|
672 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
673 | PUSHs (newSVpv (buffer, 0)); |
|
|
674 | } |
|
|
675 | } |
|
|
676 | #endif |
|
|
677 | } |
|
|
678 | |
|
|
679 | void |
654 | add_font (char *file) |
680 | add_font (char *file) |
655 | CODE: |
681 | CODE: |
656 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
682 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
657 | |
683 | |
658 | void |
684 | void |
… | |
… | |
760 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
786 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
761 | #endif |
787 | #endif |
762 | _exit (1); |
788 | _exit (1); |
763 | |
789 | |
764 | void |
790 | void |
765 | _exit (int retval) |
791 | _exit (int retval = 0) |
766 | CODE: |
792 | CODE: |
|
|
793 | #ifdef WIN32 |
|
|
794 | ExitThread (retval); // unclean, please beam me up |
|
|
795 | #else |
767 | _exit (retval); |
796 | _exit (retval); |
|
|
797 | #endif |
768 | |
798 | |
769 | MODULE = CFPlus PACKAGE = CFPlus::Font |
799 | MODULE = CFPlus PACKAGE = CFPlus::Font |
770 | |
800 | |
771 | CFPlus::Font |
801 | CFPlus::Font |
772 | new_from_file (SV *class, char *path, int id = 0) |
802 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
1019 | xy_to_index (CFPlus::Layout self, int x, int y) |
1049 | xy_to_index (CFPlus::Layout self, int x, int y) |
1020 | CODE: |
1050 | CODE: |
1021 | { |
1051 | { |
1022 | int index, trailing; |
1052 | int index, trailing; |
1023 | 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); |
1024 | RETVAL = index; |
1054 | RETVAL = index + trailing; |
1025 | } |
1055 | } |
1026 | OUTPUT: |
1056 | OUTPUT: |
1027 | RETVAL |
1057 | RETVAL |
1028 | |
1058 | |
1029 | void |
1059 | void |
… | |
… | |
1035 | |
1065 | |
1036 | EXTEND (SP, 3); |
1066 | EXTEND (SP, 3); |
1037 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1067 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1038 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1068 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1039 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1069 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
|
|
1070 | } |
|
|
1071 | |
|
|
1072 | void |
|
|
1073 | index_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 | |
|
|
1086 | void |
|
|
1087 | line_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 | } |
1040 | } |
1109 | } |
1041 | |
1110 | |
1042 | void |
1111 | void |
1043 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1112 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1044 | PPCODE: |
1113 | PPCODE: |
… | |
… | |
1138 | } |
1207 | } |
1139 | |
1208 | |
1140 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1209 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1141 | |
1210 | |
1142 | CFPlus::Map |
1211 | CFPlus::Map |
1143 | new (SV *class, int map_width, int map_height) |
1212 | new (SV *class) |
1144 | CODE: |
1213 | CODE: |
1145 | New (0, RETVAL, 1, struct map); |
1214 | New (0, RETVAL, 1, struct map); |
1146 | RETVAL->x = 0; |
1215 | RETVAL->x = 0; |
1147 | RETVAL->y = 0; |
1216 | RETVAL->y = 0; |
1148 | RETVAL->w = map_width; |
1217 | RETVAL->w = 0; |
1149 | RETVAL->h = map_height; |
1218 | RETVAL->h = 0; |
1150 | RETVAL->ox = 0; |
1219 | RETVAL->ox = 0; |
1151 | RETVAL->oy = 0; |
1220 | RETVAL->oy = 0; |
1152 | RETVAL->faces = 8192; |
1221 | RETVAL->faces = 8192; |
1153 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1222 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1154 | RETVAL->texs = 8192; |
1223 | RETVAL->texs = 8192; |
… | |
… | |
1165 | map_clear (self); |
1234 | map_clear (self); |
1166 | Safefree (self->face); |
1235 | Safefree (self->face); |
1167 | Safefree (self->tex); |
1236 | Safefree (self->tex); |
1168 | Safefree (self); |
1237 | Safefree (self); |
1169 | } |
1238 | } |
|
|
1239 | |
|
|
1240 | void |
|
|
1241 | resize (CFPlus::Map self, int map_width, int map_height) |
|
|
1242 | CODE: |
|
|
1243 | self->w = map_width; |
|
|
1244 | self->h = map_height; |
1170 | |
1245 | |
1171 | void |
1246 | void |
1172 | clear (CFPlus::Map self) |
1247 | clear (CFPlus::Map self) |
1173 | CODE: |
1248 | CODE: |
1174 | map_clear (self); |
1249 | map_clear (self); |
… | |
… | |
1244 | void |
1319 | void |
1245 | scroll (CFPlus::Map self, int dx, int dy) |
1320 | scroll (CFPlus::Map self, int dx, int dy) |
1246 | CODE: |
1321 | CODE: |
1247 | { |
1322 | { |
1248 | if (dx > 0) |
1323 | if (dx > 0) |
1249 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1324 | map_blank (self, self->x, self->y, dx, self->h); |
1250 | else if (dx < 0) |
1325 | else if (dx < 0) |
1251 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1326 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1252 | |
1327 | |
1253 | if (dy > 0) |
1328 | if (dy > 0) |
1254 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1329 | map_blank (self, self->x, self->y, self->w, dy); |
1255 | else if (dy < 0) |
1330 | else if (dy < 0) |
1256 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1331 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1257 | |
1332 | |
1258 | self->ox += dx; self->x += dx; |
1333 | self->ox += dx; self->x += dx; |
1259 | self->oy += dy; self->y += dy; |
1334 | self->oy += dy; self->y += dy; |
1260 | |
1335 | |
1261 | while (self->y < 0) |
1336 | while (self->y < 0) |
… | |
… | |
1287 | |
1362 | |
1288 | if (flags & 15) |
1363 | if (flags & 15) |
1289 | { |
1364 | { |
1290 | if (!cell->darkness) |
1365 | if (!cell->darkness) |
1291 | { |
1366 | { |
|
|
1367 | memset (cell, 0, sizeof (*cell)); |
1292 | cell->darkness = 256; |
1368 | cell->darkness = 256; |
1293 | cell->face [0] = 0; |
|
|
1294 | cell->face [1] = 0; |
|
|
1295 | cell->face [2] = 0; |
|
|
1296 | } |
1369 | } |
1297 | |
1370 | |
1298 | //TODO: don't trust server data to be in-range(!) |
1371 | //TODO: don't trust server data to be in-range(!) |
1299 | |
1372 | |
1300 | if (flags & 8) |
1373 | if (flags & 8) |
… | |
… | |
1351 | { |
1424 | { |
1352 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1425 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1353 | } |
1426 | } |
1354 | } |
1427 | } |
1355 | else |
1428 | else |
1356 | { |
|
|
1357 | cell->darkness = 0; |
1429 | cell->darkness = 0; |
1358 | cell->stat_hp = 0; |
|
|
1359 | } |
|
|
1360 | } |
1430 | } |
1361 | } |
1431 | } |
1362 | |
1432 | |
1363 | SV * |
1433 | SV * |
1364 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1434 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
… | |
… | |
1419 | } |
1489 | } |
1420 | OUTPUT: |
1490 | OUTPUT: |
1421 | RETVAL |
1491 | RETVAL |
1422 | |
1492 | |
1423 | void |
1493 | void |
1424 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1494 | draw (CFPlus::Map self, int mx, int my, int sw, int sh) |
1425 | CODE: |
1495 | CODE: |
1426 | { |
1496 | { |
1427 | int vx, vy; |
|
|
1428 | int x, y, z; |
1497 | int x, y, z; |
1429 | int last_name; |
1498 | int last_name; |
1430 | mapface face; |
1499 | mapface face; |
1431 | |
|
|
1432 | vx = self->x + self->w / 2 - sw / 2 - shift_x; |
|
|
1433 | vy = self->y + self->h / 2 - sh / 2 - shift_y; |
|
|
1434 | |
|
|
1435 | /* |
|
|
1436 | int vx = self->vx = self->w >= sw |
|
|
1437 | ? self->x + (self->w - sw) / 2 |
|
|
1438 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
|
|
1439 | |
|
|
1440 | int vy = self->vy = self->h >= sh |
|
|
1441 | ? self->y + (self->h - sh) / 2 |
|
|
1442 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
1443 | */ |
|
|
1444 | |
1500 | |
1445 | glColor4ub (255, 255, 255, 255); |
1501 | glColor4ub (255, 255, 255, 255); |
1446 | |
1502 | |
1447 | glEnable (GL_BLEND); |
1503 | glEnable (GL_BLEND); |
1448 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1504 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
… | |
… | |
1451 | |
1507 | |
1452 | glBegin (GL_QUADS); |
1508 | glBegin (GL_QUADS); |
1453 | |
1509 | |
1454 | last_name = 0; |
1510 | last_name = 0; |
1455 | |
1511 | |
|
|
1512 | mx += self->x; |
|
|
1513 | my += self->y; |
|
|
1514 | |
1456 | for (z = 0; z < 3; z++) |
1515 | for (z = 0; z < 3; z++) |
1457 | for (y = 0; y < sh; y++) |
1516 | for (y = 0; y < sh; y++) |
1458 | if (0 <= y + vy && y + vy < self->rows) |
1517 | if (0 <= y + my && y + my < self->rows) |
1459 | { |
1518 | { |
1460 | maprow *row = self->row + (y + vy); |
1519 | maprow *row = self->row + (y + my); |
1461 | |
1520 | |
1462 | for (x = 0; x < sw; x++) |
1521 | for (x = 0; x < sw; x++) |
1463 | if (row->c0 <= x + vx && x + vx < row->c1) |
1522 | if (row->c0 <= x + mx && x + mx < row->c1) |
1464 | { |
1523 | { |
1465 | mapcell *cell = row->col + (x + vx - row->c0); |
1524 | mapcell *cell = row->col + (x + mx - row->c0); |
1466 | |
1525 | |
1467 | face = cell->face [z]; |
1526 | face = cell->face [z]; |
1468 | |
1527 | |
1469 | if (face && face < self->texs) |
1528 | if (face && face < self->texs) |
1470 | { |
1529 | { |
… | |
… | |
1511 | glDisable (GL_TEXTURE_2D); |
1570 | glDisable (GL_TEXTURE_2D); |
1512 | glDisable (GL_BLEND); |
1571 | glDisable (GL_BLEND); |
1513 | |
1572 | |
1514 | // top layer: overlays such as the health bar |
1573 | // top layer: overlays such as the health bar |
1515 | for (y = 0; y < sh; y++) |
1574 | for (y = 0; y < sh; y++) |
1516 | if (0 <= y + vy && y + vy < self->rows) |
1575 | if (0 <= y + my && y + my < self->rows) |
1517 | { |
1576 | { |
1518 | maprow *row = self->row + (y + vy); |
1577 | maprow *row = self->row + (y + my); |
1519 | |
1578 | |
1520 | for (x = 0; x < sw; x++) |
1579 | for (x = 0; x < sw; x++) |
1521 | if (row->c0 <= x + vx && x + vx < row->c1) |
1580 | if (row->c0 <= x + mx && x + mx < row->c1) |
1522 | { |
1581 | { |
1523 | mapcell *cell = row->col + (x + vx - row->c0); |
1582 | mapcell *cell = row->col + (x + mx - row->c0); |
1524 | |
1583 | |
1525 | int px = x * 32; |
1584 | int px = x * 32; |
1526 | int py = y * 32; |
1585 | int py = y * 32; |
1527 | |
1586 | |
1528 | if (cell->stat_hp) |
1587 | if (cell->stat_hp) |
… | |
… | |
1602 | glDisable (GL_BLEND); |
1661 | glDisable (GL_BLEND); |
1603 | glDisable (GL_TEXTURE_2D); |
1662 | glDisable (GL_TEXTURE_2D); |
1604 | } |
1663 | } |
1605 | |
1664 | |
1606 | void |
1665 | void |
1607 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1666 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
1608 | PPCODE: |
1667 | PPCODE: |
1609 | { |
1668 | { |
1610 | int vx, vy; |
|
|
1611 | int x, y; |
1669 | int x, y; |
1612 | int sw4 = (sw + 3) & ~3; |
1670 | int sw4 = (sw + 3) & ~3; |
1613 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1671 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1614 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1672 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1615 | |
1673 | |
1616 | memset (darkness, 255, sw4 * sh); |
1674 | memset (darkness, 255, sw4 * sh); |
1617 | SvPOK_only (darkness_sv); |
1675 | SvPOK_only (darkness_sv); |
1618 | SvCUR_set (darkness_sv, sw4 * sh); |
1676 | SvCUR_set (darkness_sv, sw4 * sh); |
1619 | |
1677 | |
1620 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
1678 | mx += self->x; |
1621 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
1679 | my += self->y; |
1622 | |
1680 | |
1623 | for (y = 0; y < sh; y++) |
1681 | for (y = 0; y < sh; y++) |
1624 | if (0 <= y + vy && y + vy < self->rows) |
1682 | if (0 <= y + my && y + my < self->rows) |
1625 | { |
1683 | { |
1626 | maprow *row = self->row + (y + vy); |
1684 | maprow *row = self->row + (y + my); |
1627 | |
1685 | |
1628 | for (x = 0; x < sw; x++) |
1686 | for (x = 0; x < sw; x++) |
1629 | if (row->c0 <= x + vx && x + vx < row->c1) |
1687 | if (row->c0 <= x + mx && x + mx < row->c1) |
1630 | { |
1688 | { |
1631 | mapcell *cell = row->col + (x + vx - row->c0); |
1689 | mapcell *cell = row->col + (x + mx - row->c0); |
1632 | |
1690 | |
1633 | darkness[y * sw4 + x] = cell->darkness |
1691 | darkness[y * sw4 + x] = cell->darkness |
1634 | ? 255 - (cell->darkness - 1) |
1692 | ? 255 - (cell->darkness - 1) |
1635 | : 255 - FOW_DARKNESS; |
1693 | : 255 - FOW_DARKNESS; |
1636 | } |
1694 | } |