ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.33 by root, Thu Apr 13 23:42:14 2006 UTC vs.
Revision 1.40 by root, Sat Apr 15 01:13:46 2006 UTC

37 37
38static void 38static void
39substitute_func (FcPattern *pattern, gpointer data) 39substitute_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
45static void 45static void
46layout_update (CFClient__Layout self) 46layout_update (CFClient__Layout self)
47{ 47{
66 66
67typedef struct { 67typedef 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
73typedef struct { 74typedef struct {
74 int16_t darkness; 75 int16_t darkness;
75 uint16_t face[3]; 76 uint16_t face[3];
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
261void 264void
265average (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
289void
262fatal (char *message) 290fatal (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
271MODULE = CFClient PACKAGE = CFClient::Layout 299MODULE = CFClient PACKAGE = CFClient::Layout
272 300
285 CODE: 313 CODE:
286 g_object_unref (self->pl); 314 g_object_unref (self->pl);
287 Safefree (self); 315 Safefree (self);
288 316
289void 317void
318set_text (CFClient::Layout self, SV *text_)
319 CODE:
320{
321 STRLEN textlen;
322 char *text = SvPVutf8 (text_, textlen);
323
324 pango_layout_set_text (self->pl, text, textlen);
325}
326
327void
290set_markup (CFClient::Layout self, SV *text_) 328set_markup (CFClient::Layout self, SV *text_)
291 CODE: 329 CODE:
292{ 330{
293 STRLEN textlen; 331 STRLEN textlen;
294 char *text = SvPVutf8 (text_, textlen); 332 char *text = SvPVutf8 (text_, textlen);
381} 419}
382 420
383MODULE = CFClient PACKAGE = CFClient::Texture 421MODULE = CFClient PACKAGE = CFClient::Texture
384 422
385void 423void
386draw_quad (SV *self, double x, double y, double w = 0, double h = 0) 424draw_quad (SV *self, float x, float y, float w = 0, float h = 0)
387 PROTOTYPE: $$$;$$ 425 PROTOTYPE: $$$;$$
388 CODE: 426 CODE:
389{ 427{
390 HV *hv = (HV *)SvRV (self); 428 HV *hv = (HV *)SvRV (self);
391 double s = SvNV (*hv_fetch (hv, "s", 1, 1)); 429 float s = SvNV (*hv_fetch (hv, "s", 1, 1));
392 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 430 float t = SvNV (*hv_fetch (hv, "t", 1, 1));
393 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 431 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
432 int wrap_mode = SvIV (*hv_fetch (hv, "wrap_mode", 9, 1));
394 433
395 if (items < 5) 434 if (items < 5)
396 { 435 {
397 w = SvNV (*hv_fetch (hv, "w", 1, 1)); 436 w = SvNV (*hv_fetch (hv, "w", 1, 1));
398 h = SvNV (*hv_fetch (hv, "h", 1, 1)); 437 h = SvNV (*hv_fetch (hv, "h", 1, 1));
399 } 438 }
400 439
401 glBindTexture (GL_TEXTURE_2D, name); 440 glBindTexture (GL_TEXTURE_2D, name);
441 if (wrap_mode) {
442 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
443 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
444 }
402 glBegin (GL_QUADS); 445 glBegin (GL_QUADS);
403 glTexCoord2d (0, 0); glVertex2d (x , y ); 446 glTexCoord2f (0, 0); glVertex2f (x , y );
404 glTexCoord2d (0, t); glVertex2d (x , y + h); 447 glTexCoord2f (0, t); glVertex2f (x , y + h);
405 glTexCoord2d (s, t); glVertex2d (x + w, y + h); 448 glTexCoord2f (s, t); glVertex2f (x + w, y + h);
406 glTexCoord2d (s, 0); glVertex2d (x + w, y ); 449 glTexCoord2f (s, 0); glVertex2f (x + w, y );
407 glEnd (); 450 glEnd ();
408} 451}
409 452
410MODULE = CFClient PACKAGE = CFClient::Map 453MODULE = CFClient PACKAGE = CFClient::Map
411 454
439clear (CFClient::Map self) 482clear (CFClient::Map self)
440 CODE: 483 CODE:
441 map_clear (self); 484 map_clear (self);
442 485
443void 486void
444set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) 487set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t, int r, int g, int b, int a)
445 CODE: 488 CODE:
446{ 489{
447 while (self->faces < face) 490 while (self->faces < face)
448 { 491 {
449 Append (mapface, self->face, self->faces, self->faces); 492 Append (mapface, self->face, self->faces, self->faces);
450 self->faces *= 2; 493 self->faces *= 2;
451 } 494 }
452 495
496 mapface *f = self->face + face;
497
453 self->face [face].name = name; 498 f->name = name;
454 self->face [face].w = w; 499 f->w = w;
455 self->face [face].h = h; 500 f->h = h;
456 self->face [face].s = s; 501 f->s = s;
457 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;
458} 507}
459 508
460void 509void
461scroll (CFClient::Map self, int dx, int dy) 510scroll (CFClient::Map self, int dx, int dy)
462 CODE: 511 CODE:
562 else 611 else
563 cell->darkness = -1; 612 cell->darkness = -1;
564 } 613 }
565} 614}
566 615
616SV *
617mapmap (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
567void 676void
568draw (CFClient::Map self, int x0, int y0, int sw, int sh) 677draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
569 PPCODE: 678 PPCODE:
570{ 679{
571 int sw4 = (sw + 3) & ~3; 680 int sw4 = (sw + 3) & ~3;
572 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 681 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
573 uint8_t *darkness = SvPVX (darkness_sv); 682 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
574 683
575 SvPOK_only (darkness_sv); 684 SvPOK_only (darkness_sv);
576 SvCUR_set (darkness_sv, sw4 * sh); 685 SvCUR_set (darkness_sv, sw4 * sh);
577 686
687 int vx = self->x + (self->w - sw) / 2 - shift_x;
688 int vy = self->y + (self->h - sh) / 2 - shift_y;
689
690 if (0)
691 {
578 int vx = self->vx = self->w >= sw 692 int vx = self->vx = self->w >= sw
579 ? self->x + (self->w - sw) / 2 693 ? self->x + (self->w - sw) / 2
580 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); 694 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
581 695
582 int vy = self->vy = self->h >= sh 696 int vy = self->vy = self->h >= sh
583 ? self->y + (self->h - sh) / 2 697 ? self->y + (self->h - sh) / 2
584 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); 698 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
699 }
585 700
586 glColor4ub (255, 255, 255, 255); 701 glColor4ub (255, 255, 255, 255);
587 702
588 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 703 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
589 glEnable (GL_BLEND); 704 glEnable (GL_BLEND);
636 } 751 }
637 } 752 }
638 753
639 glEnd (); 754 glEnd ();
640 755
756 glDisable (GL_TEXTURE_2D);
757 glDisable (GL_BLEND);
758
641 EXTEND (SP, 3); 759 EXTEND (SP, 3);
642 PUSHs (sv_2mortal (newSViv (sw4))); 760 PUSHs (sv_2mortal (newSViv (sw4)));
643 PUSHs (sv_2mortal (newSViv (sh))); 761 PUSHs (sv_2mortal (newSViv (sh)));
644 PUSHs (darkness_sv); 762 PUSHs (darkness_sv);
645
646 glDisable (GL_TEXTURE_2D);
647 glDisable (GL_BLEND);
648} 763}
649 764

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines