--- deliantra/Deliantra-Client/DC/MapWidget.pm 2009/12/04 15:04:56 1.154 +++ 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; @@ -12,6 +13,11 @@ our @ISA = DC::UI::Base::; +our @TEX_HIDDEN = map { + new_from_resource DC::Texture # MUST be POT + "hidden-$_.png", mipmap => 1, wrap => 1 + } 0, 1, 2; + my $magicmap_tex = new_from_resource DC::Texture "magicmap.png", mipmap => 1, wrap => 0, internalformat => GL_ALPHA; @@ -211,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; @@ -398,16 +404,19 @@ sub scroll { my ($self, $dx, $dy) = @_; - $::MAP->scroll ($dx, $dy); - - $self->{last_fow_texture} = $self->{fow_texture}; - $self->{ldx} = $self->{sdx} + $dx * $self->{tilesize}; # smooth displacement - $self->{ldy} = $self->{sdy} + $dy * $self->{tilesize}; - $self->movement_update; $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement $self->{sdy} += $dy * $self->{tilesize}; + + # save old fow texture, if applicable + $self->{prev_fow_texture} = $::CFG->{smooth_transitions} && $self->{fow_texture}; + $self->{lfdx} = $dx; + $self->{lfdy} = $dy; + $self->{lmdx} = $self->{dx}; + $self->{lmdy} = $self->{dy}; + + $::MAP->scroll ($dx, $dy); } sub set_magicmap { @@ -426,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 @@ -457,7 +466,7 @@ $self->{sdx} = $self->{sdy} = 0; } - $self->{last_update} = EV::time; + $self->{last_update} = AE::time; } sub refresh_hook { @@ -488,14 +497,8 @@ my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; if ($::CFG->{fow_enable}) { - my ($sdx_t, $sdy_t);#d# do not anchor at player - - my ($w, $h, $data) = $::MAP->fow_texture ( - $dx + (min 0, $sdx_t), - $dy + (min 0, $sdy_t), - $sw + abs $sdx_t, - $sh + abs $sdy_t - ); + # draw_fow_texture REQUIRES the fow texture to stay the same size. + my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); $self->{fow_texture} = new DC::Texture w => $w, @@ -515,67 +518,34 @@ 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}); - #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player glScale $self->{tilesize}, $self->{tilesize}; if (my $tex = $self->{fow_texture}) { - glEnable GL_TEXTURE_2D; - glEnable GL_BLEND; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; - glBlendFunc GL_ONE, GL_ZERO; - - my $a1 = 0.9; - - if (0 && $self->{last_fow_texture}) { - my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5; - my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5; + my @prev_fow_params; - if ($d1 * $d2) { - my $a2 = $d1 / $d2; + if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) { + my $d1 = DC::distance $self->{sdx}, $self->{sdy}; + my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; - $a1 = 1 - $a2; - - #$a1 *= 0.9; - #$a2 *= 0.9; - - printf "%4g %4g %4g %4g\n", $d1, $d2, $a1, $a2;#d# - - #$a1 = 1 - (1-$a1) * 0.707; - #$a2 = 1 - (1-$a2) * 0.707; - - glColor 1,0,0,1; - glBegin GL_QUADS; - glVertex 10 + $sdx_t, 10; - glVertex 11 + $sdx_t, 10; - glVertex 11 + $sdx_t, 11; - glVertex 10 + $sdx_t, 11; - glEnd; - - glColor +($::CFG->{fow_intensity}) x 3, $a2; - glPushMatrix; - glTranslate $sdx_t, $sdy_t; # anchor at player - glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize; - glScale 1/3, 1/3; - $self->{last_fow_texture}->draw_quad_alpha (0, 0); - glPopMatrix; - } else { - delete $self->{last_fow_texture}; + if ($d1 * $d2) { + @prev_fow_params = ( + (min 1, $d1 / $d2), + $self->{lmdx} - $dx - $self->{lfdx}, + $self->{lmdy} - $dy - $self->{lfdy}, + @{$self->{prev_fow_texture}}{qw(name data)} + ); } } - glColor +($::CFG->{fow_intensity}) x 3, $a1; - glPushMatrix; - #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player - glScale 1/3, 1/3; - $self->{fow_texture}->draw_quad_alpha (0, 0); - glPopMatrix; - - glDisable GL_TEXTURE_2D; - glDisable GL_BLEND; + DC::Texture::draw_fow_texture + $::CFG->{fow_intensity}, + $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, + @{$self->{fow_texture}}{qw(name data s t w h)}, + @prev_fow_params; } if ($self->{magicmap}) { @@ -586,13 +556,16 @@ glTranslate - $x - 1, - $y - 1; glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; - $::MAP->draw_magicmap ($x, $y, $w, $h, $data); + $::MAP->draw_magicmap ($w, $h, $data); } glPopMatrix; glEndList; } } else { + delete $self->{last_fow_texture}; + delete $self->{fow_texture}; + glDeleteList delete $self->{list} if $self->{list}; } @@ -638,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 { @@ -653,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; @@ -678,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 @@ -743,7 +714,7 @@ package DC::MapWidget::Command; -use strict; +use common::sense; use DC::OpenGL; @@ -906,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; @@ -914,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> }; @@ -924,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] @@ -932,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]; }