--- deliantra/Deliantra-Client/DC/MapWidget.pm 2009/12/22 01:37:41 1.160 +++ deliantra/Deliantra-Client/DC/MapWidget.pm 2012/11/09 22:53:57 1.165 @@ -1,10 +1,11 @@ package DC::MapWidget; -use strict; -use utf8; +use common::sense; use List::Util qw(min max); +use AnyEvent (); + use DC; use DC::OpenGL; use DC::UI; @@ -216,8 +217,8 @@ # \&editor_invoke, # ]; - for my $type (qw(test name)) { - $::CONN->{editor_support}{type} ne $type + for my $type (@{ $::CONN->{editor_support}{servertypes} }) { + $::CONN->{editor_support}{servertype} ne $type or next; my $server = $::CONN->{editor_support}{"${type}server"} or next; @@ -434,7 +435,7 @@ if ($::CFG->{smooth_movement}) { if ($self->{sdx} || $self->{sdy}) { - my $diff = EV::time - ($self->{last_update} || $::LAST_REFRESH); + my $diff = AE::time - ($self->{last_update} || $::LAST_REFRESH); my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; # the minimum time for a single tile movement @@ -465,7 +466,7 @@ $self->{sdx} = $self->{sdy} = 0; } - $self->{last_update} = EV::time; + $self->{last_update} = AE::time; } sub refresh_hook { @@ -517,7 +518,7 @@ glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; $::MAP->draw ($dx, $dy, $sw, $sh, - $self->{tilesize}, + ($self->{tilesize}) x 2, $::CONN->{player}{tag}, -$self->{sdx}, -$self->{sdy}); @@ -610,12 +611,10 @@ package DC::MapWidget::MapMap; -use strict; -use utf8; +use common::sense; our @ISA = DC::UI::Base::; -use Time::HiRes qw(time); use DC::OpenGL; sub size_request { @@ -625,7 +624,7 @@ sub refresh_hook { my ($self) = @_; - if ($::MAP && $self->{texture_atime} < time) { + if ($::MAP && $self->{texture_atime} < AE::now) { my ($w, $h) = @$self{qw(w h)}; return unless $w && $h; @@ -650,7 +649,7 @@ $self->{x0} = $x0; $self->{y0} = $y0; - $self->{texture_atime} = time + 1/3; + $self->{texture_atime} = AE::now + 1/2; $self->{texture} = new DC::Texture @@ -715,7 +714,7 @@ package DC::MapWidget::Command; -use strict; +use common::sense; use DC::OpenGL; @@ -878,6 +877,8 @@ my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; + my $first_char = substr $cmd, 0, 1; + my $regexp_abbrev = do { my ($beg, @chr) = split //, lc $cmd; @@ -886,7 +887,7 @@ # - the more characters the parentheses match, the less attractive # is the match. my $regexp = "^\Q$beg\E" - . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; + . join "", map "(?:.*?[ \\\\]|(.*?))\Q$_\E", @chr; qr<$regexp> }; @@ -896,6 +897,10 @@ }; for (keys %{$self->{command}}) { + # we only match and score if the first character matches, + # so quickly rule out all others first. + next unless $first_char = substr $_, 0, 1; + my @scores; # 1. Complete command [with args] @@ -904,7 +909,7 @@ # e.g. "invoke summon pet monster bat" # "invoke" "summon pet monster bat" = 6 # "invoke summon pet monster" "bat" = 25 - if ($text =~ /^\Q$_\E(.*)/) { + if ((substr $text, 0, length $_) eq $_) { push @scores, [$_, length $_, $text]; }