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.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,
67 for values %{delete $ws->{w} || {}}; 75 for values %{delete $ws->{w} || {}};
68 } 76 }
69 77
70 delete $self->{items}; 78 delete $self->{items};
71 $::INV->clear; 79 $::INV->clear;
80 $::INVR->clear;
72 $::INVR_HB->clear; 81 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 82 $::FLOORBOX->clear;
74 }); 83 });
75 84
76 $self->{map_widget}->add_command (@$_) 85 $self->{map_widget}->add_command (@$_)
77 for @cmd_help; 86 for @cmd_help;
78 87
79 { 88 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 89 $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}}); 90 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
83 } 91 }
84 92
85 { 93 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 94 $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}}); 95 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
89 } 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# };
90 112
91 $self->{open_container} = 0; 113 $self->{open_container} = 0;
92 114
93 # per server 115 # per server
94 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 116 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
541 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),
542 ]; 564 ];
543 565
544 my @add = @$sw; 566 my @add = @$sw;
545 567
546 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>";
547 569
548 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);
549 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);
550 572
551 my ($x, $y) = (0, 1); 573 my ($x, $y) = (0, 1);
637} 659}
638 660
639sub map_scroll { 661sub map_scroll {
640 my ($self, $dx, $dy) = @_; 662 my ($self, $dx, $dy) = @_;
641 663
642 $self->{map}->scroll ($dx, $dy); 664 $self->{map_widget}->scroll ($dx, $dy);
643} 665}
644 666
645sub feed_map1a { 667sub feed_map1a {
646 my ($self, $data) = @_; 668 my ($self, $data) = @_;
647 669
651 for my $tile (@$missing) { 673 for my $tile (@$missing) {
652 next if $self->{delay}{$tile}; 674 next if $self->{delay}{$tile};
653 675
654 $delay = 1; 676 $delay = 1;
655 677
656 if (my $tex = $::CONN->{texture}[$tile]) { 678 if (my $tex = $self->{texture}[$tile]) {
657 $tex->upload; 679 $tex->upload;
658 } else { 680 } else {
659 $self->{delay}{$tile} = 1; 681 $self->{delay}{$tile} = 1;
660 682
661 # we assume the face is in-flight and will eventually come 683 # we assume the face is in-flight and will eventually arrive
662 push @{$self->{tile_cb}{$tile}}, sub { 684 push @{$self->{tile_cb}{$tile}}, sub {
663 delete $self->{delay}{$tile}; 685 delete $self->{delay}{$tile};
664 $_[0]->upload; 686 $_[0]->upload;
665 }; 687 };
666 } 688 }
667 } 689 }
668 690
669 if ($delay) { 691 if ($delay) {
670 # 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
671 EV::once undef, 0, 0.03, sub { 693 EV::once undef, 0, 0.03, sub {
672 $self->{map_widget}->update 694 $self->{map_widget}->update
673 if $self->{map_widget}; 695 if $self->{map_widget};
674 }; 696 };
675 } else { 697 } else {
684} 706}
685 707
686sub flush_map { 708sub flush_map {
687 my ($self) = @_; 709 my ($self) = @_;
688 710
689 my $map_info = delete $self->{map_info} 711 return unless $self->{map_info};
690 or return;
691 712
713 for my $map_info (values %{ $self->{map_cache} || {} }) {
692 my ($hash, $x, $y, $w, $h) = @$map_info; 714 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
693 715
694 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 716 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
695 $self->{map_cache_new}{$hash} = \$data; 717
718 if ($data ne $$rdata) {
719 $map_info->[1] = \$data;
720 my $cdata = Compress::LZF::compress $data;
696 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 721 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
722 }
723 }
697} 724}
698 725
699sub map_clear { 726sub map_clear {
700 my ($self) = @_; 727 my ($self) = @_;
701 728
702 $self->flush_map; 729 $self->flush_map;
730 delete $self->{map_info};
703 delete $self->{neigh_map}; 731 delete $self->{neigh_map};
704 732
705 $self->{map}->clear; 733 $self->{map}->clear;
706 delete $self->{map_widget}{magicmap}; 734 delete $self->{map_widget}{magicmap};
707} 735}
728 756
729 $self->bg_fetch; 757 $self->bg_fetch;
730 }; 758 };
731} 759}
732 760
733sub load_map($$$) { 761sub load_map($$$$$$) {
734 my ($self, $hash, $x, $y) = @_; 762 my ($self, $hash, $x, $y, $w, $h) = @_;
735 763
736 my $gen = $self->{map_change_gen}; 764 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
737 765
738 my $cb = sub { 766 my $cb = sub {
739 return unless $gen == $self->{map_change_gen}; 767 $map_info->[1] = \$_[0];
740 768
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} || [] }; 769 my $inprogress = @{ $self->{bg_fetch} || [] };
749 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 770 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
750 $self->bg_fetch unless $inprogress; 771 $self->bg_fetch unless $inprogress;
751 }
752 }; 772 };
753 773
754 if (my $rdata = $self->{map_cache_old}{$hash}) { 774 if (my $map_info = $self->{map_cache_old}{$hash}) {
755 $cb->($$rdata); 775 $cb->(${ $map_info->[1] });
756 } else { 776 } else {
777 my $gen = $self->{map_change_gen};
778
757 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 };
758 } 784 }
759} 785}
760 786
761# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 787# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
762# (server resource,s latency, bandwidth), so this hack is warranted. 788# (server resources, latency, bandwidth), so this hack is warranted.
763# 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
764sub send_mapinfo { 790sub send_mapinfo {
765 my ($self, $data, $cb) = @_; 791 my ($self, $data, $cb) = @_;
766 792
767 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)$%) {
792} 818}
793 819
794# this method does a "flood fill" into every tile direction 820# this method does a "flood fill" into every tile direction
795# it assumes that tiles are arranged in a rectangular grid, 821# 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. 822# 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 823# failure to comply is harmless and results in display errors
798# at worst. 824# at worst.
799sub flood_fill { 825sub flood_fill {
800 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 826 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
801 827
802 # the server does not allow map paths > 6 828 # the server does not allow map paths > 6
838 return if $mode ne "spatial"; 864 return if $mode ne "spatial";
839 865
840 $x += $self->{map}->ox; 866 $x += $self->{map}->ox;
841 $y += $self->{map}->oy; 867 $y += $self->{map}->oy;
842 868
843 $self->load_map ($hash, $x, $y) 869 $self->load_map ($hash, $x, $y, $w, $h)
844 unless $self->{neigh_map}{$hash}[5]++;#d# 870 unless $self->{neigh_map}{$hash}[5]++;#d#
845 871
846 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 872 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
847 873
848 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 874 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
856 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 882 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
857 883
858 $self->flush_map; 884 $self->flush_map;
859 885
860 ++$self->{map_change_gen}; 886 ++$self->{map_change_gen};
861 $self->{map_cache_old} = delete $self->{map_cache_new}; 887 $self->{map_cache_old} = delete $self->{map_cache};
862 888
863 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 889 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
864 890
865 my $mapmapw = $self->{mapmap}->{w}; 891 my $mapmapw = $self->{mapmap}->{w};
866 my $mapmaph = $self->{mapmap}->{h}; 892 my $mapmaph = $self->{mapmap}->{h};
878 $self->{map_info} = [$hash, $x, $y, $w, $h]; 904 $self->{map_info} = [$hash, $x, $y, $w, $h];
879 905
880 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 906 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
881 $::STATWIDS->{map}->set_text ("Map: " . $map); 907 $::STATWIDS->{map}->set_text ("Map: " . $map);
882 908
883 $self->load_map ($hash, $x, $y); 909 $self->load_map ($hash, $x, $y, $w, $h);
884 $self->flood_fill (0, 0, 0, "", $hash, $flags); 910 $self->flood_fill (0, 0, 0, "", $hash, $flags);
885} 911}
886 912
887sub face_find { 913sub face_find {
888 my ($self, $facenum, $face, $cb) = @_; 914 my ($self, $facenum, $face, $cb) = @_;
1088 1114
1089 ## 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
1090 # no longer neecssary with TRT servers 1116 # no longer neecssary with TRT servers
1091 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1117 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1092 1118
1093 for (split /\n/, $text) {
1094 ::message ({ 1119 ::message ({
1095 fg => $fg, 1120 fg => $fg,
1096 markup => $_, 1121 markup => $text,
1097 type => $type, 1122 type => $type,
1098 extra => [@extra], 1123 extra => [@extra],
1099 color_flags => $color, #d# ugly, kill 1124 color_flags => $color, #d# ugly, kill
1100 }); 1125 });
1101 1126
1102 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1127# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1103 # actually, this is an ugly design. _we_ should control the channels, 1128# # actually, this is an ugly design. _we_ should control the channels,
1104 # 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.
1105 # 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
1106 # hacks such as color_flags, above. 1131# # hacks such as color_flags, above.
1107 }
1108 1132
1109 $self->{statusbox}->add ($text, 1133 $self->{statusbox}->add ($text,
1110 group => $text, 1134 group => $text,
1111 fg => $fg, 1135 fg => $fg,
1112 timeout => $color >= 2 ? 180 : 10, 1136 timeout => $color >= 2 ? 180 : 10,
1360 1384
1361 $self->update_server_info; 1385 $self->update_server_info;
1362 1386
1363 $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;
1364 $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#
1365} 1392}
1366 1393
1367sub lookat { 1394sub lookat {
1368 my ($self, $x, $y) = @_; 1395 my ($self, $x, $y) = @_;
1369 1396
1533} 1560}
1534 1561
1535sub send { 1562sub send {
1536 my ($self, $msg) = @_; 1563 my ($self, $msg) = @_;
1537 1564
1538 $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 });
1539 $self->{textview}->scroll_to_bottom; 1571 $self->{textview}->scroll_to_bottom;
1540 1572
1541 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1573 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1542} 1574}
1543 1575

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines