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 |
… | |
… | |
651 | #ifndef _WIN32 |
646 | #ifndef _WIN32 |
652 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
647 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
653 | #endif |
648 | #endif |
654 | |
649 | |
655 | 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 |
656 | add_font (char *file) |
680 | add_font (char *file) |
657 | CODE: |
681 | CODE: |
658 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
682 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
659 | |
683 | |
660 | void |
684 | void |
… | |
… | |
762 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
786 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
763 | #endif |
787 | #endif |
764 | _exit (1); |
788 | _exit (1); |
765 | |
789 | |
766 | void |
790 | void |
767 | _exit (int retval) |
791 | _exit (int retval = 0) |
768 | CODE: |
792 | CODE: |
|
|
793 | #ifdef WIN32 |
|
|
794 | ExitThread (retval); // unclean, please beam me up |
|
|
795 | #else |
769 | _exit (retval); |
796 | _exit (retval); |
|
|
797 | #endif |
770 | |
798 | |
771 | MODULE = CFPlus PACKAGE = CFPlus::Font |
799 | MODULE = CFPlus PACKAGE = CFPlus::Font |
772 | |
800 | |
773 | CFPlus::Font |
801 | CFPlus::Font |
774 | new_from_file (SV *class, char *path, int id = 0) |
802 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
1140 | } |
1168 | } |
1141 | |
1169 | |
1142 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1170 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1143 | |
1171 | |
1144 | CFPlus::Map |
1172 | CFPlus::Map |
1145 | new (SV *class, int map_width, int map_height) |
1173 | new (SV *class) |
1146 | CODE: |
1174 | CODE: |
1147 | New (0, RETVAL, 1, struct map); |
1175 | New (0, RETVAL, 1, struct map); |
1148 | RETVAL->x = 0; |
1176 | RETVAL->x = 0; |
1149 | RETVAL->y = 0; |
1177 | RETVAL->y = 0; |
1150 | RETVAL->w = map_width; |
1178 | RETVAL->w = 0; |
1151 | RETVAL->h = map_height; |
1179 | RETVAL->h = 0; |
1152 | RETVAL->ox = 0; |
1180 | RETVAL->ox = 0; |
1153 | RETVAL->oy = 0; |
1181 | RETVAL->oy = 0; |
1154 | RETVAL->faces = 8192; |
1182 | RETVAL->faces = 8192; |
1155 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1183 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1156 | RETVAL->texs = 8192; |
1184 | RETVAL->texs = 8192; |
… | |
… | |
1167 | map_clear (self); |
1195 | map_clear (self); |
1168 | Safefree (self->face); |
1196 | Safefree (self->face); |
1169 | Safefree (self->tex); |
1197 | Safefree (self->tex); |
1170 | Safefree (self); |
1198 | Safefree (self); |
1171 | } |
1199 | } |
|
|
1200 | |
|
|
1201 | void |
|
|
1202 | resize (CFPlus::Map self, int map_width, int map_height) |
|
|
1203 | CODE: |
|
|
1204 | self->w = map_width; |
|
|
1205 | self->h = map_height; |
1172 | |
1206 | |
1173 | void |
1207 | void |
1174 | clear (CFPlus::Map self) |
1208 | clear (CFPlus::Map self) |
1175 | CODE: |
1209 | CODE: |
1176 | map_clear (self); |
1210 | map_clear (self); |
… | |
… | |
1333 | } |
1367 | } |
1334 | while (ext & 0x80); |
1368 | while (ext & 0x80); |
1335 | } |
1369 | } |
1336 | else |
1370 | else |
1337 | cell->darkness = *data++ + 1; |
1371 | cell->darkness = *data++ + 1; |
1338 | |
|
|
1339 | } |
1372 | } |
1340 | |
1373 | |
1341 | if (flags & 4) |
1374 | if (flags & 4) |
1342 | { |
1375 | { |
1343 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1376 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
… | |
… | |
1417 | } |
1450 | } |
1418 | OUTPUT: |
1451 | OUTPUT: |
1419 | RETVAL |
1452 | RETVAL |
1420 | |
1453 | |
1421 | void |
1454 | void |
1422 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1455 | draw (CFPlus::Map self, int mx, int my, int sw, int sh) |
1423 | CODE: |
1456 | CODE: |
1424 | { |
1457 | { |
1425 | int vx, vy; |
|
|
1426 | int x, y, z; |
1458 | int x, y, z; |
1427 | int last_name; |
1459 | int last_name; |
1428 | mapface face; |
1460 | mapface face; |
1429 | |
|
|
1430 | vx = self->x + self->w / 2 - sw / 2 - shift_x; |
|
|
1431 | vy = self->y + self->h / 2 - sh / 2 - shift_y; |
|
|
1432 | |
|
|
1433 | /* |
|
|
1434 | int vx = self->vx = self->w >= sw |
|
|
1435 | ? self->x + (self->w - sw) / 2 |
|
|
1436 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
|
|
1437 | |
|
|
1438 | int vy = self->vy = self->h >= sh |
|
|
1439 | ? self->y + (self->h - sh) / 2 |
|
|
1440 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
1441 | */ |
|
|
1442 | |
1461 | |
1443 | glColor4ub (255, 255, 255, 255); |
1462 | glColor4ub (255, 255, 255, 255); |
1444 | |
1463 | |
1445 | glEnable (GL_BLEND); |
1464 | glEnable (GL_BLEND); |
1446 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1465 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
… | |
… | |
1449 | |
1468 | |
1450 | glBegin (GL_QUADS); |
1469 | glBegin (GL_QUADS); |
1451 | |
1470 | |
1452 | last_name = 0; |
1471 | last_name = 0; |
1453 | |
1472 | |
|
|
1473 | mx += self->x; |
|
|
1474 | my += self->y; |
|
|
1475 | |
1454 | for (z = 0; z < 3; z++) |
1476 | for (z = 0; z < 3; z++) |
1455 | for (y = 0; y < sh; y++) |
1477 | for (y = 0; y < sh; y++) |
1456 | if (0 <= y + vy && y + vy < self->rows) |
1478 | if (0 <= y + my && y + my < self->rows) |
1457 | { |
1479 | { |
1458 | maprow *row = self->row + (y + vy); |
1480 | maprow *row = self->row + (y + my); |
1459 | |
1481 | |
1460 | for (x = 0; x < sw; x++) |
1482 | for (x = 0; x < sw; x++) |
1461 | if (row->c0 <= x + vx && x + vx < row->c1) |
1483 | if (row->c0 <= x + mx && x + mx < row->c1) |
1462 | { |
1484 | { |
1463 | mapcell *cell = row->col + (x + vx - row->c0); |
1485 | mapcell *cell = row->col + (x + mx - row->c0); |
1464 | |
1486 | |
1465 | face = cell->face [z]; |
1487 | face = cell->face [z]; |
1466 | |
1488 | |
1467 | if (face && face < self->texs) |
1489 | if (face && face < self->texs) |
1468 | { |
1490 | { |
… | |
… | |
1509 | glDisable (GL_TEXTURE_2D); |
1531 | glDisable (GL_TEXTURE_2D); |
1510 | glDisable (GL_BLEND); |
1532 | glDisable (GL_BLEND); |
1511 | |
1533 | |
1512 | // top layer: overlays such as the health bar |
1534 | // top layer: overlays such as the health bar |
1513 | for (y = 0; y < sh; y++) |
1535 | for (y = 0; y < sh; y++) |
1514 | if (0 <= y + vy && y + vy < self->rows) |
1536 | if (0 <= y + my && y + my < self->rows) |
1515 | { |
1537 | { |
1516 | maprow *row = self->row + (y + vy); |
1538 | maprow *row = self->row + (y + my); |
1517 | |
1539 | |
1518 | for (x = 0; x < sw; x++) |
1540 | for (x = 0; x < sw; x++) |
1519 | if (row->c0 <= x + vx && x + vx < row->c1) |
1541 | if (row->c0 <= x + mx && x + mx < row->c1) |
1520 | { |
1542 | { |
1521 | mapcell *cell = row->col + (x + vx - row->c0); |
1543 | mapcell *cell = row->col + (x + mx - row->c0); |
1522 | |
1544 | |
1523 | int px = x * 32; |
1545 | int px = x * 32; |
1524 | int py = y * 32; |
1546 | int py = y * 32; |
1525 | |
1547 | |
1526 | if (cell->stat_hp) |
1548 | if (cell->stat_hp) |
… | |
… | |
1600 | glDisable (GL_BLEND); |
1622 | glDisable (GL_BLEND); |
1601 | glDisable (GL_TEXTURE_2D); |
1623 | glDisable (GL_TEXTURE_2D); |
1602 | } |
1624 | } |
1603 | |
1625 | |
1604 | void |
1626 | void |
1605 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1627 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
1606 | PPCODE: |
1628 | PPCODE: |
1607 | { |
1629 | { |
1608 | int vx, vy; |
|
|
1609 | int x, y; |
1630 | int x, y; |
1610 | int sw4 = (sw + 3) & ~3; |
1631 | int sw4 = (sw + 3) & ~3; |
1611 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1632 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1612 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1633 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1613 | |
1634 | |
1614 | memset (darkness, 255, sw4 * sh); |
1635 | memset (darkness, 255, sw4 * sh); |
1615 | SvPOK_only (darkness_sv); |
1636 | SvPOK_only (darkness_sv); |
1616 | SvCUR_set (darkness_sv, sw4 * sh); |
1637 | SvCUR_set (darkness_sv, sw4 * sh); |
1617 | |
1638 | |
1618 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
1639 | mx += self->x; |
1619 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
1640 | my += self->y; |
1620 | |
1641 | |
1621 | for (y = 0; y < sh; y++) |
1642 | for (y = 0; y < sh; y++) |
1622 | if (0 <= y + vy && y + vy < self->rows) |
1643 | if (0 <= y + my && y + my < self->rows) |
1623 | { |
1644 | { |
1624 | maprow *row = self->row + (y + vy); |
1645 | maprow *row = self->row + (y + my); |
1625 | |
1646 | |
1626 | for (x = 0; x < sw; x++) |
1647 | for (x = 0; x < sw; x++) |
1627 | if (row->c0 <= x + vx && x + vx < row->c1) |
1648 | if (row->c0 <= x + mx && x + mx < row->c1) |
1628 | { |
1649 | { |
1629 | mapcell *cell = row->col + (x + vx - row->c0); |
1650 | mapcell *cell = row->col + (x + mx - row->c0); |
1630 | |
1651 | |
1631 | darkness[y * sw4 + x] = cell->darkness |
1652 | darkness[y * sw4 + x] = cell->darkness |
1632 | ? 255 - (cell->darkness - 1) |
1653 | ? 255 - (cell->darkness - 1) |
1633 | : 255 - FOW_DARKNESS; |
1654 | : 255 - FOW_DARKNESS; |
1634 | } |
1655 | } |