1 | #ifdef _WIN32 |
1 | #ifdef _WIN32 |
|
|
2 | long _ftol (double); /* defined by VC6 C libs */ |
|
|
3 | long _ftol2 (double dblSource) { return _ftol (dblSource); } |
|
|
4 | # define WIN32_LEAN_AND_MEAN |
2 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
5 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
3 | # include <malloc.h> |
6 | # include <malloc.h> |
4 | # include <windows.h> |
7 | # include <windows.h> |
|
|
8 | # include <wininet.h> |
5 | # pragma warning(disable:4244) |
9 | # pragma warning(disable:4244) |
6 | #endif |
10 | #endif |
7 | |
11 | |
8 | #include "EXTERN.h" |
12 | #include "EXTERN.h" |
9 | #include "perl.h" |
13 | #include "perl.h" |
10 | #include "XSUB.h" |
14 | #include "XSUB.h" |
|
|
15 | |
|
|
16 | #ifdef _WIN32 |
|
|
17 | # undef pipe |
|
|
18 | #endif |
11 | |
19 | |
12 | #include <math.h> |
20 | #include <math.h> |
13 | #include <string.h> |
21 | #include <string.h> |
14 | #include <stdio.h> |
22 | #include <stdio.h> |
15 | #include <stdlib.h> |
23 | #include <stdlib.h> |
… | |
… | |
40 | typedef signed char int8_t; |
48 | typedef signed char int8_t; |
41 | typedef signed short int16_t; |
49 | typedef signed short int16_t; |
42 | typedef signed int int32_t; |
50 | typedef signed int int32_t; |
43 | #endif |
51 | #endif |
44 | |
52 | |
45 | #include "glext.h" |
|
|
46 | |
|
|
47 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
53 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
48 | |
54 | |
49 | #define FOW_DARKNESS 32 |
55 | #define FOW_DARKNESS 32 |
50 | |
56 | |
51 | #define MAP_EXTEND_X 32 |
57 | #define MAP_EXTEND_X 32 |
52 | #define MAP_EXTEND_Y 512 |
58 | #define MAP_EXTEND_Y 512 |
53 | |
59 | |
54 | #define MIN_FONT_HEIGHT 10 |
60 | #define MIN_FONT_HEIGHT 10 |
55 | |
61 | |
56 | #if 1 |
62 | #if 0 |
57 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
63 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
58 | #else |
64 | #else |
59 | # define PARACHUTE 0 |
65 | # define PARACHUTE 0 |
60 | #endif |
66 | #endif |
61 | |
67 | |
… | |
… | |
80 | |
86 | |
81 | #include "pango-font.c" |
87 | #include "pango-font.c" |
82 | #include "pango-fontmap.c" |
88 | #include "pango-fontmap.c" |
83 | #include "pango-render.c" |
89 | #include "pango-render.c" |
84 | |
90 | |
85 | typedef Mix_Chunk *CFClient__MixChunk; |
91 | typedef Mix_Chunk *CFPlus__MixChunk; |
86 | typedef Mix_Music *CFClient__MixMusic; |
92 | typedef Mix_Music *CFPlus__MixMusic; |
87 | |
93 | |
88 | typedef PangoFontDescription *CFClient__Font; |
94 | typedef PangoFontDescription *CFPlus__Font; |
89 | |
95 | |
90 | static int |
96 | static int |
91 | shape_attr_p (PangoLayoutRun *run) |
97 | shape_attr_p (PangoLayoutRun *run) |
92 | { |
98 | { |
93 | GSList *attrs = run->item->analysis.extra_attrs; |
99 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
107 | |
113 | |
108 | typedef struct cf_layout { |
114 | typedef struct cf_layout { |
109 | PangoLayout *pl; |
115 | PangoLayout *pl; |
110 | float r, g, b, a; // default color for rgba mode |
116 | float r, g, b, a; // default color for rgba mode |
111 | int base_height; |
117 | int base_height; |
112 | CFClient__Font font; |
118 | CFPlus__Font font; |
113 | } *CFClient__Layout; |
119 | } *CFPlus__Layout; |
114 | |
120 | |
115 | static CFClient__Font default_font; |
121 | static CFPlus__Font default_font; |
116 | static PangoContext *opengl_context; |
122 | static PangoContext *opengl_context; |
117 | static PangoFontMap *opengl_fontmap; |
123 | static PangoFontMap *opengl_fontmap; |
118 | |
124 | |
119 | static void |
125 | static void |
120 | substitute_func (FcPattern *pattern, gpointer data) |
126 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
125 | #endif |
131 | #endif |
126 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
132 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
127 | } |
133 | } |
128 | |
134 | |
129 | static void |
135 | static void |
130 | layout_update_font (CFClient__Layout self) |
136 | layout_update_font (CFPlus__Layout self) |
131 | { |
137 | { |
132 | /* use a random scale factor to account for unknown descenders, 0.8 works |
138 | /* use a random scale factor to account for unknown descenders, 0.8 works |
133 | * reasonably well with bitstream vera |
139 | * reasonably well with bitstream vera |
134 | */ |
140 | */ |
135 | PangoFontDescription *font = self->font ? self->font : default_font; |
141 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
139 | |
145 | |
140 | pango_layout_set_font_description (self->pl, font); |
146 | pango_layout_set_font_description (self->pl, font); |
141 | } |
147 | } |
142 | |
148 | |
143 | static void |
149 | static void |
144 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
150 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
145 | { |
151 | { |
|
|
152 | PangoRectangle rect; |
|
|
153 | |
|
|
154 | // get_pixel_* wrongly rounds down |
146 | pango_layout_get_pixel_size (self->pl, w, h); |
155 | pango_layout_get_extents (self->pl, 0, &rect); |
147 | |
156 | |
148 | if (!*w) *w = 1; |
157 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
149 | if (!*h) *h = 1; |
158 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
150 | |
159 | |
151 | *w = (*w + 3) & ~3; |
160 | if (!rect.width) rect.width = 1; |
|
|
161 | if (!rect.height) rect.height = 1; |
|
|
162 | |
|
|
163 | *w = rect.width; |
|
|
164 | *h = rect.height; |
152 | } |
165 | } |
153 | |
166 | |
154 | typedef uint16_t mapface; |
167 | typedef uint16_t mapface; |
155 | |
168 | |
156 | typedef struct { |
169 | typedef struct { |
… | |
… | |
159 | float s, t; |
172 | float s, t; |
160 | uint8_t r, g, b, a; |
173 | uint8_t r, g, b, a; |
161 | } maptex; |
174 | } maptex; |
162 | |
175 | |
163 | typedef struct { |
176 | typedef struct { |
164 | int16_t darkness; |
177 | uint32_t player; |
165 | mapface face[3]; |
178 | mapface face[3]; |
|
|
179 | uint16_t darkness; |
|
|
180 | uint8_t stat_width, stat_hp, flags; |
166 | } mapcell; |
181 | } mapcell; |
167 | |
182 | |
168 | typedef struct { |
183 | typedef struct { |
169 | int32_t c0, c1; |
184 | int32_t c0, c1; |
170 | mapcell *col; |
185 | mapcell *col; |
… | |
… | |
179 | int texs; |
194 | int texs; |
180 | maptex *tex; |
195 | maptex *tex; |
181 | |
196 | |
182 | int32_t rows; |
197 | int32_t rows; |
183 | maprow *row; |
198 | maprow *row; |
184 | } *CFClient__Map; |
199 | } *CFPlus__Map; |
185 | |
200 | |
186 | static char * |
201 | static char * |
187 | prepend (char *ptr, int sze, int inc) |
202 | prepend (char *ptr, int sze, int inc) |
188 | { |
203 | { |
189 | char *p; |
204 | char *p; |
… | |
… | |
207 | |
222 | |
208 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
223 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
209 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
224 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
210 | |
225 | |
211 | static maprow * |
226 | static maprow * |
212 | map_get_row (CFClient__Map self, int y) |
227 | map_get_row (CFPlus__Map self, int y) |
213 | { |
228 | { |
214 | if (0 > y) |
229 | if (0 > y) |
215 | { |
230 | { |
216 | int extend = - y + MAP_EXTEND_Y; |
231 | int extend = - y + MAP_EXTEND_Y; |
217 | Prepend (maprow, self->row, self->rows, extend); |
232 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
255 | |
270 | |
256 | return row->col + (x - row->c0); |
271 | return row->col + (x - row->c0); |
257 | } |
272 | } |
258 | |
273 | |
259 | static mapcell * |
274 | static mapcell * |
260 | map_get_cell (CFClient__Map self, int x, int y) |
275 | map_get_cell (CFPlus__Map self, int x, int y) |
261 | { |
276 | { |
262 | return row_get_cell (map_get_row (self, y), x); |
277 | return row_get_cell (map_get_row (self, y), x); |
263 | } |
278 | } |
264 | |
279 | |
265 | static void |
280 | static void |
266 | map_clear (CFClient__Map self) |
281 | map_clear (CFPlus__Map self) |
267 | { |
282 | { |
268 | int r; |
283 | int r; |
269 | |
284 | |
270 | for (r = 0; r < self->rows; r++) |
285 | for (r = 0; r < self->rows; r++) |
271 | Safefree (self->row[r].col); |
286 | Safefree (self->row[r].col); |
… | |
… | |
279 | self->row = 0; |
294 | self->row = 0; |
280 | self->rows = 0; |
295 | self->rows = 0; |
281 | } |
296 | } |
282 | |
297 | |
283 | static void |
298 | static void |
284 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
299 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
285 | { |
300 | { |
286 | int x, y; |
301 | int x, y; |
287 | maprow *row; |
302 | maprow *row; |
|
|
303 | mapcell *cell; |
288 | |
304 | |
289 | for (y = y0; y < y0 + h; y++) |
305 | for (y = y0; y < y0 + h; y++) |
290 | if (y >= 0) |
306 | if (y >= 0) |
291 | { |
307 | { |
292 | if (y >= self->rows) |
308 | if (y >= self->rows) |
… | |
… | |
298 | if (x >= row->c0) |
314 | if (x >= row->c0) |
299 | { |
315 | { |
300 | if (x >= row->c1) |
316 | if (x >= row->c1) |
301 | break; |
317 | break; |
302 | |
318 | |
303 | row->col[x - row->c0].darkness = -1; |
319 | cell = row->col + x - row->c0; |
|
|
320 | |
|
|
321 | cell->darkness = 0; |
|
|
322 | cell->stat_hp = 0; |
|
|
323 | cell->flags = 0; |
|
|
324 | cell->player = 0; |
304 | } |
325 | } |
305 | } |
326 | } |
306 | } |
327 | } |
307 | |
328 | |
308 | static void |
329 | static void |
… | |
… | |
346 | n |= n >> 16; |
367 | n |= n >> 16; |
347 | |
368 | |
348 | return n + 1; |
369 | return n + 1; |
349 | } |
370 | } |
350 | |
371 | |
351 | MODULE = CFClient PACKAGE = CFClient |
372 | MODULE = CFPlus PACKAGE = CFPlus |
352 | |
373 | |
353 | PROTOTYPES: ENABLE |
374 | PROTOTYPES: ENABLE |
354 | |
375 | |
355 | BOOT: |
376 | BOOT: |
356 | { |
377 | { |
357 | HV *stash = gv_stashpv ("CFClient", 1); |
378 | HV *stash = gv_stashpv ("CFPlus", 1); |
358 | static const struct { |
379 | static const struct { |
359 | const char *name; |
380 | const char *name; |
360 | IV iv; |
381 | IV iv; |
361 | } *civ, const_iv[] = { |
382 | } *civ, const_iv[] = { |
362 | # define const_iv(name) { # name, (IV)name } |
383 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
463 | |
484 | |
464 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
485 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
465 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
486 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
466 | } |
487 | } |
467 | |
488 | |
|
|
489 | int |
|
|
490 | in_destruct () |
|
|
491 | CODE: |
|
|
492 | RETVAL = PL_main_cv == Nullcv; |
|
|
493 | OUTPUT: |
|
|
494 | RETVAL |
|
|
495 | |
468 | NV floor (NV x) |
496 | NV floor (NV x) |
469 | |
497 | |
470 | NV ceil (NV x) |
498 | NV ceil (NV x) |
471 | |
499 | |
472 | void |
500 | void |
… | |
… | |
502 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
530 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
503 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
531 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
504 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
532 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
505 | |
533 | |
506 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
534 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
|
|
535 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
536 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
537 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
|
|
538 | #endif |
507 | |
539 | |
508 | SDL_EnableUNICODE (1); |
540 | SDL_EnableUNICODE (1); |
509 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
541 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
510 | |
542 | |
511 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
543 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
598 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
630 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
599 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
631 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
600 | break; |
632 | break; |
601 | } |
633 | } |
602 | |
634 | |
603 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
635 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
604 | } |
636 | } |
605 | } |
637 | } |
606 | |
638 | |
607 | int |
639 | int |
608 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
640 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
… | |
… | |
622 | #ifndef _WIN32 |
654 | #ifndef _WIN32 |
623 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
655 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
624 | #endif |
656 | #endif |
625 | |
657 | |
626 | void |
658 | void |
|
|
659 | win32_proxy_info () |
|
|
660 | PPCODE: |
|
|
661 | { |
|
|
662 | #ifdef _WIN32 |
|
|
663 | char buffer[2048]; |
|
|
664 | DWORD buflen; |
|
|
665 | |
|
|
666 | EXTEND (SP, 3); |
|
|
667 | |
|
|
668 | buflen = sizeof (buffer); |
|
|
669 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
670 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
671 | { |
|
|
672 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
673 | |
|
|
674 | buflen = sizeof (buffer); |
|
|
675 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
676 | { |
|
|
677 | PUSHs (newSVpv (buffer, 0)); |
|
|
678 | |
|
|
679 | buflen = sizeof (buffer); |
|
|
680 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
681 | PUSHs (newSVpv (buffer, 0)); |
|
|
682 | } |
|
|
683 | } |
|
|
684 | #endif |
|
|
685 | } |
|
|
686 | |
|
|
687 | void |
627 | add_font (char *file) |
688 | add_font (char *file) |
628 | CODE: |
689 | CODE: |
629 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
690 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
630 | |
691 | |
631 | void |
692 | void |
632 | load_image_inline (SV *image_) |
693 | load_image_inline (SV *image_) |
633 | ALIAS: |
694 | ALIAS: |
634 | load_image_file = 1 |
695 | load_image_file = 1 |
… | |
… | |
676 | |
737 | |
677 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
738 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
678 | |
739 | |
679 | assert (surface2->pitch == surface2->w * 4); |
740 | assert (surface2->pitch == surface2->w * 4); |
680 | |
741 | |
|
|
742 | SDL_LockSurface (surface2); |
681 | EXTEND (SP, 5); |
743 | EXTEND (SP, 6); |
682 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
744 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
683 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
745 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
684 | SDL_LockSurface (surface2); |
|
|
685 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
746 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
686 | SDL_UnlockSurface (surface2); |
|
|
687 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
747 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
688 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
748 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
689 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
749 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
|
|
750 | SDL_UnlockSurface (surface2); |
690 | |
751 | |
691 | SDL_FreeSurface (surface); |
752 | SDL_FreeSurface (surface); |
692 | SDL_FreeSurface (surface2); |
753 | SDL_FreeSurface (surface2); |
693 | } |
754 | } |
694 | |
755 | |
… | |
… | |
733 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
794 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
734 | #endif |
795 | #endif |
735 | _exit (1); |
796 | _exit (1); |
736 | |
797 | |
737 | void |
798 | void |
738 | _exit (int retval) |
799 | _exit (int retval = 0) |
739 | CODE: |
800 | CODE: |
740 | _exit (retval); |
801 | _exit (retval); |
741 | |
802 | |
742 | MODULE = CFClient PACKAGE = CFClient::Font |
803 | MODULE = CFPlus PACKAGE = CFPlus::Font |
743 | |
804 | |
744 | CFClient::Font |
805 | CFPlus::Font |
745 | new_from_file (SV *class, char *path, int id = 0) |
806 | new_from_file (SV *class, char *path, int id = 0) |
746 | CODE: |
807 | CODE: |
747 | { |
808 | { |
748 | int count; |
809 | int count; |
749 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
810 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
752 | } |
813 | } |
753 | OUTPUT: |
814 | OUTPUT: |
754 | RETVAL |
815 | RETVAL |
755 | |
816 | |
756 | void |
817 | void |
757 | DESTROY (CFClient::Font self) |
818 | DESTROY (CFPlus::Font self) |
758 | CODE: |
819 | CODE: |
759 | pango_font_description_free (self); |
820 | pango_font_description_free (self); |
760 | |
821 | |
761 | void |
822 | void |
762 | make_default (CFClient::Font self) |
823 | make_default (CFPlus::Font self) |
763 | CODE: |
824 | CODE: |
764 | default_font = self; |
825 | default_font = self; |
765 | |
826 | |
766 | MODULE = CFClient PACKAGE = CFClient::Layout |
827 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
767 | |
828 | |
768 | void |
829 | void |
769 | clear_font_cache () |
830 | reset_glyph_cache () |
770 | CODE: |
831 | CODE: |
771 | pango_fc_font_map_cache_clear ((PangoFcFontMap *)opengl_fontmap); |
|
|
772 | tc_clear (); |
832 | tc_clear (); |
773 | |
833 | |
774 | CFClient::Layout |
834 | CFPlus::Layout |
775 | new (SV *class, int type = 0) |
835 | new (SV *class) |
776 | CODE: |
836 | CODE: |
777 | New (0, RETVAL, 1, struct cf_layout); |
837 | New (0, RETVAL, 1, struct cf_layout); |
778 | |
838 | |
779 | RETVAL->pl = pango_layout_new (opengl_context); |
839 | RETVAL->pl = pango_layout_new (opengl_context); |
780 | RETVAL->r = 1.; |
840 | RETVAL->r = 1.; |
… | |
… | |
788 | layout_update_font (RETVAL); |
848 | layout_update_font (RETVAL); |
789 | OUTPUT: |
849 | OUTPUT: |
790 | RETVAL |
850 | RETVAL |
791 | |
851 | |
792 | void |
852 | void |
793 | DESTROY (CFClient::Layout self) |
853 | DESTROY (CFPlus::Layout self) |
794 | CODE: |
854 | CODE: |
795 | g_object_unref (self->pl); |
855 | g_object_unref (self->pl); |
796 | Safefree (self); |
856 | Safefree (self); |
797 | |
857 | |
798 | void |
858 | void |
799 | set_text (CFClient::Layout self, SV *text_) |
859 | set_text (CFPlus::Layout self, SV *text_) |
800 | CODE: |
860 | CODE: |
801 | { |
861 | { |
802 | STRLEN textlen; |
862 | STRLEN textlen; |
803 | char *text = SvPVutf8 (text_, textlen); |
863 | char *text = SvPVutf8 (text_, textlen); |
804 | |
864 | |
805 | pango_layout_set_text (self->pl, text, textlen); |
865 | pango_layout_set_text (self->pl, text, textlen); |
806 | } |
866 | } |
807 | |
867 | |
808 | void |
868 | void |
809 | set_markup (CFClient::Layout self, SV *text_) |
869 | set_markup (CFPlus::Layout self, SV *text_) |
810 | CODE: |
870 | CODE: |
811 | { |
871 | { |
812 | STRLEN textlen; |
872 | STRLEN textlen; |
813 | char *text = SvPVutf8 (text_, textlen); |
873 | char *text = SvPVutf8 (text_, textlen); |
814 | |
874 | |
815 | pango_layout_set_markup (self->pl, text, textlen); |
875 | pango_layout_set_markup (self->pl, text, textlen); |
816 | } |
876 | } |
817 | |
877 | |
818 | void |
878 | void |
819 | set_shapes (CFClient::Layout self, ...) |
879 | set_shapes (CFPlus::Layout self, ...) |
820 | CODE: |
880 | CODE: |
821 | { |
881 | { |
822 | PangoAttrList *attrs = 0; |
882 | PangoAttrList *attrs = 0; |
823 | const char *text = pango_layout_get_text (self->pl); |
883 | const char *text = pango_layout_get_text (self->pl); |
824 | const char *pos = text; |
884 | const char *pos = text; |
… | |
… | |
859 | if (attrs) |
919 | if (attrs) |
860 | pango_layout_set_attributes (self->pl, attrs); |
920 | pango_layout_set_attributes (self->pl, attrs); |
861 | } |
921 | } |
862 | |
922 | |
863 | void |
923 | void |
864 | get_shapes (CFClient::Layout self) |
924 | get_shapes (CFPlus::Layout self) |
865 | PPCODE: |
925 | PPCODE: |
866 | { |
926 | { |
867 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
927 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
868 | |
928 | |
869 | do |
929 | do |
… | |
… | |
873 | if (run && shape_attr_p (run)) |
933 | if (run && shape_attr_p (run)) |
874 | { |
934 | { |
875 | PangoRectangle extents; |
935 | PangoRectangle extents; |
876 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
936 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
877 | |
937 | |
|
|
938 | EXTEND (SP, 2); |
878 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
939 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
879 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
940 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
880 | } |
941 | } |
881 | } |
942 | } |
882 | while (pango_layout_iter_next_run (iter)); |
943 | while (pango_layout_iter_next_run (iter)); |
883 | |
944 | |
884 | pango_layout_iter_free (iter); |
945 | pango_layout_iter_free (iter); |
885 | } |
946 | } |
886 | |
947 | |
887 | int |
948 | int |
888 | has_wrapped (CFClient::Layout self) |
949 | has_wrapped (CFPlus::Layout self) |
889 | CODE: |
950 | CODE: |
890 | { |
951 | { |
891 | int lines = 1; |
952 | int lines = 1; |
892 | const char *text = pango_layout_get_text (self->pl); |
953 | const char *text = pango_layout_get_text (self->pl); |
893 | |
954 | |
… | |
… | |
898 | } |
959 | } |
899 | OUTPUT: |
960 | OUTPUT: |
900 | RETVAL |
961 | RETVAL |
901 | |
962 | |
902 | SV * |
963 | SV * |
903 | get_text (CFClient::Layout self) |
964 | get_text (CFPlus::Layout self) |
904 | CODE: |
965 | CODE: |
905 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
966 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
906 | sv_utf8_decode (RETVAL); |
967 | sv_utf8_decode (RETVAL); |
907 | OUTPUT: |
968 | OUTPUT: |
908 | RETVAL |
969 | RETVAL |
909 | |
970 | |
910 | void |
971 | void |
911 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
972 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
912 | CODE: |
973 | CODE: |
913 | self->r = r; |
974 | self->r = r; |
914 | self->g = g; |
975 | self->g = g; |
915 | self->b = b; |
976 | self->b = b; |
916 | self->a = a; |
977 | self->a = a; |
917 | |
978 | |
918 | void |
979 | void |
919 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
980 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
920 | CODE: |
981 | CODE: |
921 | if (self->font != font) |
982 | if (self->font != font) |
922 | { |
983 | { |
923 | self->font = font; |
984 | self->font = font; |
924 | layout_update_font (self); |
985 | layout_update_font (self); |
925 | } |
986 | } |
926 | |
987 | |
927 | void |
988 | void |
928 | set_height (CFClient::Layout self, int base_height) |
989 | set_height (CFPlus::Layout self, int base_height) |
929 | CODE: |
990 | CODE: |
930 | if (self->base_height != base_height) |
991 | if (self->base_height != base_height) |
931 | { |
992 | { |
932 | self->base_height = base_height; |
993 | self->base_height = base_height; |
933 | layout_update_font (self); |
994 | layout_update_font (self); |
934 | } |
995 | } |
935 | |
996 | |
936 | void |
997 | void |
937 | set_width (CFClient::Layout self, int max_width = -1) |
998 | set_width (CFPlus::Layout self, int max_width = -1) |
938 | CODE: |
999 | CODE: |
939 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1000 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
940 | |
1001 | |
941 | void |
1002 | void |
942 | set_indent (CFClient::Layout self, int indent) |
1003 | set_indent (CFPlus::Layout self, int indent) |
943 | CODE: |
1004 | CODE: |
944 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1005 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
945 | |
1006 | |
946 | void |
1007 | void |
947 | set_spacing (CFClient::Layout self, int spacing) |
1008 | set_spacing (CFPlus::Layout self, int spacing) |
948 | CODE: |
1009 | CODE: |
949 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1010 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
950 | |
1011 | |
951 | void |
1012 | void |
952 | set_ellipsise (CFClient::Layout self, int ellipsise) |
1013 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
953 | CODE: |
1014 | CODE: |
954 | pango_layout_set_ellipsize (self->pl, |
1015 | pango_layout_set_ellipsize (self->pl, |
955 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1016 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
956 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1017 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
957 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1018 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
958 | : PANGO_ELLIPSIZE_NONE |
1019 | : PANGO_ELLIPSIZE_NONE |
959 | ); |
1020 | ); |
960 | |
1021 | |
961 | void |
1022 | void |
962 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
1023 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
963 | CODE: |
1024 | CODE: |
964 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1025 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
965 | |
1026 | |
966 | void |
1027 | void |
967 | size (CFClient::Layout self) |
1028 | size (CFPlus::Layout self) |
968 | PPCODE: |
1029 | PPCODE: |
969 | { |
1030 | { |
970 | int w, h; |
1031 | int w, h; |
971 | |
1032 | |
972 | layout_get_pixel_size (self, &w, &h); |
1033 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
975 | PUSHs (sv_2mortal (newSViv (w))); |
1036 | PUSHs (sv_2mortal (newSViv (w))); |
976 | PUSHs (sv_2mortal (newSViv (h))); |
1037 | PUSHs (sv_2mortal (newSViv (h))); |
977 | } |
1038 | } |
978 | |
1039 | |
979 | int |
1040 | int |
980 | descent (CFClient::Layout self) |
1041 | descent (CFPlus::Layout self) |
981 | CODE: |
1042 | CODE: |
982 | { |
1043 | { |
983 | PangoRectangle rect; |
1044 | PangoRectangle rect; |
984 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1045 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
985 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1046 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
… | |
… | |
987 | } |
1048 | } |
988 | OUTPUT: |
1049 | OUTPUT: |
989 | RETVAL |
1050 | RETVAL |
990 | |
1051 | |
991 | int |
1052 | int |
992 | xy_to_index (CFClient::Layout self, int x, int y) |
1053 | xy_to_index (CFPlus::Layout self, int x, int y) |
993 | CODE: |
1054 | CODE: |
994 | { |
1055 | { |
995 | int index, trailing; |
1056 | int index, trailing; |
996 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1057 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
997 | RETVAL = index; |
1058 | RETVAL = index; |
998 | } |
1059 | } |
999 | OUTPUT: |
1060 | OUTPUT: |
1000 | RETVAL |
1061 | RETVAL |
1001 | |
1062 | |
1002 | void |
1063 | void |
1003 | cursor_pos (CFClient::Layout self, int index) |
1064 | cursor_pos (CFPlus::Layout self, int index) |
1004 | PPCODE: |
1065 | PPCODE: |
1005 | { |
1066 | { |
1006 | PangoRectangle strong_pos; |
1067 | PangoRectangle strong_pos; |
1007 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1068 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1008 | |
1069 | |
… | |
… | |
1011 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1072 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1012 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1073 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1013 | } |
1074 | } |
1014 | |
1075 | |
1015 | void |
1076 | void |
1016 | render (CFClient::Layout self, float x, float y) |
1077 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1017 | PPCODE: |
1078 | PPCODE: |
1018 | pango_opengl_render_layout_subpixel ( |
1079 | pango_opengl_render_layout_subpixel ( |
1019 | self->pl, |
1080 | self->pl, |
1020 | x * PANGO_SCALE, y * PANGO_SCALE, |
1081 | x * PANGO_SCALE, y * PANGO_SCALE, |
1021 | self->r, self->g, self->b, self->a |
1082 | self->r, self->g, self->b, self->a, |
|
|
1083 | flags |
1022 | ); |
1084 | ); |
1023 | |
1085 | |
1024 | MODULE = CFClient PACKAGE = CFClient::Texture |
1086 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1025 | |
1087 | |
1026 | void |
1088 | void |
1027 | pad2pot (SV *data_, SV *w_, SV *h_) |
1089 | pad2pot (SV *data_, SV *w_, SV *h_) |
1028 | CODE: |
1090 | CODE: |
1029 | { |
1091 | { |
… | |
… | |
1107 | glDisable (GL_ALPHA_TEST); |
1169 | glDisable (GL_ALPHA_TEST); |
1108 | glDisable (GL_BLEND); |
1170 | glDisable (GL_BLEND); |
1109 | } |
1171 | } |
1110 | } |
1172 | } |
1111 | |
1173 | |
1112 | MODULE = CFClient PACKAGE = CFClient::Map |
1174 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1113 | |
1175 | |
1114 | CFClient::Map |
1176 | CFPlus::Map |
1115 | new (SV *class, int map_width, int map_height) |
1177 | new (SV *class, int map_width, int map_height) |
1116 | CODE: |
1178 | CODE: |
1117 | New (0, RETVAL, 1, struct map); |
1179 | New (0, RETVAL, 1, struct map); |
1118 | RETVAL->x = 0; |
1180 | RETVAL->x = 0; |
1119 | RETVAL->y = 0; |
1181 | RETVAL->y = 0; |
… | |
… | |
1129 | RETVAL->row = 0; |
1191 | RETVAL->row = 0; |
1130 | OUTPUT: |
1192 | OUTPUT: |
1131 | RETVAL |
1193 | RETVAL |
1132 | |
1194 | |
1133 | void |
1195 | void |
1134 | DESTROY (CFClient::Map self) |
1196 | DESTROY (CFPlus::Map self) |
1135 | CODE: |
1197 | CODE: |
1136 | { |
1198 | { |
1137 | map_clear (self); |
1199 | map_clear (self); |
1138 | Safefree (self->face); |
1200 | Safefree (self->face); |
1139 | Safefree (self->tex); |
1201 | Safefree (self->tex); |
1140 | Safefree (self); |
1202 | Safefree (self); |
1141 | } |
1203 | } |
1142 | |
1204 | |
1143 | void |
1205 | void |
1144 | clear (CFClient::Map self) |
1206 | clear (CFPlus::Map self) |
1145 | CODE: |
1207 | CODE: |
1146 | map_clear (self); |
1208 | map_clear (self); |
1147 | |
1209 | |
1148 | void |
1210 | void |
1149 | set_face (CFClient::Map self, int face, int texid) |
1211 | set_face (CFPlus::Map self, int face, int texid) |
1150 | CODE: |
1212 | CODE: |
1151 | { |
1213 | { |
1152 | while (self->faces <= face) |
1214 | while (self->faces <= face) |
1153 | { |
1215 | { |
1154 | Append (mapface, self->face, self->faces, self->faces); |
1216 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1157 | |
1219 | |
1158 | self->face [face] = texid; |
1220 | self->face [face] = texid; |
1159 | } |
1221 | } |
1160 | |
1222 | |
1161 | void |
1223 | void |
1162 | set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1224 | set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1163 | CODE: |
1225 | CODE: |
1164 | { |
1226 | { |
1165 | while (self->texs <= texid) |
1227 | while (self->texs <= texid) |
1166 | { |
1228 | { |
1167 | Append (maptex, self->tex, self->texs, self->texs); |
1229 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1191 | // from transparent color bleeding and ugly wrapping effects. |
1253 | // from transparent color bleeding and ugly wrapping effects. |
1192 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1254 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1193 | } |
1255 | } |
1194 | |
1256 | |
1195 | int |
1257 | int |
1196 | ox (CFClient::Map self) |
1258 | ox (CFPlus::Map self) |
1197 | ALIAS: |
1259 | ALIAS: |
1198 | oy = 1 |
1260 | oy = 1 |
1199 | x = 2 |
1261 | x = 2 |
1200 | y = 3 |
1262 | y = 3 |
1201 | w = 4 |
1263 | w = 4 |
… | |
… | |
1212 | } |
1274 | } |
1213 | OUTPUT: |
1275 | OUTPUT: |
1214 | RETVAL |
1276 | RETVAL |
1215 | |
1277 | |
1216 | void |
1278 | void |
1217 | scroll (CFClient::Map self, int dx, int dy) |
1279 | scroll (CFPlus::Map self, int dx, int dy) |
1218 | CODE: |
1280 | CODE: |
1219 | { |
1281 | { |
1220 | if (dx > 0) |
1282 | if (dx > 0) |
1221 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1283 | map_blank (self, self->x, self->y, dx, self->h); |
1222 | else if (dx < 0) |
1284 | else if (dx < 0) |
1223 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1285 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1224 | |
1286 | |
1225 | if (dy > 0) |
1287 | if (dy > 0) |
1226 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1288 | map_blank (self, self->x, self->y, self->w, dy); |
1227 | else if (dy < 0) |
1289 | else if (dy < 0) |
1228 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1290 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1229 | |
1291 | |
1230 | self->ox += dx; self->x += dx; |
1292 | self->ox += dx; self->x += dx; |
1231 | self->oy += dy; self->y += dy; |
1293 | self->oy += dy; self->y += dy; |
1232 | |
1294 | |
1233 | while (self->y < 0) |
1295 | while (self->y < 0) |
… | |
… | |
1238 | self->y += MAP_EXTEND_Y; |
1300 | self->y += MAP_EXTEND_Y; |
1239 | } |
1301 | } |
1240 | } |
1302 | } |
1241 | |
1303 | |
1242 | void |
1304 | void |
1243 | map1a_update (CFClient::Map self, SV *data_) |
1305 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1244 | CODE: |
1306 | CODE: |
1245 | { |
1307 | { |
1246 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1308 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1247 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1309 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1248 | mapcell *cell; |
1310 | mapcell *cell; |
1249 | int x, y, flags; |
1311 | int x, y, flags; |
1250 | |
1312 | |
1251 | while (data < data_end) |
1313 | while (data < data_end - 1) |
1252 | { |
1314 | { |
1253 | flags = (data [0] << 8) + data [1]; data += 2; |
1315 | flags = (data [0] << 8) + data [1]; data += 2; |
1254 | |
1316 | |
1255 | x = self->x + ((flags >> 10) & 63); |
1317 | x = self->x + ((flags >> 10) & 63); |
1256 | y = self->y + ((flags >> 4) & 63); |
1318 | y = self->y + ((flags >> 4) & 63); |
1257 | |
1319 | |
1258 | cell = map_get_cell (self, x, y); |
1320 | cell = map_get_cell (self, x, y); |
1259 | |
1321 | |
1260 | if (flags & 15) |
1322 | if (flags & 15) |
1261 | { |
1323 | { |
1262 | if (cell->darkness < 0) |
1324 | if (!cell->darkness) |
1263 | { |
1325 | { |
|
|
1326 | memset (cell, 0, sizeof (*cell)); |
1264 | cell->darkness = 0; |
1327 | cell->darkness = 256; |
1265 | cell->face [0] = 0; |
|
|
1266 | cell->face [1] = 0; |
|
|
1267 | cell->face [2] = 0; |
|
|
1268 | } |
1328 | } |
1269 | |
1329 | |
1270 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1271 | |
|
|
1272 | //TODO: don't trust server data to be in-range(!) |
1330 | //TODO: don't trust server data to be in-range(!) |
|
|
1331 | |
|
|
1332 | if (flags & 8) |
|
|
1333 | { |
|
|
1334 | if (extmap) |
|
|
1335 | { |
|
|
1336 | uint8_t ext, cmd; |
|
|
1337 | |
|
|
1338 | do |
|
|
1339 | { |
|
|
1340 | ext = *data++; |
|
|
1341 | cmd = ext & 0x3f; |
|
|
1342 | |
|
|
1343 | if (cmd < 4) |
|
|
1344 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1345 | else if (cmd == 5) // health |
|
|
1346 | { |
|
|
1347 | cell->stat_width = 1; |
|
|
1348 | cell->stat_hp = *data++; |
|
|
1349 | } |
|
|
1350 | else if (cmd == 6) // monster width |
|
|
1351 | cell->stat_width = *data++ + 1; |
|
|
1352 | else if (cmd == 0x47) // monster width |
|
|
1353 | { |
|
|
1354 | if (*data == 4) |
|
|
1355 | ; // decode player tag |
|
|
1356 | |
|
|
1357 | data += *data + 1; |
|
|
1358 | } |
|
|
1359 | else if (cmd == 8) // cell flags |
|
|
1360 | cell->flags = *data++; |
|
|
1361 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1362 | data += *data + 1; |
|
|
1363 | else |
|
|
1364 | data++; |
|
|
1365 | } |
|
|
1366 | while (ext & 0x80); |
|
|
1367 | } |
|
|
1368 | else |
|
|
1369 | cell->darkness = *data++ + 1; |
|
|
1370 | } |
1273 | |
1371 | |
1274 | if (flags & 4) |
1372 | if (flags & 4) |
1275 | { |
1373 | { |
1276 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1374 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1277 | } |
1375 | } |
… | |
… | |
1285 | { |
1383 | { |
1286 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1384 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1287 | } |
1385 | } |
1288 | } |
1386 | } |
1289 | else |
1387 | else |
1290 | cell->darkness = -1; |
1388 | cell->darkness = 0; |
1291 | } |
1389 | } |
1292 | } |
1390 | } |
1293 | |
1391 | |
1294 | SV * |
1392 | SV * |
1295 | mapmap (CFClient::Map self, int x0, int y0, int w, int h) |
1393 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1296 | CODE: |
1394 | CODE: |
1297 | { |
1395 | { |
1298 | int x1, x; |
1396 | int x1, x; |
1299 | int y1, y; |
1397 | int y1, y; |
1300 | int z; |
1398 | int z; |
… | |
… | |
1350 | } |
1448 | } |
1351 | OUTPUT: |
1449 | OUTPUT: |
1352 | RETVAL |
1450 | RETVAL |
1353 | |
1451 | |
1354 | void |
1452 | void |
1355 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1453 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1356 | CODE: |
1454 | CODE: |
1357 | { |
1455 | { |
1358 | int vx, vy; |
1456 | int vx, vy; |
1359 | int x, y, z; |
1457 | int x, y, z; |
1360 | int last_name; |
1458 | int last_name; |
… | |
… | |
1395 | { |
1493 | { |
1396 | mapcell *cell = row->col + (x + vx - row->c0); |
1494 | mapcell *cell = row->col + (x + vx - row->c0); |
1397 | |
1495 | |
1398 | face = cell->face [z]; |
1496 | face = cell->face [z]; |
1399 | |
1497 | |
1400 | if (face) |
1498 | if (face && face < self->texs) |
1401 | { |
1499 | { |
1402 | maptex tex = self->tex [face]; |
1500 | maptex tex = self->tex [face]; |
1403 | |
|
|
1404 | int px = (x + 1) * 32 - tex.w; |
1501 | int px = (x + 1) * 32 - tex.w; |
1405 | int py = (y + 1) * 32 - tex.h; |
1502 | int py = (y + 1) * 32 - tex.h; |
1406 | |
1503 | |
1407 | if (last_name != tex.name) |
1504 | if (last_name != tex.name) |
1408 | { |
1505 | { |
1409 | glEnd (); |
1506 | glEnd (); |
1410 | last_name = tex.name; |
|
|
1411 | glBindTexture (GL_TEXTURE_2D, last_name); |
1507 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1412 | glBegin (GL_QUADS); |
1508 | glBegin (GL_QUADS); |
1413 | } |
1509 | } |
1414 | |
1510 | |
1415 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1511 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1416 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1512 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1417 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1513 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1418 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1514 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1419 | } |
1515 | } |
|
|
1516 | |
|
|
1517 | if (cell->flags && z == 2) |
|
|
1518 | { |
|
|
1519 | if (cell->flags & 1) |
|
|
1520 | { |
|
|
1521 | maptex tex = self->tex [1]; |
|
|
1522 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1523 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1524 | |
|
|
1525 | glEnd (); |
|
|
1526 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1527 | glBegin (GL_QUADS); |
|
|
1528 | |
|
|
1529 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1530 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1531 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1532 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1533 | } |
|
|
1534 | } |
1420 | } |
1535 | } |
1421 | } |
1536 | } |
1422 | |
1537 | |
1423 | glEnd (); |
1538 | glEnd (); |
1424 | |
1539 | |
1425 | glDisable (GL_TEXTURE_2D); |
1540 | glDisable (GL_TEXTURE_2D); |
1426 | glDisable (GL_BLEND); |
1541 | glDisable (GL_BLEND); |
1427 | } |
|
|
1428 | |
1542 | |
|
|
1543 | // top layer: overlays such as the health bar |
|
|
1544 | for (y = 0; y < sh; y++) |
|
|
1545 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1546 | { |
|
|
1547 | maprow *row = self->row + (y + vy); |
|
|
1548 | |
|
|
1549 | for (x = 0; x < sw; x++) |
|
|
1550 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1551 | { |
|
|
1552 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1553 | |
|
|
1554 | int px = x * 32; |
|
|
1555 | int py = y * 32; |
|
|
1556 | |
|
|
1557 | if (cell->stat_hp) |
|
|
1558 | { |
|
|
1559 | int width = cell->stat_width * 32; |
|
|
1560 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1561 | |
|
|
1562 | glColor3ub (0, 0, 0); |
|
|
1563 | glRectf (px + 1, py - thick - 2, |
|
|
1564 | px + width - 1, py); |
|
|
1565 | |
|
|
1566 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1567 | glRectf (px + 2, |
|
|
1568 | py - thick - 1, |
|
|
1569 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
|
|
1570 | } |
|
|
1571 | } |
|
|
1572 | } |
|
|
1573 | } |
|
|
1574 | |
1429 | void |
1575 | void |
1430 | draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1576 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1431 | CODE: |
1577 | CODE: |
1432 | { |
1578 | { |
1433 | static float color[16][3] = { |
1579 | static float color[16][3] = { |
1434 | { 0.00F, 0.00F, 0.00F }, |
1580 | { 0.00F, 0.00F, 0.00F }, |
1435 | { 1.00F, 1.00F, 1.00F }, |
1581 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
1485 | glDisable (GL_BLEND); |
1631 | glDisable (GL_BLEND); |
1486 | glDisable (GL_TEXTURE_2D); |
1632 | glDisable (GL_TEXTURE_2D); |
1487 | } |
1633 | } |
1488 | |
1634 | |
1489 | void |
1635 | void |
1490 | fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1636 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1491 | PPCODE: |
1637 | PPCODE: |
1492 | { |
1638 | { |
1493 | int vx, vy; |
1639 | int vx, vy; |
1494 | int x, y; |
1640 | int x, y; |
1495 | int sw4 = (sw + 3) & ~3; |
1641 | int sw4 = (sw + 3) & ~3; |
… | |
… | |
1511 | for (x = 0; x < sw; x++) |
1657 | for (x = 0; x < sw; x++) |
1512 | if (row->c0 <= x + vx && x + vx < row->c1) |
1658 | if (row->c0 <= x + vx && x + vx < row->c1) |
1513 | { |
1659 | { |
1514 | mapcell *cell = row->col + (x + vx - row->c0); |
1660 | mapcell *cell = row->col + (x + vx - row->c0); |
1515 | |
1661 | |
1516 | darkness[y * sw4 + x] = cell->darkness < 0 |
1662 | darkness[y * sw4 + x] = cell->darkness |
|
|
1663 | ? 255 - (cell->darkness - 1) |
1517 | ? 255 - FOW_DARKNESS |
1664 | : 255 - FOW_DARKNESS; |
1518 | : 255 - cell->darkness; |
|
|
1519 | } |
1665 | } |
1520 | } |
1666 | } |
1521 | |
1667 | |
1522 | EXTEND (SP, 3); |
1668 | EXTEND (SP, 3); |
1523 | PUSHs (sv_2mortal (newSViv (sw4))); |
1669 | PUSHs (sv_2mortal (newSViv (sw4))); |
1524 | PUSHs (sv_2mortal (newSViv (sh))); |
1670 | PUSHs (sv_2mortal (newSViv (sh))); |
1525 | PUSHs (darkness_sv); |
1671 | PUSHs (darkness_sv); |
1526 | } |
1672 | } |
1527 | |
1673 | |
1528 | SV * |
1674 | SV * |
1529 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
1675 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
1530 | CODE: |
1676 | CODE: |
1531 | { |
1677 | { |
1532 | int x, y, x1, y1; |
1678 | int x, y, x1, y1; |
1533 | SV *data_sv = newSV (w * h * 7 + 5); |
1679 | SV *data_sv = newSV (w * h * 7 + 5); |
1534 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1680 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1596 | } |
1742 | } |
1597 | OUTPUT: |
1743 | OUTPUT: |
1598 | RETVAL |
1744 | RETVAL |
1599 | |
1745 | |
1600 | void |
1746 | void |
1601 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
1747 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
1602 | PPCODE: |
1748 | PPCODE: |
1603 | { |
1749 | { |
1604 | int x, y, z; |
1750 | int x, y, z; |
1605 | int w, h; |
1751 | int w, h; |
1606 | int x1, y1; |
1752 | int x1, y1; |
… | |
… | |
1638 | |
1784 | |
1639 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1785 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1640 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1786 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1641 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1787 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1642 | |
1788 | |
1643 | if (cell->darkness <= 0) |
1789 | if (cell->darkness == 0) |
1644 | { |
1790 | { |
1645 | cell->darkness = -1; |
1791 | cell->darkness = 0; |
1646 | |
1792 | |
1647 | for (z = 0; z <= 2; z++) |
1793 | for (z = 0; z <= 2; z++) |
1648 | { |
1794 | { |
1649 | cell->face[z] = face[z]; |
1795 | cell->face[z] = face[z]; |
1650 | |
1796 | |
… | |
… | |
1655 | } |
1801 | } |
1656 | } |
1802 | } |
1657 | } |
1803 | } |
1658 | } |
1804 | } |
1659 | |
1805 | |
1660 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1806 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1661 | |
1807 | |
1662 | CFClient::MixChunk |
1808 | CFPlus::MixChunk |
1663 | new_from_file (SV *class, char *path) |
1809 | new_from_file (SV *class, char *path) |
1664 | CODE: |
1810 | CODE: |
1665 | RETVAL = Mix_LoadWAV (path); |
1811 | RETVAL = Mix_LoadWAV (path); |
1666 | OUTPUT: |
1812 | OUTPUT: |
1667 | RETVAL |
1813 | RETVAL |
1668 | |
1814 | |
1669 | void |
1815 | void |
1670 | DESTROY (CFClient::MixChunk self) |
1816 | DESTROY (CFPlus::MixChunk self) |
1671 | CODE: |
1817 | CODE: |
1672 | Mix_FreeChunk (self); |
1818 | Mix_FreeChunk (self); |
1673 | |
1819 | |
1674 | int |
1820 | int |
1675 | volume (CFClient::MixChunk self, int volume = -1) |
1821 | volume (CFPlus::MixChunk self, int volume = -1) |
1676 | CODE: |
1822 | CODE: |
1677 | RETVAL = Mix_VolumeChunk (self, volume); |
1823 | RETVAL = Mix_VolumeChunk (self, volume); |
1678 | OUTPUT: |
1824 | OUTPUT: |
1679 | RETVAL |
1825 | RETVAL |
1680 | |
1826 | |
1681 | int |
1827 | int |
1682 | play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1828 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1683 | CODE: |
1829 | CODE: |
1684 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1830 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1685 | OUTPUT: |
1831 | OUTPUT: |
1686 | RETVAL |
1832 | RETVAL |
1687 | |
1833 | |
1688 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1834 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1689 | |
1835 | |
1690 | int |
1836 | int |
1691 | volume (int volume = -1) |
1837 | volume (int volume = -1) |
1692 | CODE: |
1838 | CODE: |
1693 | RETVAL = Mix_VolumeMusic (volume); |
1839 | RETVAL = Mix_VolumeMusic (volume); |
1694 | OUTPUT: |
1840 | OUTPUT: |
1695 | RETVAL |
1841 | RETVAL |
1696 | |
1842 | |
1697 | CFClient::MixMusic |
1843 | CFPlus::MixMusic |
1698 | new_from_file (SV *class, char *path) |
1844 | new_from_file (SV *class, char *path) |
1699 | CODE: |
1845 | CODE: |
1700 | RETVAL = Mix_LoadMUS (path); |
1846 | RETVAL = Mix_LoadMUS (path); |
1701 | OUTPUT: |
1847 | OUTPUT: |
1702 | RETVAL |
1848 | RETVAL |
1703 | |
1849 | |
1704 | void |
1850 | void |
1705 | DESTROY (CFClient::MixMusic self) |
1851 | DESTROY (CFPlus::MixMusic self) |
1706 | CODE: |
1852 | CODE: |
1707 | Mix_FreeMusic (self); |
1853 | Mix_FreeMusic (self); |
1708 | |
1854 | |
1709 | int |
1855 | int |
1710 | play (CFClient::MixMusic self, int loops = -1) |
1856 | play (CFPlus::MixMusic self, int loops = -1) |
1711 | CODE: |
1857 | CODE: |
1712 | RETVAL = Mix_PlayMusic (self, loops); |
1858 | RETVAL = Mix_PlayMusic (self, loops); |
1713 | OUTPUT: |
1859 | OUTPUT: |
1714 | RETVAL |
1860 | RETVAL |
1715 | |
1861 | |
1716 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1862 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1717 | |
1863 | |
1718 | BOOT: |
1864 | BOOT: |
1719 | { |
1865 | { |
1720 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1866 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1721 | static const struct { |
1867 | static const struct { |
1722 | const char *name; |
1868 | const char *name; |
1723 | IV iv; |
1869 | IV iv; |
1724 | } *civ, const_iv[] = { |
1870 | } *civ, const_iv[] = { |
1725 | # define const_iv(name) { # name, (IV)name } |
1871 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1788 | const_iv (GL_SEPARABLE_2D), |
1934 | const_iv (GL_SEPARABLE_2D), |
1789 | const_iv (GL_CONVOLUTION_2D), |
1935 | const_iv (GL_CONVOLUTION_2D), |
1790 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1936 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1791 | const_iv (GL_CONSTANT_BORDER), |
1937 | const_iv (GL_CONSTANT_BORDER), |
1792 | const_iv (GL_LINES), |
1938 | const_iv (GL_LINES), |
|
|
1939 | const_iv (GL_LINE_STRIP), |
1793 | const_iv (GL_LINE_LOOP), |
1940 | const_iv (GL_LINE_LOOP), |
1794 | const_iv (GL_QUADS), |
1941 | const_iv (GL_QUADS), |
1795 | const_iv (GL_QUAD_STRIP), |
1942 | const_iv (GL_QUAD_STRIP), |
1796 | const_iv (GL_TRIANGLES), |
1943 | const_iv (GL_TRIANGLES), |
1797 | const_iv (GL_TRIANGLE_STRIP), |
1944 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
1907 | r *= a; |
2054 | r *= a; |
1908 | g *= a; |
2055 | g *= a; |
1909 | b *= a; |
2056 | b *= a; |
1910 | } |
2057 | } |
1911 | // microsoft visual "c" rounds instead of truncating... |
2058 | // microsoft visual "c" rounds instead of truncating... |
1912 | glColor4ub (MIN ((int)(r * 256.f), 255), |
2059 | glColor4f (r, g, b, a); |
1913 | MIN ((int)(g * 256.f), 255), |
|
|
1914 | MIN ((int)(b * 256.f), 255), |
|
|
1915 | MIN ((int)(a * 256.f), 255)); |
|
|
1916 | |
2060 | |
1917 | void glInterleavedArrays (int format, int stride, char *data) |
2061 | void glInterleavedArrays (int format, int stride, char *data) |
1918 | |
2062 | |
1919 | void glDrawElements (int mode, int count, int type, char *indices) |
2063 | void glDrawElements (int mode, int count, int type, char *indices) |
1920 | |
2064 | |
… | |
… | |
1997 | |
2141 | |
1998 | void glEndList () |
2142 | void glEndList () |
1999 | |
2143 | |
2000 | void glCallList (int list) |
2144 | void glCallList (int list) |
2001 | |
2145 | |
2002 | |
|
|