… | |
… | |
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" |
13 | |
14 | |
14 | #ifdef _WIN32 |
15 | #ifdef _WIN32 |
15 | # undef pipe |
16 | # undef pipe |
16 | #endif |
17 | #endif |
17 | |
18 | |
|
|
19 | #include <assert.h> |
18 | #include <math.h> |
20 | #include <math.h> |
19 | #include <string.h> |
21 | #include <string.h> |
20 | #include <stdio.h> |
22 | #include <stdio.h> |
21 | #include <stdlib.h> |
23 | #include <stdlib.h> |
22 | |
24 | |
… | |
… | |
37 | # include <sys/types.h> |
39 | # include <sys/types.h> |
38 | # include <sys/socket.h> |
40 | # include <sys/socket.h> |
39 | # include <netinet/in.h> |
41 | # include <netinet/in.h> |
40 | # include <netinet/tcp.h> |
42 | # include <netinet/tcp.h> |
41 | # include <inttypes.h> |
43 | # 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 |
44 | #endif |
50 | |
45 | |
51 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
46 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
52 | |
47 | |
53 | #define FOW_DARKNESS 32 |
48 | #define FOW_DARKNESS 32 |
54 | |
49 | |
55 | #define MAP_EXTEND_X 32 |
50 | #define MAP_EXTEND_X 32 |
56 | #define MAP_EXTEND_Y 512 |
51 | #define MAP_EXTEND_Y 512 |
… | |
… | |
365 | n |= n >> 16; |
360 | n |= n >> 16; |
366 | |
361 | |
367 | return n + 1; |
362 | return n + 1; |
368 | } |
363 | } |
369 | |
364 | |
|
|
365 | /* SDL should provide this, really. */ |
|
|
366 | #define SDLK_MODIFIER_MIN 300 |
|
|
367 | #define SDLK_MODIFIER_MAX 314 |
|
|
368 | |
370 | MODULE = CFPlus PACKAGE = CFPlus |
369 | MODULE = CFPlus PACKAGE = CFPlus |
371 | |
370 | |
372 | PROTOTYPES: ENABLE |
371 | PROTOTYPES: ENABLE |
373 | |
372 | |
374 | BOOT: |
373 | BOOT: |
… | |
… | |
377 | static const struct { |
376 | static const struct { |
378 | const char *name; |
377 | const char *name; |
379 | IV iv; |
378 | IV iv; |
380 | } *civ, const_iv[] = { |
379 | } *civ, const_iv[] = { |
381 | # define const_iv(name) { # name, (IV)name } |
380 | # define const_iv(name) { # name, (IV)name } |
|
|
381 | const_iv (SDLK_MODIFIER_MIN), |
|
|
382 | const_iv (SDLK_MODIFIER_MAX), |
|
|
383 | |
382 | const_iv (SDL_ACTIVEEVENT), |
384 | const_iv (SDL_ACTIVEEVENT), |
383 | const_iv (SDL_KEYDOWN), |
385 | const_iv (SDL_KEYDOWN), |
384 | const_iv (SDL_KEYUP), |
386 | const_iv (SDL_KEYUP), |
385 | const_iv (SDL_MOUSEMOTION), |
387 | const_iv (SDL_MOUSEMOTION), |
386 | const_iv (SDL_MOUSEBUTTONDOWN), |
388 | const_iv (SDL_MOUSEBUTTONDOWN), |
… | |
… | |
395 | const_iv (SDL_EVENT_RESERVEDA), |
397 | const_iv (SDL_EVENT_RESERVEDA), |
396 | const_iv (SDL_EVENT_RESERVEDB), |
398 | const_iv (SDL_EVENT_RESERVEDB), |
397 | const_iv (SDL_VIDEORESIZE), |
399 | const_iv (SDL_VIDEORESIZE), |
398 | const_iv (SDL_VIDEOEXPOSE), |
400 | const_iv (SDL_VIDEOEXPOSE), |
399 | const_iv (SDL_USEREVENT), |
401 | const_iv (SDL_USEREVENT), |
|
|
402 | |
|
|
403 | const_iv (SDL_APPINPUTFOCUS), |
|
|
404 | const_iv (SDL_APPMOUSEFOCUS), |
|
|
405 | const_iv (SDL_APPACTIVE), |
|
|
406 | |
400 | const_iv (SDLK_KP0), |
407 | const_iv (SDLK_KP0), |
401 | const_iv (SDLK_KP1), |
408 | const_iv (SDLK_KP1), |
402 | const_iv (SDLK_KP2), |
409 | const_iv (SDLK_KP2), |
403 | const_iv (SDLK_KP3), |
410 | const_iv (SDLK_KP3), |
404 | const_iv (SDLK_KP4), |
411 | const_iv (SDLK_KP4), |
… | |
… | |
459 | const_iv (SDLK_BREAK), |
466 | const_iv (SDLK_BREAK), |
460 | const_iv (SDLK_MENU), |
467 | const_iv (SDLK_MENU), |
461 | const_iv (SDLK_POWER), |
468 | const_iv (SDLK_POWER), |
462 | const_iv (SDLK_EURO), |
469 | const_iv (SDLK_EURO), |
463 | const_iv (SDLK_UNDO), |
470 | const_iv (SDLK_UNDO), |
|
|
471 | |
464 | const_iv (KMOD_NONE), |
472 | const_iv (KMOD_NONE), |
|
|
473 | const_iv (KMOD_SHIFT), |
465 | const_iv (KMOD_LSHIFT), |
474 | const_iv (KMOD_LSHIFT), |
466 | const_iv (KMOD_RSHIFT), |
475 | const_iv (KMOD_RSHIFT), |
|
|
476 | const_iv (KMOD_CTRL), |
467 | const_iv (KMOD_LCTRL), |
477 | const_iv (KMOD_LCTRL), |
468 | const_iv (KMOD_RCTRL), |
478 | const_iv (KMOD_RCTRL), |
|
|
479 | const_iv (KMOD_ALT), |
469 | const_iv (KMOD_LALT), |
480 | const_iv (KMOD_LALT), |
470 | const_iv (KMOD_RALT), |
481 | const_iv (KMOD_RALT), |
|
|
482 | const_iv (KMOD_META), |
471 | const_iv (KMOD_LMETA), |
483 | const_iv (KMOD_LMETA), |
472 | const_iv (KMOD_RMETA), |
484 | const_iv (KMOD_RMETA), |
473 | const_iv (KMOD_NUM), |
485 | const_iv (KMOD_NUM), |
474 | const_iv (KMOD_CAPS), |
486 | const_iv (KMOD_CAPS), |
475 | const_iv (KMOD_MODE), |
487 | const_iv (KMOD_MODE), |
476 | const_iv (KMOD_CTRL), |
|
|
477 | const_iv (KMOD_SHIFT), |
|
|
478 | const_iv (KMOD_ALT), |
|
|
479 | const_iv (KMOD_META) |
|
|
480 | # undef const_iv |
488 | # undef const_iv |
481 | }; |
489 | }; |
482 | |
490 | |
483 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
491 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
484 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
492 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
493 | |
|
|
494 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
|
|
495 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
485 | } |
496 | } |
|
|
497 | |
|
|
498 | void |
|
|
499 | weaken (SV *rv) |
|
|
500 | PROTOTYPE: $ |
|
|
501 | CODE: |
|
|
502 | sv_rvweaken (rv); |
486 | |
503 | |
487 | int |
504 | int |
488 | in_destruct () |
505 | in_destruct () |
489 | CODE: |
506 | CODE: |
490 | RETVAL = PL_main_cv == Nullcv; |
507 | RETVAL = PL_main_cv == Nullcv; |
… | |
… | |
593 | case SDL_KEYDOWN: |
610 | case SDL_KEYDOWN: |
594 | case SDL_KEYUP: |
611 | case SDL_KEYUP: |
595 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
612 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
596 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
613 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
597 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
614 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
|
|
615 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
598 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
616 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
599 | break; |
617 | break; |
600 | |
618 | |
601 | case SDL_ACTIVEEVENT: |
619 | case SDL_ACTIVEEVENT: |
602 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
620 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
656 | void |
674 | void |
657 | win32_proxy_info () |
675 | win32_proxy_info () |
658 | PPCODE: |
676 | PPCODE: |
659 | { |
677 | { |
660 | #ifdef _WIN32 |
678 | #ifdef _WIN32 |
661 | INTERNET_PROXY_INFO proxyinfo; |
|
|
662 | char buffer[2048]; |
679 | char buffer[2048]; |
663 | DWORD buflen; |
680 | DWORD buflen; |
664 | |
681 | |
665 | EXTEND (SP, 3); |
682 | EXTEND (SP, 3); |
666 | |
683 | |
… | |
… | |
793 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
810 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
794 | #endif |
811 | #endif |
795 | _exit (1); |
812 | _exit (1); |
796 | |
813 | |
797 | void |
814 | void |
798 | _exit (int retval) |
815 | _exit (int retval = 0) |
799 | CODE: |
816 | CODE: |
|
|
817 | #ifdef WIN32 |
|
|
818 | ExitThread (retval); // unclean, please beam me up |
|
|
819 | #else |
800 | _exit (retval); |
820 | _exit (retval); |
|
|
821 | #endif |
801 | |
822 | |
802 | MODULE = CFPlus PACKAGE = CFPlus::Font |
823 | MODULE = CFPlus PACKAGE = CFPlus::Font |
803 | |
824 | |
804 | CFPlus::Font |
825 | CFPlus::Font |
805 | new_from_file (SV *class, char *path, int id = 0) |
826 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
1052 | xy_to_index (CFPlus::Layout self, int x, int y) |
1073 | xy_to_index (CFPlus::Layout self, int x, int y) |
1053 | CODE: |
1074 | CODE: |
1054 | { |
1075 | { |
1055 | int index, trailing; |
1076 | int index, trailing; |
1056 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1077 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1057 | RETVAL = index; |
1078 | RETVAL = index + trailing; |
1058 | } |
1079 | } |
1059 | OUTPUT: |
1080 | OUTPUT: |
1060 | RETVAL |
1081 | RETVAL |
1061 | |
1082 | |
1062 | void |
1083 | void |
… | |
… | |
1068 | |
1089 | |
1069 | EXTEND (SP, 3); |
1090 | EXTEND (SP, 3); |
1070 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1091 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1071 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1092 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1072 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1093 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
|
|
1094 | } |
|
|
1095 | |
|
|
1096 | void |
|
|
1097 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
|
|
1098 | PPCODE: |
|
|
1099 | { |
|
|
1100 | int line, x; |
|
|
1101 | |
|
|
1102 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1103 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
|
|
1104 | |
|
|
1105 | EXTEND (SP, 2); |
|
|
1106 | PUSHs (sv_2mortal (newSViv (line - 1))); |
|
|
1107 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
|
|
1108 | } |
|
|
1109 | |
|
|
1110 | void |
|
|
1111 | line_x_to_index (CFPlus::Layout self, int line, int x) |
|
|
1112 | PPCODE: |
|
|
1113 | { |
|
|
1114 | PangoLayoutLine *lp; |
|
|
1115 | int index, trailing; |
|
|
1116 | |
|
|
1117 | if (line < 0) |
|
|
1118 | XSRETURN_EMPTY; |
|
|
1119 | |
|
|
1120 | if (!(lp = pango_layout_get_line (self->pl, line))) |
|
|
1121 | XSRETURN_EMPTY; /* do better */ |
|
|
1122 | |
|
|
1123 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
|
|
1124 | |
|
|
1125 | EXTEND (SP, 2); |
|
|
1126 | if (GIMME_V == G_SCALAR) |
|
|
1127 | PUSHs (sv_2mortal (newSViv (index + trailing))); |
|
|
1128 | else |
|
|
1129 | { |
|
|
1130 | PUSHs (sv_2mortal (newSViv (index))); |
|
|
1131 | PUSHs (sv_2mortal (newSViv (trailing))); |
|
|
1132 | } |
1073 | } |
1133 | } |
1074 | |
1134 | |
1075 | void |
1135 | void |
1076 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1136 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1077 | PPCODE: |
1137 | PPCODE: |
… | |
… | |
1171 | } |
1231 | } |
1172 | |
1232 | |
1173 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1233 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1174 | |
1234 | |
1175 | CFPlus::Map |
1235 | CFPlus::Map |
1176 | new (SV *class, int map_width, int map_height) |
1236 | new (SV *class) |
1177 | CODE: |
1237 | CODE: |
1178 | New (0, RETVAL, 1, struct map); |
1238 | New (0, RETVAL, 1, struct map); |
1179 | RETVAL->x = 0; |
1239 | RETVAL->x = 0; |
1180 | RETVAL->y = 0; |
1240 | RETVAL->y = 0; |
1181 | RETVAL->w = map_width; |
1241 | RETVAL->w = 0; |
1182 | RETVAL->h = map_height; |
1242 | RETVAL->h = 0; |
1183 | RETVAL->ox = 0; |
1243 | RETVAL->ox = 0; |
1184 | RETVAL->oy = 0; |
1244 | RETVAL->oy = 0; |
1185 | RETVAL->faces = 8192; |
1245 | RETVAL->faces = 8192; |
1186 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1246 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1187 | RETVAL->texs = 8192; |
1247 | RETVAL->texs = 8192; |
… | |
… | |
1198 | map_clear (self); |
1258 | map_clear (self); |
1199 | Safefree (self->face); |
1259 | Safefree (self->face); |
1200 | Safefree (self->tex); |
1260 | Safefree (self->tex); |
1201 | Safefree (self); |
1261 | Safefree (self); |
1202 | } |
1262 | } |
|
|
1263 | |
|
|
1264 | void |
|
|
1265 | resize (CFPlus::Map self, int map_width, int map_height) |
|
|
1266 | CODE: |
|
|
1267 | self->w = map_width; |
|
|
1268 | self->h = map_height; |
1203 | |
1269 | |
1204 | void |
1270 | void |
1205 | clear (CFPlus::Map self) |
1271 | clear (CFPlus::Map self) |
1206 | CODE: |
1272 | CODE: |
1207 | map_clear (self); |
1273 | map_clear (self); |
… | |
… | |
1346 | cell->stat_width = 1; |
1412 | cell->stat_width = 1; |
1347 | cell->stat_hp = *data++; |
1413 | cell->stat_hp = *data++; |
1348 | } |
1414 | } |
1349 | else if (cmd == 6) // monster width |
1415 | else if (cmd == 6) // monster width |
1350 | cell->stat_width = *data++ + 1; |
1416 | cell->stat_width = *data++ + 1; |
1351 | else if (cmd == 0x47) // monster width |
1417 | else if (cmd == 0x47) |
1352 | { |
1418 | { |
1353 | if (*data == 4) |
1419 | if (*data == 8) |
1354 | ; // decode player tag |
1420 | ; // decode player uuid |
1355 | |
1421 | |
1356 | data += *data + 1; |
1422 | data += *data + 1; |
1357 | } |
1423 | } |
1358 | else if (cmd == 8) // cell flags |
1424 | else if (cmd == 8) // cell flags |
1359 | cell->flags = *data++; |
1425 | cell->flags = *data++; |
… | |
… | |
1447 | } |
1513 | } |
1448 | OUTPUT: |
1514 | OUTPUT: |
1449 | RETVAL |
1515 | RETVAL |
1450 | |
1516 | |
1451 | void |
1517 | void |
1452 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1518 | draw (CFPlus::Map self, int mx, int my, int sw, int sh) |
1453 | CODE: |
1519 | CODE: |
1454 | { |
1520 | { |
1455 | int vx, vy; |
|
|
1456 | int x, y, z; |
1521 | int x, y, z; |
1457 | int last_name; |
1522 | int last_name; |
1458 | mapface face; |
1523 | 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 | |
1524 | |
1473 | glColor4ub (255, 255, 255, 255); |
1525 | glColor4ub (255, 255, 255, 255); |
1474 | |
1526 | |
1475 | glEnable (GL_BLEND); |
1527 | glEnable (GL_BLEND); |
1476 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1528 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
… | |
… | |
1479 | |
1531 | |
1480 | glBegin (GL_QUADS); |
1532 | glBegin (GL_QUADS); |
1481 | |
1533 | |
1482 | last_name = 0; |
1534 | last_name = 0; |
1483 | |
1535 | |
|
|
1536 | mx += self->x; |
|
|
1537 | my += self->y; |
|
|
1538 | |
1484 | for (z = 0; z < 3; z++) |
1539 | for (z = 0; z < 3; z++) |
1485 | for (y = 0; y < sh; y++) |
1540 | for (y = 0; y < sh; y++) |
1486 | if (0 <= y + vy && y + vy < self->rows) |
1541 | if (0 <= y + my && y + my < self->rows) |
1487 | { |
1542 | { |
1488 | maprow *row = self->row + (y + vy); |
1543 | maprow *row = self->row + (y + my); |
1489 | |
1544 | |
1490 | for (x = 0; x < sw; x++) |
1545 | for (x = 0; x < sw; x++) |
1491 | if (row->c0 <= x + vx && x + vx < row->c1) |
1546 | if (row->c0 <= x + mx && x + mx < row->c1) |
1492 | { |
1547 | { |
1493 | mapcell *cell = row->col + (x + vx - row->c0); |
1548 | mapcell *cell = row->col + (x + mx - row->c0); |
1494 | |
1549 | |
1495 | face = cell->face [z]; |
1550 | face = cell->face [z]; |
1496 | |
1551 | |
1497 | if (face && face < self->texs) |
1552 | if (face && face < self->texs) |
1498 | { |
1553 | { |
… | |
… | |
1539 | glDisable (GL_TEXTURE_2D); |
1594 | glDisable (GL_TEXTURE_2D); |
1540 | glDisable (GL_BLEND); |
1595 | glDisable (GL_BLEND); |
1541 | |
1596 | |
1542 | // top layer: overlays such as the health bar |
1597 | // top layer: overlays such as the health bar |
1543 | for (y = 0; y < sh; y++) |
1598 | for (y = 0; y < sh; y++) |
1544 | if (0 <= y + vy && y + vy < self->rows) |
1599 | if (0 <= y + my && y + my < self->rows) |
1545 | { |
1600 | { |
1546 | maprow *row = self->row + (y + vy); |
1601 | maprow *row = self->row + (y + my); |
1547 | |
1602 | |
1548 | for (x = 0; x < sw; x++) |
1603 | for (x = 0; x < sw; x++) |
1549 | if (row->c0 <= x + vx && x + vx < row->c1) |
1604 | if (row->c0 <= x + mx && x + mx < row->c1) |
1550 | { |
1605 | { |
1551 | mapcell *cell = row->col + (x + vx - row->c0); |
1606 | mapcell *cell = row->col + (x + mx - row->c0); |
1552 | |
1607 | |
1553 | int px = x * 32; |
1608 | int px = x * 32; |
1554 | int py = y * 32; |
1609 | int py = y * 32; |
1555 | |
1610 | |
1556 | if (cell->stat_hp) |
1611 | if (cell->stat_hp) |
… | |
… | |
1630 | glDisable (GL_BLEND); |
1685 | glDisable (GL_BLEND); |
1631 | glDisable (GL_TEXTURE_2D); |
1686 | glDisable (GL_TEXTURE_2D); |
1632 | } |
1687 | } |
1633 | |
1688 | |
1634 | void |
1689 | void |
1635 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1690 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
1636 | PPCODE: |
1691 | PPCODE: |
1637 | { |
1692 | { |
1638 | int vx, vy; |
|
|
1639 | int x, y; |
1693 | int x, y; |
1640 | int sw4 = (sw + 3) & ~3; |
1694 | int sw4 = (sw + 3) & ~3; |
1641 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1695 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1642 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1696 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1643 | |
1697 | |
1644 | memset (darkness, 255, sw4 * sh); |
1698 | memset (darkness, 255, sw4 * sh); |
1645 | SvPOK_only (darkness_sv); |
1699 | SvPOK_only (darkness_sv); |
1646 | SvCUR_set (darkness_sv, sw4 * sh); |
1700 | SvCUR_set (darkness_sv, sw4 * sh); |
1647 | |
1701 | |
1648 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
1702 | mx += self->x; |
1649 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
1703 | my += self->y; |
1650 | |
1704 | |
1651 | for (y = 0; y < sh; y++) |
1705 | for (y = 0; y < sh; y++) |
1652 | if (0 <= y + vy && y + vy < self->rows) |
1706 | if (0 <= y + my && y + my < self->rows) |
1653 | { |
1707 | { |
1654 | maprow *row = self->row + (y + vy); |
1708 | maprow *row = self->row + (y + my); |
1655 | |
1709 | |
1656 | for (x = 0; x < sw; x++) |
1710 | for (x = 0; x < sw; x++) |
1657 | if (row->c0 <= x + vx && x + vx < row->c1) |
1711 | if (row->c0 <= x + mx && x + mx < row->c1) |
1658 | { |
1712 | { |
1659 | mapcell *cell = row->col + (x + vx - row->c0); |
1713 | mapcell *cell = row->col + (x + mx - row->c0); |
1660 | |
1714 | |
1661 | darkness[y * sw4 + x] = cell->darkness |
1715 | darkness[y * sw4 + x] = cell->darkness |
1662 | ? 255 - (cell->darkness - 1) |
1716 | ? 255 - (cell->darkness - 1) |
1663 | : 255 - FOW_DARKNESS; |
1717 | : 255 - FOW_DARKNESS; |
1664 | } |
1718 | } |