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.206 by elmex, Sun Dec 7 16:20:44 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;
22
23sub MIN_TEXTURE_UNUSED() { 1 }#d#
16 24
17sub new { 25sub new {
18 my ($class, %arg) = @_; 26 my ($class, %arg) = @_;
19 27
20 my $self = $class->SUPER::new (%arg, 28 my $self = $class->SUPER::new (%arg,
64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 72 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
65 for my $ws (values %{delete $self->{widgetset} || {}}) { 73 for my $ws (values %{delete $self->{widgetset} || {}}) {
66 $_->destroy 74 $_->destroy
67 for values %{delete $ws->{w} || {}}; 75 for values %{delete $ws->{w} || {}};
68 } 76 }
77
78 delete $self->{items};
79 $::INV->clear;
80 $::INVR->clear;
81 $::INVR_HB->clear;
82 $::FLOORBOX->clear;
69 }); 83 });
70 84
71 $self->{map_widget}->add_command (@$_) 85 $self->{map_widget}->add_command (@$_)
72 for @cmd_help; 86 for @cmd_help;
73 87
74 { 88 {
75 $self->{dialogue} = my $tex = new_from_file DC::Texture 89 $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}}); 90 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
78 } 91 }
79 92
80 { 93 {
81 $self->{noface} = my $tex = new_from_file DC::Texture 94 $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}}); 95 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
84 } 96 }
97
98# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
99# $self->{expire_w} = EV::timer 1, 1, sub {
100# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
101#
102# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
103# warn DC::SvREFCNT $self->{texture}[$_];
104# $self->{texture}[$_]->unload;
105# warn "expire texture $_\n";#d#
106# }
107#
108# ($self->{expire_count} += $count) < @{ $self->{texture} }
109# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
110# warn "count is $count\n";#d#
111# };
85 112
86 $self->{open_container} = 0; 113 $self->{open_container} = 0;
87 114
88 # per server 115 # per server
89 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 116 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
536 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 563 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
537 ]; 564 ];
538 565
539 my @add = @$sw; 566 my @add = @$sw;
540 567
541 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 568 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
542 569
543 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 570 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
544 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 571 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
545 572
546 my ($x, $y) = (0, 1); 573 my ($x, $y) = (0, 1);
632} 659}
633 660
634sub map_scroll { 661sub map_scroll {
635 my ($self, $dx, $dy) = @_; 662 my ($self, $dx, $dy) = @_;
636 663
637 $self->{map}->scroll ($dx, $dy); 664 $self->{map_widget}->scroll ($dx, $dy);
638} 665}
639 666
640sub feed_map1a { 667sub feed_map1a {
641 my ($self, $data) = @_; 668 my ($self, $data) = @_;
642 669
646 for my $tile (@$missing) { 673 for my $tile (@$missing) {
647 next if $self->{delay}{$tile}; 674 next if $self->{delay}{$tile};
648 675
649 $delay = 1; 676 $delay = 1;
650 677
651 if (my $tex = $::CONN->{texture}[$tile]) { 678 if (my $tex = $self->{texture}[$tile]) {
652 $tex->upload; 679 $tex->upload;
653 } else { 680 } else {
654 $self->{delay}{$tile} = 1; 681 $self->{delay}{$tile} = 1;
655 682
656 # we assume the face is in-flight and will eventually come 683 # we assume the face is in-flight and will eventually arrive
657 push @{$self->{tile_cb}{$tile}}, sub { 684 push @{$self->{tile_cb}{$tile}}, sub {
658 delete $self->{delay}{$tile}; 685 delete $self->{delay}{$tile};
659 $_[0]->upload; 686 $_[0]->upload;
660 }; 687 };
661 } 688 }
662 } 689 }
663 690
664 if ($delay) { 691 if ($delay) {
665 # delay the map drawing a tiny bit in the hope of getting the missing fetched 692 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
666 EV::once undef, 0, 0.03, sub { 693 EV::once undef, 0, 0.03, sub {
667 $self->{map_widget}->update 694 $self->{map_widget}->update
668 if $self->{map_widget}; 695 if $self->{map_widget};
669 }; 696 };
670 } else { 697 } else {
679} 706}
680 707
681sub flush_map { 708sub flush_map {
682 my ($self) = @_; 709 my ($self) = @_;
683 710
684 my $map_info = delete $self->{map_info} 711 return unless $self->{map_info};
685 or return;
686 712
713 for my $map_info (values %{ $self->{map_cache} || {} }) {
687 my ($hash, $x, $y, $w, $h) = @$map_info; 714 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
688 715
689 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 716 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
690 $self->{map_cache_new}{$hash} = \$data; 717
718 if ($data ne $$rdata) {
719 $map_info->[1] = \$data;
720 my $cdata = Compress::LZF::compress $data;
691 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 721 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
722 }
723 }
692} 724}
693 725
694sub map_clear { 726sub map_clear {
695 my ($self) = @_; 727 my ($self) = @_;
696 728
697 $self->flush_map; 729 $self->flush_map;
730 delete $self->{map_info};
698 delete $self->{neigh_map}; 731 delete $self->{neigh_map};
699 732
700 $self->{map}->clear; 733 $self->{map}->clear;
701 delete $self->{map_widget}{magicmap}; 734 delete $self->{map_widget}{magicmap};
702} 735}
723 756
724 $self->bg_fetch; 757 $self->bg_fetch;
725 }; 758 };
726} 759}
727 760
728sub load_map($$$) { 761sub load_map($$$$$$) {
729 my ($self, $hash, $x, $y) = @_; 762 my ($self, $hash, $x, $y, $w, $h) = @_;
730 763
731 my $gen = $self->{map_change_gen}; 764 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
732 765
733 my $cb = sub { 766 my $cb = sub {
734 return unless $gen == $self->{map_change_gen}; 767 $map_info->[1] = \$_[0];
735 768
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} || [] }; 769 my $inprogress = @{ $self->{bg_fetch} || [] };
744 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 770 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
745 $self->bg_fetch unless $inprogress; 771 $self->bg_fetch unless $inprogress;
746 }
747 }; 772 };
748 773
749 if (my $rdata = $self->{map_cache_old}{$hash}) { 774 if (my $map_info = $self->{map_cache_old}{$hash}) {
750 $cb->($$rdata); 775 $cb->(${ $map_info->[1] });
751 } else { 776 } else {
777 my $gen = $self->{map_change_gen};
778
752 DC::DB::get $self->{mapcache} => $hash, $cb; 779 DC::DB::get $self->{mapcache} => $hash, sub {
780 return unless $gen == $self->{map_change_gen};
781 return unless defined $_[0];
782 $cb->(Compress::LZF::decompress $_[0]);
783 };
753 } 784 }
754} 785}
755 786
756# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 787# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
757# (server resource,s latency, bandwidth), so this hack is warranted. 788# (server resources, latency, bandwidth), so this hack is warranted.
758# the right fix is to make real tiled maps with an overview file 789# the right fix is to make real tiled maps with an overview file
759sub send_mapinfo { 790sub send_mapinfo {
760 my ($self, $data, $cb) = @_; 791 my ($self, $data, $cb) = @_;
761 792
762 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 793 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
787} 818}
788 819
789# this method does a "flood fill" into every tile direction 820# this method does a "flood fill" into every tile direction
790# it assumes that tiles are arranged in a rectangular grid, 821# 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. 822# 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 823# failure to comply is harmless and results in display errors
793# at worst. 824# at worst.
794sub flood_fill { 825sub flood_fill {
795 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 826 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
796 827
797 # the server does not allow map paths > 6 828 # the server does not allow map paths > 6
833 return if $mode ne "spatial"; 864 return if $mode ne "spatial";
834 865
835 $x += $self->{map}->ox; 866 $x += $self->{map}->ox;
836 $y += $self->{map}->oy; 867 $y += $self->{map}->oy;
837 868
838 $self->load_map ($hash, $x, $y) 869 $self->load_map ($hash, $x, $y, $w, $h)
839 unless $self->{neigh_map}{$hash}[5]++;#d# 870 unless $self->{neigh_map}{$hash}[5]++;#d#
840 871
841 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 872 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
842 873
843 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 874 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
851 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 882 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
852 883
853 $self->flush_map; 884 $self->flush_map;
854 885
855 ++$self->{map_change_gen}; 886 ++$self->{map_change_gen};
856 $self->{map_cache_old} = delete $self->{map_cache_new}; 887 $self->{map_cache_old} = delete $self->{map_cache};
857 888
858 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 889 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
859 890
860 my $mapmapw = $self->{mapmap}->{w}; 891 my $mapmapw = $self->{mapmap}->{w};
861 my $mapmaph = $self->{mapmap}->{h}; 892 my $mapmaph = $self->{mapmap}->{h};
873 $self->{map_info} = [$hash, $x, $y, $w, $h]; 904 $self->{map_info} = [$hash, $x, $y, $w, $h];
874 905
875 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 906 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
876 $::STATWIDS->{map}->set_text ("Map: " . $map); 907 $::STATWIDS->{map}->set_text ("Map: " . $map);
877 908
878 $self->load_map ($hash, $x, $y); 909 $self->load_map ($hash, $x, $y, $w, $h);
879 $self->flood_fill (0, 0, 0, "", $hash, $flags); 910 $self->flood_fill (0, 0, 0, "", $hash, $flags);
880} 911}
881 912
882sub face_find { 913sub face_find {
883 my ($self, $facenum, $face, $cb) = @_; 914 my ($self, $facenum, $face, $cb) = @_;
1025 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g; 1056 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
1026 1057
1027 # handle some elements 1058 # handle some elements
1028 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1059 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1029 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; 1060 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1061
1062 s/\s+$//;
1030 1063
1031 $_ 1064 $_
1032} 1065}
1033 1066
1034our %NAME_TO_COLOR = ( 1067our %NAME_TO_COLOR = (
1081 1114
1082 ## try to create single paragraphs of multiple lines sent by the server 1115 ## try to create single paragraphs of multiple lines sent by the server
1083 # no longer neecssary with TRT servers 1116 # no longer neecssary with TRT servers
1084 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1117 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1085 1118
1086 for (split /\n/, $text) {
1087 ::message ({ 1119 ::message ({
1088 fg => $fg, 1120 fg => $fg,
1089 markup => $_, 1121 markup => $text,
1090 type => $type, 1122 type => $type,
1091 extra => [@extra], 1123 extra => [@extra],
1092 color_flags => $color, #d# ugly, kill 1124 color_flags => $color, #d# ugly, kill
1093 }); 1125 });
1094 1126
1095 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1127# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1096 # actually, this is an ugly design. _we_ should control the channels, 1128# # actually, this is an ugly design. _we_ should control the channels,
1097 # not some random other widget, as the channels are clearly protocol-specific. 1129# # 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 1130# # then we could also react to flags such as CLEAR without resorting to
1099 # hacks such as color_flags, above. 1131# # hacks such as color_flags, above.
1100 }
1101 1132
1102 $self->{statusbox}->add ($text, 1133 $self->{statusbox}->add ($text,
1103 group => $text, 1134 group => $text,
1104 fg => $fg, 1135 fg => $fg,
1105 timeout => $color >= 2 ? 180 : 10, 1136 timeout => $color >= 2 ? 180 : 10,
1170 $::FLOORBOX->clear; 1201 $::FLOORBOX->clear;
1171 1202
1172 my @add; 1203 my @add;
1173 1204
1174 my $row; 1205 my $row;
1175 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1206 for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
1207 next if $_->{tag} & 0x80000000;
1176 if ($row < 6) { 1208 if ($row < 6) {
1177 local $_->{face_widget}; # hack to force recreation of widget 1209 local $_->{face_widget}; # hack to force recreation of widget
1178 local $_->{desc_widget}; # hack to force recreation of widget 1210 local $_->{desc_widget}; # hack to force recreation of widget
1179 DC::Item::update_widgets $_; 1211 DC::Item::update_widgets $_;
1180 1212
1207sub set_opencont { 1239sub set_opencont {
1208 my ($conn, $tag, $name) = @_; 1240 my ($conn, $tag, $name) = @_;
1209 $conn->{open_container} = $tag; 1241 $conn->{open_container} = $tag;
1210 update_floorbox; 1242 update_floorbox;
1211 1243
1212 $::INVR_HB->clear (); 1244 $::INVR_HB->clear;
1213 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); 1245 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1214 1246
1215 if ($tag != 0) { # Floor isn't closable, is it? 1247 if ($tag != 0) { # Floor isn't closable, is it?
1216 $::INVR_HB->add (new DC::UI::Button 1248 $::INVR_HB->add (new DC::UI::Button
1217 text => "Close container", 1249 text => "Close container",
1273} 1305}
1274 1306
1275sub item_update { 1307sub item_update {
1276 my ($self, $item) = @_; 1308 my ($self, $item) = @_;
1277 1309
1278 #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; 1310 #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n";
1279 1311
1280 DC::Item::update_widgets $item; 1312 DC::Item::update_widgets $item;
1281 1313
1282 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1314 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1283 set_opencont ($::CONN, 0, "Floor"); 1315 set_opencont ($::CONN, 0, "Floor");
1284 1316
1285 } elsif ($item->{flags} & F_OPEN) { 1317 } elsif ($item->{flags} & F_OPEN) {
1286 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); 1318 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1352 1384
1353 $self->update_server_info; 1385 $self->update_server_info;
1354 1386
1355 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1387 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1356 $self->send_command ("pickup $::CFG->{pickup}"); 1388 $self->send_command ("pickup $::CFG->{pickup}");
1389
1390 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1391 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1357} 1392}
1358 1393
1359sub lookat { 1394sub lookat {
1360 my ($self, $x, $y) = @_; 1395 my ($self, $x, $y) = @_;
1361 1396
1525} 1560}
1526 1561
1527sub send { 1562sub send {
1528 my ($self, $msg) = @_; 1563 my ($self, $msg) = @_;
1529 1564
1530 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1565 $self->{textview}->add_paragraph ({
1566 markup =>
1567 "\n<span foreground='#ffff00'><b>"
1568 . (DC::asxml $msg)
1569 . "</b></span>"
1570 });
1531 $self->{textview}->scroll_to_bottom; 1571 $self->{textview}->scroll_to_bottom;
1532 1572
1533 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1573 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1534} 1574}
1535 1575

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines