--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/12/27 19:12:19 1.185 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2008/05/20 02:49:56 1.198 @@ -29,8 +29,8 @@ $self->{map_widget}->clr_commands; my @cmd_help = map { - $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x - or die "unparseable command help: $_->{kw}[0]"; + $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x + or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; my $cmd = $1; my @args = split /\|/, $2; @@ -45,7 +45,7 @@ map ["$cmd$_", $text], sort { (length $a) <=> (length $b) } @args - } sort { $a->{par} <=> $b->{par} } + } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } DC::Pod::find command => "*"; $self->{json_coder} @@ -66,6 +66,11 @@ $_->destroy for values %{delete $ws->{w} || {}}; } + + delete $self->{items}; + $::INV->clear; + $::INVR_HB->clear; + $::FLOORBOX->clear; }); $self->{map_widget}->add_command (@$_) @@ -227,11 +232,16 @@ # either array reference, or face # if ($type eq "inline") { - $parse_list->($template); $done_cb->(); + $parse_list->($template); } elsif ($type eq "face") { - #... - $done_cb->(0); + my $handler; $handler = $self->register_face_handler ($template, sub { + my ($face) = @_; + + undef $handler; + $done_cb->(); + $parse_list->($self->{json_coder}->decode ($face->{data})); + }); } else { $done_cb->(0); } @@ -272,6 +282,7 @@ floorbox => $::FLOORBOX, help_window => $::HELP_WINDOW, message_window => $::MESSAGE_WINDOW, + message_dist => $::MESSAGE_DIST, statusbox => $::SDTATUSBOX, inv => $::INV, @@ -330,7 +341,7 @@ sub ext_channel_info { my ($self, $info) = @_; $self->{channels}->{$info->{id}} = $info; - $::MESSAGE_WINDOW->add_channel ($info); + $::MESSAGE_DIST->add_channel ($info); } ############################################################################# @@ -522,12 +533,12 @@ my $sw = $self->{skillwid}{""} ||= [ 0, 0, (new DC::UI::Label text => "Experience", align => 1), 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), - 2, 0, (new DC::UI::Label text => "Progress", align => 0), - 3, 0, (new DC::UI::Label text => "Skill", expand => 1), + 2, 0, (new DC::UI::Label text => "Progress"), + 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 4, 0, (new DC::UI::Label text => "Experience", align => 1), 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), - 6, 0, (new DC::UI::Label text => "Progress", align => 0), - 7, 0, (new DC::UI::Label text => "Skill", expand => 1), + 6, 0, (new DC::UI::Label text => "Progress"), + 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), ]; my @add = @$sw; @@ -576,7 +587,7 @@ (new DC::UI::ExperienceProgress), # label - (new DC::UI::Label text => $name, on_button_down => $spell_cb, + (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), ]; @@ -675,20 +686,26 @@ sub flush_map { my ($self) = @_; - my $map_info = delete $self->{map_info} - or return; + return unless $self->{map_info}; - my ($hash, $x, $y, $w, $h) = @$map_info; + for my $map_info (values %{ $self->{map_cache} || {} }) { + my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; - my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); - $self->{map_cache_new}{$hash} = \$data; - DC::DB::put $self->{mapcache} => $hash => $data, sub { }; + my $data = $self->{map}->get_rect ($x, $y, $w, $h); + + if ($data ne $$rdata) { + $map_info->[1] = \$data; + my $cdata = Compress::LZF::compress $data; + DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; + } + } } sub map_clear { my ($self) = @_; $self->flush_map; + delete $self->{map_info}; delete $self->{neigh_map}; $self->{map}->clear; @@ -719,36 +736,34 @@ }; } -sub load_map($$$) { - my ($self, $hash, $x, $y) = @_; +sub load_map($$$$$$) { + my ($self, $hash, $x, $y, $w, $h) = @_; - my $gen = $self->{map_change_gen}; + my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; my $cb = sub { - return unless $gen == $self->{map_change_gen}; + $map_info->[1] = \$_[0]; - my ($data) = @_; - - if (defined $data) { - $self->{map_cache_new}{$hash} = \$data; - - my $data = Compress::LZF::decompress $data; - - my $inprogress = @{ $self->{bg_fetch} || [] }; - unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); - $self->bg_fetch unless $inprogress; - } + my $inprogress = @{ $self->{bg_fetch} || [] }; + unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); + $self->bg_fetch unless $inprogress; }; - if (my $rdata = $self->{map_cache_old}{$hash}) { - $cb->($$rdata); + if (my $map_info = $self->{map_cache_old}{$hash}) { + $cb->(${ $map_info->[1] }); } else { - DC::DB::get $self->{mapcache} => $hash, $cb; + my $gen = $self->{map_change_gen}; + + DC::DB::get $self->{mapcache} => $hash, sub { + return unless $gen == $self->{map_change_gen}; + return unless defined $_[0]; + $cb->(Compress::LZF::decompress $_[0]); + }; } } # hardcode /world/world_xxx_xxx map names, the savings are enourmous, -# (server resource,s latency, bandwidth), so this hack is warranted. +# (server resources, latency, bandwidth), so this hack is warranted. # the right fix is to make real tiled maps with an overview file sub send_mapinfo { my ($self, $data, $cb) = @_; @@ -783,7 +798,7 @@ # this method does a "flood fill" into every tile direction # it assumes that tiles are arranged in a rectangular grid, # i.e. a map is the same as the left of the right map etc. -# failure to comply are harmless and result in display errors +# failure to comply is harmless and results in display errors # at worst. sub flood_fill { my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; @@ -829,7 +844,7 @@ $x += $self->{map}->ox; $y += $self->{map}->oy; - $self->load_map ($hash, $x, $y) + $self->load_map ($hash, $x, $y, $w, $h) unless $self->{neigh_map}{$hash}[5]++;#d# $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; @@ -847,7 +862,7 @@ $self->flush_map; ++$self->{map_change_gen}; - $self->{map_cache_old} = delete $self->{map_cache_new}; + $self->{map_cache_old} = delete $self->{map_cache}; my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); @@ -869,7 +884,7 @@ (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; $::STATWIDS->{map}->set_text ("Map: " . $map); - $self->load_map ($hash, $x, $y); + $self->load_map ($hash, $x, $y, $w, $h); $self->flood_fill (0, 0, 0, "", $hash, $flags); } @@ -1022,6 +1037,8 @@ s/(.*?)<\/fg>/$2<\/span>/gs; s/(.*?)<\/fg>/$2<\/span>/gs; + s/\s+$//; + $_ } @@ -1136,7 +1153,7 @@ for my $node (DC::Pod::find skill_description => "*") { my (undef, @par) = DC::Pod::section_of $node; - $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; + $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; }; for my $skill (values %{$self->{skill_info}}) { @@ -1166,7 +1183,8 @@ my @add; my $row; - for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { + for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { + next if $_->{tag} & 0x80000000; if ($row < 6) { local $_->{face_widget}; # hack to force recreation of widget local $_->{desc_widget}; # hack to force recreation of widget @@ -1203,8 +1221,8 @@ $conn->{open_container} = $tag; update_floorbox; - $::INVR_HB->clear (); - $::INVR_HB->add (new DC::UI::Label align => 0, expand => 1, text => $name); + $::INVR_HB->clear; + $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); if ($tag != 0) { # Floor isn't closable, is it? $::INVR_HB->add (new DC::UI::Button @@ -1269,10 +1287,10 @@ sub item_update { my ($self, $item) = @_; - #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; + #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; DC::Item::update_widgets $item; - + if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { set_opencont ($::CONN, 0, "Floor"); @@ -1298,7 +1316,7 @@ my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); - $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); + $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit); $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); } @@ -1316,7 +1334,7 @@ . "editing support $yesno[!!$self->{editor_support}]\n" . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" - . "cfplus support $yesno[$self->{cfplus_ext} > 0]" + . "client support $yesno[$self->{cfplus_ext} > 0]" . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" . "map size $self->{mapw}×$self->{maph}\n" );