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.209 by root, Sun Jan 11 22:11:23 2009 UTC

1package DC::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5
6use Guard ();
5 7
6use Deliantra::Protocol::Constants; 8use Deliantra::Protocol::Constants;
7 9
8use DC; 10use DC;
9use DC::DB; 11use DC::DB;
11use DC::Pod; 13use DC::Pod;
12use DC::Macro; 14use DC::Macro;
13use DC::Item; 15use DC::Item;
14 16
15use base 'Deliantra::Protocol::Base'; 17use base 'Deliantra::Protocol::Base';
18
19our $TEX_DIALOGUE = new_from_resource DC::Texture
20 "dialogue.png", minify => 1, mipmap => 1;
21
22our $TEX_NOFACE = new_from_resource DC::Texture
23 "noface.png", minify => 1, mipmap => 1;
24
25our $TEX_HIDDEN = new_from_resource DC::Texture
26 "hidden.png", minify => 1, mipmap => 1;
27
28sub MIN_TEXTURE_UNUSED() { 1 }#d#
16 29
17sub new { 30sub new {
18 my ($class, %arg) = @_; 31 my ($class, %arg) = @_;
19 32
20 my $self = $class->SUPER::new (%arg, 33 my $self = $class->SUPER::new (%arg,
67 for values %{delete $ws->{w} || {}}; 80 for values %{delete $ws->{w} || {}};
68 } 81 }
69 82
70 delete $self->{items}; 83 delete $self->{items};
71 $::INV->clear; 84 $::INV->clear;
85 $::INVR->clear;
72 $::INVR_HB->clear; 86 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 87 $::FLOORBOX->clear;
74 }); 88 });
75 89
76 $self->{map_widget}->add_command (@$_) 90 $self->{map_widget}->add_command (@$_)
77 for @cmd_help; 91 for @cmd_help;
78 92
79 { 93 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 94 $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}}); 95 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
83 } 96 }
84 97
85 { 98 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 99 $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}}); 100 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
89 } 101 }
102
103 {
104 $self->{hidden} = my $tex = $TEX_HIDDEN;
105 $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}});
106 }
107
108# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
109# $self->{expire_w} = EV::timer 1, 1, sub {
110# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
111#
112# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
113# warn DC::SvREFCNT $self->{texture}[$_];
114# $self->{texture}[$_]->unload;
115# warn "expire texture $_\n";#d#
116# }
117#
118# ($self->{expire_count} += $count) < @{ $self->{texture} }
119# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
120# warn "count is $count\n";#d#
121# };
90 122
91 $self->{open_container} = 0; 123 $self->{open_container} = 0;
92 124
93 # per server 125 # per server
94 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 126 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
255 my %wkw = ( 287 my %wkw = (
256 root => $DC::UI::ROOT, 288 root => $DC::UI::ROOT,
257 tooltip => $DC::UI::TOOLTIP, 289 tooltip => $DC::UI::TOOLTIP,
258 290
259 mapwidget => $::MAPWIDGET, 291 mapwidget => $::MAPWIDGET,
292 menubar => $::MENUBAR,
293 menupopup => $::MENUPOPUP,
294 pickup_enable => $::PICKUP_ENABLE,
260 buttonbar => $::BUTTONBAR, 295 buttonbar => $::BUTTONBAR,
261 metaserver => $::METASERVER, 296 metaserver => $::METASERVER,
262 buttonbar => $::BUTTONBAR, 297 buttonbar => $::BUTTONBAR,
263 login_button => $::LOGIN_BUTTON, 298 login_button => $::LOGIN_BUTTON,
264 quit_dialog => $::QUIT_DIALOG, 299 quit_dialog => $::QUIT_DIALOG,
281 316
282 floorbox => $::FLOORBOX, 317 floorbox => $::FLOORBOX,
283 help_window => $::HELP_WINDOW, 318 help_window => $::HELP_WINDOW,
284 message_window => $::MESSAGE_WINDOW, 319 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST, 320 message_dist => $::MESSAGE_DIST,
286 statusbox => $::SDTATUSBOX, 321 statusbox => $::STATUSBOX,
287 322
288 inv => $::INV, 323 inv => $::INV,
289 invr => $::INVR, 324 invr => $::INVR,
290 invr_hb => $::INVR_HB, 325 invr_hb => $::INVR_HB,
291 ); 326 );
488 523
489 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 524 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
490 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 525 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
491 $::GAUGES->{food} ->set_value ($fo, $fo_m); 526 $::GAUGES->{food} ->set_value ($fo, $fo_m);
492 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 527 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
493 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 528 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
494 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 529 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
495 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 530 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
496 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 531 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
497 my $title = $stats->{+CS_STAT_TITLE}; 532 my $title = $stats->{+CS_STAT_TITLE};
498 $title =~ s/^Player: //; 533 $title =~ s/^Player: //;
499 $::STATWIDS->{title} ->set_text ("Title: " . $title); 534 $::STATWIDS->{title} ->set_text ("Title: " . $title);
500 535
541 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 576 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
542 ]; 577 ];
543 578
544 my @add = @$sw; 579 my @add = @$sw;
545 580
546 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 581 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
547 582
548 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 583 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); 584 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
550 585
551 my ($x, $y) = (0, 1); 586 my ($x, $y) = (0, 1);
613 my $sw = $self->{skillwid}{$idx}; 648 my $sw = $self->{skillwid}{$idx};
614 $sw->[0]->set_text (::formsep ($val->[1])); 649 $sw->[0]->set_text (::formsep ($val->[1]));
615 $sw->[1]->set_text ($val->[0] * 1); 650 $sw->[1]->set_text ($val->[0] * 1);
616 $sw->[2]->set_value (@$val); 651 $sw->[2]->set_value (@$val);
617 652
618 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 653 $::GAUGES->{skillexp}->set_label ("$name %d%%");
619 $::GAUGES->{sklprg}->set_value (@$val); 654 $::GAUGES->{skillexp}->set_value (@$val);
620 } 655 }
621} 656}
622 657
623sub user_send { 658sub user_send {
624 my ($self, $command) = @_; 659 my ($self, $command) = @_;
637} 672}
638 673
639sub map_scroll { 674sub map_scroll {
640 my ($self, $dx, $dy) = @_; 675 my ($self, $dx, $dy) = @_;
641 676
642 $self->{map}->scroll ($dx, $dy); 677 $self->{map_widget}->scroll ($dx, $dy);
643} 678}
644 679
645sub feed_map1a { 680sub feed_map1a {
646 my ($self, $data) = @_; 681 my ($self, $data) = @_;
647 682
651 for my $tile (@$missing) { 686 for my $tile (@$missing) {
652 next if $self->{delay}{$tile}; 687 next if $self->{delay}{$tile};
653 688
654 $delay = 1; 689 $delay = 1;
655 690
656 if (my $tex = $::CONN->{texture}[$tile]) { 691 if (my $tex = $self->{texture}[$tile]) {
657 $tex->upload; 692 $tex->upload;
658 } else { 693 } else {
659 $self->{delay}{$tile} = 1; 694 $self->{delay}{$tile} = 1;
660 695
661 # we assume the face is in-flight and will eventually come 696 # we assume the face is in-flight and will eventually arrive
662 push @{$self->{tile_cb}{$tile}}, sub { 697 push @{$self->{tile_cb}{$tile}}, sub {
663 delete $self->{delay}{$tile}; 698 delete $self->{delay}{$tile};
664 $_[0]->upload; 699 $_[0]->upload;
665 }; 700 };
666 } 701 }
667 } 702 }
668 703
669 if ($delay) { 704 if ($delay) {
670 # delay the map drawing a tiny bit in the hope of getting the missing fetched 705 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
671 EV::once undef, 0, 0.03, sub { 706 EV::once undef, 0, 0.03, sub {
672 $self->{map_widget}->update 707 $self->{map_widget}->update
673 if $self->{map_widget}; 708 if $self->{map_widget};
674 }; 709 };
675 } else { 710 } else {
684} 719}
685 720
686sub flush_map { 721sub flush_map {
687 my ($self) = @_; 722 my ($self) = @_;
688 723
689 my $map_info = delete $self->{map_info} 724 return unless $self->{map_info};
690 or return;
691 725
726 for my $map_info (values %{ $self->{map_cache} || {} }) {
692 my ($hash, $x, $y, $w, $h) = @$map_info; 727 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
693 728
694 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 729 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
695 $self->{map_cache_new}{$hash} = \$data; 730
731 if ($data ne $$rdata) {
732 $map_info->[1] = \$data;
733 my $cdata = Compress::LZF::compress $data;
696 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 734 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
735 }
736 }
697} 737}
698 738
699sub map_clear { 739sub map_clear {
700 my ($self) = @_; 740 my ($self) = @_;
701 741
702 $self->flush_map; 742 $self->flush_map;
743 delete $self->{map_info};
703 delete $self->{neigh_map}; 744 delete $self->{neigh_map};
704 745
705 $self->{map}->clear; 746 $self->{map}->clear;
706 delete $self->{map_widget}{magicmap}; 747 delete $self->{map_widget}{magicmap};
707} 748}
728 769
729 $self->bg_fetch; 770 $self->bg_fetch;
730 }; 771 };
731} 772}
732 773
733sub load_map($$$) { 774sub load_map($$$$$$) {
734 my ($self, $hash, $x, $y) = @_; 775 my ($self, $hash, $x, $y, $w, $h) = @_;
735 776
736 my $gen = $self->{map_change_gen}; 777 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
737 778
738 my $cb = sub { 779 my $cb = sub {
739 return unless $gen == $self->{map_change_gen}; 780 $map_info->[1] = \$_[0];
740 781
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} || [] }; 782 my $inprogress = @{ $self->{bg_fetch} || [] };
749 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 783 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
750 $self->bg_fetch unless $inprogress; 784 $self->bg_fetch unless $inprogress;
751 }
752 }; 785 };
753 786
754 if (my $rdata = $self->{map_cache_old}{$hash}) { 787 if (my $map_info = $self->{map_cache_old}{$hash}) {
755 $cb->($$rdata); 788 $cb->(${ $map_info->[1] });
756 } else { 789 } else {
790 my $gen = $self->{map_change_gen};
791
757 DC::DB::get $self->{mapcache} => $hash, $cb; 792 DC::DB::get $self->{mapcache} => $hash, sub {
793 return unless $gen == $self->{map_change_gen};
794 return unless defined $_[0];
795 $cb->(Compress::LZF::decompress $_[0]);
796 };
758 } 797 }
759} 798}
760 799
761# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 800# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
762# (server resource,s latency, bandwidth), so this hack is warranted. 801# (server resources, latency, bandwidth), so this hack is warranted.
763# the right fix is to make real tiled maps with an overview file 802# the right fix is to make real tiled maps with an overview file
764sub send_mapinfo { 803sub send_mapinfo {
765 my ($self, $data, $cb) = @_; 804 my ($self, $data, $cb) = @_;
766 805
767 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 806 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
792} 831}
793 832
794# this method does a "flood fill" into every tile direction 833# this method does a "flood fill" into every tile direction
795# it assumes that tiles are arranged in a rectangular grid, 834# 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. 835# 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 836# failure to comply is harmless and results in display errors
798# at worst. 837# at worst.
799sub flood_fill { 838sub flood_fill {
800 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 839 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
801 840
802 # the server does not allow map paths > 6 841 # the server does not allow map paths > 6
838 return if $mode ne "spatial"; 877 return if $mode ne "spatial";
839 878
840 $x += $self->{map}->ox; 879 $x += $self->{map}->ox;
841 $y += $self->{map}->oy; 880 $y += $self->{map}->oy;
842 881
843 $self->load_map ($hash, $x, $y) 882 $self->load_map ($hash, $x, $y, $w, $h)
844 unless $self->{neigh_map}{$hash}[5]++;#d# 883 unless $self->{neigh_map}{$hash}[5]++;#d#
845 884
846 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 885 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
847 886
848 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 887 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
856 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 895 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
857 896
858 $self->flush_map; 897 $self->flush_map;
859 898
860 ++$self->{map_change_gen}; 899 ++$self->{map_change_gen};
861 $self->{map_cache_old} = delete $self->{map_cache_new}; 900 $self->{map_cache_old} = delete $self->{map_cache};
862 901
863 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 902 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
864 903
865 my $mapmapw = $self->{mapmap}->{w}; 904 my $mapmapw = $self->{mapmap}->{w};
866 my $mapmaph = $self->{mapmap}->{h}; 905 my $mapmaph = $self->{mapmap}->{h};
878 $self->{map_info} = [$hash, $x, $y, $w, $h]; 917 $self->{map_info} = [$hash, $x, $y, $w, $h];
879 918
880 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 919 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
881 $::STATWIDS->{map}->set_text ("Map: " . $map); 920 $::STATWIDS->{map}->set_text ("Map: " . $map);
882 921
883 $self->load_map ($hash, $x, $y); 922 $self->load_map ($hash, $x, $y, $w, $h);
884 $self->flood_fill (0, 0, 0, "", $hash, $flags); 923 $self->flood_fill (0, 0, 0, "", $hash, $flags);
885} 924}
886 925
887sub face_find { 926sub face_find {
888 my ($self, $facenum, $face, $cb) = @_; 927 my ($self, $facenum, $face, $cb) = @_;
974 my ($self, $num, $cb) = @_; 1013 my ($self, $num, $cb) = @_;
975 1014
976 push @{$self->{face_cb}{$num}}, $cb; 1015 push @{$self->{face_cb}{$num}}, $cb;
977 1016
978 defined wantarray 1017 defined wantarray
979 ? DC::guard { 1018 ? Guard::guard {
980 @{$self->{face_cb}{$num}} 1019 @{$self->{face_cb}{$num}}
981 = grep $_ != $cb, 1020 = grep $_ != $cb,
982 @{$self->{face_cb}{$num}}; 1021 @{$self->{face_cb}{$num}};
983 } 1022 }
984 : () 1023 : ()
1088 1127
1089 ## try to create single paragraphs of multiple lines sent by the server 1128 ## try to create single paragraphs of multiple lines sent by the server
1090 # no longer neecssary with TRT servers 1129 # no longer neecssary with TRT servers
1091 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1130 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1092 1131
1093 for (split /\n/, $text) {
1094 ::message ({ 1132 ::message ({
1095 fg => $fg, 1133 fg => $fg,
1096 markup => $_, 1134 markup => $text,
1097 type => $type, 1135 type => $type,
1098 extra => [@extra], 1136 extra => [@extra],
1099 color_flags => $color, #d# ugly, kill 1137 color_flags => $color, #d# ugly, kill
1100 }); 1138 });
1101 1139
1102 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1140# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1103 # actually, this is an ugly design. _we_ should control the channels, 1141# # actually, this is an ugly design. _we_ should control the channels,
1104 # not some random other widget, as the channels are clearly protocol-specific. 1142# # 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 1143# # then we could also react to flags such as CLEAR without resorting to
1106 # hacks such as color_flags, above. 1144# # hacks such as color_flags, above.
1107 }
1108 1145
1109 $self->{statusbox}->add ($text, 1146 $self->{statusbox}->add ($text,
1110 group => $text, 1147 group => $text,
1111 fg => $fg, 1148 fg => $fg,
1112 timeout => $color >= 2 ? 180 : 10, 1149 timeout => $color >= 2 ? 180 : 10,
1359 }); 1396 });
1360 1397
1361 $self->update_server_info; 1398 $self->update_server_info;
1362 1399
1363 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1400 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1364 $self->send_command ("pickup $::CFG->{pickup}"); 1401 $self->send_pickup ($::CFG->{pickup});
1402
1403 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1404 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1365} 1405}
1366 1406
1367sub lookat { 1407sub lookat {
1368 my ($self, $x, $y) = @_; 1408 my ($self, $x, $y) = @_;
1369 1409
1533} 1573}
1534 1574
1535sub send { 1575sub send {
1536 my ($self, $msg) = @_; 1576 my ($self, $msg) = @_;
1537 1577
1538 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1578 $self->{textview}->add_paragraph ({
1579 markup =>
1580 "\n<span foreground='#ffff00'><b>"
1581 . (DC::asxml $msg)
1582 . "</b></span>"
1583 });
1539 $self->{textview}->scroll_to_bottom; 1584 $self->{textview}->scroll_to_bottom;
1540 1585
1541 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1586 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1542} 1587}
1543 1588

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines