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.196 by root, Thu May 8 21:30:23 2008 UTC vs.
Revision 1.204 by elmex, Fri Oct 17 11:21:55 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,
67 for values %{delete $ws->{w} || {}}; 73 for values %{delete $ws->{w} || {}};
68 } 74 }
69 75
70 delete $self->{items}; 76 delete $self->{items};
71 $::INV->clear; 77 $::INV->clear;
78 $::INVR->clear;
72 $::INVR_HB->clear; 79 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 80 $::FLOORBOX->clear;
74 }); 81 });
75 82
76 $self->{map_widget}->add_command (@$_) 83 $self->{map_widget}->add_command (@$_)
77 for @cmd_help; 84 for @cmd_help;
78 85
79 { 86 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 87 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
81 DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
82 $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}});
83 } 89 }
84 90
85 { 91 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 92 $self->{noface} = my $tex = $TEX_NOFACE;
87 DC::find_rcfile "noface.png", minify => 1, mipmap => 1;
88 $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}});
89 } 94 }
90 95
91 $self->{open_container} = 0; 96 $self->{open_container} = 0;
92 97
637} 642}
638 643
639sub map_scroll { 644sub map_scroll {
640 my ($self, $dx, $dy) = @_; 645 my ($self, $dx, $dy) = @_;
641 646
642 $self->{map}->scroll ($dx, $dy); 647 $self->{map_widget}->scroll ($dx, $dy);
643} 648}
644 649
645sub feed_map1a { 650sub feed_map1a {
646 my ($self, $data) = @_; 651 my ($self, $data) = @_;
647 652
684} 689}
685 690
686sub flush_map { 691sub flush_map {
687 my ($self) = @_; 692 my ($self) = @_;
688 693
689 my $map_info = delete $self->{map_info} 694 return unless $self->{map_info};
690 or return;
691 695
696 for my $map_info (values %{ $self->{map_cache} || {} }) {
692 my ($hash, $x, $y, $w, $h) = @$map_info; 697 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
693 698
694 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 699 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
695 $self->{map_cache_new}{$hash} = \$data; 700
701 if ($data ne $$rdata) {
702 $map_info->[1] = \$data;
703 my $cdata = Compress::LZF::compress $data;
696 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 704 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
705 }
706 }
697} 707}
698 708
699sub map_clear { 709sub map_clear {
700 my ($self) = @_; 710 my ($self) = @_;
701 711
702 $self->flush_map; 712 $self->flush_map;
713 delete $self->{map_info};
703 delete $self->{neigh_map}; 714 delete $self->{neigh_map};
704 715
705 $self->{map}->clear; 716 $self->{map}->clear;
706 delete $self->{map_widget}{magicmap}; 717 delete $self->{map_widget}{magicmap};
707} 718}
728 739
729 $self->bg_fetch; 740 $self->bg_fetch;
730 }; 741 };
731} 742}
732 743
733sub load_map($$$) { 744sub load_map($$$$$$) {
734 my ($self, $hash, $x, $y) = @_; 745 my ($self, $hash, $x, $y, $w, $h) = @_;
735 746
736 my $gen = $self->{map_change_gen}; 747 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
737 748
738 my $cb = sub { 749 my $cb = sub {
739 return unless $gen == $self->{map_change_gen}; 750 $map_info->[1] = \$_[0];
740 751
741 my ($data) = @_;
742
743 if (defined $data) {
744 $self->{map_cache_new}{$hash} = \$data;
745
746 my $data = Compress::LZF::decompress $data;
747
748 my $inprogress = @{ $self->{bg_fetch} || [] }; 752 my $inprogress = @{ $self->{bg_fetch} || [] };
749 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 753 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
750 $self->bg_fetch unless $inprogress; 754 $self->bg_fetch unless $inprogress;
751 }
752 }; 755 };
753 756
754 if (my $rdata = $self->{map_cache_old}{$hash}) { 757 if (my $map_info = $self->{map_cache_old}{$hash}) {
755 $cb->($$rdata); 758 $cb->(${ $map_info->[1] });
756 } else { 759 } else {
760 my $gen = $self->{map_change_gen};
761
757 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 };
758 } 767 }
759} 768}
760 769
761# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 770# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
762# (server resource,s latency, bandwidth), so this hack is warranted. 771# (server resources, latency, bandwidth), so this hack is warranted.
763# 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
764sub send_mapinfo { 773sub send_mapinfo {
765 my ($self, $data, $cb) = @_; 774 my ($self, $data, $cb) = @_;
766 775
767 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)$%) {
792} 801}
793 802
794# this method does a "flood fill" into every tile direction 803# this method does a "flood fill" into every tile direction
795# it assumes that tiles are arranged in a rectangular grid, 804# it assumes that tiles are arranged in a rectangular grid,
796# 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.
797# failure to comply are harmless and result in display errors 806# failure to comply is harmless and results in display errors
798# at worst. 807# at worst.
799sub flood_fill { 808sub flood_fill {
800 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 809 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
801 810
802 # the server does not allow map paths > 6 811 # the server does not allow map paths > 6
838 return if $mode ne "spatial"; 847 return if $mode ne "spatial";
839 848
840 $x += $self->{map}->ox; 849 $x += $self->{map}->ox;
841 $y += $self->{map}->oy; 850 $y += $self->{map}->oy;
842 851
843 $self->load_map ($hash, $x, $y) 852 $self->load_map ($hash, $x, $y, $w, $h)
844 unless $self->{neigh_map}{$hash}[5]++;#d# 853 unless $self->{neigh_map}{$hash}[5]++;#d#
845 854
846 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 855 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
847 856
848 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 857 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
856 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 865 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
857 866
858 $self->flush_map; 867 $self->flush_map;
859 868
860 ++$self->{map_change_gen}; 869 ++$self->{map_change_gen};
861 $self->{map_cache_old} = delete $self->{map_cache_new}; 870 $self->{map_cache_old} = delete $self->{map_cache};
862 871
863 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 872 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
864 873
865 my $mapmapw = $self->{mapmap}->{w}; 874 my $mapmapw = $self->{mapmap}->{w};
866 my $mapmaph = $self->{mapmap}->{h}; 875 my $mapmaph = $self->{mapmap}->{h};
878 $self->{map_info} = [$hash, $x, $y, $w, $h]; 887 $self->{map_info} = [$hash, $x, $y, $w, $h];
879 888
880 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 889 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
881 $::STATWIDS->{map}->set_text ("Map: " . $map); 890 $::STATWIDS->{map}->set_text ("Map: " . $map);
882 891
883 $self->load_map ($hash, $x, $y); 892 $self->load_map ($hash, $x, $y, $w, $h);
884 $self->flood_fill (0, 0, 0, "", $hash, $flags); 893 $self->flood_fill (0, 0, 0, "", $hash, $flags);
885} 894}
886 895
887sub face_find { 896sub face_find {
888 my ($self, $facenum, $face, $cb) = @_; 897 my ($self, $facenum, $face, $cb) = @_;
1088 1097
1089 ## 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
1090 # no longer neecssary with TRT servers 1099 # no longer neecssary with TRT servers
1091 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1100 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1092 1101
1093 for (split /\n/, $text) {
1094 ::message ({ 1102 ::message ({
1095 fg => $fg, 1103 fg => $fg,
1096 markup => $_, 1104 markup => $text,
1097 type => $type, 1105 type => $type,
1098 extra => [@extra], 1106 extra => [@extra],
1099 color_flags => $color, #d# ugly, kill 1107 color_flags => $color, #d# ugly, kill
1100 }); 1108 });
1101 1109
1102 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1110# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1103 # actually, this is an ugly design. _we_ should control the channels, 1111# # actually, this is an ugly design. _we_ should control the channels,
1104 # 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.
1105 # 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
1106 # hacks such as color_flags, above. 1114# # hacks such as color_flags, above.
1107 }
1108 1115
1109 $self->{statusbox}->add ($text, 1116 $self->{statusbox}->add ($text,
1110 group => $text, 1117 group => $text,
1111 fg => $fg, 1118 fg => $fg,
1112 timeout => $color >= 2 ? 180 : 10, 1119 timeout => $color >= 2 ? 180 : 10,
1360 1367
1361 $self->update_server_info; 1368 $self->update_server_info;
1362 1369
1363 $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;
1364 $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#
1365} 1375}
1366 1376
1367sub lookat { 1377sub lookat {
1368 my ($self, $x, $y) = @_; 1378 my ($self, $x, $y) = @_;
1369 1379
1533} 1543}
1534 1544
1535sub send { 1545sub send {
1536 my ($self, $msg) = @_; 1546 my ($self, $msg) = @_;
1537 1547
1538 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1548 $self->{textview}->add_paragraph ({
1549 markup =>
1550 "\n<span foreground='#ffff00'><b>"
1551 . (DC::asxml $msg)
1552 . "</b></span>"
1553 });
1539 $self->{textview}->scroll_to_bottom; 1554 $self->{textview}->scroll_to_bottom;
1540 1555
1541 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1556 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1542} 1557}
1543 1558

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines