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.192 by root, Thu Mar 27 20:42:23 2008 UTC vs.
Revision 1.202 by root, Tue Sep 9 10:27:26 2008 UTC

11use DC::Pod; 11use DC::Pod;
12use DC::Macro; 12use DC::Macro;
13use DC::Item; 13use DC::Item;
14 14
15use base 'Deliantra::Protocol::Base'; 15use base 'Deliantra::Protocol::Base';
16
17our $TEX_DIALOGUE = new_from_resource DC::Texture
18 "dialogue.png", minify => 1, mipmap => 1;
19
20our $TEX_NOFACE = new_from_resource DC::Texture
21 "noface.png", minify => 1, mipmap => 1;
16 22
17sub new { 23sub new {
18 my ($class, %arg) = @_; 24 my ($class, %arg) = @_;
19 25
20 my $self = $class->SUPER::new (%arg, 26 my $self = $class->SUPER::new (%arg,
64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 70 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
65 for my $ws (values %{delete $self->{widgetset} || {}}) { 71 for my $ws (values %{delete $self->{widgetset} || {}}) {
66 $_->destroy 72 $_->destroy
67 for values %{delete $ws->{w} || {}}; 73 for values %{delete $ws->{w} || {}};
68 } 74 }
75
76 delete $self->{items};
77 $::INV->clear;
78 $::INVR_HB->clear;
79 $::FLOORBOX->clear;
69 }); 80 });
70 81
71 $self->{map_widget}->add_command (@$_) 82 $self->{map_widget}->add_command (@$_)
72 for @cmd_help; 83 for @cmd_help;
73 84
74 { 85 {
75 $self->{dialogue} = my $tex = new_from_file DC::Texture 86 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
76 DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
77 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 87 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
78 } 88 }
79 89
80 { 90 {
81 $self->{noface} = my $tex = new_from_file DC::Texture 91 $self->{noface} = my $tex = $TEX_NOFACE;
82 DC::find_rcfile "noface.png", minify => 1, mipmap => 1;
83 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 92 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
84 } 93 }
85 94
86 $self->{open_container} = 0; 95 $self->{open_container} = 0;
87 96
632} 641}
633 642
634sub map_scroll { 643sub map_scroll {
635 my ($self, $dx, $dy) = @_; 644 my ($self, $dx, $dy) = @_;
636 645
637 $self->{map}->scroll ($dx, $dy); 646 $self->{map_widget}->scroll ($dx, $dy);
638} 647}
639 648
640sub feed_map1a { 649sub feed_map1a {
641 my ($self, $data) = @_; 650 my ($self, $data) = @_;
642 651
679} 688}
680 689
681sub flush_map { 690sub flush_map {
682 my ($self) = @_; 691 my ($self) = @_;
683 692
684 my $map_info = delete $self->{map_info} 693 return unless $self->{map_info};
685 or return;
686 694
695 for my $map_info (values %{ $self->{map_cache} || {} }) {
687 my ($hash, $x, $y, $w, $h) = @$map_info; 696 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
688 697
689 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 698 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
690 $self->{map_cache_new}{$hash} = \$data; 699
700 if ($data ne $$rdata) {
701 $map_info->[1] = \$data;
702 my $cdata = Compress::LZF::compress $data;
691 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 703 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
704 }
705 }
692} 706}
693 707
694sub map_clear { 708sub map_clear {
695 my ($self) = @_; 709 my ($self) = @_;
696 710
697 $self->flush_map; 711 $self->flush_map;
712 delete $self->{map_info};
698 delete $self->{neigh_map}; 713 delete $self->{neigh_map};
699 714
700 $self->{map}->clear; 715 $self->{map}->clear;
701 delete $self->{map_widget}{magicmap}; 716 delete $self->{map_widget}{magicmap};
702} 717}
723 738
724 $self->bg_fetch; 739 $self->bg_fetch;
725 }; 740 };
726} 741}
727 742
728sub load_map($$$) { 743sub load_map($$$$$$) {
729 my ($self, $hash, $x, $y) = @_; 744 my ($self, $hash, $x, $y, $w, $h) = @_;
730 745
731 my $gen = $self->{map_change_gen}; 746 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
732 747
733 my $cb = sub { 748 my $cb = sub {
734 return unless $gen == $self->{map_change_gen}; 749 $map_info->[1] = \$_[0];
735 750
736 my ($data) = @_;
737
738 if (defined $data) {
739 $self->{map_cache_new}{$hash} = \$data;
740
741 my $data = Compress::LZF::decompress $data;
742
743 my $inprogress = @{ $self->{bg_fetch} || [] }; 751 my $inprogress = @{ $self->{bg_fetch} || [] };
744 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 752 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
745 $self->bg_fetch unless $inprogress; 753 $self->bg_fetch unless $inprogress;
746 }
747 }; 754 };
748 755
749 if (my $rdata = $self->{map_cache_old}{$hash}) { 756 if (my $map_info = $self->{map_cache_old}{$hash}) {
750 $cb->($$rdata); 757 $cb->(${ $map_info->[1] });
751 } else { 758 } else {
759 my $gen = $self->{map_change_gen};
760
752 DC::DB::get $self->{mapcache} => $hash, $cb; 761 DC::DB::get $self->{mapcache} => $hash, sub {
762 return unless $gen == $self->{map_change_gen};
763 return unless defined $_[0];
764 $cb->(Compress::LZF::decompress $_[0]);
765 };
753 } 766 }
754} 767}
755 768
756# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 769# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
757# (server resource,s latency, bandwidth), so this hack is warranted. 770# (server resources, latency, bandwidth), so this hack is warranted.
758# the right fix is to make real tiled maps with an overview file 771# the right fix is to make real tiled maps with an overview file
759sub send_mapinfo { 772sub send_mapinfo {
760 my ($self, $data, $cb) = @_; 773 my ($self, $data, $cb) = @_;
761 774
762 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 775 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
787} 800}
788 801
789# this method does a "flood fill" into every tile direction 802# this method does a "flood fill" into every tile direction
790# it assumes that tiles are arranged in a rectangular grid, 803# it assumes that tiles are arranged in a rectangular grid,
791# i.e. a map is the same as the left of the right map etc. 804# i.e. a map is the same as the left of the right map etc.
792# failure to comply are harmless and result in display errors 805# failure to comply is harmless and results in display errors
793# at worst. 806# at worst.
794sub flood_fill { 807sub flood_fill {
795 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 808 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
796 809
797 # the server does not allow map paths > 6 810 # the server does not allow map paths > 6
833 return if $mode ne "spatial"; 846 return if $mode ne "spatial";
834 847
835 $x += $self->{map}->ox; 848 $x += $self->{map}->ox;
836 $y += $self->{map}->oy; 849 $y += $self->{map}->oy;
837 850
838 $self->load_map ($hash, $x, $y) 851 $self->load_map ($hash, $x, $y, $w, $h)
839 unless $self->{neigh_map}{$hash}[5]++;#d# 852 unless $self->{neigh_map}{$hash}[5]++;#d#
840 853
841 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 854 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
842 855
843 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 856 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
851 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 864 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
852 865
853 $self->flush_map; 866 $self->flush_map;
854 867
855 ++$self->{map_change_gen}; 868 ++$self->{map_change_gen};
856 $self->{map_cache_old} = delete $self->{map_cache_new}; 869 $self->{map_cache_old} = delete $self->{map_cache};
857 870
858 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 871 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
859 872
860 my $mapmapw = $self->{mapmap}->{w}; 873 my $mapmapw = $self->{mapmap}->{w};
861 my $mapmaph = $self->{mapmap}->{h}; 874 my $mapmaph = $self->{mapmap}->{h};
873 $self->{map_info} = [$hash, $x, $y, $w, $h]; 886 $self->{map_info} = [$hash, $x, $y, $w, $h];
874 887
875 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 888 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
876 $::STATWIDS->{map}->set_text ("Map: " . $map); 889 $::STATWIDS->{map}->set_text ("Map: " . $map);
877 890
878 $self->load_map ($hash, $x, $y); 891 $self->load_map ($hash, $x, $y, $w, $h);
879 $self->flood_fill (0, 0, 0, "", $hash, $flags); 892 $self->flood_fill (0, 0, 0, "", $hash, $flags);
880} 893}
881 894
882sub face_find { 895sub face_find {
883 my ($self, $facenum, $face, $cb) = @_; 896 my ($self, $facenum, $face, $cb) = @_;
1025 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; 1038 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g;
1026 1039
1027 # handle some elements 1040 # handle some elements
1028 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1041 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1029 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; 1042 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1043
1044 s/\s+$//;
1030 1045
1031 $_ 1046 $_
1032} 1047}
1033 1048
1034our %NAME_TO_COLOR = ( 1049our %NAME_TO_COLOR = (
1081 1096
1082 ## try to create single paragraphs of multiple lines sent by the server 1097 ## try to create single paragraphs of multiple lines sent by the server
1083 # no longer neecssary with TRT servers 1098 # no longer neecssary with TRT servers
1084 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1099 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1085 1100
1086 for (split /\n/, $text) {
1087 ::message ({ 1101 ::message ({
1088 fg => $fg, 1102 fg => $fg,
1089 markup => $_, 1103 markup => $text,
1090 type => $type, 1104 type => $type,
1091 extra => [@extra], 1105 extra => [@extra],
1092 color_flags => $color, #d# ugly, kill 1106 color_flags => $color, #d# ugly, kill
1093 }); 1107 });
1094 1108
1095 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1109# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1096 # actually, this is an ugly design. _we_ should control the channels, 1110# # actually, this is an ugly design. _we_ should control the channels,
1097 # not some random other widget, as the channels are clearly protocol-specific. 1111# # not some random other widget, as the channels are clearly protocol-specific.
1098 # then we could also react to flags such as CLEAR without resorting to 1112# # then we could also react to flags such as CLEAR without resorting to
1099 # hacks such as color_flags, above. 1113# # hacks such as color_flags, above.
1100 }
1101 1114
1102 $self->{statusbox}->add ($text, 1115 $self->{statusbox}->add ($text,
1103 group => $text, 1116 group => $text,
1104 fg => $fg, 1117 fg => $fg,
1105 timeout => $color >= 2 ? 180 : 10, 1118 timeout => $color >= 2 ? 180 : 10,
1170 $::FLOORBOX->clear; 1183 $::FLOORBOX->clear;
1171 1184
1172 my @add; 1185 my @add;
1173 1186
1174 my $row; 1187 my $row;
1175 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1188 for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
1189 next if $_->{tag} & 0x80000000;
1176 if ($row < 6) { 1190 if ($row < 6) {
1177 local $_->{face_widget}; # hack to force recreation of widget 1191 local $_->{face_widget}; # hack to force recreation of widget
1178 local $_->{desc_widget}; # hack to force recreation of widget 1192 local $_->{desc_widget}; # hack to force recreation of widget
1179 DC::Item::update_widgets $_; 1193 DC::Item::update_widgets $_;
1180 1194
1207sub set_opencont { 1221sub set_opencont {
1208 my ($conn, $tag, $name) = @_; 1222 my ($conn, $tag, $name) = @_;
1209 $conn->{open_container} = $tag; 1223 $conn->{open_container} = $tag;
1210 update_floorbox; 1224 update_floorbox;
1211 1225
1212 $::INVR_HB->clear (); 1226 $::INVR_HB->clear;
1213 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); 1227 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1214 1228
1215 if ($tag != 0) { # Floor isn't closable, is it? 1229 if ($tag != 0) { # Floor isn't closable, is it?
1216 $::INVR_HB->add (new DC::UI::Button 1230 $::INVR_HB->add (new DC::UI::Button
1217 text => "Close container", 1231 text => "Close container",
1273} 1287}
1274 1288
1275sub item_update { 1289sub item_update {
1276 my ($self, $item) = @_; 1290 my ($self, $item) = @_;
1277 1291
1278 #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; 1292 #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n";
1279 1293
1280 DC::Item::update_widgets $item; 1294 DC::Item::update_widgets $item;
1281 1295
1282 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1296 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1283 set_opencont ($::CONN, 0, "Floor"); 1297 set_opencont ($::CONN, 0, "Floor");
1284 1298
1285 } elsif ($item->{flags} & F_OPEN) { 1299 } elsif ($item->{flags} & F_OPEN) {
1286 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); 1300 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1352 1366
1353 $self->update_server_info; 1367 $self->update_server_info;
1354 1368
1355 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1369 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1356 $self->send_command ("pickup $::CFG->{pickup}"); 1370 $self->send_command ("pickup $::CFG->{pickup}");
1371
1372 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1373 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1357} 1374}
1358 1375
1359sub lookat { 1376sub lookat {
1360 my ($self, $x, $y) = @_; 1377 my ($self, $x, $y) = @_;
1361 1378

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines