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.162 by root, Sat Apr 3 02:58:25 2010 UTC vs.
Revision 1.166 by root, Sat Nov 10 18:29:32 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
514 glTranslate $sx0, $sy0; 516 glTranslate $sx0, $sy0;
515 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 517 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
516 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; 518 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy};
517 519
518 $::MAP->draw ($dx, $dy, $sw, $sh, 520 $::MAP->draw ($dx, $dy, $sw, $sh,
519 $self->{tilesize}, 521 ($self->{tilesize}) x 2,
520 $::CONN->{player}{tag}, 522 $::CONN->{player}{tag},
521 -$self->{sdx}, -$self->{sdy}); 523 -$self->{sdx}, -$self->{sdy});
522 524
523 glScale $self->{tilesize}, $self->{tilesize}; 525 glScale $self->{tilesize}, $self->{tilesize};
524 526
611 613
612use common::sense; 614use common::sense;
613 615
614our @ISA = DC::UI::Base::; 616our @ISA = DC::UI::Base::;
615 617
616use Time::HiRes qw(time);
617use DC::OpenGL; 618use DC::OpenGL;
618 619
619sub size_request { 620sub size_request {
620 ($::HEIGHT * 0.2, $::HEIGHT * 0.2) 621 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
621} 622}
622 623
623sub refresh_hook { 624sub refresh_hook {
624 my ($self) = @_; 625 my ($self) = @_;
625 626
626 if ($::MAP && $self->{texture_atime} < time) { 627 if ($::MAP && $self->{texture_atime} < AE::now) {
627 my ($w, $h) = @$self{qw(w h)}; 628 my ($w, $h) = @$self{qw(w h)};
628 629
629 return unless $w && $h; 630 return unless $w && $h;
630 631
631 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 632 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
646 $self->{sh} = $sh; 647 $self->{sh} = $sh;
647 648
648 $self->{x0} = $x0; 649 $self->{x0} = $x0;
649 $self->{y0} = $y0; 650 $self->{y0} = $y0;
650 651
651 $self->{texture_atime} = time + 1/3; 652 $self->{texture_atime} = AE::now + 1/2;
652 653
653 $self->{texture} = 654 $self->{texture} =
654 new DC::Texture 655 new DC::Texture
655 w => $w, 656 w => $w,
656 h => $h, 657 h => $h,
874 } else { 875 } else {
875 # @match is [command, penalty, command with arguments] until sort 876 # @match is [command, penalty, command with arguments] until sort
876 877
877 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; 878 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
878 879
880 my $first_char = substr $cmd, 0, 1;
881
879 my $regexp_abbrev = do { 882 my $regexp_abbrev = do {
880 my ($beg, @chr) = split //, lc $cmd; 883 my ($beg, @chr) = split //, lc $cmd;
881 884
882 # the following regex is used to match our "completion entry" 885 # the following regex is used to match our "completion entry"
883 # to an actual command - the parentheses match kind of "overhead" 886 # to an actual command - the parentheses match kind of "overhead"
884 # - the more characters the parentheses match, the less attractive 887 # - the more characters the parentheses match, the less attractive
885 # is the match. 888 # is the match.
886 my $regexp = "^\Q$beg\E" 889 my $regexp = "^\Q$beg\E"
887 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; 890 . join "", map "(?:.*?[ _\-]|(.*?))\Q$_\E", @chr;
888 qr<$regexp> 891 qr<$regexp>
889 }; 892 };
890 893
891 my $regexp_partial = do { 894 my $regexp_partial = do {
892 my $regexp = "^\Q$text\E(.*)"; 895 my $regexp = "^\Q$text\E(.*)";
893 qr<$regexp> 896 qr<$regexp>
894 }; 897 };
895 898
896 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
897 my @scores; 904 my @scores;
898 905
899 # 1. Complete command [with args] 906 # 1. Complete command [with args]
900 # command is a prefix of the text 907 # command is a prefix of the text
901 # score is length of complete command matched 908 # score is length of complete command matched
902 # e.g. "invoke summon pet monster bat" 909 # e.g. "invoke summon pet monster bat"
903 # "invoke" "summon pet monster bat" = 6 910 # "invoke" "summon pet monster bat" = 6
904 # "invoke summon pet monster" "bat" = 25 911 # "invoke summon pet monster" "bat" = 25
905 if ($text =~ /^\Q$_\E(.*)/) { 912 if ((substr $text, 0, length $_) eq $_) {
906 push @scores, [$_, length $_, $text]; 913 push @scores, [$_, length $_, $text];
907 } 914 }
908 915
909 # 2. Partial command 916 # 2. Partial command
910 # 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