1 | package DC::MapWidget; |
1 | package DC::MapWidget; |
2 | |
2 | |
3 | use common::sense; |
3 | use common::sense; |
4 | |
4 | |
5 | use List::Util qw(min max); |
5 | use List::Util qw(min max); |
|
|
6 | |
|
|
7 | use AnyEvent (); |
6 | |
8 | |
7 | use DC; |
9 | use DC; |
8 | use DC::OpenGL; |
10 | use DC::OpenGL; |
9 | use DC::UI; |
11 | use DC::UI; |
10 | use DC::Macro; |
12 | use DC::Macro; |
… | |
… | |
431 | sub movement_update { |
433 | sub 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 | |
470 | sub refresh_hook { |
472 | sub 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 | |
612 | use common::sense; |
614 | use common::sense; |
613 | |
615 | |
614 | our @ISA = DC::UI::Base::; |
616 | our @ISA = DC::UI::Base::; |
615 | |
617 | |
616 | use Time::HiRes qw(time); |
|
|
617 | use DC::OpenGL; |
618 | use DC::OpenGL; |
618 | |
619 | |
619 | sub size_request { |
620 | sub size_request { |
620 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
621 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
621 | } |
622 | } |
622 | |
623 | |
623 | sub refresh_hook { |
624 | sub 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 |