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 |
… | |
… | |
144 | } |
140 | } |
145 | |
141 | |
146 | static void |
142 | static void |
147 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
143 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
148 | { |
144 | { |
|
|
145 | PangoRectangle rect; |
|
|
146 | |
|
|
147 | // get_pixel_* wrongly rounds down |
149 | pango_layout_get_pixel_size (self->pl, w, h); |
148 | pango_layout_get_extents (self->pl, 0, &rect); |
150 | |
149 | |
151 | if (!*w) *w = 1; |
150 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
152 | if (!*h) *h = 1; |
151 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
153 | |
152 | |
154 | *w = (*w + 3) & ~3; |
153 | if (!rect.width) rect.width = 1; |
|
|
154 | if (!rect.height) rect.height = 1; |
|
|
155 | |
|
|
156 | *w = rect.width; |
|
|
157 | *h = rect.height; |
155 | } |
158 | } |
156 | |
159 | |
157 | typedef uint16_t mapface; |
160 | typedef uint16_t mapface; |
158 | |
161 | |
159 | typedef struct { |
162 | typedef struct { |
… | |
… | |
162 | float s, t; |
165 | float s, t; |
163 | uint8_t r, g, b, a; |
166 | uint8_t r, g, b, a; |
164 | } maptex; |
167 | } maptex; |
165 | |
168 | |
166 | typedef struct { |
169 | typedef struct { |
167 | int16_t darkness; |
170 | uint32_t player; |
168 | mapface face[3]; |
171 | mapface face[3]; |
|
|
172 | uint16_t darkness; |
|
|
173 | uint8_t stat_width, stat_hp, flags; |
169 | } mapcell; |
174 | } mapcell; |
170 | |
175 | |
171 | typedef struct { |
176 | typedef struct { |
172 | int32_t c0, c1; |
177 | int32_t c0, c1; |
173 | mapcell *col; |
178 | mapcell *col; |
… | |
… | |
286 | static void |
291 | static void |
287 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
292 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
288 | { |
293 | { |
289 | int x, y; |
294 | int x, y; |
290 | maprow *row; |
295 | maprow *row; |
|
|
296 | mapcell *cell; |
291 | |
297 | |
292 | for (y = y0; y < y0 + h; y++) |
298 | for (y = y0; y < y0 + h; y++) |
293 | if (y >= 0) |
299 | if (y >= 0) |
294 | { |
300 | { |
295 | if (y >= self->rows) |
301 | if (y >= self->rows) |
… | |
… | |
301 | if (x >= row->c0) |
307 | if (x >= row->c0) |
302 | { |
308 | { |
303 | if (x >= row->c1) |
309 | if (x >= row->c1) |
304 | break; |
310 | break; |
305 | |
311 | |
306 | row->col[x - row->c0].darkness = -1; |
312 | cell = row->col + x - row->c0; |
|
|
313 | |
|
|
314 | cell->darkness = 0; |
|
|
315 | cell->stat_hp = 0; |
|
|
316 | cell->flags = 0; |
|
|
317 | cell->player = 0; |
307 | } |
318 | } |
308 | } |
319 | } |
309 | } |
320 | } |
310 | |
321 | |
311 | static void |
322 | static void |
… | |
… | |
348 | n |= n >> 8; |
359 | n |= n >> 8; |
349 | n |= n >> 16; |
360 | n |= n >> 16; |
350 | |
361 | |
351 | return n + 1; |
362 | return n + 1; |
352 | } |
363 | } |
|
|
364 | |
|
|
365 | /* SDL should provide this, really. */ |
|
|
366 | #define SDLK_MODIFIER_MIN 300 |
|
|
367 | #define SDLK_MODIFIER_MAX 314 |
353 | |
368 | |
354 | MODULE = CFPlus PACKAGE = CFPlus |
369 | MODULE = CFPlus PACKAGE = CFPlus |
355 | |
370 | |
356 | PROTOTYPES: ENABLE |
371 | PROTOTYPES: ENABLE |
357 | |
372 | |
… | |
… | |
361 | static const struct { |
376 | static const struct { |
362 | const char *name; |
377 | const char *name; |
363 | IV iv; |
378 | IV iv; |
364 | } *civ, const_iv[] = { |
379 | } *civ, const_iv[] = { |
365 | # 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 | |
366 | const_iv (SDL_ACTIVEEVENT), |
384 | const_iv (SDL_ACTIVEEVENT), |
367 | const_iv (SDL_KEYDOWN), |
385 | const_iv (SDL_KEYDOWN), |
368 | const_iv (SDL_KEYUP), |
386 | const_iv (SDL_KEYUP), |
369 | const_iv (SDL_MOUSEMOTION), |
387 | const_iv (SDL_MOUSEMOTION), |
370 | const_iv (SDL_MOUSEBUTTONDOWN), |
388 | const_iv (SDL_MOUSEBUTTONDOWN), |
… | |
… | |
379 | const_iv (SDL_EVENT_RESERVEDA), |
397 | const_iv (SDL_EVENT_RESERVEDA), |
380 | const_iv (SDL_EVENT_RESERVEDB), |
398 | const_iv (SDL_EVENT_RESERVEDB), |
381 | const_iv (SDL_VIDEORESIZE), |
399 | const_iv (SDL_VIDEORESIZE), |
382 | const_iv (SDL_VIDEOEXPOSE), |
400 | const_iv (SDL_VIDEOEXPOSE), |
383 | 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 | |
384 | const_iv (SDLK_KP0), |
407 | const_iv (SDLK_KP0), |
385 | const_iv (SDLK_KP1), |
408 | const_iv (SDLK_KP1), |
386 | const_iv (SDLK_KP2), |
409 | const_iv (SDLK_KP2), |
387 | const_iv (SDLK_KP3), |
410 | const_iv (SDLK_KP3), |
388 | const_iv (SDLK_KP4), |
411 | const_iv (SDLK_KP4), |
… | |
… | |
443 | const_iv (SDLK_BREAK), |
466 | const_iv (SDLK_BREAK), |
444 | const_iv (SDLK_MENU), |
467 | const_iv (SDLK_MENU), |
445 | const_iv (SDLK_POWER), |
468 | const_iv (SDLK_POWER), |
446 | const_iv (SDLK_EURO), |
469 | const_iv (SDLK_EURO), |
447 | const_iv (SDLK_UNDO), |
470 | const_iv (SDLK_UNDO), |
|
|
471 | |
448 | const_iv (KMOD_NONE), |
472 | const_iv (KMOD_NONE), |
|
|
473 | const_iv (KMOD_SHIFT), |
449 | const_iv (KMOD_LSHIFT), |
474 | const_iv (KMOD_LSHIFT), |
450 | const_iv (KMOD_RSHIFT), |
475 | const_iv (KMOD_RSHIFT), |
|
|
476 | const_iv (KMOD_CTRL), |
451 | const_iv (KMOD_LCTRL), |
477 | const_iv (KMOD_LCTRL), |
452 | const_iv (KMOD_RCTRL), |
478 | const_iv (KMOD_RCTRL), |
|
|
479 | const_iv (KMOD_ALT), |
453 | const_iv (KMOD_LALT), |
480 | const_iv (KMOD_LALT), |
454 | const_iv (KMOD_RALT), |
481 | const_iv (KMOD_RALT), |
|
|
482 | const_iv (KMOD_META), |
455 | const_iv (KMOD_LMETA), |
483 | const_iv (KMOD_LMETA), |
456 | const_iv (KMOD_RMETA), |
484 | const_iv (KMOD_RMETA), |
457 | const_iv (KMOD_NUM), |
485 | const_iv (KMOD_NUM), |
458 | const_iv (KMOD_CAPS), |
486 | const_iv (KMOD_CAPS), |
459 | const_iv (KMOD_MODE), |
487 | const_iv (KMOD_MODE), |
460 | const_iv (KMOD_CTRL), |
|
|
461 | const_iv (KMOD_SHIFT), |
|
|
462 | const_iv (KMOD_ALT), |
|
|
463 | const_iv (KMOD_META) |
|
|
464 | # undef const_iv |
488 | # undef const_iv |
465 | }; |
489 | }; |
466 | |
490 | |
467 | 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; ) |
468 | 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); |
469 | } |
496 | } |
|
|
497 | |
|
|
498 | void |
|
|
499 | weaken (SV *rv) |
|
|
500 | PROTOTYPE: $ |
|
|
501 | CODE: |
|
|
502 | sv_rvweaken (rv); |
470 | |
503 | |
471 | int |
504 | int |
472 | in_destruct () |
505 | in_destruct () |
473 | CODE: |
506 | CODE: |
474 | RETVAL = PL_main_cv == Nullcv; |
507 | RETVAL = PL_main_cv == Nullcv; |
… | |
… | |
577 | case SDL_KEYDOWN: |
610 | case SDL_KEYDOWN: |
578 | case SDL_KEYUP: |
611 | case SDL_KEYUP: |
579 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
612 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
580 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
613 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
581 | 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 */ |
582 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
616 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
583 | break; |
617 | break; |
584 | |
618 | |
585 | case SDL_ACTIVEEVENT: |
619 | case SDL_ACTIVEEVENT: |
586 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
620 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
634 | lowdelay (int fd, int val = 1) |
668 | lowdelay (int fd, int val = 1) |
635 | CODE: |
669 | CODE: |
636 | #ifndef _WIN32 |
670 | #ifndef _WIN32 |
637 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
671 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
638 | #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 | } |
639 | |
702 | |
640 | void |
703 | void |
641 | add_font (char *file) |
704 | add_font (char *file) |
642 | CODE: |
705 | CODE: |
643 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
706 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
… | |
… | |
747 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
810 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
748 | #endif |
811 | #endif |
749 | _exit (1); |
812 | _exit (1); |
750 | |
813 | |
751 | void |
814 | void |
752 | _exit (int retval) |
815 | _exit (int retval = 0) |
753 | CODE: |
816 | CODE: |
|
|
817 | #ifdef WIN32 |
|
|
818 | ExitThread (retval); // unclean, please beam me up |
|
|
819 | #else |
754 | _exit (retval); |
820 | _exit (retval); |
|
|
821 | #endif |
755 | |
822 | |
756 | MODULE = CFPlus PACKAGE = CFPlus::Font |
823 | MODULE = CFPlus PACKAGE = CFPlus::Font |
757 | |
824 | |
758 | CFPlus::Font |
825 | CFPlus::Font |
759 | new_from_file (SV *class, char *path, int id = 0) |
826 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
1006 | xy_to_index (CFPlus::Layout self, int x, int y) |
1073 | xy_to_index (CFPlus::Layout self, int x, int y) |
1007 | CODE: |
1074 | CODE: |
1008 | { |
1075 | { |
1009 | int index, trailing; |
1076 | int index, trailing; |
1010 | 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); |
1011 | RETVAL = index; |
1078 | RETVAL = index + trailing; |
1012 | } |
1079 | } |
1013 | OUTPUT: |
1080 | OUTPUT: |
1014 | RETVAL |
1081 | RETVAL |
1015 | |
1082 | |
1016 | void |
1083 | void |
… | |
… | |
1025 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1092 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1026 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1093 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1027 | } |
1094 | } |
1028 | |
1095 | |
1029 | void |
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 | } |
|
|
1133 | } |
|
|
1134 | |
|
|
1135 | void |
1030 | render (CFPlus::Layout self, float x, float y) |
1136 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1031 | PPCODE: |
1137 | PPCODE: |
1032 | pango_opengl_render_layout_subpixel ( |
1138 | pango_opengl_render_layout_subpixel ( |
1033 | self->pl, |
1139 | self->pl, |
1034 | x * PANGO_SCALE, y * PANGO_SCALE, |
1140 | x * PANGO_SCALE, y * PANGO_SCALE, |
1035 | self->r, self->g, self->b, self->a |
1141 | self->r, self->g, self->b, self->a, |
|
|
1142 | flags |
1036 | ); |
1143 | ); |
1037 | |
1144 | |
1038 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1145 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1039 | |
1146 | |
1040 | void |
1147 | void |
… | |
… | |
1124 | } |
1231 | } |
1125 | |
1232 | |
1126 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1233 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1127 | |
1234 | |
1128 | CFPlus::Map |
1235 | CFPlus::Map |
1129 | new (SV *class, int map_width, int map_height) |
1236 | new (SV *class) |
1130 | CODE: |
1237 | CODE: |
1131 | New (0, RETVAL, 1, struct map); |
1238 | New (0, RETVAL, 1, struct map); |
1132 | RETVAL->x = 0; |
1239 | RETVAL->x = 0; |
1133 | RETVAL->y = 0; |
1240 | RETVAL->y = 0; |
1134 | RETVAL->w = map_width; |
1241 | RETVAL->w = 0; |
1135 | RETVAL->h = map_height; |
1242 | RETVAL->h = 0; |
1136 | RETVAL->ox = 0; |
1243 | RETVAL->ox = 0; |
1137 | RETVAL->oy = 0; |
1244 | RETVAL->oy = 0; |
1138 | RETVAL->faces = 8192; |
1245 | RETVAL->faces = 8192; |
1139 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1246 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1140 | RETVAL->texs = 8192; |
1247 | RETVAL->texs = 8192; |
… | |
… | |
1151 | map_clear (self); |
1258 | map_clear (self); |
1152 | Safefree (self->face); |
1259 | Safefree (self->face); |
1153 | Safefree (self->tex); |
1260 | Safefree (self->tex); |
1154 | Safefree (self); |
1261 | Safefree (self); |
1155 | } |
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; |
1156 | |
1269 | |
1157 | void |
1270 | void |
1158 | clear (CFPlus::Map self) |
1271 | clear (CFPlus::Map self) |
1159 | CODE: |
1272 | CODE: |
1160 | map_clear (self); |
1273 | map_clear (self); |
… | |
… | |
1230 | void |
1343 | void |
1231 | scroll (CFPlus::Map self, int dx, int dy) |
1344 | scroll (CFPlus::Map self, int dx, int dy) |
1232 | CODE: |
1345 | CODE: |
1233 | { |
1346 | { |
1234 | if (dx > 0) |
1347 | if (dx > 0) |
1235 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1348 | map_blank (self, self->x, self->y, dx, self->h); |
1236 | else if (dx < 0) |
1349 | else if (dx < 0) |
1237 | 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); |
1238 | |
1351 | |
1239 | if (dy > 0) |
1352 | if (dy > 0) |
1240 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1353 | map_blank (self, self->x, self->y, self->w, dy); |
1241 | else if (dy < 0) |
1354 | else if (dy < 0) |
1242 | 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); |
1243 | |
1356 | |
1244 | self->ox += dx; self->x += dx; |
1357 | self->ox += dx; self->x += dx; |
1245 | self->oy += dy; self->y += dy; |
1358 | self->oy += dy; self->y += dy; |
1246 | |
1359 | |
1247 | while (self->y < 0) |
1360 | while (self->y < 0) |
… | |
… | |
1252 | self->y += MAP_EXTEND_Y; |
1365 | self->y += MAP_EXTEND_Y; |
1253 | } |
1366 | } |
1254 | } |
1367 | } |
1255 | |
1368 | |
1256 | void |
1369 | void |
1257 | map1a_update (CFPlus::Map self, SV *data_) |
1370 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1258 | CODE: |
1371 | CODE: |
1259 | { |
1372 | { |
1260 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1373 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1261 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1374 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1262 | mapcell *cell; |
1375 | mapcell *cell; |
1263 | int x, y, flags; |
1376 | int x, y, flags; |
1264 | |
1377 | |
1265 | while (data < data_end) |
1378 | while (data < data_end - 1) |
1266 | { |
1379 | { |
1267 | flags = (data [0] << 8) + data [1]; data += 2; |
1380 | flags = (data [0] << 8) + data [1]; data += 2; |
1268 | |
1381 | |
1269 | x = self->x + ((flags >> 10) & 63); |
1382 | x = self->x + ((flags >> 10) & 63); |
1270 | y = self->y + ((flags >> 4) & 63); |
1383 | y = self->y + ((flags >> 4) & 63); |
1271 | |
1384 | |
1272 | cell = map_get_cell (self, x, y); |
1385 | cell = map_get_cell (self, x, y); |
1273 | |
1386 | |
1274 | if (flags & 15) |
1387 | if (flags & 15) |
1275 | { |
1388 | { |
1276 | if (cell->darkness < 0) |
1389 | if (!cell->darkness) |
1277 | { |
1390 | { |
|
|
1391 | memset (cell, 0, sizeof (*cell)); |
1278 | cell->darkness = 0; |
1392 | cell->darkness = 256; |
1279 | cell->face [0] = 0; |
|
|
1280 | cell->face [1] = 0; |
|
|
1281 | cell->face [2] = 0; |
|
|
1282 | } |
1393 | } |
1283 | |
1394 | |
1284 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1285 | |
|
|
1286 | //TODO: don't trust server data to be in-range(!) |
1395 | //TODO: don't trust server data to be in-range(!) |
|
|
1396 | |
|
|
1397 | if (flags & 8) |
|
|
1398 | { |
|
|
1399 | if (extmap) |
|
|
1400 | { |
|
|
1401 | uint8_t ext, cmd; |
|
|
1402 | |
|
|
1403 | do |
|
|
1404 | { |
|
|
1405 | ext = *data++; |
|
|
1406 | cmd = ext & 0x3f; |
|
|
1407 | |
|
|
1408 | if (cmd < 4) |
|
|
1409 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1410 | else if (cmd == 5) // health |
|
|
1411 | { |
|
|
1412 | cell->stat_width = 1; |
|
|
1413 | cell->stat_hp = *data++; |
|
|
1414 | } |
|
|
1415 | else if (cmd == 6) // monster width |
|
|
1416 | cell->stat_width = *data++ + 1; |
|
|
1417 | else if (cmd == 0x47) // monster width |
|
|
1418 | { |
|
|
1419 | if (*data == 4) |
|
|
1420 | ; // decode player tag |
|
|
1421 | |
|
|
1422 | data += *data + 1; |
|
|
1423 | } |
|
|
1424 | else if (cmd == 8) // cell flags |
|
|
1425 | cell->flags = *data++; |
|
|
1426 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1427 | data += *data + 1; |
|
|
1428 | else |
|
|
1429 | data++; |
|
|
1430 | } |
|
|
1431 | while (ext & 0x80); |
|
|
1432 | } |
|
|
1433 | else |
|
|
1434 | cell->darkness = *data++ + 1; |
|
|
1435 | } |
1287 | |
1436 | |
1288 | if (flags & 4) |
1437 | if (flags & 4) |
1289 | { |
1438 | { |
1290 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1439 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1291 | } |
1440 | } |
… | |
… | |
1299 | { |
1448 | { |
1300 | 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; |
1301 | } |
1450 | } |
1302 | } |
1451 | } |
1303 | else |
1452 | else |
1304 | cell->darkness = -1; |
1453 | cell->darkness = 0; |
1305 | } |
1454 | } |
1306 | } |
1455 | } |
1307 | |
1456 | |
1308 | SV * |
1457 | SV * |
1309 | 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) |
… | |
… | |
1364 | } |
1513 | } |
1365 | OUTPUT: |
1514 | OUTPUT: |
1366 | RETVAL |
1515 | RETVAL |
1367 | |
1516 | |
1368 | void |
1517 | void |
1369 | 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) |
1370 | CODE: |
1519 | CODE: |
1371 | { |
1520 | { |
1372 | int vx, vy; |
|
|
1373 | int x, y, z; |
1521 | int x, y, z; |
1374 | int last_name; |
1522 | int last_name; |
1375 | mapface face; |
1523 | mapface face; |
1376 | |
|
|
1377 | vx = self->x + self->w / 2 - sw / 2 - shift_x; |
|
|
1378 | vy = self->y + self->h / 2 - sh / 2 - shift_y; |
|
|
1379 | |
|
|
1380 | /* |
|
|
1381 | int vx = self->vx = self->w >= sw |
|
|
1382 | ? self->x + (self->w - sw) / 2 |
|
|
1383 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
|
|
1384 | |
|
|
1385 | int vy = self->vy = self->h >= sh |
|
|
1386 | ? self->y + (self->h - sh) / 2 |
|
|
1387 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
1388 | */ |
|
|
1389 | |
1524 | |
1390 | glColor4ub (255, 255, 255, 255); |
1525 | glColor4ub (255, 255, 255, 255); |
1391 | |
1526 | |
1392 | glEnable (GL_BLEND); |
1527 | glEnable (GL_BLEND); |
1393 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1528 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
… | |
… | |
1396 | |
1531 | |
1397 | glBegin (GL_QUADS); |
1532 | glBegin (GL_QUADS); |
1398 | |
1533 | |
1399 | last_name = 0; |
1534 | last_name = 0; |
1400 | |
1535 | |
|
|
1536 | mx += self->x; |
|
|
1537 | my += self->y; |
|
|
1538 | |
1401 | for (z = 0; z < 3; z++) |
1539 | for (z = 0; z < 3; z++) |
1402 | for (y = 0; y < sh; y++) |
1540 | for (y = 0; y < sh; y++) |
1403 | if (0 <= y + vy && y + vy < self->rows) |
1541 | if (0 <= y + my && y + my < self->rows) |
1404 | { |
1542 | { |
1405 | maprow *row = self->row + (y + vy); |
1543 | maprow *row = self->row + (y + my); |
1406 | |
1544 | |
1407 | for (x = 0; x < sw; x++) |
1545 | for (x = 0; x < sw; x++) |
1408 | if (row->c0 <= x + vx && x + vx < row->c1) |
1546 | if (row->c0 <= x + mx && x + mx < row->c1) |
1409 | { |
1547 | { |
1410 | mapcell *cell = row->col + (x + vx - row->c0); |
1548 | mapcell *cell = row->col + (x + mx - row->c0); |
1411 | |
1549 | |
1412 | face = cell->face [z]; |
1550 | face = cell->face [z]; |
1413 | |
1551 | |
1414 | if (face) |
1552 | if (face && face < self->texs) |
1415 | { |
1553 | { |
1416 | maptex tex = self->tex [face]; |
1554 | maptex tex = self->tex [face]; |
1417 | |
|
|
1418 | int px = (x + 1) * 32 - tex.w; |
1555 | int px = (x + 1) * 32 - tex.w; |
1419 | int py = (y + 1) * 32 - tex.h; |
1556 | int py = (y + 1) * 32 - tex.h; |
1420 | |
1557 | |
1421 | if (last_name != tex.name) |
1558 | if (last_name != tex.name) |
1422 | { |
1559 | { |
1423 | glEnd (); |
1560 | glEnd (); |
1424 | last_name = tex.name; |
|
|
1425 | glBindTexture (GL_TEXTURE_2D, last_name); |
1561 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1426 | glBegin (GL_QUADS); |
1562 | glBegin (GL_QUADS); |
1427 | } |
1563 | } |
1428 | |
1564 | |
1429 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1565 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1430 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1566 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1431 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1567 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1432 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1568 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1433 | } |
1569 | } |
|
|
1570 | |
|
|
1571 | if (cell->flags && z == 2) |
|
|
1572 | { |
|
|
1573 | if (cell->flags & 1) |
|
|
1574 | { |
|
|
1575 | maptex tex = self->tex [1]; |
|
|
1576 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1577 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1578 | |
|
|
1579 | glEnd (); |
|
|
1580 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1581 | glBegin (GL_QUADS); |
|
|
1582 | |
|
|
1583 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1584 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1585 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1586 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1587 | } |
|
|
1588 | } |
1434 | } |
1589 | } |
1435 | } |
1590 | } |
1436 | |
1591 | |
1437 | glEnd (); |
1592 | glEnd (); |
1438 | |
1593 | |
1439 | glDisable (GL_TEXTURE_2D); |
1594 | glDisable (GL_TEXTURE_2D); |
1440 | glDisable (GL_BLEND); |
1595 | glDisable (GL_BLEND); |
|
|
1596 | |
|
|
1597 | // top layer: overlays such as the health bar |
|
|
1598 | for (y = 0; y < sh; y++) |
|
|
1599 | if (0 <= y + my && y + my < self->rows) |
|
|
1600 | { |
|
|
1601 | maprow *row = self->row + (y + my); |
|
|
1602 | |
|
|
1603 | for (x = 0; x < sw; x++) |
|
|
1604 | if (row->c0 <= x + mx && x + mx < row->c1) |
|
|
1605 | { |
|
|
1606 | mapcell *cell = row->col + (x + mx - row->c0); |
|
|
1607 | |
|
|
1608 | int px = x * 32; |
|
|
1609 | int py = y * 32; |
|
|
1610 | |
|
|
1611 | if (cell->stat_hp) |
|
|
1612 | { |
|
|
1613 | int width = cell->stat_width * 32; |
|
|
1614 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1615 | |
|
|
1616 | glColor3ub (0, 0, 0); |
|
|
1617 | glRectf (px + 1, py - thick - 2, |
|
|
1618 | px + width - 1, py); |
|
|
1619 | |
|
|
1620 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1621 | glRectf (px + 2, |
|
|
1622 | py - thick - 1, |
|
|
1623 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
|
|
1624 | } |
|
|
1625 | } |
|
|
1626 | } |
1441 | } |
1627 | } |
1442 | |
1628 | |
1443 | void |
1629 | void |
1444 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1630 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1445 | CODE: |
1631 | CODE: |
… | |
… | |
1499 | glDisable (GL_BLEND); |
1685 | glDisable (GL_BLEND); |
1500 | glDisable (GL_TEXTURE_2D); |
1686 | glDisable (GL_TEXTURE_2D); |
1501 | } |
1687 | } |
1502 | |
1688 | |
1503 | void |
1689 | void |
1504 | 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) |
1505 | PPCODE: |
1691 | PPCODE: |
1506 | { |
1692 | { |
1507 | int vx, vy; |
|
|
1508 | int x, y; |
1693 | int x, y; |
1509 | int sw4 = (sw + 3) & ~3; |
1694 | int sw4 = (sw + 3) & ~3; |
1510 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1695 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1511 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1696 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1512 | |
1697 | |
1513 | memset (darkness, 255, sw4 * sh); |
1698 | memset (darkness, 255, sw4 * sh); |
1514 | SvPOK_only (darkness_sv); |
1699 | SvPOK_only (darkness_sv); |
1515 | SvCUR_set (darkness_sv, sw4 * sh); |
1700 | SvCUR_set (darkness_sv, sw4 * sh); |
1516 | |
1701 | |
1517 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
1702 | mx += self->x; |
1518 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
1703 | my += self->y; |
1519 | |
1704 | |
1520 | for (y = 0; y < sh; y++) |
1705 | for (y = 0; y < sh; y++) |
1521 | if (0 <= y + vy && y + vy < self->rows) |
1706 | if (0 <= y + my && y + my < self->rows) |
1522 | { |
1707 | { |
1523 | maprow *row = self->row + (y + vy); |
1708 | maprow *row = self->row + (y + my); |
1524 | |
1709 | |
1525 | for (x = 0; x < sw; x++) |
1710 | for (x = 0; x < sw; x++) |
1526 | if (row->c0 <= x + vx && x + vx < row->c1) |
1711 | if (row->c0 <= x + mx && x + mx < row->c1) |
1527 | { |
1712 | { |
1528 | mapcell *cell = row->col + (x + vx - row->c0); |
1713 | mapcell *cell = row->col + (x + mx - row->c0); |
1529 | |
1714 | |
1530 | darkness[y * sw4 + x] = cell->darkness < 0 |
1715 | darkness[y * sw4 + x] = cell->darkness |
|
|
1716 | ? 255 - (cell->darkness - 1) |
1531 | ? 255 - FOW_DARKNESS |
1717 | : 255 - FOW_DARKNESS; |
1532 | : 255 - cell->darkness; |
|
|
1533 | } |
1718 | } |
1534 | } |
1719 | } |
1535 | |
1720 | |
1536 | EXTEND (SP, 3); |
1721 | EXTEND (SP, 3); |
1537 | PUSHs (sv_2mortal (newSViv (sw4))); |
1722 | PUSHs (sv_2mortal (newSViv (sw4))); |
… | |
… | |
1652 | |
1837 | |
1653 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1838 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1654 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1839 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1655 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1840 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1656 | |
1841 | |
1657 | if (cell->darkness <= 0) |
1842 | if (cell->darkness == 0) |
1658 | { |
1843 | { |
1659 | cell->darkness = -1; |
1844 | cell->darkness = 0; |
1660 | |
1845 | |
1661 | for (z = 0; z <= 2; z++) |
1846 | for (z = 0; z <= 2; z++) |
1662 | { |
1847 | { |
1663 | cell->face[z] = face[z]; |
1848 | cell->face[z] = face[z]; |
1664 | |
1849 | |
… | |
… | |
1802 | const_iv (GL_SEPARABLE_2D), |
1987 | const_iv (GL_SEPARABLE_2D), |
1803 | const_iv (GL_CONVOLUTION_2D), |
1988 | const_iv (GL_CONVOLUTION_2D), |
1804 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1989 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1805 | const_iv (GL_CONSTANT_BORDER), |
1990 | const_iv (GL_CONSTANT_BORDER), |
1806 | const_iv (GL_LINES), |
1991 | const_iv (GL_LINES), |
|
|
1992 | const_iv (GL_LINE_STRIP), |
1807 | const_iv (GL_LINE_LOOP), |
1993 | const_iv (GL_LINE_LOOP), |
1808 | const_iv (GL_QUADS), |
1994 | const_iv (GL_QUADS), |
1809 | const_iv (GL_QUAD_STRIP), |
1995 | const_iv (GL_QUAD_STRIP), |
1810 | const_iv (GL_TRIANGLES), |
1996 | const_iv (GL_TRIANGLES), |
1811 | const_iv (GL_TRIANGLE_STRIP), |
1997 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
2008 | |
2194 | |
2009 | void glEndList () |
2195 | void glEndList () |
2010 | |
2196 | |
2011 | void glCallList (int list) |
2197 | void glCallList (int list) |
2012 | |
2198 | |
2013 | |
|
|