… | |
… | |
263 | |
263 | |
264 | void |
264 | void |
265 | average (int x, int y, uint32_t *data) |
265 | average (int x, int y, uint32_t *data) |
266 | PPCODE: |
266 | PPCODE: |
267 | { |
267 | { |
268 | // only good for x * y < 32768 |
|
|
269 | uint32_t r = 0, g = 0, b = 0, a = 0; |
268 | uint32_t r = 0, g = 0, b = 0, a = 0; |
270 | |
269 | |
271 | x = y = x * y; |
270 | x = y = x * y; |
272 | |
|
|
273 | assert (x < 32768); |
|
|
274 | |
271 | |
275 | while (x--) |
272 | while (x--) |
276 | { |
273 | { |
277 | uint32_t p = *data++; |
274 | uint32_t p = *data++; |
278 | |
275 | |
… | |
… | |
281 | b += (p >> 16) & 255; |
278 | b += (p >> 16) & 255; |
282 | a += (p >> 24) & 255; |
279 | a += (p >> 24) & 255; |
283 | } |
280 | } |
284 | |
281 | |
285 | EXTEND (SP, 4); |
282 | EXTEND (SP, 4); |
286 | PUSHs (sv_2mortal (newSViv (r * 255 / y))); |
283 | PUSHs (sv_2mortal (newSViv (r / y))); |
287 | PUSHs (sv_2mortal (newSViv (g * 255 / y))); |
284 | PUSHs (sv_2mortal (newSViv (g / y))); |
288 | PUSHs (sv_2mortal (newSViv (b * 255 / y))); |
285 | PUSHs (sv_2mortal (newSViv (b / y))); |
289 | PUSHs (sv_2mortal (newSViv (a * 255 / y))); |
286 | PUSHs (sv_2mortal (newSViv (a / y))); |
290 | } |
287 | } |
291 | |
288 | |
292 | void |
289 | void |
293 | fatal (char *message) |
290 | fatal (char *message) |
294 | CODE: |
291 | CODE: |
295 | #ifdef WIN32 |
292 | #ifdef WIN32 |
296 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
293 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
297 | #else |
294 | #else |
298 | fprintf (stderr, "%s\n", message); |
295 | fprintf (stderr, "FATAL: %s\n", message); |
299 | #endif |
296 | #endif |
300 | exit (1); |
297 | exit (1); |
301 | |
298 | |
302 | MODULE = CFClient PACKAGE = CFClient::Layout |
299 | MODULE = CFClient PACKAGE = CFClient::Layout |
303 | |
300 | |
… | |
… | |
614 | else |
611 | else |
615 | cell->darkness = -1; |
612 | cell->darkness = -1; |
616 | } |
613 | } |
617 | } |
614 | } |
618 | |
615 | |
|
|
616 | SV * |
|
|
617 | mapmap (CFClient::Map self, int w, int h) |
|
|
618 | CODE: |
|
|
619 | { |
|
|
620 | int x0, x1, x; |
|
|
621 | int y0, y1, y; |
|
|
622 | int z; |
|
|
623 | SV *map_sv = newSV (w * h * sizeof (uint32_t)); |
|
|
624 | uint32_t *map = (uint32_t *)SvPVX (map_sv); |
|
|
625 | |
|
|
626 | SvPOK_only (map_sv); |
|
|
627 | SvCUR_set (map_sv, w * h * sizeof (uint32_t)); |
|
|
628 | |
|
|
629 | x0 = self->x - w / 2; x1 = x0 + w; |
|
|
630 | y0 = self->y - h / 2; y1 = y0 + h; |
|
|
631 | |
|
|
632 | for (y = y0; y < y1; y++) |
|
|
633 | { |
|
|
634 | maprow *row = 0 <= y && y < self->rows |
|
|
635 | ? self->row + y |
|
|
636 | : 0; |
|
|
637 | |
|
|
638 | for (x = x0; x < x1; x++) |
|
|
639 | { |
|
|
640 | int r = 32, g = 32, b = 32, a = 192; |
|
|
641 | |
|
|
642 | if (row && row->c0 <= x && x < row->c1) |
|
|
643 | { |
|
|
644 | mapcell *cell = row->col + (x - row->c0); |
|
|
645 | |
|
|
646 | for (z = 0; z <= 0; z++) |
|
|
647 | { |
|
|
648 | uint16_t face = cell->face [z]; |
|
|
649 | |
|
|
650 | if (face) |
|
|
651 | { |
|
|
652 | mapface tex = self->face [face]; |
|
|
653 | int a0 = 255 - tex.a; |
|
|
654 | int a1 = tex.a; |
|
|
655 | |
|
|
656 | r = (r * a0 + tex.r * a1) / 255; |
|
|
657 | g = (g * a0 + tex.g * a1) / 255; |
|
|
658 | b = (b * a0 + tex.b * a1) / 255; |
|
|
659 | a = (a * a0 + tex.a * a1) / 255; |
|
|
660 | } |
|
|
661 | } |
|
|
662 | } |
|
|
663 | |
|
|
664 | *map++ = (r ) |
|
|
665 | | (g << 8) |
|
|
666 | | (b << 16) |
|
|
667 | | (a << 24); |
|
|
668 | } |
|
|
669 | } |
|
|
670 | |
|
|
671 | RETVAL = map_sv; |
|
|
672 | } |
|
|
673 | OUTPUT: |
|
|
674 | RETVAL |
|
|
675 | |
619 | void |
676 | void |
620 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
677 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
621 | PPCODE: |
678 | PPCODE: |
622 | { |
679 | { |
623 | int sw4 = (sw + 3) & ~3; |
680 | int sw4 = (sw + 3) & ~3; |