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" |
12 | |
14 | |
13 | #ifdef _WIN32 |
15 | #ifdef _WIN32 |
14 | # undef pipe |
16 | # undef pipe |
15 | #endif |
17 | #endif |
16 | |
18 | |
|
|
19 | #include <assert.h> |
17 | #include <math.h> |
20 | #include <math.h> |
18 | #include <string.h> |
21 | #include <string.h> |
19 | #include <stdio.h> |
22 | #include <stdio.h> |
20 | #include <stdlib.h> |
23 | #include <stdlib.h> |
21 | |
24 | |
… | |
… | |
36 | # include <sys/types.h> |
39 | # include <sys/types.h> |
37 | # include <sys/socket.h> |
40 | # include <sys/socket.h> |
38 | # include <netinet/in.h> |
41 | # include <netinet/in.h> |
39 | # include <netinet/tcp.h> |
42 | # include <netinet/tcp.h> |
40 | # include <inttypes.h> |
43 | # 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 |
44 | #endif |
49 | |
45 | |
50 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
46 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
51 | |
47 | |
52 | #define FOW_DARKNESS 32 |
48 | #define FOW_DARKNESS 32 |
53 | |
49 | |
54 | #define MAP_EXTEND_X 32 |
50 | #define MAP_EXTEND_X 32 |
55 | #define MAP_EXTEND_Y 512 |
51 | #define MAP_EXTEND_Y 512 |
… | |
… | |
315 | |
311 | |
316 | cell = row->col + x - row->c0; |
312 | cell = row->col + x - row->c0; |
317 | |
313 | |
318 | cell->darkness = 0; |
314 | cell->darkness = 0; |
319 | cell->stat_hp = 0; |
315 | cell->stat_hp = 0; |
|
|
316 | cell->flags = 0; |
|
|
317 | cell->player = 0; |
320 | } |
318 | } |
321 | } |
319 | } |
322 | } |
320 | } |
323 | |
321 | |
324 | static void |
322 | static void |
… | |
… | |
361 | n |= n >> 8; |
359 | n |= n >> 8; |
362 | n |= n >> 16; |
360 | n |= n >> 16; |
363 | |
361 | |
364 | return n + 1; |
362 | return n + 1; |
365 | } |
363 | } |
|
|
364 | |
|
|
365 | /* SDL should provide this, really. */ |
|
|
366 | #define SDLK_MODIFIER_MIN 300 |
|
|
367 | #define SDLK_MODIFIER_MAX 314 |
366 | |
368 | |
367 | MODULE = CFPlus PACKAGE = CFPlus |
369 | MODULE = CFPlus PACKAGE = CFPlus |
368 | |
370 | |
369 | PROTOTYPES: ENABLE |
371 | PROTOTYPES: ENABLE |
370 | |
372 | |
… | |
… | |
374 | static const struct { |
376 | static const struct { |
375 | const char *name; |
377 | const char *name; |
376 | IV iv; |
378 | IV iv; |
377 | } *civ, const_iv[] = { |
379 | } *civ, const_iv[] = { |
378 | # 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 | |
379 | const_iv (SDL_ACTIVEEVENT), |
384 | const_iv (SDL_ACTIVEEVENT), |
380 | const_iv (SDL_KEYDOWN), |
385 | const_iv (SDL_KEYDOWN), |
381 | const_iv (SDL_KEYUP), |
386 | const_iv (SDL_KEYUP), |
382 | const_iv (SDL_MOUSEMOTION), |
387 | const_iv (SDL_MOUSEMOTION), |
383 | const_iv (SDL_MOUSEBUTTONDOWN), |
388 | const_iv (SDL_MOUSEBUTTONDOWN), |
… | |
… | |
392 | const_iv (SDL_EVENT_RESERVEDA), |
397 | const_iv (SDL_EVENT_RESERVEDA), |
393 | const_iv (SDL_EVENT_RESERVEDB), |
398 | const_iv (SDL_EVENT_RESERVEDB), |
394 | const_iv (SDL_VIDEORESIZE), |
399 | const_iv (SDL_VIDEORESIZE), |
395 | const_iv (SDL_VIDEOEXPOSE), |
400 | const_iv (SDL_VIDEOEXPOSE), |
396 | 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 | |
397 | const_iv (SDLK_KP0), |
407 | const_iv (SDLK_KP0), |
398 | const_iv (SDLK_KP1), |
408 | const_iv (SDLK_KP1), |
399 | const_iv (SDLK_KP2), |
409 | const_iv (SDLK_KP2), |
400 | const_iv (SDLK_KP3), |
410 | const_iv (SDLK_KP3), |
401 | const_iv (SDLK_KP4), |
411 | const_iv (SDLK_KP4), |
… | |
… | |
456 | const_iv (SDLK_BREAK), |
466 | const_iv (SDLK_BREAK), |
457 | const_iv (SDLK_MENU), |
467 | const_iv (SDLK_MENU), |
458 | const_iv (SDLK_POWER), |
468 | const_iv (SDLK_POWER), |
459 | const_iv (SDLK_EURO), |
469 | const_iv (SDLK_EURO), |
460 | const_iv (SDLK_UNDO), |
470 | const_iv (SDLK_UNDO), |
|
|
471 | |
461 | const_iv (KMOD_NONE), |
472 | const_iv (KMOD_NONE), |
|
|
473 | const_iv (KMOD_SHIFT), |
462 | const_iv (KMOD_LSHIFT), |
474 | const_iv (KMOD_LSHIFT), |
463 | const_iv (KMOD_RSHIFT), |
475 | const_iv (KMOD_RSHIFT), |
|
|
476 | const_iv (KMOD_CTRL), |
464 | const_iv (KMOD_LCTRL), |
477 | const_iv (KMOD_LCTRL), |
465 | const_iv (KMOD_RCTRL), |
478 | const_iv (KMOD_RCTRL), |
|
|
479 | const_iv (KMOD_ALT), |
466 | const_iv (KMOD_LALT), |
480 | const_iv (KMOD_LALT), |
467 | const_iv (KMOD_RALT), |
481 | const_iv (KMOD_RALT), |
|
|
482 | const_iv (KMOD_META), |
468 | const_iv (KMOD_LMETA), |
483 | const_iv (KMOD_LMETA), |
469 | const_iv (KMOD_RMETA), |
484 | const_iv (KMOD_RMETA), |
470 | const_iv (KMOD_NUM), |
485 | const_iv (KMOD_NUM), |
471 | const_iv (KMOD_CAPS), |
486 | const_iv (KMOD_CAPS), |
472 | const_iv (KMOD_MODE), |
487 | const_iv (KMOD_MODE), |
473 | const_iv (KMOD_CTRL), |
|
|
474 | const_iv (KMOD_SHIFT), |
|
|
475 | const_iv (KMOD_ALT), |
|
|
476 | const_iv (KMOD_META) |
|
|
477 | # undef const_iv |
488 | # undef const_iv |
478 | }; |
489 | }; |
479 | |
490 | |
480 | 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; ) |
481 | 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); |
482 | } |
496 | } |
|
|
497 | |
|
|
498 | void |
|
|
499 | weaken (SV *rv) |
|
|
500 | PROTOTYPE: $ |
|
|
501 | CODE: |
|
|
502 | sv_rvweaken (rv); |
483 | |
503 | |
484 | int |
504 | int |
485 | in_destruct () |
505 | in_destruct () |
486 | CODE: |
506 | CODE: |
487 | RETVAL = PL_main_cv == Nullcv; |
507 | RETVAL = PL_main_cv == Nullcv; |
… | |
… | |
590 | case SDL_KEYDOWN: |
610 | case SDL_KEYDOWN: |
591 | case SDL_KEYUP: |
611 | case SDL_KEYUP: |
592 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
612 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
593 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
613 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
594 | 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 */ |
595 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
616 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
596 | break; |
617 | break; |
597 | |
618 | |
598 | case SDL_ACTIVEEVENT: |
619 | case SDL_ACTIVEEVENT: |
599 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
620 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
647 | lowdelay (int fd, int val = 1) |
668 | lowdelay (int fd, int val = 1) |
648 | CODE: |
669 | CODE: |
649 | #ifndef _WIN32 |
670 | #ifndef _WIN32 |
650 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
671 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
651 | #endif |
672 | #endif |
|
|
673 | |
|
|
674 | void |
|
|
675 | win32_proxy_info () |
|
|
676 | PPCODE: |
|
|
677 | { |
|
|
678 | #ifdef _WIN32 |
|
|
679 | char buffer[2048]; |
|
|
680 | DWORD buflen; |
|
|
681 | |
|
|
682 | EXTEND (SP, 3); |
|
|
683 | |
|
|
684 | buflen = sizeof (buffer); |
|
|
685 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
686 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
687 | { |
|
|
688 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
689 | |
|
|
690 | buflen = sizeof (buffer); |
|
|
691 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
692 | { |
|
|
693 | PUSHs (newSVpv (buffer, 0)); |
|
|
694 | |
|
|
695 | buflen = sizeof (buffer); |
|
|
696 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
697 | PUSHs (newSVpv (buffer, 0)); |
|
|
698 | } |
|
|
699 | } |
|
|
700 | #endif |
|
|
701 | } |
652 | |
702 | |
653 | void |
703 | void |
654 | add_font (char *file) |
704 | add_font (char *file) |
655 | CODE: |
705 | CODE: |
656 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
706 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
… | |
… | |
760 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
810 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
761 | #endif |
811 | #endif |
762 | _exit (1); |
812 | _exit (1); |
763 | |
813 | |
764 | void |
814 | void |
765 | _exit (int retval) |
815 | _exit (int retval = 0) |
766 | CODE: |
816 | CODE: |
|
|
817 | #ifdef WIN32 |
|
|
818 | ExitThread (retval); // unclean, please beam me up |
|
|
819 | #else |
767 | _exit (retval); |
820 | _exit (retval); |
|
|
821 | #endif |
768 | |
822 | |
769 | MODULE = CFPlus PACKAGE = CFPlus::Font |
823 | MODULE = CFPlus PACKAGE = CFPlus::Font |
770 | |
824 | |
771 | CFPlus::Font |
825 | CFPlus::Font |
772 | new_from_file (SV *class, char *path, int id = 0) |
826 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
1019 | xy_to_index (CFPlus::Layout self, int x, int y) |
1073 | xy_to_index (CFPlus::Layout self, int x, int y) |
1020 | CODE: |
1074 | CODE: |
1021 | { |
1075 | { |
1022 | int index, trailing; |
1076 | int index, trailing; |
1023 | 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); |
1024 | RETVAL = index; |
1078 | RETVAL = index + trailing; |
1025 | } |
1079 | } |
1026 | OUTPUT: |
1080 | OUTPUT: |
1027 | RETVAL |
1081 | RETVAL |
1028 | |
1082 | |
1029 | void |
1083 | void |
… | |
… | |
1035 | |
1089 | |
1036 | EXTEND (SP, 3); |
1090 | EXTEND (SP, 3); |
1037 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1091 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1038 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1092 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1039 | 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 | } |
1040 | } |
1133 | } |
1041 | |
1134 | |
1042 | void |
1135 | void |
1043 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1136 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1044 | PPCODE: |
1137 | PPCODE: |
… | |
… | |
1138 | } |
1231 | } |
1139 | |
1232 | |
1140 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1233 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1141 | |
1234 | |
1142 | CFPlus::Map |
1235 | CFPlus::Map |
1143 | new (SV *class, int map_width, int map_height) |
1236 | new (SV *class) |
1144 | CODE: |
1237 | CODE: |
1145 | New (0, RETVAL, 1, struct map); |
1238 | New (0, RETVAL, 1, struct map); |
1146 | RETVAL->x = 0; |
1239 | RETVAL->x = 0; |
1147 | RETVAL->y = 0; |
1240 | RETVAL->y = 0; |
1148 | RETVAL->w = map_width; |
1241 | RETVAL->w = 0; |
1149 | RETVAL->h = map_height; |
1242 | RETVAL->h = 0; |
1150 | RETVAL->ox = 0; |
1243 | RETVAL->ox = 0; |
1151 | RETVAL->oy = 0; |
1244 | RETVAL->oy = 0; |
1152 | RETVAL->faces = 8192; |
1245 | RETVAL->faces = 8192; |
1153 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1246 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1154 | RETVAL->texs = 8192; |
1247 | RETVAL->texs = 8192; |
… | |
… | |
1165 | map_clear (self); |
1258 | map_clear (self); |
1166 | Safefree (self->face); |
1259 | Safefree (self->face); |
1167 | Safefree (self->tex); |
1260 | Safefree (self->tex); |
1168 | Safefree (self); |
1261 | Safefree (self); |
1169 | } |
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; |
1170 | |
1269 | |
1171 | void |
1270 | void |
1172 | clear (CFPlus::Map self) |
1271 | clear (CFPlus::Map self) |
1173 | CODE: |
1272 | CODE: |
1174 | map_clear (self); |
1273 | map_clear (self); |
… | |
… | |
1244 | void |
1343 | void |
1245 | scroll (CFPlus::Map self, int dx, int dy) |
1344 | scroll (CFPlus::Map self, int dx, int dy) |
1246 | CODE: |
1345 | CODE: |
1247 | { |
1346 | { |
1248 | if (dx > 0) |
1347 | if (dx > 0) |
1249 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1348 | map_blank (self, self->x, self->y, dx, self->h); |
1250 | else if (dx < 0) |
1349 | else if (dx < 0) |
1251 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1350 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1252 | |
1351 | |
1253 | if (dy > 0) |
1352 | if (dy > 0) |
1254 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1353 | map_blank (self, self->x, self->y, self->w, dy); |
1255 | else if (dy < 0) |
1354 | else if (dy < 0) |
1256 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1355 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1257 | |
1356 | |
1258 | self->ox += dx; self->x += dx; |
1357 | self->ox += dx; self->x += dx; |
1259 | self->oy += dy; self->y += dy; |
1358 | self->oy += dy; self->y += dy; |
1260 | |
1359 | |
1261 | while (self->y < 0) |
1360 | while (self->y < 0) |
… | |
… | |
1287 | |
1386 | |
1288 | if (flags & 15) |
1387 | if (flags & 15) |
1289 | { |
1388 | { |
1290 | if (!cell->darkness) |
1389 | if (!cell->darkness) |
1291 | { |
1390 | { |
|
|
1391 | memset (cell, 0, sizeof (*cell)); |
1292 | cell->darkness = 256; |
1392 | cell->darkness = 256; |
1293 | cell->face [0] = 0; |
|
|
1294 | cell->face [1] = 0; |
|
|
1295 | cell->face [2] = 0; |
|
|
1296 | } |
1393 | } |
1297 | |
1394 | |
1298 | //TODO: don't trust server data to be in-range(!) |
1395 | //TODO: don't trust server data to be in-range(!) |
1299 | |
1396 | |
1300 | if (flags & 8) |
1397 | if (flags & 8) |
… | |
… | |
1351 | { |
1448 | { |
1352 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1449 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1353 | } |
1450 | } |
1354 | } |
1451 | } |
1355 | else |
1452 | else |
1356 | { |
|
|
1357 | cell->darkness = 0; |
1453 | cell->darkness = 0; |
1358 | cell->stat_hp = 0; |
|
|
1359 | } |
|
|
1360 | } |
1454 | } |
1361 | } |
1455 | } |
1362 | |
1456 | |
1363 | SV * |
1457 | SV * |
1364 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1458 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
… | |
… | |
1419 | } |
1513 | } |
1420 | OUTPUT: |
1514 | OUTPUT: |
1421 | RETVAL |
1515 | RETVAL |
1422 | |
1516 | |
1423 | void |
1517 | void |
1424 | 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) |
1425 | CODE: |
1519 | CODE: |
1426 | { |
1520 | { |
1427 | int vx, vy; |
|
|
1428 | int x, y, z; |
1521 | int x, y, z; |
1429 | int last_name; |
1522 | int last_name; |
1430 | mapface face; |
1523 | 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 | |
1524 | |
1445 | glColor4ub (255, 255, 255, 255); |
1525 | glColor4ub (255, 255, 255, 255); |
1446 | |
1526 | |
1447 | glEnable (GL_BLEND); |
1527 | glEnable (GL_BLEND); |
1448 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1528 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
… | |
… | |
1451 | |
1531 | |
1452 | glBegin (GL_QUADS); |
1532 | glBegin (GL_QUADS); |
1453 | |
1533 | |
1454 | last_name = 0; |
1534 | last_name = 0; |
1455 | |
1535 | |
|
|
1536 | mx += self->x; |
|
|
1537 | my += self->y; |
|
|
1538 | |
1456 | for (z = 0; z < 3; z++) |
1539 | for (z = 0; z < 3; z++) |
1457 | for (y = 0; y < sh; y++) |
1540 | for (y = 0; y < sh; y++) |
1458 | if (0 <= y + vy && y + vy < self->rows) |
1541 | if (0 <= y + my && y + my < self->rows) |
1459 | { |
1542 | { |
1460 | maprow *row = self->row + (y + vy); |
1543 | maprow *row = self->row + (y + my); |
1461 | |
1544 | |
1462 | for (x = 0; x < sw; x++) |
1545 | for (x = 0; x < sw; x++) |
1463 | if (row->c0 <= x + vx && x + vx < row->c1) |
1546 | if (row->c0 <= x + mx && x + mx < row->c1) |
1464 | { |
1547 | { |
1465 | mapcell *cell = row->col + (x + vx - row->c0); |
1548 | mapcell *cell = row->col + (x + mx - row->c0); |
1466 | |
1549 | |
1467 | face = cell->face [z]; |
1550 | face = cell->face [z]; |
1468 | |
1551 | |
1469 | if (face && face < self->texs) |
1552 | if (face && face < self->texs) |
1470 | { |
1553 | { |
… | |
… | |
1511 | glDisable (GL_TEXTURE_2D); |
1594 | glDisable (GL_TEXTURE_2D); |
1512 | glDisable (GL_BLEND); |
1595 | glDisable (GL_BLEND); |
1513 | |
1596 | |
1514 | // top layer: overlays such as the health bar |
1597 | // top layer: overlays such as the health bar |
1515 | for (y = 0; y < sh; y++) |
1598 | for (y = 0; y < sh; y++) |
1516 | if (0 <= y + vy && y + vy < self->rows) |
1599 | if (0 <= y + my && y + my < self->rows) |
1517 | { |
1600 | { |
1518 | maprow *row = self->row + (y + vy); |
1601 | maprow *row = self->row + (y + my); |
1519 | |
1602 | |
1520 | for (x = 0; x < sw; x++) |
1603 | for (x = 0; x < sw; x++) |
1521 | if (row->c0 <= x + vx && x + vx < row->c1) |
1604 | if (row->c0 <= x + mx && x + mx < row->c1) |
1522 | { |
1605 | { |
1523 | mapcell *cell = row->col + (x + vx - row->c0); |
1606 | mapcell *cell = row->col + (x + mx - row->c0); |
1524 | |
1607 | |
1525 | int px = x * 32; |
1608 | int px = x * 32; |
1526 | int py = y * 32; |
1609 | int py = y * 32; |
1527 | |
1610 | |
1528 | if (cell->stat_hp) |
1611 | if (cell->stat_hp) |
… | |
… | |
1602 | glDisable (GL_BLEND); |
1685 | glDisable (GL_BLEND); |
1603 | glDisable (GL_TEXTURE_2D); |
1686 | glDisable (GL_TEXTURE_2D); |
1604 | } |
1687 | } |
1605 | |
1688 | |
1606 | void |
1689 | void |
1607 | 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) |
1608 | PPCODE: |
1691 | PPCODE: |
1609 | { |
1692 | { |
1610 | int vx, vy; |
|
|
1611 | int x, y; |
1693 | int x, y; |
1612 | int sw4 = (sw + 3) & ~3; |
1694 | int sw4 = (sw + 3) & ~3; |
1613 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1695 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1614 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1696 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1615 | |
1697 | |
1616 | memset (darkness, 255, sw4 * sh); |
1698 | memset (darkness, 255, sw4 * sh); |
1617 | SvPOK_only (darkness_sv); |
1699 | SvPOK_only (darkness_sv); |
1618 | SvCUR_set (darkness_sv, sw4 * sh); |
1700 | SvCUR_set (darkness_sv, sw4 * sh); |
1619 | |
1701 | |
1620 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
1702 | mx += self->x; |
1621 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
1703 | my += self->y; |
1622 | |
1704 | |
1623 | for (y = 0; y < sh; y++) |
1705 | for (y = 0; y < sh; y++) |
1624 | if (0 <= y + vy && y + vy < self->rows) |
1706 | if (0 <= y + my && y + my < self->rows) |
1625 | { |
1707 | { |
1626 | maprow *row = self->row + (y + vy); |
1708 | maprow *row = self->row + (y + my); |
1627 | |
1709 | |
1628 | for (x = 0; x < sw; x++) |
1710 | for (x = 0; x < sw; x++) |
1629 | if (row->c0 <= x + vx && x + vx < row->c1) |
1711 | if (row->c0 <= x + mx && x + mx < row->c1) |
1630 | { |
1712 | { |
1631 | mapcell *cell = row->col + (x + vx - row->c0); |
1713 | mapcell *cell = row->col + (x + mx - row->c0); |
1632 | |
1714 | |
1633 | darkness[y * sw4 + x] = cell->darkness |
1715 | darkness[y * sw4 + x] = cell->darkness |
1634 | ? 255 - (cell->darkness - 1) |
1716 | ? 255 - (cell->darkness - 1) |
1635 | : 255 - FOW_DARKNESS; |
1717 | : 255 - FOW_DARKNESS; |
1636 | } |
1718 | } |