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.30 by root, Thu Apr 13 23:07:56 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];
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
162MODULE = CFClient PACKAGE = CFClient 161MODULE = 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
263void 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
264fatal (char *message) 290fatal (char *message)
265 CODE: 291 CODE:
266#ifdef WIN32 292#ifdef WIN32
267 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);
268#else 294#else
269 fprintf (stderr, "%s\n", message); 295 fprintf (stderr, "FATAL: %s\n", message);
270#endif 296#endif
271 exit (1); 297 exit (1);
272 298
273MODULE = CFClient PACKAGE = CFClient::Layout 299MODULE = CFClient PACKAGE = CFClient::Layout
274 300
287 CODE: 313 CODE:
288 g_object_unref (self->pl); 314 g_object_unref (self->pl);
289 Safefree (self); 315 Safefree (self);
290 316
291void 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
292set_markup (CFClient::Layout self, SV *text_) 328set_markup (CFClient::Layout self, SV *text_)
293 CODE: 329 CODE:
294{ 330{
295 STRLEN textlen; 331 STRLEN textlen;
296 char *text = SvPVutf8 (text_, textlen); 332 char *text = SvPVutf8 (text_, textlen);
383} 419}
384 420
385MODULE = CFClient PACKAGE = CFClient::Texture 421MODULE = CFClient PACKAGE = CFClient::Texture
386 422
387void 423void
388draw_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)
389 PROTOTYPE: $$$;$$ 425 PROTOTYPE: $$$;$$
390 CODE: 426 CODE:
391{ 427{
392 HV *hv = (HV *)SvRV (self); 428 HV *hv = (HV *)SvRV (self);
393 double s = SvNV (*hv_fetch (hv, "s", 1, 1)); 429 float s = SvNV (*hv_fetch (hv, "s", 1, 1));
394 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 430 float t = SvNV (*hv_fetch (hv, "t", 1, 1));
395 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));
396 433
397 if (items < 5) 434 if (items < 5)
398 { 435 {
399 w = SvNV (*hv_fetch (hv, "w", 1, 1)); 436 w = SvNV (*hv_fetch (hv, "w", 1, 1));
400 h = SvNV (*hv_fetch (hv, "h", 1, 1)); 437 h = SvNV (*hv_fetch (hv, "h", 1, 1));
401 } 438 }
402 439
403 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 }
404 glBegin (GL_QUADS); 445 glBegin (GL_QUADS);
405 glTexCoord2d (0, 0); glVertex2d (x , y ); 446 glTexCoord2f (0, 0); glVertex2f (x , y );
406 glTexCoord2d (0, t); glVertex2d (x , y + h); 447 glTexCoord2f (0, t); glVertex2f (x , y + h);
407 glTexCoord2d (s, t); glVertex2d (x + w, y + h); 448 glTexCoord2f (s, t); glVertex2f (x + w, y + h);
408 glTexCoord2d (s, 0); glVertex2d (x + w, y ); 449 glTexCoord2f (s, 0); glVertex2f (x + w, y );
409 glEnd (); 450 glEnd ();
410} 451}
411 452
412MODULE = CFClient PACKAGE = CFClient::Map 453MODULE = CFClient PACKAGE = CFClient::Map
413 454
441clear (CFClient::Map self) 482clear (CFClient::Map self)
442 CODE: 483 CODE:
443 map_clear (self); 484 map_clear (self);
444 485
445void 486void
446set_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)
447 CODE: 488 CODE:
448{ 489{
449 while (self->faces < face) 490 while (self->faces < face)
450 { 491 {
451 Append (mapface, self->face, self->faces, self->faces); 492 Append (mapface, self->face, self->faces, self->faces);
452 self->faces *= 2; 493 self->faces *= 2;
453 } 494 }
454 495
496 mapface *f = self->face + face;
497
455 self->face [face].name = name; 498 f->name = name;
456 self->face [face].w = w; 499 f->w = w;
457 self->face [face].h = h; 500 f->h = h;
458 self->face [face].s = s; 501 f->s = s;
459 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;
460} 507}
461 508
462void 509void
463scroll (CFClient::Map self, int dx, int dy) 510scroll (CFClient::Map self, int dx, int dy)
464 CODE: 511 CODE:
560 { 607 {
561 cell->face [2] = (data [0] << 8) + data [1]; data += 2; 608 cell->face [2] = (data [0] << 8) + data [1]; data += 2;
562 } 609 }
563 } 610 }
564 else 611 else
612 cell->darkness = -1;
613 }
614}
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++)
565 { 639 {
566 cell->darkness = -1; 640 int r = 32, g = 32, b = 32, a = 192;
567 cell->face [2] = 0; 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);
568 } 668 }
569 } 669 }
570}
571 670
671 RETVAL = map_sv;
672}
673 OUTPUT:
674 RETVAL
675
572void 676void
573draw (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)
574 CODE: 678 PPCODE:
575{ 679{
680 int sw4 = (sw + 3) & ~3;
681 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
682 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
683
684 SvPOK_only (darkness_sv);
685 SvCUR_set (darkness_sv, sw4 * sh);
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 {
576 int vx = self->vx = self->w >= sw 692 int vx = self->vx = self->w >= sw
577 ? self->x + (self->w - sw) / 2 693 ? self->x + (self->w - sw) / 2
578 : 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));
579 695
580 int vy = self->vy = self->h >= sh 696 int vy = self->vy = self->h >= sh
581 ? self->y + (self->h - sh) / 2 697 ? self->y + (self->h - sh) / 2
582 : 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 }
583 700
584 glColor4ub (255, 255, 255, 255); 701 glColor4ub (255, 255, 255, 255);
585 702
586 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 703 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
587 glEnable (GL_BLEND); 704 glEnable (GL_BLEND);
602 719
603 for (x = 0; x < sw; x++) 720 for (x = 0; x < sw; x++)
604 if (row->c0 <= x + vx && x + vx < row->c1) 721 if (row->c0 <= x + vx && x + vx < row->c1)
605 { 722 {
606 mapcell *cell = row->col + (x + vx - row->c0); 723 mapcell *cell = row->col + (x + vx - row->c0);
724
725 darkness[y * sw4 + x] = cell->darkness < 0
726 ? 255 - FOW_DARKNESS
727 : 255 - cell->darkness;
728
607 uint16_t face = cell->face [z]; 729 uint16_t face = cell->face [z];
608 730
609 if (face) 731 if (face)
610 { 732 {
611 mapface tex = self->face [face]; 733 mapface tex = self->face [face];
628 } 750 }
629 } 751 }
630 } 752 }
631 753
632 glEnd (); 754 glEnd ();
633}
634 755
756 glDisable (GL_TEXTURE_2D);
757 glDisable (GL_BLEND);
758
759 EXTEND (SP, 3);
760 PUSHs (sv_2mortal (newSViv (sw4)));
761 PUSHs (sv_2mortal (newSViv (sh)));
762 PUSHs (darkness_sv);
763}
764

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines