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.35 by root, Fri Apr 14 02:03:10 2006 UTC vs.
Revision 1.39 by root, Sat Apr 15 00:04:58 2006 UTC

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 // 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
292void
262fatal (char *message) 293fatal (char *message)
263 CODE: 294 CODE:
264#ifdef WIN32 295#ifdef WIN32
265 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);
266#else 297#else
391} 422}
392 423
393MODULE = CFClient PACKAGE = CFClient::Texture 424MODULE = CFClient PACKAGE = CFClient::Texture
394 425
395void 426void
396draw_quad (SV *self, double x, double y, double w = 0, double h = 0) 427draw_quad (SV *self, float x, float y, float w = 0, float h = 0)
397 PROTOTYPE: $$$;$$ 428 PROTOTYPE: $$$;$$
398 CODE: 429 CODE:
399{ 430{
400 HV *hv = (HV *)SvRV (self); 431 HV *hv = (HV *)SvRV (self);
401 double s = SvNV (*hv_fetch (hv, "s", 1, 1)); 432 float s = SvNV (*hv_fetch (hv, "s", 1, 1));
402 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 433 float t = SvNV (*hv_fetch (hv, "t", 1, 1));
403 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));
404 436
405 if (items < 5) 437 if (items < 5)
406 { 438 {
407 w = SvNV (*hv_fetch (hv, "w", 1, 1)); 439 w = SvNV (*hv_fetch (hv, "w", 1, 1));
408 h = SvNV (*hv_fetch (hv, "h", 1, 1)); 440 h = SvNV (*hv_fetch (hv, "h", 1, 1));
409 } 441 }
410 442
411 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 }
412 glBegin (GL_QUADS); 448 glBegin (GL_QUADS);
413 glTexCoord2d (0, 0); glVertex2d (x , y ); 449 glTexCoord2f (0, 0); glVertex2f (x , y );
414 glTexCoord2d (0, t); glVertex2d (x , y + h); 450 glTexCoord2f (0, t); glVertex2f (x , y + h);
415 glTexCoord2d (s, t); glVertex2d (x + w, y + h); 451 glTexCoord2f (s, t); glVertex2f (x + w, y + h);
416 glTexCoord2d (s, 0); glVertex2d (x + w, y ); 452 glTexCoord2f (s, 0); glVertex2f (x + w, y );
417 glEnd (); 453 glEnd ();
418} 454}
419 455
420MODULE = CFClient PACKAGE = CFClient::Map 456MODULE = CFClient PACKAGE = CFClient::Map
421 457
449clear (CFClient::Map self) 485clear (CFClient::Map self)
450 CODE: 486 CODE:
451 map_clear (self); 487 map_clear (self);
452 488
453void 489void
454set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) 490set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t, int r, int g, int b, int a)
455 CODE: 491 CODE:
456{ 492{
457 while (self->faces < face) 493 while (self->faces < face)
458 { 494 {
459 Append (mapface, self->face, self->faces, self->faces); 495 Append (mapface, self->face, self->faces, self->faces);
460 self->faces *= 2; 496 self->faces *= 2;
461 } 497 }
462 498
499 mapface *f = self->face + face;
500
463 self->face [face].name = name; 501 f->name = name;
464 self->face [face].w = w; 502 f->w = w;
465 self->face [face].h = h; 503 f->h = h;
466 self->face [face].s = s; 504 f->s = s;
467 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;
468} 510}
469 511
470void 512void
471scroll (CFClient::Map self, int dx, int dy) 513scroll (CFClient::Map self, int dx, int dy)
472 CODE: 514 CODE:
573 cell->darkness = -1; 615 cell->darkness = -1;
574 } 616 }
575} 617}
576 618
577void 619void
578draw (CFClient::Map self, int x0, int y0, int sw, int sh) 620draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
579 PPCODE: 621 PPCODE:
580{ 622{
581 int sw4 = (sw + 3) & ~3; 623 int sw4 = (sw + 3) & ~3;
582 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 624 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
583 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 625 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
584 626
585 SvPOK_only (darkness_sv); 627 SvPOK_only (darkness_sv);
586 SvCUR_set (darkness_sv, sw4 * sh); 628 SvCUR_set (darkness_sv, sw4 * sh);
587 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 {
588 int vx = self->vx = self->w >= sw 635 int vx = self->vx = self->w >= sw
589 ? self->x + (self->w - sw) / 2 636 ? self->x + (self->w - sw) / 2
590 : 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));
591 638
592 int vy = self->vy = self->h >= sh 639 int vy = self->vy = self->h >= sh
593 ? self->y + (self->h - sh) / 2 640 ? self->y + (self->h - sh) / 2
594 : 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 }
595 643
596 glColor4ub (255, 255, 255, 255); 644 glColor4ub (255, 255, 255, 255);
597 645
598 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 646 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
599 glEnable (GL_BLEND); 647 glEnable (GL_BLEND);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines