ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.187 by root, Sat Dec 29 13:44:30 2007 UTC vs.
Revision 1.198 by root, Tue May 20 02:49:56 2008 UTC

27 ); 27 );
28 28
29 $self->{map_widget}->clr_commands; 29 $self->{map_widget}->clr_commands;
30 30
31 my @cmd_help = map { 31 my @cmd_help = map {
32 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 32 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
33 or die "unparseable command help: $_->{kw}[0]"; 33 or die "unparseable command help: $_->[DC::Pod::N_KW][0]";
34 34
35 my $cmd = $1; 35 my $cmd = $1;
36 my @args = split /\|/, $2; 36 my @args = split /\|/, $2;
37 @args = (".*") unless @args; 37 @args = (".*") unless @args;
38 38
43 for @args; 43 for @args;
44 44
45 map ["$cmd$_", $text], 45 map ["$cmd$_", $text],
46 sort { (length $a) <=> (length $b) } 46 sort { (length $a) <=> (length $b) }
47 @args 47 @args
48 } sort { $a->{par} <=> $b->{par} } 48 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] }
49 DC::Pod::find command => "*"; 49 DC::Pod::find command => "*";
50 50
51 $self->{json_coder} 51 $self->{json_coder}
52 ->convert_blessed 52 ->convert_blessed
53 ->filter_json_single_key_object ("\fw" => sub { 53 ->filter_json_single_key_object ("\fw" => sub {
64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
65 for my $ws (values %{delete $self->{widgetset} || {}}) { 65 for my $ws (values %{delete $self->{widgetset} || {}}) {
66 $_->destroy 66 $_->destroy
67 for values %{delete $ws->{w} || {}}; 67 for values %{delete $ws->{w} || {}};
68 } 68 }
69
70 delete $self->{items};
71 $::INV->clear;
72 $::INVR_HB->clear;
73 $::FLOORBOX->clear;
69 }); 74 });
70 75
71 $self->{map_widget}->add_command (@$_) 76 $self->{map_widget}->add_command (@$_)
72 for @cmd_help; 77 for @cmd_help;
73 78
275 spell_list => $::SPELL_LIST, 280 spell_list => $::SPELL_LIST,
276 281
277 floorbox => $::FLOORBOX, 282 floorbox => $::FLOORBOX,
278 help_window => $::HELP_WINDOW, 283 help_window => $::HELP_WINDOW,
279 message_window => $::MESSAGE_WINDOW, 284 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST,
280 statusbox => $::SDTATUSBOX, 286 statusbox => $::SDTATUSBOX,
281 287
282 inv => $::INV, 288 inv => $::INV,
283 invr => $::INVR, 289 invr => $::INVR,
284 invr_hb => $::INVR_HB, 290 invr_hb => $::INVR_HB,
333 339
334# message window 340# message window
335sub ext_channel_info { 341sub ext_channel_info {
336 my ($self, $info) = @_; 342 my ($self, $info) = @_;
337 $self->{channels}->{$info->{id}} = $info; 343 $self->{channels}->{$info->{id}} = $info;
338 $::MESSAGE_WINDOW->add_channel ($info); 344 $::MESSAGE_DIST->add_channel ($info);
339} 345}
340 346
341############################################################################# 347#############################################################################
342 348
343sub logprint { 349sub logprint {
678} 684}
679 685
680sub flush_map { 686sub flush_map {
681 my ($self) = @_; 687 my ($self) = @_;
682 688
683 my $map_info = delete $self->{map_info} 689 return unless $self->{map_info};
684 or return;
685 690
691 for my $map_info (values %{ $self->{map_cache} || {} }) {
686 my ($hash, $x, $y, $w, $h) = @$map_info; 692 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
687 693
688 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 694 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
689 $self->{map_cache_new}{$hash} = \$data; 695
696 if ($data ne $$rdata) {
697 $map_info->[1] = \$data;
698 my $cdata = Compress::LZF::compress $data;
690 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 699 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
700 }
701 }
691} 702}
692 703
693sub map_clear { 704sub map_clear {
694 my ($self) = @_; 705 my ($self) = @_;
695 706
696 $self->flush_map; 707 $self->flush_map;
708 delete $self->{map_info};
697 delete $self->{neigh_map}; 709 delete $self->{neigh_map};
698 710
699 $self->{map}->clear; 711 $self->{map}->clear;
700 delete $self->{map_widget}{magicmap}; 712 delete $self->{map_widget}{magicmap};
701} 713}
722 734
723 $self->bg_fetch; 735 $self->bg_fetch;
724 }; 736 };
725} 737}
726 738
727sub load_map($$$) { 739sub load_map($$$$$$) {
728 my ($self, $hash, $x, $y) = @_; 740 my ($self, $hash, $x, $y, $w, $h) = @_;
729 741
730 my $gen = $self->{map_change_gen}; 742 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
731 743
732 my $cb = sub { 744 my $cb = sub {
733 return unless $gen == $self->{map_change_gen}; 745 $map_info->[1] = \$_[0];
734 746
735 my ($data) = @_;
736
737 if (defined $data) {
738 $self->{map_cache_new}{$hash} = \$data;
739
740 my $data = Compress::LZF::decompress $data;
741
742 my $inprogress = @{ $self->{bg_fetch} || [] }; 747 my $inprogress = @{ $self->{bg_fetch} || [] };
743 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 748 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
744 $self->bg_fetch unless $inprogress; 749 $self->bg_fetch unless $inprogress;
745 }
746 }; 750 };
747 751
748 if (my $rdata = $self->{map_cache_old}{$hash}) { 752 if (my $map_info = $self->{map_cache_old}{$hash}) {
749 $cb->($$rdata); 753 $cb->(${ $map_info->[1] });
750 } else { 754 } else {
755 my $gen = $self->{map_change_gen};
756
751 DC::DB::get $self->{mapcache} => $hash, $cb; 757 DC::DB::get $self->{mapcache} => $hash, sub {
758 return unless $gen == $self->{map_change_gen};
759 return unless defined $_[0];
760 $cb->(Compress::LZF::decompress $_[0]);
761 };
752 } 762 }
753} 763}
754 764
755# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 765# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
756# (server resource,s latency, bandwidth), so this hack is warranted. 766# (server resources, latency, bandwidth), so this hack is warranted.
757# the right fix is to make real tiled maps with an overview file 767# the right fix is to make real tiled maps with an overview file
758sub send_mapinfo { 768sub send_mapinfo {
759 my ($self, $data, $cb) = @_; 769 my ($self, $data, $cb) = @_;
760 770
761 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 771 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
786} 796}
787 797
788# this method does a "flood fill" into every tile direction 798# this method does a "flood fill" into every tile direction
789# it assumes that tiles are arranged in a rectangular grid, 799# it assumes that tiles are arranged in a rectangular grid,
790# i.e. a map is the same as the left of the right map etc. 800# i.e. a map is the same as the left of the right map etc.
791# failure to comply are harmless and result in display errors 801# failure to comply is harmless and results in display errors
792# at worst. 802# at worst.
793sub flood_fill { 803sub flood_fill {
794 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 804 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
795 805
796 # the server does not allow map paths > 6 806 # the server does not allow map paths > 6
832 return if $mode ne "spatial"; 842 return if $mode ne "spatial";
833 843
834 $x += $self->{map}->ox; 844 $x += $self->{map}->ox;
835 $y += $self->{map}->oy; 845 $y += $self->{map}->oy;
836 846
837 $self->load_map ($hash, $x, $y) 847 $self->load_map ($hash, $x, $y, $w, $h)
838 unless $self->{neigh_map}{$hash}[5]++;#d# 848 unless $self->{neigh_map}{$hash}[5]++;#d#
839 849
840 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 850 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
841 851
842 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 852 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
850 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 860 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
851 861
852 $self->flush_map; 862 $self->flush_map;
853 863
854 ++$self->{map_change_gen}; 864 ++$self->{map_change_gen};
855 $self->{map_cache_old} = delete $self->{map_cache_new}; 865 $self->{map_cache_old} = delete $self->{map_cache};
856 866
857 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 867 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
858 868
859 my $mapmapw = $self->{mapmap}->{w}; 869 my $mapmapw = $self->{mapmap}->{w};
860 my $mapmaph = $self->{mapmap}->{h}; 870 my $mapmaph = $self->{mapmap}->{h};
872 $self->{map_info} = [$hash, $x, $y, $w, $h]; 882 $self->{map_info} = [$hash, $x, $y, $w, $h];
873 883
874 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 884 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
875 $::STATWIDS->{map}->set_text ("Map: " . $map); 885 $::STATWIDS->{map}->set_text ("Map: " . $map);
876 886
877 $self->load_map ($hash, $x, $y); 887 $self->load_map ($hash, $x, $y, $w, $h);
878 $self->flood_fill (0, 0, 0, "", $hash, $flags); 888 $self->flood_fill (0, 0, 0, "", $hash, $flags);
879} 889}
880 890
881sub face_find { 891sub face_find {
882 my ($self, $facenum, $face, $cb) = @_; 892 my ($self, $facenum, $face, $cb) = @_;
1024 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g; 1034 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
1025 1035
1026 # handle some elements 1036 # handle some elements
1027 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1037 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1028 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; 1038 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1039
1040 s/\s+$//;
1029 1041
1030 $_ 1042 $_
1031} 1043}
1032 1044
1033our %NAME_TO_COLOR = ( 1045our %NAME_TO_COLOR = (
1139 1151
1140 my %skill_help; 1152 my %skill_help;
1141 1153
1142 for my $node (DC::Pod::find skill_description => "*") { 1154 for my $node (DC::Pod::find skill_description => "*") {
1143 my (undef, @par) = DC::Pod::section_of $node; 1155 my (undef, @par) = DC::Pod::section_of $node;
1144 $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; 1156 $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par;
1145 }; 1157 };
1146 1158
1147 for my $skill (values %{$self->{skill_info}}) { 1159 for my $skill (values %{$self->{skill_info}}) {
1148 $self->{map_widget}->add_command ("ready_skill $skill", 1160 $self->{map_widget}->add_command ("ready_skill $skill",
1149 (DC::asxml "Ready the skill '$skill'\n\n") 1161 (DC::asxml "Ready the skill '$skill'\n\n")
1169 $::FLOORBOX->clear; 1181 $::FLOORBOX->clear;
1170 1182
1171 my @add; 1183 my @add;
1172 1184
1173 my $row; 1185 my $row;
1174 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1186 for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
1187 next if $_->{tag} & 0x80000000;
1175 if ($row < 6) { 1188 if ($row < 6) {
1176 local $_->{face_widget}; # hack to force recreation of widget 1189 local $_->{face_widget}; # hack to force recreation of widget
1177 local $_->{desc_widget}; # hack to force recreation of widget 1190 local $_->{desc_widget}; # hack to force recreation of widget
1178 DC::Item::update_widgets $_; 1191 DC::Item::update_widgets $_;
1179 1192
1206sub set_opencont { 1219sub set_opencont {
1207 my ($conn, $tag, $name) = @_; 1220 my ($conn, $tag, $name) = @_;
1208 $conn->{open_container} = $tag; 1221 $conn->{open_container} = $tag;
1209 update_floorbox; 1222 update_floorbox;
1210 1223
1211 $::INVR_HB->clear (); 1224 $::INVR_HB->clear;
1212 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); 1225 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1213 1226
1214 if ($tag != 0) { # Floor isn't closable, is it? 1227 if ($tag != 0) { # Floor isn't closable, is it?
1215 $::INVR_HB->add (new DC::UI::Button 1228 $::INVR_HB->add (new DC::UI::Button
1216 text => "Close container", 1229 text => "Close container",
1272} 1285}
1273 1286
1274sub item_update { 1287sub item_update {
1275 my ($self, $item) = @_; 1288 my ($self, $item) = @_;
1276 1289
1277 #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; 1290 #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n";
1278 1291
1279 DC::Item::update_widgets $item; 1292 DC::Item::update_widgets $item;
1280 1293
1281 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1294 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1282 set_opencont ($::CONN, 0, "Floor"); 1295 set_opencont ($::CONN, 0, "Floor");
1283 1296
1284 } elsif ($item->{flags} & F_OPEN) { 1297 } elsif ($item->{flags} & F_OPEN) {
1285 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); 1298 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1319 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 1332 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1320 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" 1333 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1321 . "editing support $yesno[!!$self->{editor_support}]\n" 1334 . "editing support $yesno[!!$self->{editor_support}]\n"
1322 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 1335 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1323 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" 1336 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1324 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1337 . "client support $yesno[$self->{cfplus_ext} > 0]"
1325 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1338 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1326 . "map size $self->{mapw}×$self->{maph}\n" 1339 . "map size $self->{mapw}×$self->{maph}\n"
1327 ); 1340 );
1328 1341
1329} 1342}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines