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.156 by root, Sat Dec 19 05:06:57 2009 UTC vs.
Revision 1.161 by root, Sat Mar 20 01:25:56 2010 UTC

9use DC::OpenGL; 9use DC::OpenGL;
10use DC::UI; 10use DC::UI;
11use DC::Macro; 11use DC::Macro;
12 12
13our @ISA = DC::UI::Base::; 13our @ISA = DC::UI::Base::;
14
15our @TEX_HIDDEN = map {
16 new_from_resource DC::Texture # MUST be POT
17 "hidden-$_.png", mipmap => 1, wrap => 1
18 } 0, 1, 2;
14 19
15my $magicmap_tex = 20my $magicmap_tex =
16 new_from_resource DC::Texture "magicmap.png", 21 new_from_resource DC::Texture "magicmap.png",
17 mipmap => 1, wrap => 0, internalformat => GL_ALPHA; 22 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
18 23
209# push @items, [ 214# push @items, [
210# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", 215# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>",
211# \&editor_invoke, 216# \&editor_invoke,
212# ]; 217# ];
213 218
214 for my $type (qw(test name)) { 219 for my $type (@{ $::CONN->{editor_support}{servertypes} }) {
215 $::CONN->{editor_support}{type} ne $type 220 $::CONN->{editor_support}{servertype} ne $type
216 or next; 221 or next;
217 my $server = $::CONN->{editor_support}{"${type}server"} 222 my $server = $::CONN->{editor_support}{"${type}server"}
218 or next; 223 or next;
219 224
220 push @items, [ 225 push @items, [
396} 401}
397 402
398sub scroll { 403sub scroll {
399 my ($self, $dx, $dy) = @_; 404 my ($self, $dx, $dy) = @_;
400 405
401 $::MAP->scroll ($dx, $dy);
402 $self->movement_update; 406 $self->movement_update;
403 407
404 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement 408 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement
405 $self->{sdy} += $dy * $self->{tilesize}; 409 $self->{sdy} += $dy * $self->{tilesize};
406 410
407 $self->{last_fow_texture} = $self->{fow_texture}; 411 # save old fow texture, if applicable
412 $self->{prev_fow_texture} = $::CFG->{smooth_transitions} && $self->{fow_texture};
413 $self->{lfdx} = $dx;
414 $self->{lfdy} = $dy;
408 $self->{ldx} = $self->{sdx}; 415 $self->{lmdx} = $self->{dx};
409 $self->{ldy} = $self->{sdy}; 416 $self->{lmdy} = $self->{dy};
410 417
418 $::MAP->scroll ($dx, $dy);
411} 419}
412 420
413sub set_magicmap { 421sub set_magicmap {
414 my ($self, $w, $h, $x, $y, $data) = @_; 422 my ($self, $w, $h, $x, $y, $data) = @_;
415 423
486 494
487 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; 495 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; 496 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy;
489 497
490 if ($::CFG->{fow_enable}) { 498 if ($::CFG->{fow_enable}) {
491 my ($sdx_t, $sdy_t);#d# do not anchor at player 499 # draw_fow_texture REQUIRES the fow texture to stay the same size.
492
493 my ($w, $h, $data) = $::MAP->fow_texture ( 500 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 501
500 $self->{fow_texture} = new DC::Texture 502 $self->{fow_texture} = new DC::Texture
501 w => $w, 503 w => $w,
502 h => $h, 504 h => $h,
503 data => $data, 505 data => $data,
517 $::MAP->draw ($dx, $dy, $sw, $sh, 519 $::MAP->draw ($dx, $dy, $sw, $sh,
518 $self->{tilesize}, 520 $self->{tilesize},
519 $::CONN->{player}{tag}, 521 $::CONN->{player}{tag},
520 -$self->{sdx}, -$self->{sdy}); 522 -$self->{sdx}, -$self->{sdy});
521 523
522 #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player
523 glScale $self->{tilesize}, $self->{tilesize}; 524 glScale $self->{tilesize}, $self->{tilesize};
524 525
525 if (my $tex = $self->{fow_texture}) { 526 if (my $tex = $self->{fow_texture}) {
527 my @prev_fow_params;
528
526 if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture} && 0) {#d# 529 if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) {
527 my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5; 530 my $d1 = DC::distance $self->{sdx}, $self->{sdy};
528 my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5; 531 my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize;
529 532
530 if ($d1 * $d2) { 533 if ($d1 * $d2) {
531 DC::Texture::draw_fow_texture 534 @prev_fow_params = (
532 $::CFG->{fow_intensity}, 535 (min 1, $d1 / $d2),
536 $self->{lmdx} - $dx - $self->{lfdx},
537 $self->{lmdy} - $dy - $self->{lfdy},
533 @{$self->{fow_texture}}{qw(name s t w h)}, 538 @{$self->{prev_fow_texture}}{qw(name data)}
534 $d1 / $d2, 539 );
535 $sdx_t - $self->{ldx} / $tilesize, $sdy_t - $self->{ldy} / $tilesize,
536 @{$self->{last_fow_texture}}{qw(name s t w h)};
537 } else {
538 delete $self->{last_fow_texture};
539
540 # same as a few lines below :/
541 DC::Texture::draw_fow_texture
542 $::CFG->{fow_intensity},
543 @{$self->{fow_texture}}{qw(name s t w h)};
544 } 540 }
545 } else {
546 #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player
547 DC::Texture::draw_fow_texture
548 $::CFG->{fow_intensity},
549 @{$self->{fow_texture}}{qw(name s t w h)};
550 } 541 }
542
543 DC::Texture::draw_fow_texture
544 $::CFG->{fow_intensity},
545 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
546 @{$self->{fow_texture}}{qw(name data s t w h)},
547 @prev_fow_params;
551 } 548 }
552 549
553 if ($self->{magicmap}) { 550 if ($self->{magicmap}) {
554 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 551 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
555 552
556 $x += $::MAP->ox + $self->{dx}; 553 $x += $::MAP->ox + $self->{dx};
557 $y += $::MAP->oy + $self->{dy}; 554 $y += $::MAP->oy + $self->{dy};
558 555
559 glTranslate - $x - 1, - $y - 1; 556 glTranslate - $x - 1, - $y - 1;
560 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 557 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
561 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 558 $::MAP->draw_magicmap ($w, $h, $data);
562 } 559 }
563 560
564 glPopMatrix; 561 glPopMatrix;
565 glEndList; 562 glEndList;
566 } 563 }
567 } else { 564 } else {
565 delete $self->{last_fow_texture};
566 delete $self->{fow_texture};
567
568 glDeleteList delete $self->{list} 568 glDeleteList delete $self->{list}
569 if $self->{list}; 569 if $self->{list};
570 } 570 }
571} 571}
572 572

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines