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.154 by root, Fri Dec 4 15:04:56 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 glBlendFunc GL_ONE, GL_ZERO;
530 527
531 my $a1 = 0.9; 528 if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) {
532 529 my $d1 = DC::distance $self->{sdx}, $self->{sdy};
533 if (0 && $self->{last_fow_texture}) { 530 my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize;
534 my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5;
535 my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5;
536 531
537 if ($d1 * $d2) { 532 if ($d1 * $d2) {
533 @prev_fow_params = (
538 my $a2 = $d1 / $d2; 534 (min 1, $d1 / $d2),
539 535 $self->{lmdx} - $dx - $self->{lfdx},
540 $a1 = 1 - $a2; 536 $self->{lmdy} - $dy - $self->{lfdy},
541 537 @{$self->{prev_fow_texture}}{qw(name data)}
542 #$a1 *= 0.9;
543 #$a2 *= 0.9;
544
545 printf "%4g %4g %4g %4g\n", $d1, $d2, $a1, $a2;#d#
546
547 #$a1 = 1 - (1-$a1) * 0.707;
548 #$a2 = 1 - (1-$a2) * 0.707;
549
550 glColor 1,0,0,1;
551 glBegin GL_QUADS;
552 glVertex 10 + $sdx_t, 10;
553 glVertex 11 + $sdx_t, 10;
554 glVertex 11 + $sdx_t, 11;
555 glVertex 10 + $sdx_t, 11;
556 glEnd; 538 );
557
558 glColor +($::CFG->{fow_intensity}) x 3, $a2;
559 glPushMatrix;
560 glTranslate $sdx_t, $sdy_t; # anchor at player
561 glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize;
562 glScale 1/3, 1/3;
563 $self->{last_fow_texture}->draw_quad_alpha (0, 0);
564 glPopMatrix;
565 } else {
566 delete $self->{last_fow_texture};
567 } 539 }
568 } 540 }
569 541
542 DC::Texture::draw_fow_texture
570 glColor +($::CFG->{fow_intensity}) x 3, $a1; 543 $::CFG->{fow_intensity},
571 glPushMatrix; 544 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
572 #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player 545 @{$self->{fow_texture}}{qw(name data s t w h)},
573 glScale 1/3, 1/3; 546 @prev_fow_params;
574 $self->{fow_texture}->draw_quad_alpha (0, 0);
575 glPopMatrix;
576
577 glDisable GL_TEXTURE_2D;
578 glDisable GL_BLEND;
579 } 547 }
580 548
581 if ($self->{magicmap}) { 549 if ($self->{magicmap}) {
582 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 550 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
583 551
584 $x += $::MAP->ox + $self->{dx}; 552 $x += $::MAP->ox + $self->{dx};
585 $y += $::MAP->oy + $self->{dy}; 553 $y += $::MAP->oy + $self->{dy};
586 554
587 glTranslate - $x - 1, - $y - 1; 555 glTranslate - $x - 1, - $y - 1;
588 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 556 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
589 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 557 $::MAP->draw_magicmap ($w, $h, $data);
590 } 558 }
591 559
592 glPopMatrix; 560 glPopMatrix;
593 glEndList; 561 glEndList;
594 } 562 }
595 } else { 563 } else {
564 delete $self->{last_fow_texture};
565 delete $self->{fow_texture};
566
596 glDeleteList delete $self->{list} 567 glDeleteList delete $self->{list}
597 if $self->{list}; 568 if $self->{list};
598 } 569 }
599} 570}
600 571
636 $self->SUPER::DESTROY; 607 $self->SUPER::DESTROY;
637} 608}
638 609
639package DC::MapWidget::MapMap; 610package DC::MapWidget::MapMap;
640 611
641use strict; 612use common::sense;
642use utf8;
643 613
644our @ISA = DC::UI::Base::; 614our @ISA = DC::UI::Base::;
645 615
646use Time::HiRes qw(time); 616use Time::HiRes qw(time);
647use DC::OpenGL; 617use DC::OpenGL;
741 glDisable GL_BLEND; 711 glDisable GL_BLEND;
742} 712}
743 713
744package DC::MapWidget::Command; 714package DC::MapWidget::Command;
745 715
746use strict; 716use common::sense;
747 717
748use DC::OpenGL; 718use DC::OpenGL;
749 719
750our @ISA = DC::UI::Frame::; 720our @ISA = DC::UI::Frame::;
751 721

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines