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.149 by root, Fri Aug 10 04:33:41 2007 UTC vs.
Revision 1.155 by root, Fri Aug 17 21:18:01 2007 UTC

21 21
22 my $self = $class->SUPER::new (%arg, 22 my $self = $class->SUPER::new (%arg,
23 setup_req => { 23 setup_req => {
24 extmap => 1, 24 extmap => 1,
25 excmd => 1, 25 excmd => 1,
26 ywidget => 1,#d# 26 xwidget1 => 1,#d#
27 %{$arg{setup_req} || {}}, 27 %{$arg{setup_req} || {}},
28 }, 28 },
29 ); 29 );
30 30
31 $self->{map_widget}->clr_commands; 31 $self->{map_widget}->clr_commands;
104 # widgetset create 104 # widgetset create
105 $self->connect_ext (ws_c => sub { 105 $self->connect_ext (ws_c => sub {
106 my ($ws, $id, $class, $args) = @_; 106 my ($ws, $id, $class, $args) = @_;
107 107
108 for my $ev (grep /^on_/, keys %$args) { 108 for my $ev (grep /^on_/, keys %$args) {
109 my $rid = $args->{$ev};
109 $args->{$ev} = sub { 110 $args->{$ev} = sub {
110 my $id = shift->{s_id}; 111 my $id = shift->{s_id};
111 $self->send_exti_msg (w_e => $id, $ev, \@_); 112 $self->send_exti_msg (w_e => $id, $rid, @_);
112 113
113 1 114 1
114 }; 115 };
115 } 116 }
116 117
117 if (my $widget = eval { 118 $self->widget_associate (
119 $ws, $id => scalar eval {
118 local $SIG{__DIE__}; 120 local $SIG{__DIE__};
119 "CFPlus::UI::$class"->new ( 121 "CFPlus::UI::$class"->new (%$args)
120 %$args,
121 s_ws => $ws,
122 s_id => $id,
123 )
124 } 122 }
125 ) {
126 $self->{widget}{$id}
127 = $self->{widgetset}{$ws}{w}{$id}
128 = $widget;
129
130 $widget->connect (on_destroy => sub {
131 my ($widget) = @_;
132
133 delete $self->{widget}{$widget->{s_id}};
134 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}};
135 });
136 } else {
137 warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n"; 123 ) or warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n";
138 $self->send_exti_msg (w_e => $id, "destroy"); 124 });
125
126 # widgetset associate
127 $self->connect_ext (ws_a => sub {
128 my (%ass) = @_;
129
130 # everything that has a name, wether conceivably useful or not
131 my %wkw = (
132 root => $CFPlus::UI::ROOT,
133 tooltip => $CFPlus::UI::TOOLTIP,
134
135 mapwidget => $::MAPWIDGET,
136 buttonbar => $::BUTTONBAR,
137 metaserver => $::METASERVER,
138 buttonbar => $::BUTTONBAR,
139 login_button => $::LOGIN_BUTTON,
140 quit_dialog => $::QUIT_DIALOG,
141 host_entry => $::HOST_ENTRY,
142 metaserver => $::METASERVER,
143 server_info => $::SERVER_INFO,
144
145 setup_dialog => $::SETUP_DIALOG,
146 setup_notebook => $::SETUP_NOTEBOOK,
147 setup_server => $::SETUP_SERVER,
148 setup_keyboard => $::SETUP_KEYBOARD,
149
150 pl_notebook => $::PL_NOTEBOOK,
151 pl_window => $::PL_WINDOW,
152 inventory_page => $::INVENTORY_PAGE,
153 stats_page => $::STATS_PAGE,
154 skill_page => $::SKILL_PAGE,
155 spell_page => $::SPELL_PAGE,
156 spell_list => $::SPELL_LIST,
157
158 floorbox => $::FLOORBOX,
159 help_window => $::HELP_WINDOW,
160 message_window => $::MESSAGE_WINDOW,
161 statusbox => $::SDTATUSBOX,
162
163 inv => $::INV,
164 invr => $::INVR,
165 invr_hb => $::INVR_HB,
166
167 );
168
169 while (my ($id, $name) = each %ass) {
170 $self->widget_associate (undef, $id => $wkw{$name})
171 or warn "server failed to associate non-existent well-known widget $name\n";
139 } 172 }
140 }); 173 });
141 174
142 # widget call 175 # widget call
143 $self->connect_ext (w_c => sub { 176 $self->connect_ext (w_c => sub {
144 my ($id, $rid, $method, $args) = @_; 177 my ($id, $rid, $method, @args) = @_;
145 178
146 my $w = $self->{widget}{$id} 179 my $w = $self->{widget}{$id}
147 or return; 180 or return;
148 181
149 $args ||= [];
150
151 if ($rid) { 182 if ($rid) {
152 $self->send_exti_msg (w_r => $rid, [$w->$method (@$args)]); 183 $self->send_exti_msg (w_r => $rid, $w->$method (@args));
153 } else { 184 } else {
154 $w->$method (@$args); 185 $w->$method (@args);
155 } 186 }
156 }); 187 });
157 188
158 # widget set 189 # widget set
159 $self->connect_ext (w_s => sub { 190 $self->connect_ext (w_s => sub {
217 248
218 # per server 249 # per server
219 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 250 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
220 251
221 $self 252 $self
253}
254
255sub widget_associate {
256 my ($self, $ws, $id, $widget) = @_;
257
258 if ($widget) {
259 $widget->{s_id} = $id;
260 $self->{widget}{$id} = $widget;
261
262 if ($ws) {
263 $widget->{s_ws} = $ws;
264 $self->{widgetset}{$ws}{w}{$id} = $widget;
265 }
266
267 $widget->connect (on_destroy => sub {
268 my ($widget) = @_;
269
270 delete $self->{widget}{$widget->{s_id}};
271 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}}
272 if exists $widget->{s_ws};
273 });
274
275 1
276 } else {
277 $self->send_exti_msg (w_e => $id, undef);
278
279 0
280 }
222} 281}
223 282
224sub update_fx_want { 283sub update_fx_want {
225 my ($self) = @_; 284 my ($self) = @_;
226 285
552 my $map_info = delete $self->{map_info} 611 my $map_info = delete $self->{map_info}
553 or return; 612 or return;
554 613
555 my ($hash, $x, $y, $w, $h) = @$map_info; 614 my ($hash, $x, $y, $w, $h) = @$map_info;
556 615
557 my $data = $self->{map}->get_rect ($x, $y, $w, $h); 616 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h);
617 $self->{map_cache_new}{$hash} = \$data;
558 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; 618 CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { };
559 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
560} 619}
561 620
562sub map_clear { 621sub map_clear {
563 my ($self) = @_; 622 my ($self) = @_;
564 623
582 CFPlus::DB::exists tilecache => $id, sub { 641 CFPlus::DB::exists tilecache => $id, sub {
583 my ($exists) = @_; 642 my ($exists) = @_;
584 643
585 return unless $self->{map}; # stop when destroyed 644 return unless $self->{map}; # stop when destroyed
586 645
646 if ($exists) {
587 $self->have_tile ($id) 647 $self->have_tile ($id);
588 if $exists;
589
590 $self->{texture}[$id]->upload; 648 $self->{texture}[$id]->upload;
649 }
591 650
592 $self->bg_fetch; 651 $self->bg_fetch;
593 }; 652 };
594} 653}
595 654
596sub load_map($$$) { 655sub load_map($$$) {
597 my ($self, $hash, $x, $y) = @_; 656 my ($self, $hash, $x, $y) = @_;
598 657
599 my $gen = $self->{map_change_gen}; 658 my $gen = $self->{map_change_gen};
600 659
601 CFPlus::DB::get $self->{mapcache} => $hash, sub { 660 my $cb = sub {
602 return unless $gen == $self->{map_change_gen}; 661 return unless $gen == $self->{map_change_gen};
603 662
604 my ($data) = @_; 663 my ($data) = @_;
605 664
606 if (defined $data) { 665 if (defined $data) {
666 $self->{map_cache_new}{$hash} = \$data;
667
607 $data = Compress::LZF::decompress $data; 668 my $data = Compress::LZF::decompress $data;
608 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
609 669
610 my $inprogress = @{ $self->{bg_fetch} || [] }; 670 my $inprogress = @{ $self->{bg_fetch} || [] };
611 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 671 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
612 $self->bg_fetch unless $inprogress; 672 $self->bg_fetch unless $inprogress;
613 } 673 }
614 }; 674 };
675
676 if (my $rdata = $self->{map_cache_old}{$hash}) {
677 $cb->($$rdata);
678 } else {
679 CFPlus::DB::get $self->{mapcache} => $hash, $cb;
680 }
615} 681}
616 682
617# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 683# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
618# (server resource,s latency, bandwidth), so this hack is warranted. 684# (server resource,s latency, bandwidth), so this hack is warranted.
619# the right fix is to make real tiled maps with an overview file 685# the right fix is to make real tiled maps with an overview file
712 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 778 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
713 779
714 $self->flush_map; 780 $self->flush_map;
715 781
716 ++$self->{map_change_gen}; 782 ++$self->{map_change_gen};
783 $self->{map_cache_old} = delete $self->{map_cache_new};
717 784
718 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 785 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
719 786
720 my $mapmapw = $self->{mapmap}->{w}; 787 my $mapmapw = $self->{mapmap}->{w};
721 my $mapmaph = $self->{mapmap}->{h}; 788 my $mapmaph = $self->{mapmap}->{h};
905 $self->{$type} = $text; 972 $self->{$type} = $text;
906 } else { 973 } else {
907 $self->logprint ("msg: ", $text); 974 $self->logprint ("msg: ", $text);
908 return if $color < 0; # negative color == ignore if not understood 975 return if $color < 0; # negative color == ignore if not understood
909 976
910 my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; 977 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
911 978
912 ## try to create single paragraphs of multiple lines sent by the server 979 ## try to create single paragraphs of multiple lines sent by the server
913 # no longer neecssary with TRT servers 980 # no longer neecssary with TRT servers
914 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 981 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
915 982
916 ::message ({ fg => $fg, markup => $_, type => $type, extra => [@extra] }) 983 ::message ({
984 fg => $fg,
985 markup => $_,
986 type => $type,
987 extra => [@extra],
988 color_flags => $color
917 for split /\n/, $text; 989 }) for split /\n/, $text;
918 990
919 $self->{statusbox}->add ($text, 991 $self->{statusbox}->add ($text,
920 group => $text, 992 group => $text,
921 fg => $fg, 993 fg => $fg,
922 timeout => $color >= 2 ? 180 : 10, 994 timeout => $color >= 2 ? 180 : 10,
1024sub set_opencont { 1096sub set_opencont {
1025 my ($conn, $tag, $name) = @_; 1097 my ($conn, $tag, $name) = @_;
1026 $conn->{open_container} = $tag; 1098 $conn->{open_container} = $tag;
1027 update_floorbox; 1099 update_floorbox;
1028 1100
1029 $::INV_RIGHT_HB->clear (); 1101 $::INVR_HB->clear ();
1030 $::INV_RIGHT_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); 1102 $::INVR_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name);
1031 1103
1032 if ($tag != 0) { # Floor isn't closable, is it? 1104 if ($tag != 0) { # Floor isn't closable, is it?
1033 $::INV_RIGHT_HB->add (new CFPlus::UI::Button 1105 $::INVR_HB->add (new CFPlus::UI::Button
1034 text => "Close container", 1106 text => "Close container",
1035 tooltip => "Close the currently open container (if one is open)", 1107 tooltip => "Close the currently open container (if one is open)",
1036 on_activate => sub { 1108 on_activate => sub {
1037 $::CONN->send ("apply $tag") # $::CONN->{open_container}") 1109 $::CONN->send ("apply $tag") # $::CONN->{open_container}")
1038 if $tag != 0; 1110 if $tag != 0;
1039 #if $CONN->{open_container} != 0;
1040 0 1111 0
1041 }, 1112 },
1042 ); 1113 );
1043 } 1114 }
1044 1115

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines