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.159 by root, Tue Dec 22 00:35:44 2009 UTC vs.
Revision 1.165 by root, Fri Nov 9 22:53:57 2012 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;
214# push @items, [ 215# push @items, [
215# "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>",
216# \&editor_invoke, 217# \&editor_invoke,
217# ]; 218# ];
218 219
219 for my $type (qw(test name)) { 220 for my $type (@{ $::CONN->{editor_support}{servertypes} }) {
220 $::CONN->{editor_support}{type} ne $type 221 $::CONN->{editor_support}{servertype} ne $type
221 or next; 222 or next;
222 my $server = $::CONN->{editor_support}{"${type}server"} 223 my $server = $::CONN->{editor_support}{"${type}server"}
223 or next; 224 or next;
224 225
225 push @items, [ 226 push @items, [
407 408
408 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement 409 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement
409 $self->{sdy} += $dy * $self->{tilesize}; 410 $self->{sdy} += $dy * $self->{tilesize};
410 411
411 # save old fow texture, if applicable 412 # save old fow texture, if applicable
412 $self->{last_fow_texture} = $self->{fow_texture} 413 $self->{prev_fow_texture} = $::CFG->{smooth_transitions} && $self->{fow_texture};
413 if $::CFG->{smooth_transitions};
414 $self->{lfdx} = $dx; 414 $self->{lfdx} = $dx;
415 $self->{lfdy} = $dy; 415 $self->{lfdy} = $dy;
416 $self->{lmdx} = $self->{dx}; 416 $self->{lmdx} = $self->{dx};
417 $self->{lmdy} = $self->{dy}; 417 $self->{lmdy} = $self->{dy};
418 418
433sub movement_update { 433sub movement_update {
434 my ($self) = @_; 434 my ($self) = @_;
435 435
436 if ($::CFG->{smooth_movement}) { 436 if ($::CFG->{smooth_movement}) {
437 if ($self->{sdx} || $self->{sdy}) { 437 if ($self->{sdx} || $self->{sdy}) {
438 my $diff = EV::time - ($self->{last_update} || $::LAST_REFRESH); 438 my $diff = AE::time - ($self->{last_update} || $::LAST_REFRESH);
439 my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; 439 my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED};
440 440
441 # the minimum time for a single tile movement 441 # the minimum time for a single tile movement
442 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);
443 443
464 } 464 }
465 } else { 465 } else {
466 $self->{sdx} = $self->{sdy} = 0; 466 $self->{sdx} = $self->{sdy} = 0;
467 } 467 }
468 468
469 $self->{last_update} = EV::time; 469 $self->{last_update} = AE::time;
470} 470}
471 471
472sub refresh_hook { 472sub refresh_hook {
473 my ($self) = @_; 473 my ($self) = @_;
474 474
516 glTranslate $sx0, $sy0; 516 glTranslate $sx0, $sy0;
517 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 517 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
518 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; 518 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy};
519 519
520 $::MAP->draw ($dx, $dy, $sw, $sh, 520 $::MAP->draw ($dx, $dy, $sw, $sh,
521 $self->{tilesize}, 521 ($self->{tilesize}) x 2,
522 $::CONN->{player}{tag}, 522 $::CONN->{player}{tag},
523 -$self->{sdx}, -$self->{sdy}); 523 -$self->{sdx}, -$self->{sdy});
524 524
525 glScale $self->{tilesize}, $self->{tilesize}; 525 glScale $self->{tilesize}, $self->{tilesize};
526 526
527 if (my $tex = $self->{fow_texture}) { 527 if (my $tex = $self->{fow_texture}) {
528 my @prev_fow_params;
529
528 if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture}) { 530 if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) {
529 my $d1 = DC::distance $self->{sdx}, $self->{sdy}; 531 my $d1 = DC::distance $self->{sdx}, $self->{sdy};
530 my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; 532 my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize;
531 533
532 if ($d1 * $d2) { 534 if ($d1 * $d2) {
533 DC::Texture::draw_fow_texture 535 @prev_fow_params = (
534 $::CFG->{fow_intensity},
535 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
536 @{$self->{fow_texture}}{qw(name data s t w h)},
537 (min 1, $d1 / $d2), 536 (min 1, $d1 / $d2),
538 $self->{lmdx} - $dx - $self->{lfdx}, 537 $self->{lmdx} - $dx - $self->{lfdx},
539 $self->{lmdy} - $dy - $self->{lfdy}, 538 $self->{lmdy} - $dy - $self->{lfdy},
540 @{$self->{last_fow_texture}}{qw(name data)}; 539 @{$self->{prev_fow_texture}}{qw(name data)}
541 } else { 540 );
542 delete $self->{last_fow_texture};
543 } 541 }
544 } 542 }
545 543
546 unless ($self->{last_fow_texture}) {
547 DC::Texture::draw_fow_texture 544 DC::Texture::draw_fow_texture
548 $::CFG->{fow_intensity}, 545 $::CFG->{fow_intensity},
549 $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, 546 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
550 @{$self->{fow_texture}}{qw(name data s t w h)}; 547 @{$self->{fow_texture}}{qw(name data s t w h)},
551 } 548 @prev_fow_params;
552 } 549 }
553 550
554 if ($self->{magicmap}) { 551 if ($self->{magicmap}) {
555 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 552 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
556 553
612 $self->SUPER::DESTROY; 609 $self->SUPER::DESTROY;
613} 610}
614 611
615package DC::MapWidget::MapMap; 612package DC::MapWidget::MapMap;
616 613
617use strict; 614use common::sense;
618use utf8;
619 615
620our @ISA = DC::UI::Base::; 616our @ISA = DC::UI::Base::;
621 617
622use Time::HiRes qw(time);
623use DC::OpenGL; 618use DC::OpenGL;
624 619
625sub size_request { 620sub size_request {
626 ($::HEIGHT * 0.2, $::HEIGHT * 0.2) 621 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
627} 622}
628 623
629sub refresh_hook { 624sub refresh_hook {
630 my ($self) = @_; 625 my ($self) = @_;
631 626
632 if ($::MAP && $self->{texture_atime} < time) { 627 if ($::MAP && $self->{texture_atime} < AE::now) {
633 my ($w, $h) = @$self{qw(w h)}; 628 my ($w, $h) = @$self{qw(w h)};
634 629
635 return unless $w && $h; 630 return unless $w && $h;
636 631
637 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 632 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
652 $self->{sh} = $sh; 647 $self->{sh} = $sh;
653 648
654 $self->{x0} = $x0; 649 $self->{x0} = $x0;
655 $self->{y0} = $y0; 650 $self->{y0} = $y0;
656 651
657 $self->{texture_atime} = time + 1/3; 652 $self->{texture_atime} = AE::now + 1/2;
658 653
659 $self->{texture} = 654 $self->{texture} =
660 new DC::Texture 655 new DC::Texture
661 w => $w, 656 w => $w,
662 h => $h, 657 h => $h,
717 glDisable GL_BLEND; 712 glDisable GL_BLEND;
718} 713}
719 714
720package DC::MapWidget::Command; 715package DC::MapWidget::Command;
721 716
722use strict; 717use common::sense;
723 718
724use DC::OpenGL; 719use DC::OpenGL;
725 720
726our @ISA = DC::UI::Frame::; 721our @ISA = DC::UI::Frame::;
727 722
880 } else { 875 } else {
881 # @match is [command, penalty, command with arguments] until sort 876 # @match is [command, penalty, command with arguments] until sort
882 877
883 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; 878 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
884 879
880 my $first_char = substr $cmd, 0, 1;
881
885 my $regexp_abbrev = do { 882 my $regexp_abbrev = do {
886 my ($beg, @chr) = split //, lc $cmd; 883 my ($beg, @chr) = split //, lc $cmd;
887 884
888 # the following regex is used to match our "completion entry" 885 # the following regex is used to match our "completion entry"
889 # to an actual command - the parentheses match kind of "overhead" 886 # to an actual command - the parentheses match kind of "overhead"
890 # - the more characters the parentheses match, the less attractive 887 # - the more characters the parentheses match, the less attractive
891 # is the match. 888 # is the match.
892 my $regexp = "^\Q$beg\E" 889 my $regexp = "^\Q$beg\E"
893 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; 890 . join "", map "(?:.*?[ \\\\]|(.*?))\Q$_\E", @chr;
894 qr<$regexp> 891 qr<$regexp>
895 }; 892 };
896 893
897 my $regexp_partial = do { 894 my $regexp_partial = do {
898 my $regexp = "^\Q$text\E(.*)"; 895 my $regexp = "^\Q$text\E(.*)";
899 qr<$regexp> 896 qr<$regexp>
900 }; 897 };
901 898
902 for (keys %{$self->{command}}) { 899 for (keys %{$self->{command}}) {
900 # we only match and score if the first character matches,
901 # so quickly rule out all others first.
902 next unless $first_char = substr $_, 0, 1;
903
903 my @scores; 904 my @scores;
904 905
905 # 1. Complete command [with args] 906 # 1. Complete command [with args]
906 # command is a prefix of the text 907 # command is a prefix of the text
907 # score is length of complete command matched 908 # score is length of complete command matched
908 # e.g. "invoke summon pet monster bat" 909 # e.g. "invoke summon pet monster bat"
909 # "invoke" "summon pet monster bat" = 6 910 # "invoke" "summon pet monster bat" = 6
910 # "invoke summon pet monster" "bat" = 25 911 # "invoke summon pet monster" "bat" = 25
911 if ($text =~ /^\Q$_\E(.*)/) { 912 if ((substr $text, 0, length $_) eq $_) {
912 push @scores, [$_, length $_, $text]; 913 push @scores, [$_, length $_, $text];
913 } 914 }
914 915
915 # 2. Partial command 916 # 2. Partial command
916 # text is a prefix of the full command 917 # text is a prefix of the full command

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines