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.153 by root, Thu Nov 26 07:19:12 2009 UTC vs.
Revision 1.162 by root, Sat Apr 3 02:58:25 2010 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);
7 6
8use DC; 7use DC;
9use DC::OpenGL; 8use DC::OpenGL;
10use DC::UI; 9use DC::UI;
11use DC::Macro; 10use DC::Macro;
12 11
13our @ISA = DC::UI::Base::; 12our @ISA = DC::UI::Base::;
13
14our @TEX_HIDDEN = map {
15 new_from_resource DC::Texture # MUST be POT
16 "hidden-$_.png", mipmap => 1, wrap => 1
17 } 0, 1, 2;
14 18
15my $magicmap_tex = 19my $magicmap_tex =
16 new_from_resource DC::Texture "magicmap.png", 20 new_from_resource DC::Texture "magicmap.png",
17 mipmap => 1, wrap => 0, internalformat => GL_ALPHA; 21 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
18 22
209# push @items, [ 213# push @items, [
210# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", 214# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>",
211# \&editor_invoke, 215# \&editor_invoke,
212# ]; 216# ];
213 217
214 for my $type (qw(test name)) { 218 for my $type (@{ $::CONN->{editor_support}{servertypes} }) {
215 $::CONN->{editor_support}{type} ne $type 219 $::CONN->{editor_support}{servertype} ne $type
216 or next; 220 or next;
217 my $server = $::CONN->{editor_support}{"${type}server"} 221 my $server = $::CONN->{editor_support}{"${type}server"}
218 or next; 222 or next;
219 223
220 push @items, [ 224 push @items, [
396} 400}
397 401
398sub scroll { 402sub scroll {
399 my ($self, $dx, $dy) = @_; 403 my ($self, $dx, $dy) = @_;
400 404
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; 405 $self->movement_update;
408 406
409 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement 407 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement
410 $self->{sdy} += $dy * $self->{tilesize}; 408 $self->{sdy} += $dy * $self->{tilesize};
409
410 # save old fow texture, if applicable
411 $self->{prev_fow_texture} = $::CFG->{smooth_transitions} && $self->{fow_texture};
412 $self->{lfdx} = $dx;
413 $self->{lfdy} = $dy;
414 $self->{lmdx} = $self->{dx};
415 $self->{lmdy} = $self->{dy};
416
417 $::MAP->scroll ($dx, $dy);
411} 418}
412 419
413sub set_magicmap { 420sub set_magicmap {
414 my ($self, $w, $h, $x, $y, $data) = @_; 421 my ($self, $w, $h, $x, $y, $data) = @_;
415 422
486 493
487 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; 494 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; 495 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy;
489 496
490 if ($::CFG->{fow_enable}) { 497 if ($::CFG->{fow_enable}) {
491 my ($sdx_t, $sdy_t);#d# do not anchor at player 498 # draw_fow_texture REQUIRES the fow texture to stay the same size.
492
493 my ($w, $h, $data) = $::MAP->fow_texture ( 499 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 500
500 $self->{fow_texture} = new DC::Texture 501 $self->{fow_texture} = new DC::Texture
501 w => $w, 502 w => $w,
502 h => $h, 503 h => $h,
503 data => $data, 504 data => $data,
517 $::MAP->draw ($dx, $dy, $sw, $sh, 518 $::MAP->draw ($dx, $dy, $sw, $sh,
518 $self->{tilesize}, 519 $self->{tilesize},
519 $::CONN->{player}{tag}, 520 $::CONN->{player}{tag},
520 -$self->{sdx}, -$self->{sdy}); 521 -$self->{sdx}, -$self->{sdy});
521 522
522 #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player
523 glScale $self->{tilesize}, $self->{tilesize}; 523 glScale $self->{tilesize}, $self->{tilesize};
524 524
525 if (my $tex = $self->{fow_texture}) { 525 if (my $tex = $self->{fow_texture}) {
526 glEnable GL_TEXTURE_2D; 526 my @prev_fow_params;
527 glEnable GL_BLEND;
528 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
529 glBlendEquation GL_FUNC_REVERSE_SUBTRACT;
530 glBlendFunc GL_ONE, GL_ZERO;
531 527
532 my $a1 = 0.9; 528 if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) {
533 529 my $d1 = DC::distance $self->{sdx}, $self->{sdy};
534 if (0 && $self->{last_fow_texture}) { 530 my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize;
535 my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5;
536 my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5;
537 531
538 if ($d1 * $d2) { 532 if ($d1 * $d2) {
533 @prev_fow_params = (
539 my $a2 = $d1 / $d2; 534 (min 1, $d1 / $d2),
540 535 $self->{lmdx} - $dx - $self->{lfdx},
541 $a1 = 1 - $a2; 536 $self->{lmdy} - $dy - $self->{lfdy},
542 537 @{$self->{prev_fow_texture}}{qw(name data)}
543 #$a1 *= 0.9;
544 #$a2 *= 0.9;
545
546 printf "%4g %4g %4g %4g\n", $d1, $d2, $a1, $a2;#d#
547
548 #$a1 = 1 - (1-$a1) * 0.707;
549 #$a2 = 1 - (1-$a2) * 0.707;
550
551 glColor 1,0,0,1;
552 glBegin GL_QUADS;
553 glVertex 10 + $sdx_t, 10;
554 glVertex 11 + $sdx_t, 10;
555 glVertex 11 + $sdx_t, 11;
556 glVertex 10 + $sdx_t, 11;
557 glEnd; 538 );
558
559 glColor +($::CFG->{fow_intensity}) x 3, $a2;
560 glPushMatrix;
561 glTranslate $sdx_t, $sdy_t; # anchor at player
562 glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize;
563 glScale 1/3, 1/3;
564 $self->{last_fow_texture}->draw_quad_alpha (0, 0);
565 glPopMatrix;
566 } else {
567 delete $self->{last_fow_texture};
568 } 539 }
569 } 540 }
570 541
542 DC::Texture::draw_fow_texture
571 glColor +($::CFG->{fow_intensity}) x 3, $a1; 543 $::CFG->{fow_intensity},
572 glPushMatrix; 544 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
573 #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player 545 @{$self->{fow_texture}}{qw(name data s t w h)},
574 glScale 1/3, 1/3; 546 @prev_fow_params;
575 $self->{fow_texture}->draw_quad_alpha (0, 0);
576 glPopMatrix;
577
578 glBlendEquation GL_FUNC_ADD;
579 glDisable GL_TEXTURE_2D;
580 glDisable GL_BLEND;
581 } 547 }
582 548
583 if ($self->{magicmap}) { 549 if ($self->{magicmap}) {
584 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 550 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
585 551
586 $x += $::MAP->ox + $self->{dx}; 552 $x += $::MAP->ox + $self->{dx};
587 $y += $::MAP->oy + $self->{dy}; 553 $y += $::MAP->oy + $self->{dy};
588 554
589 glTranslate - $x - 1, - $y - 1; 555 glTranslate - $x - 1, - $y - 1;
590 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 556 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
591 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 557 $::MAP->draw_magicmap ($w, $h, $data);
592 } 558 }
593 559
594 glPopMatrix; 560 glPopMatrix;
595 glEndList; 561 glEndList;
596 } 562 }
597 } else { 563 } else {
564 delete $self->{last_fow_texture};
565 delete $self->{fow_texture};
566
598 glDeleteList delete $self->{list} 567 glDeleteList delete $self->{list}
599 if $self->{list}; 568 if $self->{list};
600 } 569 }
601} 570}
602 571
638 $self->SUPER::DESTROY; 607 $self->SUPER::DESTROY;
639} 608}
640 609
641package DC::MapWidget::MapMap; 610package DC::MapWidget::MapMap;
642 611
643use strict; 612use common::sense;
644use utf8;
645 613
646our @ISA = DC::UI::Base::; 614our @ISA = DC::UI::Base::;
647 615
648use Time::HiRes qw(time); 616use Time::HiRes qw(time);
649use DC::OpenGL; 617use DC::OpenGL;
743 glDisable GL_BLEND; 711 glDisable GL_BLEND;
744} 712}
745 713
746package DC::MapWidget::Command; 714package DC::MapWidget::Command;
747 715
748use strict; 716use common::sense;
749 717
750use DC::OpenGL; 718use DC::OpenGL;
751 719
752our @ISA = DC::UI::Frame::; 720our @ISA = DC::UI::Frame::;
753 721

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines