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.163 by root, Thu Oct 14 00:02:39 2010 UTC vs.
Revision 1.165 by root, Fri Nov 9 22:53:57 2012 UTC

1package DC::MapWidget; 1package DC::MapWidget;
2 2
3use common::sense; 3use common::sense;
4 4
5use List::Util qw(min max); 5use List::Util qw(min max);
6
7use AnyEvent ();
6 8
7use DC; 9use DC;
8use DC::OpenGL; 10use DC::OpenGL;
9use DC::UI; 11use DC::UI;
10use DC::Macro; 12use DC::Macro;
431sub movement_update { 433sub movement_update {
432 my ($self) = @_; 434 my ($self) = @_;
433 435
434 if ($::CFG->{smooth_movement}) { 436 if ($::CFG->{smooth_movement}) {
435 if ($self->{sdx} || $self->{sdy}) { 437 if ($self->{sdx} || $self->{sdy}) {
436 my $diff = EV::time - ($self->{last_update} || $::LAST_REFRESH); 438 my $diff = AE::time - ($self->{last_update} || $::LAST_REFRESH);
437 my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; 439 my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED};
438 440
439 # the minimum time for a single tile movement 441 # the minimum time for a single tile movement
440 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);
441 443
462 } 464 }
463 } else { 465 } else {
464 $self->{sdx} = $self->{sdy} = 0; 466 $self->{sdx} = $self->{sdy} = 0;
465 } 467 }
466 468
467 $self->{last_update} = EV::time; 469 $self->{last_update} = AE::time;
468} 470}
469 471
470sub refresh_hook { 472sub refresh_hook {
471 my ($self) = @_; 473 my ($self) = @_;
472 474
620} 622}
621 623
622sub refresh_hook { 624sub refresh_hook {
623 my ($self) = @_; 625 my ($self) = @_;
624 626
625 if ($::MAP && $self->{texture_atime} < EV::now) { 627 if ($::MAP && $self->{texture_atime} < AE::now) {
626 my ($w, $h) = @$self{qw(w h)}; 628 my ($w, $h) = @$self{qw(w h)};
627 629
628 return unless $w && $h; 630 return unless $w && $h;
629 631
630 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 632 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
645 $self->{sh} = $sh; 647 $self->{sh} = $sh;
646 648
647 $self->{x0} = $x0; 649 $self->{x0} = $x0;
648 $self->{y0} = $y0; 650 $self->{y0} = $y0;
649 651
650 $self->{texture_atime} = EV::now + 1/2; 652 $self->{texture_atime} = AE::now + 1/2;
651 653
652 $self->{texture} = 654 $self->{texture} =
653 new DC::Texture 655 new DC::Texture
654 w => $w, 656 w => $w,
655 h => $h, 657 h => $h,
873 } else { 875 } else {
874 # @match is [command, penalty, command with arguments] until sort 876 # @match is [command, penalty, command with arguments] until sort
875 877
876 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; 878 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
877 879
880 my $first_char = substr $cmd, 0, 1;
881
878 my $regexp_abbrev = do { 882 my $regexp_abbrev = do {
879 my ($beg, @chr) = split //, lc $cmd; 883 my ($beg, @chr) = split //, lc $cmd;
880 884
881 # the following regex is used to match our "completion entry" 885 # the following regex is used to match our "completion entry"
882 # to an actual command - the parentheses match kind of "overhead" 886 # to an actual command - the parentheses match kind of "overhead"
883 # - the more characters the parentheses match, the less attractive 887 # - the more characters the parentheses match, the less attractive
884 # is the match. 888 # is the match.
885 my $regexp = "^\Q$beg\E" 889 my $regexp = "^\Q$beg\E"
886 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; 890 . join "", map "(?:.*?[ \\\\]|(.*?))\Q$_\E", @chr;
887 qr<$regexp> 891 qr<$regexp>
888 }; 892 };
889 893
890 my $regexp_partial = do { 894 my $regexp_partial = do {
891 my $regexp = "^\Q$text\E(.*)"; 895 my $regexp = "^\Q$text\E(.*)";
892 qr<$regexp> 896 qr<$regexp>
893 }; 897 };
894 898
895 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
896 my @scores; 904 my @scores;
897 905
898 # 1. Complete command [with args] 906 # 1. Complete command [with args]
899 # command is a prefix of the text 907 # command is a prefix of the text
900 # score is length of complete command matched 908 # score is length of complete command matched
901 # e.g. "invoke summon pet monster bat" 909 # e.g. "invoke summon pet monster bat"
902 # "invoke" "summon pet monster bat" = 6 910 # "invoke" "summon pet monster bat" = 6
903 # "invoke summon pet monster" "bat" = 25 911 # "invoke summon pet monster" "bat" = 25
904 if ($text =~ /^\Q$_\E(.*)/) { 912 if ((substr $text, 0, length $_) eq $_) {
905 push @scores, [$_, length $_, $text]; 913 push @scores, [$_, length $_, $text];
906 } 914 }
907 915
908 # 2. Partial command 916 # 2. Partial command
909 # 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