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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines