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.208 by root, Sun Jan 11 03:19:47 2009 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
23our $TEX_HIDDEN = new_from_resource DC::Texture
24 "hidden.png", minify => 1, mipmap => 1;
25
26sub MIN_TEXTURE_UNUSED() { 1 }#d#
16 27
17sub new { 28sub new {
18 my ($class, %arg) = @_; 29 my ($class, %arg) = @_;
19 30
20 my $self = $class->SUPER::new (%arg, 31 my $self = $class->SUPER::new (%arg,
67 for values %{delete $ws->{w} || {}}; 78 for values %{delete $ws->{w} || {}};
68 } 79 }
69 80
70 delete $self->{items}; 81 delete $self->{items};
71 $::INV->clear; 82 $::INV->clear;
83 $::INVR->clear;
72 $::INVR_HB->clear; 84 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 85 $::FLOORBOX->clear;
74 }); 86 });
75 87
76 $self->{map_widget}->add_command (@$_) 88 $self->{map_widget}->add_command (@$_)
77 for @cmd_help; 89 for @cmd_help;
78 90
79 { 91 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 92 $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}}); 93 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
83 } 94 }
84 95
85 { 96 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 97 $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}}); 98 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
89 } 99 }
100
101 {
102 $self->{hidden} = my $tex = $TEX_HIDDEN;
103 $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}});
104 }
105
106# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
107# $self->{expire_w} = EV::timer 1, 1, sub {
108# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
109#
110# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
111# warn DC::SvREFCNT $self->{texture}[$_];
112# $self->{texture}[$_]->unload;
113# warn "expire texture $_\n";#d#
114# }
115#
116# ($self->{expire_count} += $count) < @{ $self->{texture} }
117# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
118# warn "count is $count\n";#d#
119# };
90 120
91 $self->{open_container} = 0; 121 $self->{open_container} = 0;
92 122
93 # per server 123 # per server
94 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 124 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
255 my %wkw = ( 285 my %wkw = (
256 root => $DC::UI::ROOT, 286 root => $DC::UI::ROOT,
257 tooltip => $DC::UI::TOOLTIP, 287 tooltip => $DC::UI::TOOLTIP,
258 288
259 mapwidget => $::MAPWIDGET, 289 mapwidget => $::MAPWIDGET,
290 menubar => $::MENUBAR,
291 menupopup => $::MENUPOPUP,
260 buttonbar => $::BUTTONBAR, 292 buttonbar => $::BUTTONBAR,
261 metaserver => $::METASERVER, 293 metaserver => $::METASERVER,
262 buttonbar => $::BUTTONBAR, 294 buttonbar => $::BUTTONBAR,
263 login_button => $::LOGIN_BUTTON, 295 login_button => $::LOGIN_BUTTON,
264 quit_dialog => $::QUIT_DIALOG, 296 quit_dialog => $::QUIT_DIALOG,
281 313
282 floorbox => $::FLOORBOX, 314 floorbox => $::FLOORBOX,
283 help_window => $::HELP_WINDOW, 315 help_window => $::HELP_WINDOW,
284 message_window => $::MESSAGE_WINDOW, 316 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST, 317 message_dist => $::MESSAGE_DIST,
286 statusbox => $::SDTATUSBOX, 318 statusbox => $::STATUSBOX,
287 319
288 inv => $::INV, 320 inv => $::INV,
289 invr => $::INVR, 321 invr => $::INVR,
290 invr_hb => $::INVR_HB, 322 invr_hb => $::INVR_HB,
291 ); 323 );
541 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 573 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
542 ]; 574 ];
543 575
544 my @add = @$sw; 576 my @add = @$sw;
545 577
546 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 578 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
547 579
548 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 580 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); 581 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
550 582
551 my ($x, $y) = (0, 1); 583 my ($x, $y) = (0, 1);
637} 669}
638 670
639sub map_scroll { 671sub map_scroll {
640 my ($self, $dx, $dy) = @_; 672 my ($self, $dx, $dy) = @_;
641 673
642 $self->{map}->scroll ($dx, $dy); 674 $self->{map_widget}->scroll ($dx, $dy);
643} 675}
644 676
645sub feed_map1a { 677sub feed_map1a {
646 my ($self, $data) = @_; 678 my ($self, $data) = @_;
647 679
651 for my $tile (@$missing) { 683 for my $tile (@$missing) {
652 next if $self->{delay}{$tile}; 684 next if $self->{delay}{$tile};
653 685
654 $delay = 1; 686 $delay = 1;
655 687
656 if (my $tex = $::CONN->{texture}[$tile]) { 688 if (my $tex = $self->{texture}[$tile]) {
657 $tex->upload; 689 $tex->upload;
658 } else { 690 } else {
659 $self->{delay}{$tile} = 1; 691 $self->{delay}{$tile} = 1;
660 692
661 # we assume the face is in-flight and will eventually come 693 # we assume the face is in-flight and will eventually arrive
662 push @{$self->{tile_cb}{$tile}}, sub { 694 push @{$self->{tile_cb}{$tile}}, sub {
663 delete $self->{delay}{$tile}; 695 delete $self->{delay}{$tile};
664 $_[0]->upload; 696 $_[0]->upload;
665 }; 697 };
666 } 698 }
667 } 699 }
668 700
669 if ($delay) { 701 if ($delay) {
670 # delay the map drawing a tiny bit in the hope of getting the missing fetched 702 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
671 EV::once undef, 0, 0.03, sub { 703 EV::once undef, 0, 0.03, sub {
672 $self->{map_widget}->update 704 $self->{map_widget}->update
673 if $self->{map_widget}; 705 if $self->{map_widget};
674 }; 706 };
675 } else { 707 } else {
684} 716}
685 717
686sub flush_map { 718sub flush_map {
687 my ($self) = @_; 719 my ($self) = @_;
688 720
689 my $map_info = delete $self->{map_info} 721 return unless $self->{map_info};
690 or return;
691 722
723 for my $map_info (values %{ $self->{map_cache} || {} }) {
692 my ($hash, $x, $y, $w, $h) = @$map_info; 724 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
693 725
694 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 726 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
695 $self->{map_cache_new}{$hash} = \$data; 727
728 if ($data ne $$rdata) {
729 $map_info->[1] = \$data;
730 my $cdata = Compress::LZF::compress $data;
696 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 731 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
732 }
733 }
697} 734}
698 735
699sub map_clear { 736sub map_clear {
700 my ($self) = @_; 737 my ($self) = @_;
701 738
702 $self->flush_map; 739 $self->flush_map;
740 delete $self->{map_info};
703 delete $self->{neigh_map}; 741 delete $self->{neigh_map};
704 742
705 $self->{map}->clear; 743 $self->{map}->clear;
706 delete $self->{map_widget}{magicmap}; 744 delete $self->{map_widget}{magicmap};
707} 745}
728 766
729 $self->bg_fetch; 767 $self->bg_fetch;
730 }; 768 };
731} 769}
732 770
733sub load_map($$$) { 771sub load_map($$$$$$) {
734 my ($self, $hash, $x, $y) = @_; 772 my ($self, $hash, $x, $y, $w, $h) = @_;
735 773
736 my $gen = $self->{map_change_gen}; 774 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
737 775
738 my $cb = sub { 776 my $cb = sub {
739 return unless $gen == $self->{map_change_gen}; 777 $map_info->[1] = \$_[0];
740 778
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} || [] }; 779 my $inprogress = @{ $self->{bg_fetch} || [] };
749 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 780 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
750 $self->bg_fetch unless $inprogress; 781 $self->bg_fetch unless $inprogress;
751 }
752 }; 782 };
753 783
754 if (my $rdata = $self->{map_cache_old}{$hash}) { 784 if (my $map_info = $self->{map_cache_old}{$hash}) {
755 $cb->($$rdata); 785 $cb->(${ $map_info->[1] });
756 } else { 786 } else {
787 my $gen = $self->{map_change_gen};
788
757 DC::DB::get $self->{mapcache} => $hash, $cb; 789 DC::DB::get $self->{mapcache} => $hash, sub {
790 return unless $gen == $self->{map_change_gen};
791 return unless defined $_[0];
792 $cb->(Compress::LZF::decompress $_[0]);
793 };
758 } 794 }
759} 795}
760 796
761# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 797# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
762# (server resource,s latency, bandwidth), so this hack is warranted. 798# (server resources, latency, bandwidth), so this hack is warranted.
763# the right fix is to make real tiled maps with an overview file 799# the right fix is to make real tiled maps with an overview file
764sub send_mapinfo { 800sub send_mapinfo {
765 my ($self, $data, $cb) = @_; 801 my ($self, $data, $cb) = @_;
766 802
767 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 803 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
792} 828}
793 829
794# this method does a "flood fill" into every tile direction 830# this method does a "flood fill" into every tile direction
795# it assumes that tiles are arranged in a rectangular grid, 831# 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. 832# 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 833# failure to comply is harmless and results in display errors
798# at worst. 834# at worst.
799sub flood_fill { 835sub flood_fill {
800 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 836 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
801 837
802 # the server does not allow map paths > 6 838 # the server does not allow map paths > 6
838 return if $mode ne "spatial"; 874 return if $mode ne "spatial";
839 875
840 $x += $self->{map}->ox; 876 $x += $self->{map}->ox;
841 $y += $self->{map}->oy; 877 $y += $self->{map}->oy;
842 878
843 $self->load_map ($hash, $x, $y) 879 $self->load_map ($hash, $x, $y, $w, $h)
844 unless $self->{neigh_map}{$hash}[5]++;#d# 880 unless $self->{neigh_map}{$hash}[5]++;#d#
845 881
846 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 882 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
847 883
848 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 884 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
856 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 892 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
857 893
858 $self->flush_map; 894 $self->flush_map;
859 895
860 ++$self->{map_change_gen}; 896 ++$self->{map_change_gen};
861 $self->{map_cache_old} = delete $self->{map_cache_new}; 897 $self->{map_cache_old} = delete $self->{map_cache};
862 898
863 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 899 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
864 900
865 my $mapmapw = $self->{mapmap}->{w}; 901 my $mapmapw = $self->{mapmap}->{w};
866 my $mapmaph = $self->{mapmap}->{h}; 902 my $mapmaph = $self->{mapmap}->{h};
878 $self->{map_info} = [$hash, $x, $y, $w, $h]; 914 $self->{map_info} = [$hash, $x, $y, $w, $h];
879 915
880 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 916 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
881 $::STATWIDS->{map}->set_text ("Map: " . $map); 917 $::STATWIDS->{map}->set_text ("Map: " . $map);
882 918
883 $self->load_map ($hash, $x, $y); 919 $self->load_map ($hash, $x, $y, $w, $h);
884 $self->flood_fill (0, 0, 0, "", $hash, $flags); 920 $self->flood_fill (0, 0, 0, "", $hash, $flags);
885} 921}
886 922
887sub face_find { 923sub face_find {
888 my ($self, $facenum, $face, $cb) = @_; 924 my ($self, $facenum, $face, $cb) = @_;
1088 1124
1089 ## try to create single paragraphs of multiple lines sent by the server 1125 ## try to create single paragraphs of multiple lines sent by the server
1090 # no longer neecssary with TRT servers 1126 # no longer neecssary with TRT servers
1091 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1127 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1092 1128
1093 for (split /\n/, $text) {
1094 ::message ({ 1129 ::message ({
1095 fg => $fg, 1130 fg => $fg,
1096 markup => $_, 1131 markup => $text,
1097 type => $type, 1132 type => $type,
1098 extra => [@extra], 1133 extra => [@extra],
1099 color_flags => $color, #d# ugly, kill 1134 color_flags => $color, #d# ugly, kill
1100 }); 1135 });
1101 1136
1102 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1137# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1103 # actually, this is an ugly design. _we_ should control the channels, 1138# # actually, this is an ugly design. _we_ should control the channels,
1104 # not some random other widget, as the channels are clearly protocol-specific. 1139# # 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 1140# # then we could also react to flags such as CLEAR without resorting to
1106 # hacks such as color_flags, above. 1141# # hacks such as color_flags, above.
1107 }
1108 1142
1109 $self->{statusbox}->add ($text, 1143 $self->{statusbox}->add ($text,
1110 group => $text, 1144 group => $text,
1111 fg => $fg, 1145 fg => $fg,
1112 timeout => $color >= 2 ? 180 : 10, 1146 timeout => $color >= 2 ? 180 : 10,
1360 1394
1361 $self->update_server_info; 1395 $self->update_server_info;
1362 1396
1363 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1397 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1364 $self->send_command ("pickup $::CFG->{pickup}"); 1398 $self->send_command ("pickup $::CFG->{pickup}");
1399
1400 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1401 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1365} 1402}
1366 1403
1367sub lookat { 1404sub lookat {
1368 my ($self, $x, $y) = @_; 1405 my ($self, $x, $y) = @_;
1369 1406
1533} 1570}
1534 1571
1535sub send { 1572sub send {
1536 my ($self, $msg) = @_; 1573 my ($self, $msg) = @_;
1537 1574
1538 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1575 $self->{textview}->add_paragraph ({
1576 markup =>
1577 "\n<span foreground='#ffff00'><b>"
1578 . (DC::asxml $msg)
1579 . "</b></span>"
1580 });
1539 $self->{textview}->scroll_to_bottom; 1581 $self->{textview}->scroll_to_bottom;
1540 1582
1541 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1583 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1542} 1584}
1543 1585

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines