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

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.155 by root, Thu Dec 17 02:49:38 2009 UTC vs.
Revision 1.164 by root, Sat Aug 13 23:18:19 2011 UTC

1package DC::MapWidget; 1package DC::MapWidget;
2 2
3use strict; 3use common::sense;
4use utf8;
5 4
6use List::Util qw(min max); 5use List::Util qw(min max);
6
7use AnyEvent ();
7 8
8use DC; 9use DC;
9use DC::OpenGL; 10use DC::OpenGL;
10use DC::UI; 11use DC::UI;
11use DC::Macro; 12use DC::Macro;
12 13
13our @ISA = DC::UI::Base::; 14our @ISA = DC::UI::Base::;
15
16our @TEX_HIDDEN = map {
17 new_from_resource DC::Texture # MUST be POT
18 "hidden-$_.png", mipmap => 1, wrap => 1
19 } 0, 1, 2;
14 20
15my $magicmap_tex = 21my $magicmap_tex =
16 new_from_resource DC::Texture "magicmap.png", 22 new_from_resource DC::Texture "magicmap.png",
17 mipmap => 1, wrap => 0, internalformat => GL_ALPHA; 23 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
18 24
209# push @items, [ 215# push @items, [
210# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", 216# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>",
211# \&editor_invoke, 217# \&editor_invoke,
212# ]; 218# ];
213 219
214 for my $type (qw(test name)) { 220 for my $type (@{ $::CONN->{editor_support}{servertypes} }) {
215 $::CONN->{editor_support}{type} ne $type 221 $::CONN->{editor_support}{servertype} ne $type
216 or next; 222 or next;
217 my $server = $::CONN->{editor_support}{"${type}server"} 223 my $server = $::CONN->{editor_support}{"${type}server"}
218 or next; 224 or next;
219 225
220 push @items, [ 226 push @items, [
396} 402}
397 403
398sub scroll { 404sub scroll {
399 my ($self, $dx, $dy) = @_; 405 my ($self, $dx, $dy) = @_;
400 406
401 $::MAP->scroll ($dx, $dy);
402
403 $self->{last_fow_texture} = $self->{fow_texture};
404 $self->{ldx} = $self->{sdx} + $dx * $self->{tilesize}; # smooth displacement
405 $self->{ldy} = $self->{sdy} + $dy * $self->{tilesize};
406
407 $self->movement_update; 407 $self->movement_update;
408 408
409 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement 409 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement
410 $self->{sdy} += $dy * $self->{tilesize}; 410 $self->{sdy} += $dy * $self->{tilesize};
411
412 # save old fow texture, if applicable
413 $self->{prev_fow_texture} = $::CFG->{smooth_transitions} && $self->{fow_texture};
414 $self->{lfdx} = $dx;
415 $self->{lfdy} = $dy;
416 $self->{lmdx} = $self->{dx};
417 $self->{lmdy} = $self->{dy};
418
419 $::MAP->scroll ($dx, $dy);
411} 420}
412 421
413sub set_magicmap { 422sub set_magicmap {
414 my ($self, $w, $h, $x, $y, $data) = @_; 423 my ($self, $w, $h, $x, $y, $data) = @_;
415 424
424sub movement_update { 433sub movement_update {
425 my ($self) = @_; 434 my ($self) = @_;
426 435
427 if ($::CFG->{smooth_movement}) { 436 if ($::CFG->{smooth_movement}) {
428 if ($self->{sdx} || $self->{sdy}) { 437 if ($self->{sdx} || $self->{sdy}) {
429 my $diff = EV::time - ($self->{last_update} || $::LAST_REFRESH); 438 my $diff = AE::time - ($self->{last_update} || $::LAST_REFRESH);
430 my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; 439 my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED};
431 440
432 # the minimum time for a single tile movement 441 # the minimum time for a single tile movement
433 my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK || 1); 442 my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK || 1);
434 443
455 } 464 }
456 } else { 465 } else {
457 $self->{sdx} = $self->{sdy} = 0; 466 $self->{sdx} = $self->{sdy} = 0;
458 } 467 }
459 468
460 $self->{last_update} = EV::time; 469 $self->{last_update} = AE::time;
461} 470}
462 471
463sub refresh_hook { 472sub refresh_hook {
464 my ($self) = @_; 473 my ($self) = @_;
465 474
486 495
487 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; 496 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx;
488 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; 497 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy;
489 498
490 if ($::CFG->{fow_enable}) { 499 if ($::CFG->{fow_enable}) {
491 my ($sdx_t, $sdy_t);#d# do not anchor at player 500 # draw_fow_texture REQUIRES the fow texture to stay the same size.
492
493 my ($w, $h, $data) = $::MAP->fow_texture ( 501 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
494 $dx + (min 0, $sdx_t),
495 $dy + (min 0, $sdy_t),
496 $sw + abs $sdx_t,
497 $sh + abs $sdy_t
498 );
499 502
500 $self->{fow_texture} = new DC::Texture 503 $self->{fow_texture} = new DC::Texture
501 w => $w, 504 w => $w,
502 h => $h, 505 h => $h,
503 data => $data, 506 data => $data,
504 internalformat => GL_INTENSITY, 507 internalformat => GL_ALPHA,
505 format => GL_LUMINANCE; 508 format => GL_ALPHA;
506 } else { 509 } else {
507 delete $self->{fow_texture}; 510 delete $self->{fow_texture};
508 } 511 }
509 512
510 glNewList ($self->{list} ||= glGenList); 513 glNewList ($self->{list} ||= glGenList);
513 glTranslate $sx0, $sy0; 516 glTranslate $sx0, $sy0;
514 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 517 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
515 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; 518 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy};
516 519
517 $::MAP->draw ($dx, $dy, $sw, $sh, 520 $::MAP->draw ($dx, $dy, $sw, $sh,
518 $self->{tilesize}, 521 ($self->{tilesize}) x 2,
519 $::CONN->{player}{tag}, 522 $::CONN->{player}{tag},
520 -$self->{sdx}, -$self->{sdy}); 523 -$self->{sdx}, -$self->{sdy});
521 524
522 #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player
523 glScale $self->{tilesize}, $self->{tilesize}; 525 glScale $self->{tilesize}, $self->{tilesize};
524 526
525 if (my $tex = $self->{fow_texture}) { 527 if (my $tex = $self->{fow_texture}) {
526 if (0 && $self->{last_fow_texture}) { 528 my @prev_fow_params;
527 my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5; 529
528 my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5; 530 if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) {
531 my $d1 = DC::distance $self->{sdx}, $self->{sdy};
532 my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize;
529 533
530 if ($d1 * $d2) { 534 if ($d1 * $d2) {
535 @prev_fow_params = (
531 my $a2 = $d1 / $d2; 536 (min 1, $d1 / $d2),
532 my $a1 = 1 - $a2; 537 $self->{lmdx} - $dx - $self->{lfdx},
533 538 $self->{lmdy} - $dy - $self->{lfdy},
534 #$a1 *= 0.9; 539 @{$self->{prev_fow_texture}}{qw(name data)}
535 #$a2 *= 0.9;
536
537 printf "%8g %8g %8g %8g\n", $d1, $d2, $a1, $a2;#d#
538
539 #$a1 = 1 - (1-$a1) * 0.707;
540 #$a2 = 1 - (1-$a2) * 0.707;
541
542 glColor 1,0,0,1;
543 glBegin GL_QUADS;
544 glVertex 10 + $sdx_t, 10;
545 glVertex 11 + $sdx_t, 10;
546 glVertex 11 + $sdx_t, 11;
547 glVertex 10 + $sdx_t, 11;
548 glEnd;
549
550 if(0){
551 glBlendFunc GL_ZERO, GL_DST_COLOR;
552 glColor +($::CFG->{fow_intensity}) x 3, $a2;
553 glPushMatrix;
554 glTranslate $sdx_t, $sdy_t; # anchor at player
555 glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize;
556 glScale 1/3, 1/3;
557 $self->{last_fow_texture}->draw_quad_alpha (0, 0);
558 glPopMatrix;
559 } 540 );
560 } else {
561 delete $self->{last_fow_texture};
562 } 541 }
563 } else {
564 DC::Texture::draw_fow_texture
565 $::CFG->{fow_intensity},
566 @{$self->{fow_texture}}{qw(name s t w h)};
567 #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player
568 } 542 }
543
544 DC::Texture::draw_fow_texture
545 $::CFG->{fow_intensity},
546 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
547 @{$self->{fow_texture}}{qw(name data s t w h)},
548 @prev_fow_params;
569 } 549 }
570 550
571 if ($self->{magicmap}) { 551 if ($self->{magicmap}) {
572 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 552 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
573 553
574 $x += $::MAP->ox + $self->{dx}; 554 $x += $::MAP->ox + $self->{dx};
575 $y += $::MAP->oy + $self->{dy}; 555 $y += $::MAP->oy + $self->{dy};
576 556
577 glTranslate - $x - 1, - $y - 1; 557 glTranslate - $x - 1, - $y - 1;
578 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 558 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
579 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 559 $::MAP->draw_magicmap ($w, $h, $data);
580 } 560 }
581 561
582 glPopMatrix; 562 glPopMatrix;
583 glEndList; 563 glEndList;
584 } 564 }
585 } else { 565 } else {
566 delete $self->{last_fow_texture};
567 delete $self->{fow_texture};
568
586 glDeleteList delete $self->{list} 569 glDeleteList delete $self->{list}
587 if $self->{list}; 570 if $self->{list};
588 } 571 }
589} 572}
590 573
626 $self->SUPER::DESTROY; 609 $self->SUPER::DESTROY;
627} 610}
628 611
629package DC::MapWidget::MapMap; 612package DC::MapWidget::MapMap;
630 613
631use strict; 614use common::sense;
632use utf8;
633 615
634our @ISA = DC::UI::Base::; 616our @ISA = DC::UI::Base::;
635 617
636use Time::HiRes qw(time);
637use DC::OpenGL; 618use DC::OpenGL;
638 619
639sub size_request { 620sub size_request {
640 ($::HEIGHT * 0.2, $::HEIGHT * 0.2) 621 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
641} 622}
642 623
643sub refresh_hook { 624sub refresh_hook {
644 my ($self) = @_; 625 my ($self) = @_;
645 626
646 if ($::MAP && $self->{texture_atime} < time) { 627 if ($::MAP && $self->{texture_atime} < AE::now) {
647 my ($w, $h) = @$self{qw(w h)}; 628 my ($w, $h) = @$self{qw(w h)};
648 629
649 return unless $w && $h; 630 return unless $w && $h;
650 631
651 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 632 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
666 $self->{sh} = $sh; 647 $self->{sh} = $sh;
667 648
668 $self->{x0} = $x0; 649 $self->{x0} = $x0;
669 $self->{y0} = $y0; 650 $self->{y0} = $y0;
670 651
671 $self->{texture_atime} = time + 1/3; 652 $self->{texture_atime} = AE::now + 1/2;
672 653
673 $self->{texture} = 654 $self->{texture} =
674 new DC::Texture 655 new DC::Texture
675 w => $w, 656 w => $w,
676 h => $h, 657 h => $h,
731 glDisable GL_BLEND; 712 glDisable GL_BLEND;
732} 713}
733 714
734package DC::MapWidget::Command; 715package DC::MapWidget::Command;
735 716
736use strict; 717use common::sense;
737 718
738use DC::OpenGL; 719use DC::OpenGL;
739 720
740our @ISA = DC::UI::Frame::; 721our @ISA = DC::UI::Frame::;
741 722

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines