… | |
… | |
37 | |
37 | |
38 | static void |
38 | static void |
39 | substitute_func (FcPattern *pattern, gpointer data) |
39 | substitute_func (FcPattern *pattern, gpointer data) |
40 | { |
40 | { |
41 | FcPatternAddBool (pattern, FC_HINTING , 1); |
41 | FcPatternAddBool (pattern, FC_HINTING , 1); |
42 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
42 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
43 | } |
43 | } |
44 | |
44 | |
45 | static void |
45 | static void |
46 | layout_update (CFClient__Layout self) |
46 | layout_update (CFClient__Layout self) |
47 | { |
47 | { |
… | |
… | |
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]; |
… | |
… | |
150 | if (x >= row->c0) |
151 | if (x >= row->c0) |
151 | { |
152 | { |
152 | if (x >= row->c1) |
153 | if (x >= row->c1) |
153 | break; |
154 | break; |
154 | |
155 | |
155 | mapcell *cell = row->col + (x - row->c0); |
156 | row->col[x - row->c0].darkness = -1; |
156 | cell->darkness = -1; |
|
|
157 | cell->face [2] = 0; |
|
|
158 | } |
157 | } |
159 | } |
158 | } |
160 | } |
159 | } |
161 | |
160 | |
162 | MODULE = CFClient PACKAGE = CFClient |
161 | MODULE = CFClient PACKAGE = CFClient |
… | |
… | |
244 | fmt.colorkey = 0; |
243 | fmt.colorkey = 0; |
245 | fmt.alpha = 0; |
244 | fmt.alpha = 0; |
246 | |
245 | |
247 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
246 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
248 | |
247 | |
|
|
248 | assert (surface2->pitch == surface2->w * 4); |
|
|
249 | |
249 | EXTEND (SP, 5); |
250 | EXTEND (SP, 5); |
250 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
251 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
251 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
252 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
252 | SDL_LockSurface (surface2); |
253 | SDL_LockSurface (surface2); |
253 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
254 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
… | |
… | |
259 | SDL_FreeSurface (surface); |
260 | SDL_FreeSurface (surface); |
260 | SDL_FreeSurface (surface2); |
261 | SDL_FreeSurface (surface2); |
261 | } |
262 | } |
262 | |
263 | |
263 | void |
264 | void |
|
|
265 | average (int x, int y, uint32_t *data) |
|
|
266 | PPCODE: |
|
|
267 | { |
|
|
268 | // only good for x * y < 32768 |
|
|
269 | uint32_t r = 0, g = 0, b = 0, a = 0; |
|
|
270 | |
|
|
271 | x = y = x * y; |
|
|
272 | |
|
|
273 | assert (x < 32768); |
|
|
274 | |
|
|
275 | while (x--) |
|
|
276 | { |
|
|
277 | uint32_t p = *data++; |
|
|
278 | |
|
|
279 | r += (p ) & 255; |
|
|
280 | g += (p >> 8) & 255; |
|
|
281 | b += (p >> 16) & 255; |
|
|
282 | a += (p >> 24) & 255; |
|
|
283 | } |
|
|
284 | |
|
|
285 | EXTEND (SP, 4); |
|
|
286 | PUSHs (sv_2mortal (newSViv (r * 255 / y))); |
|
|
287 | PUSHs (sv_2mortal (newSViv (g * 255 / y))); |
|
|
288 | PUSHs (sv_2mortal (newSViv (b * 255 / y))); |
|
|
289 | PUSHs (sv_2mortal (newSViv (a * 255 / y))); |
|
|
290 | } |
|
|
291 | |
|
|
292 | void |
264 | fatal (char *message) |
293 | fatal (char *message) |
265 | CODE: |
294 | CODE: |
266 | #ifdef WIN32 |
295 | #ifdef WIN32 |
267 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
296 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
268 | #else |
297 | #else |
… | |
… | |
287 | CODE: |
316 | CODE: |
288 | g_object_unref (self->pl); |
317 | g_object_unref (self->pl); |
289 | Safefree (self); |
318 | Safefree (self); |
290 | |
319 | |
291 | void |
320 | void |
|
|
321 | set_text (CFClient::Layout self, SV *text_) |
|
|
322 | CODE: |
|
|
323 | { |
|
|
324 | STRLEN textlen; |
|
|
325 | char *text = SvPVutf8 (text_, textlen); |
|
|
326 | |
|
|
327 | pango_layout_set_text (self->pl, text, textlen); |
|
|
328 | } |
|
|
329 | |
|
|
330 | void |
292 | set_markup (CFClient::Layout self, SV *text_) |
331 | set_markup (CFClient::Layout self, SV *text_) |
293 | CODE: |
332 | CODE: |
294 | { |
333 | { |
295 | STRLEN textlen; |
334 | STRLEN textlen; |
296 | char *text = SvPVutf8 (text_, textlen); |
335 | char *text = SvPVutf8 (text_, textlen); |
… | |
… | |
383 | } |
422 | } |
384 | |
423 | |
385 | MODULE = CFClient PACKAGE = CFClient::Texture |
424 | MODULE = CFClient PACKAGE = CFClient::Texture |
386 | |
425 | |
387 | void |
426 | void |
388 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
427 | draw_quad (SV *self, float x, float y, float w = 0, float h = 0) |
389 | PROTOTYPE: $$$;$$ |
428 | PROTOTYPE: $$$;$$ |
390 | CODE: |
429 | CODE: |
391 | { |
430 | { |
392 | HV *hv = (HV *)SvRV (self); |
431 | HV *hv = (HV *)SvRV (self); |
393 | double s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
432 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
394 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
433 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
395 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
434 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
|
|
435 | int wrap_mode = SvIV (*hv_fetch (hv, "wrap_mode", 9, 1)); |
396 | |
436 | |
397 | if (items < 5) |
437 | if (items < 5) |
398 | { |
438 | { |
399 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
439 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
400 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
440 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
401 | } |
441 | } |
402 | |
442 | |
403 | glBindTexture (GL_TEXTURE_2D, name); |
443 | glBindTexture (GL_TEXTURE_2D, name); |
|
|
444 | if (wrap_mode) { |
|
|
445 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
|
|
446 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
|
|
447 | } |
404 | glBegin (GL_QUADS); |
448 | glBegin (GL_QUADS); |
405 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
449 | glTexCoord2f (0, 0); glVertex2f (x , y ); |
406 | glTexCoord2d (0, t); glVertex2d (x , y + h); |
450 | glTexCoord2f (0, t); glVertex2f (x , y + h); |
407 | glTexCoord2d (s, t); glVertex2d (x + w, y + h); |
451 | glTexCoord2f (s, t); glVertex2f (x + w, y + h); |
408 | glTexCoord2d (s, 0); glVertex2d (x + w, y ); |
452 | glTexCoord2f (s, 0); glVertex2f (x + w, y ); |
409 | glEnd (); |
453 | glEnd (); |
410 | } |
454 | } |
411 | |
455 | |
412 | MODULE = CFClient PACKAGE = CFClient::Map |
456 | MODULE = CFClient PACKAGE = CFClient::Map |
413 | |
457 | |
… | |
… | |
441 | clear (CFClient::Map self) |
485 | clear (CFClient::Map self) |
442 | CODE: |
486 | CODE: |
443 | map_clear (self); |
487 | map_clear (self); |
444 | |
488 | |
445 | void |
489 | void |
446 | set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) |
490 | 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) |
447 | CODE: |
491 | CODE: |
448 | { |
492 | { |
449 | while (self->faces < face) |
493 | while (self->faces < face) |
450 | { |
494 | { |
451 | Append (mapface, self->face, self->faces, self->faces); |
495 | Append (mapface, self->face, self->faces, self->faces); |
452 | self->faces *= 2; |
496 | self->faces *= 2; |
453 | } |
497 | } |
454 | |
498 | |
|
|
499 | mapface *f = self->face + face; |
|
|
500 | |
455 | self->face [face].name = name; |
501 | f->name = name; |
456 | self->face [face].w = w; |
502 | f->w = w; |
457 | self->face [face].h = h; |
503 | f->h = h; |
458 | self->face [face].s = s; |
504 | f->s = s; |
459 | self->face [face].t = t; |
505 | f->t = t; |
|
|
506 | f->r = r; |
|
|
507 | f->g = g; |
|
|
508 | f->b = b; |
|
|
509 | f->a = a; |
460 | } |
510 | } |
461 | |
511 | |
462 | void |
512 | void |
463 | scroll (CFClient::Map self, int dx, int dy) |
513 | scroll (CFClient::Map self, int dx, int dy) |
464 | CODE: |
514 | CODE: |
… | |
… | |
560 | { |
610 | { |
561 | cell->face [2] = (data [0] << 8) + data [1]; data += 2; |
611 | cell->face [2] = (data [0] << 8) + data [1]; data += 2; |
562 | } |
612 | } |
563 | } |
613 | } |
564 | else |
614 | else |
565 | { |
|
|
566 | cell->darkness = -1; |
615 | cell->darkness = -1; |
567 | cell->face [2] = 0; |
|
|
568 | } |
|
|
569 | } |
616 | } |
570 | } |
617 | } |
571 | |
618 | |
572 | void |
619 | void |
573 | draw (CFClient::Map self, int x0, int y0, int sw, int sh) |
620 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
574 | CODE: |
621 | PPCODE: |
575 | { |
622 | { |
|
|
623 | int sw4 = (sw + 3) & ~3; |
|
|
624 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
|
|
625 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
626 | |
|
|
627 | SvPOK_only (darkness_sv); |
|
|
628 | SvCUR_set (darkness_sv, sw4 * sh); |
|
|
629 | |
|
|
630 | int vx = self->x + (self->w - sw) / 2 - shift_x; |
|
|
631 | int vy = self->y + (self->h - sh) / 2 - shift_y; |
|
|
632 | |
|
|
633 | if (0) |
|
|
634 | { |
576 | int vx = self->vx = self->w >= sw |
635 | int vx = self->vx = self->w >= sw |
577 | ? self->x + (self->w - sw) / 2 |
636 | ? self->x + (self->w - sw) / 2 |
578 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
637 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
579 | |
638 | |
580 | int vy = self->vy = self->h >= sh |
639 | int vy = self->vy = self->h >= sh |
581 | ? self->y + (self->h - sh) / 2 |
640 | ? self->y + (self->h - sh) / 2 |
582 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
641 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
642 | } |
583 | |
643 | |
584 | glColor4ub (255, 255, 255, 255); |
644 | glColor4ub (255, 255, 255, 255); |
585 | |
645 | |
586 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
646 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
587 | glEnable (GL_BLEND); |
647 | glEnable (GL_BLEND); |
… | |
… | |
602 | |
662 | |
603 | for (x = 0; x < sw; x++) |
663 | for (x = 0; x < sw; x++) |
604 | if (row->c0 <= x + vx && x + vx < row->c1) |
664 | if (row->c0 <= x + vx && x + vx < row->c1) |
605 | { |
665 | { |
606 | mapcell *cell = row->col + (x + vx - row->c0); |
666 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
667 | |
|
|
668 | darkness[y * sw4 + x] = cell->darkness < 0 |
|
|
669 | ? 255 - FOW_DARKNESS |
|
|
670 | : 255 - cell->darkness; |
|
|
671 | |
607 | uint16_t face = cell->face [z]; |
672 | uint16_t face = cell->face [z]; |
608 | |
673 | |
609 | if (face) |
674 | if (face) |
610 | { |
675 | { |
611 | mapface tex = self->face [face]; |
676 | mapface tex = self->face [face]; |
… | |
… | |
628 | } |
693 | } |
629 | } |
694 | } |
630 | } |
695 | } |
631 | |
696 | |
632 | glEnd (); |
697 | glEnd (); |
633 | } |
|
|
634 | |
698 | |
|
|
699 | glDisable (GL_TEXTURE_2D); |
|
|
700 | glDisable (GL_BLEND); |
|
|
701 | |
|
|
702 | EXTEND (SP, 3); |
|
|
703 | PUSHs (sv_2mortal (newSViv (sw4))); |
|
|
704 | PUSHs (sv_2mortal (newSViv (sh))); |
|
|
705 | PUSHs (darkness_sv); |
|
|
706 | } |
|
|
707 | |