… | |
… | |
66 | |
66 | |
67 | typedef struct { |
67 | typedef struct { |
68 | GLint name; |
68 | GLint name; |
69 | int w, h; |
69 | int w, h; |
70 | float s, t; |
70 | float s, t; |
|
|
71 | uint8_t r, g, b, a; |
71 | } mapface; |
72 | } mapface; |
72 | |
73 | |
73 | typedef struct { |
74 | typedef struct { |
74 | int16_t darkness; |
75 | int16_t darkness; |
75 | uint16_t face[3]; |
76 | uint16_t face[3]; |
… | |
… | |
216 | SDL_RWops *rw = ix |
217 | SDL_RWops *rw = ix |
217 | ? SDL_RWFromFile (image, "r") |
218 | ? SDL_RWFromFile (image, "r") |
218 | : SDL_RWFromConstMem (image, image_len); |
219 | : SDL_RWFromConstMem (image, image_len); |
219 | |
220 | |
220 | if (!rw) |
221 | if (!rw) |
221 | croak ("load_image: unable to open file"); |
222 | croak ("load_image: %s", SDL_GetError ()); |
222 | |
223 | |
223 | surface = IMG_Load_RW (rw, 1); |
224 | surface = IMG_Load_RW (rw, 1); |
224 | if (!surface) |
225 | if (!surface) |
225 | croak ("load_image: unable to read file"); |
226 | croak ("load_image: %s", SDL_GetError ()); |
226 | |
227 | |
227 | fmt.palette = NULL; |
228 | fmt.palette = NULL; |
228 | fmt.BitsPerPixel = 32; |
229 | fmt.BitsPerPixel = 32; |
229 | fmt.BytesPerPixel = 4; |
230 | fmt.BytesPerPixel = 4; |
230 | fmt.Rmask = 0x000000ff; |
231 | fmt.Rmask = 0x000000ff; |
… | |
… | |
242 | fmt.colorkey = 0; |
243 | fmt.colorkey = 0; |
243 | fmt.alpha = 0; |
244 | fmt.alpha = 0; |
244 | |
245 | |
245 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
246 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
246 | |
247 | |
|
|
248 | assert (surface2->pitch == surface2->w * 4); |
|
|
249 | |
247 | EXTEND (SP, 5); |
250 | EXTEND (SP, 5); |
248 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
251 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
249 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
252 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
250 | SDL_LockSurface (surface2); |
253 | SDL_LockSurface (surface2); |
251 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
254 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
… | |
… | |
257 | SDL_FreeSurface (surface); |
260 | SDL_FreeSurface (surface); |
258 | SDL_FreeSurface (surface2); |
261 | SDL_FreeSurface (surface2); |
259 | } |
262 | } |
260 | |
263 | |
261 | void |
264 | void |
|
|
265 | average (int x, int y, uint32_t *data) |
|
|
266 | PPCODE: |
|
|
267 | { |
|
|
268 | uint32_t r = 0, g = 0, b = 0, a = 0; |
|
|
269 | |
|
|
270 | x = y = x * y; |
|
|
271 | |
|
|
272 | while (x--) |
|
|
273 | { |
|
|
274 | uint32_t p = *data++; |
|
|
275 | |
|
|
276 | r += (p ) & 255; |
|
|
277 | g += (p >> 8) & 255; |
|
|
278 | b += (p >> 16) & 255; |
|
|
279 | a += (p >> 24) & 255; |
|
|
280 | } |
|
|
281 | |
|
|
282 | EXTEND (SP, 4); |
|
|
283 | PUSHs (sv_2mortal (newSViv (r / y))); |
|
|
284 | PUSHs (sv_2mortal (newSViv (g / y))); |
|
|
285 | PUSHs (sv_2mortal (newSViv (b / y))); |
|
|
286 | PUSHs (sv_2mortal (newSViv (a / y))); |
|
|
287 | } |
|
|
288 | |
|
|
289 | void |
262 | fatal (char *message) |
290 | fatal (char *message) |
263 | CODE: |
291 | CODE: |
264 | #ifdef WIN32 |
292 | #ifdef WIN32 |
265 | 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); |
266 | #else |
294 | #else |
267 | fprintf (stderr, "%s\n", message); |
295 | fprintf (stderr, "FATAL: %s\n", message); |
268 | #endif |
296 | #endif |
269 | exit (1); |
297 | exit (1); |
270 | |
298 | |
271 | MODULE = CFClient PACKAGE = CFClient::Layout |
299 | MODULE = CFClient PACKAGE = CFClient::Layout |
272 | |
300 | |
… | |
… | |
454 | clear (CFClient::Map self) |
482 | clear (CFClient::Map self) |
455 | CODE: |
483 | CODE: |
456 | map_clear (self); |
484 | map_clear (self); |
457 | |
485 | |
458 | void |
486 | void |
459 | set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) |
487 | set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
460 | CODE: |
488 | CODE: |
461 | { |
489 | { |
462 | while (self->faces < face) |
490 | while (self->faces < face) |
463 | { |
491 | { |
464 | Append (mapface, self->face, self->faces, self->faces); |
492 | Append (mapface, self->face, self->faces, self->faces); |
465 | self->faces *= 2; |
493 | self->faces *= 2; |
466 | } |
494 | } |
467 | |
495 | |
|
|
496 | mapface *f = self->face + face; |
|
|
497 | |
468 | self->face [face].name = name; |
498 | f->name = name; |
469 | self->face [face].w = w; |
499 | f->w = w; |
470 | self->face [face].h = h; |
500 | f->h = h; |
471 | self->face [face].s = s; |
501 | f->s = s; |
472 | self->face [face].t = t; |
502 | f->t = t; |
|
|
503 | f->r = r; |
|
|
504 | f->g = g; |
|
|
505 | f->b = b; |
|
|
506 | f->a = a; |
473 | } |
507 | } |
474 | |
508 | |
475 | void |
509 | void |
476 | scroll (CFClient::Map self, int dx, int dy) |
510 | scroll (CFClient::Map self, int dx, int dy) |
477 | CODE: |
511 | CODE: |
… | |
… | |
577 | else |
611 | else |
578 | cell->darkness = -1; |
612 | cell->darkness = -1; |
579 | } |
613 | } |
580 | } |
614 | } |
581 | |
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 | |
582 | void |
676 | void |
583 | 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) |
584 | PPCODE: |
678 | PPCODE: |
585 | { |
679 | { |
586 | int sw4 = (sw + 3) & ~3; |
680 | int sw4 = (sw + 3) & ~3; |