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.192 by root, Thu Mar 27 20:42:23 2008 UTC vs.
Revision 1.221 by root, Sun Nov 4 02:13:53 2012 UTC

1package DC::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use common::sense;
4use strict; 4
5use Guard ();
5 6
6use Deliantra::Protocol::Constants; 7use Deliantra::Protocol::Constants;
7 8
8use DC; 9use DC;
9use DC::DB; 10use DC::DB;
12use DC::Macro; 13use DC::Macro;
13use DC::Item; 14use DC::Item;
14 15
15use base 'Deliantra::Protocol::Base'; 16use base 'Deliantra::Protocol::Base';
16 17
18our $TEX_DIALOGUE = new_from_resource DC::Texture
19 "dialogue.png", minify => 1, mipmap => 1;
20
21our $TEX_NOFACE = new_from_resource DC::Texture
22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
23
24sub MIN_TEXTURE_UNUSED() { 1 }#d#
25
17sub new { 26sub new {
18 my ($class, %arg) = @_; 27 my ($class, %arg) = @_;
19 28
20 my $self = $class->SUPER::new (%arg, 29 my $self = $class->SUPER::new (%arg,
21 setup_req => { 30 setup_req => {
22 extmap => 1, 31 extmap => 1,
23 excmd => 1,
24 widget => 2, 32 widget => 2,
25 %{$arg{setup_req} || {}}, 33 %{$arg{setup_req} || {}},
26 }, 34 },
27 ); 35 );
36
37 $self->update_fx_want;
38
39 my $guard = $self->addme_guard;
40 $self->send_exti_req (resource => "exp_table", sub {
41 my ($idx) = @_;
42
43 $self->register_face_handler ($idx, sub {
44 my ($face) = @_;
45
46 undef $guard;
47 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
48 $_->() for values %{ $self->{on_exp_update} };
49 });
50
51 ()
52 });
53
54 my $guard = $self->addme_guard;
55 $self->send_exti_req (resource => "skill_info", sub {
56 my ($idx) = @_;
57
58 $self->register_face_handler ($idx, sub {
59 my ($face) = @_;
60
61 undef $guard;
62 my $info = $self->{json_coder}->decode (delete $face->{data});
63 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
64 });
65
66 ()
67 });
68
69 my $guard = $self->addme_guard;
70 $self->send_exti_req (resource => "spell_paths", sub {
71 my ($idx) = @_;
72
73 $self->register_face_handler ($idx, sub {
74 my ($face) = @_;
75
76 undef $guard;
77 my $info = $self->{json_coder}->decode (delete $face->{data});
78 $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info };
79 });
80
81 ()
82 });
28 83
29 $self->{map_widget}->clr_commands; 84 $self->{map_widget}->clr_commands;
30 85
31 my @cmd_help = map { 86 my @cmd_help = map {
32 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 87 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 119 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
65 for my $ws (values %{delete $self->{widgetset} || {}}) { 120 for my $ws (values %{delete $self->{widgetset} || {}}) {
66 $_->destroy 121 $_->destroy
67 for values %{delete $ws->{w} || {}}; 122 for values %{delete $ws->{w} || {}};
68 } 123 }
124
125 delete $self->{items};
126 $::INV->clear;
127 $::INVR->clear;
128 $::INVR_HB->clear;
129 $::FLOORBOX->clear;
69 }); 130 });
70 131
71 $self->{map_widget}->add_command (@$_) 132 $self->{map_widget}->add_command (@$_)
72 for @cmd_help; 133 for @cmd_help;
73 134
74 { 135 {
75 $self->{dialogue} = my $tex = new_from_file DC::Texture 136 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
76 DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
77 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 137 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
78 } 138 }
79 139
80 { 140 {
81 $self->{noface} = my $tex = new_from_file DC::Texture 141 $self->{noface} = my $tex = $TEX_NOFACE;
82 DC::find_rcfile "noface.png", minify => 1, mipmap => 1;
83 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 142 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
84 } 143 }
144
145# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
146# $self->{expire_w} = AE::timer 1, 1, sub {
147# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
148#
149# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
150# warn DC::SvREFCNT $self->{texture}[$_];
151# $self->{texture}[$_]->unload;
152# warn "expire texture $_\n";#d#
153# }
154#
155# ($self->{expire_count} += $count) < @{ $self->{texture} }
156# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
157# warn "count is $count\n";#d#
158# };
85 159
86 $self->{open_container} = 0; 160 $self->{open_container} = 0;
87 161
88 # per server 162 # per server
89 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 163 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
101 }); 175 });
102} 176}
103 177
104sub ext_capabilities { 178sub ext_capabilities {
105 my ($self, %cap) = @_; 179 my ($self, %cap) = @_;
106
107 $self->update_fx_want;
108
109 $self->send_exti_req (resource => "exp_table", sub {
110 my ($exp_table) = @_;
111
112 $self->register_face_handler ($exp_table, sub {
113 my ($face) = @_;
114
115 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
116 $_->() for values %{ $self->{on_exp_update} || {} };
117 });
118
119 ()
120 });
121 180
122 if (my $ts = $cap{tileset}) { 181 if (my $ts = $cap{tileset}) {
123 if (my ($default) = grep $_->[2] & 1, @$ts) { 182 if (my ($default) = grep $_->[2] & 1, @$ts) {
124 $self->{tileset} = $default; 183 $self->{tileset} = $default;
125 $self->{tilesize} = $default->[3]; 184 $self->{tilesize} = $default->[3];
250 my %wkw = ( 309 my %wkw = (
251 root => $DC::UI::ROOT, 310 root => $DC::UI::ROOT,
252 tooltip => $DC::UI::TOOLTIP, 311 tooltip => $DC::UI::TOOLTIP,
253 312
254 mapwidget => $::MAPWIDGET, 313 mapwidget => $::MAPWIDGET,
314 menubar => $::MENUBAR,
315 menupopup => $::MENUPOPUP,
316 pickup_enable => $::PICKUP_ENABLE,
255 buttonbar => $::BUTTONBAR, 317 buttonbar => $::BUTTONBAR,
256 metaserver => $::METASERVER, 318 metaserver => $::METASERVER,
257 buttonbar => $::BUTTONBAR, 319 buttonbar => $::BUTTONBAR,
258 login_button => $::LOGIN_BUTTON, 320 login_button => $::LOGIN_BUTTON,
259 quit_dialog => $::QUIT_DIALOG, 321 quit_dialog => $::QUIT_DIALOG,
276 338
277 floorbox => $::FLOORBOX, 339 floorbox => $::FLOORBOX,
278 help_window => $::HELP_WINDOW, 340 help_window => $::HELP_WINDOW,
279 message_window => $::MESSAGE_WINDOW, 341 message_window => $::MESSAGE_WINDOW,
280 message_dist => $::MESSAGE_DIST, 342 message_dist => $::MESSAGE_DIST,
281 statusbox => $::SDTATUSBOX, 343 statusbox => $::STATUSBOX,
282 344
283 inv => $::INV, 345 inv => $::INV,
284 invr => $::INVR, 346 invr => $::INVR,
285 invr_hb => $::INVR_HB, 347 invr_hb => $::INVR_HB,
286 ); 348 );
370 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 432 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
371 : () 433 : ()
372 } 434 }
373 sort { $a <=> $b } keys %{$self->{spell_paths}}; 435 sort { $a <=> $b } keys %{$self->{spell_paths}};
374 436
375 join "", @diff 437 "\u$name: " . (join ", ", @diff)
376} 438}
377 439
378# all stats that are chacked against changes 440# all stats that are chacked against changes
379my @statchange = ( 441my @statchange = (
380 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 442 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
423 485
424 if (my @diffs = 486 if (my @diffs =
425 ( 487 (
426 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 488 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
427 map { 489 map {
428 $stats->{$_} && $prev->{$_} 490 $stats->{$_} && $prev->{$_}
429 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 491 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
430 } sort { $a <=> $b } keys %{$self->{skill_info}} 492 } sort { $a <=> $b } keys %{$self->{skill_info}}
431 ) 493 )
432 ) { 494 ) {
433 my $msg = join " ", @diffs; 495 my $msg = join " ", @diffs;
435 } 497 }
436 498
437 if ( 499 if (
438 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 500 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
439 ) { 501 ) {
440 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 502 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
441 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); 503 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
442 } 504 }
443 505
444 $self->update_stats_window ($stats, $prev); 506 $self->update_stats_window ($stats, $prev);
445 507
483 545
484 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 546 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
485 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 547 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
486 $::GAUGES->{food} ->set_value ($fo, $fo_m); 548 $::GAUGES->{food} ->set_value ($fo, $fo_m);
487 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 549 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
488 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 550 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
489 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 551 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
490 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 552 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
491 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 553 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
492 my $title = $stats->{+CS_STAT_TITLE}; 554 my $title = $stats->{+CS_STAT_TITLE};
493 $title =~ s/^Player: //; 555 $title =~ s/^Player: //;
494 $::STATWIDS->{title} ->set_text ("Title: " . $title); 556 $::STATWIDS->{title} ->set_text ("Title: " . $title);
495 557
507 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 569 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
508 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 570 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
509 571
510 $self->update_weight; 572 $self->update_weight;
511 573
512 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 574 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
513 for keys %RES_TBL; 575 for keys %RES_TBL;
514 576
515 my $sktbl = $::STATWIDS->{skill_tbl}; 577 my $sktbl = $::STATWIDS->{skill_tbl};
516 my @skills = keys %{ $self->{skill_info} }; 578 my @skills = keys %{ $self->{skill_info} };
517 579
536 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 598 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
537 ]; 599 ];
538 600
539 my @add = @$sw; 601 my @add = @$sw;
540 602
541 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 603 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
542 604
543 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 605 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
544 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 606 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
545 607
546 my ($x, $y) = (0, 1); 608 my ($x, $y) = (0, 1);
608 my $sw = $self->{skillwid}{$idx}; 670 my $sw = $self->{skillwid}{$idx};
609 $sw->[0]->set_text (::formsep ($val->[1])); 671 $sw->[0]->set_text (::formsep ($val->[1]));
610 $sw->[1]->set_text ($val->[0] * 1); 672 $sw->[1]->set_text ($val->[0] * 1);
611 $sw->[2]->set_value (@$val); 673 $sw->[2]->set_value (@$val);
612 674
613 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 675 $::GAUGES->{skillexp}->set_label ("$name %d%%");
614 $::GAUGES->{sklprg}->set_value (@$val); 676 $::GAUGES->{skillexp}->set_value (@$val);
615 } 677 }
616} 678}
617 679
618sub user_send { 680sub user_send {
619 my ($self, $command) = @_; 681 my ($self, $command) = @_;
632} 694}
633 695
634sub map_scroll { 696sub map_scroll {
635 my ($self, $dx, $dy) = @_; 697 my ($self, $dx, $dy) = @_;
636 698
637 $self->{map}->scroll ($dx, $dy); 699 $self->{map_widget}->scroll ($dx, $dy);
638} 700}
639 701
640sub feed_map1a { 702sub feed_map1a {
641 my ($self, $data) = @_; 703 my ($self, $data) = @_;
642 704
643 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 705 my $missing = $self->{map}->map1a_update ($data);
644 my $delay; 706 my $delay;
645 707
646 for my $tile (@$missing) { 708 for my $tile (@$missing) {
647 next if $self->{delay}{$tile}; 709 next if $self->{delay}{$tile};
648 710
649 $delay = 1; 711 $delay = 1;
650 712
651 if (my $tex = $::CONN->{texture}[$tile]) { 713 if (my $tex = $self->{texture}[$tile]) {
652 $tex->upload; 714 $tex->upload;
653 } else { 715 } else {
654 $self->{delay}{$tile} = 1; 716 $self->{delay}{$tile} = 1;
655 717
656 # we assume the face is in-flight and will eventually come 718 # we assume the face is in-flight and will eventually arrive
657 push @{$self->{tile_cb}{$tile}}, sub { 719 push @{$self->{tile_cb}{$tile}}, sub {
658 delete $self->{delay}{$tile}; 720 delete $self->{delay}{$tile};
659 $_[0]->upload; 721 $_[0]->upload;
660 }; 722 };
661 } 723 }
662 } 724 }
663 725
664 if ($delay) { 726 if ($delay) {
665 # delay the map drawing a tiny bit in the hope of getting the missing fetched 727 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
666 EV::once undef, 0, 0.03, sub { 728 EV::once undef, 0, 0.03, sub {
667 $self->{map_widget}->update 729 $self->{map_widget}->update
668 if $self->{map_widget}; 730 if $self->{map_widget};
669 }; 731 };
670 } else { 732 } else {
679} 741}
680 742
681sub flush_map { 743sub flush_map {
682 my ($self) = @_; 744 my ($self) = @_;
683 745
684 my $map_info = delete $self->{map_info} 746 return unless $self->{map_info};
685 or return;
686 747
748 for my $map_info (values %{ $self->{map_cache} || {} }) {
687 my ($hash, $x, $y, $w, $h) = @$map_info; 749 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
688 750
689 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 751 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
690 $self->{map_cache_new}{$hash} = \$data; 752
753 if ($data ne $$rdata) {
754 $map_info->[1] = \$data;
755 my $cdata = Compress::LZF::compress $data;
691 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 756 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
757 }
758 }
692} 759}
693 760
694sub map_clear { 761sub map_clear {
695 my ($self) = @_; 762 my ($self) = @_;
696 763
697 $self->flush_map; 764 $self->flush_map;
765 delete $self->{map_info};
698 delete $self->{neigh_map}; 766 delete $self->{neigh_map};
699 767
700 $self->{map}->clear; 768 $self->{map}->clear;
701 delete $self->{map_widget}{magicmap}; 769 delete $self->{map_widget}{magicmap};
702} 770}
723 791
724 $self->bg_fetch; 792 $self->bg_fetch;
725 }; 793 };
726} 794}
727 795
728sub load_map($$$) { 796sub load_map($$$$$$) {
729 my ($self, $hash, $x, $y) = @_; 797 my ($self, $hash, $x, $y, $w, $h) = @_;
730 798
731 my $gen = $self->{map_change_gen}; 799 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
732 800
733 my $cb = sub { 801 my $cb = sub {
734 return unless $gen == $self->{map_change_gen}; 802 $map_info->[1] = \$_[0];
735 803
736 my ($data) = @_;
737
738 if (defined $data) {
739 $self->{map_cache_new}{$hash} = \$data;
740
741 my $data = Compress::LZF::decompress $data;
742
743 my $inprogress = @{ $self->{bg_fetch} || [] }; 804 my $inprogress = @{ $self->{bg_fetch} || [] };
744 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 805 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
745 $self->bg_fetch unless $inprogress; 806 $self->bg_fetch unless $inprogress;
746 }
747 }; 807 };
748 808
749 if (my $rdata = $self->{map_cache_old}{$hash}) { 809 if (my $map_info = $self->{map_cache_old}{$hash}) {
750 $cb->($$rdata); 810 $cb->(${ $map_info->[1] });
751 } else { 811 } else {
812 my $gen = $self->{map_change_gen};
813
752 DC::DB::get $self->{mapcache} => $hash, $cb; 814 DC::DB::get $self->{mapcache} => $hash, sub {
815 return unless $gen == $self->{map_change_gen};
816 return unless defined $_[0];
817 $cb->(Compress::LZF::decompress $_[0]);
818 };
753 } 819 }
754} 820}
755 821
756# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 822# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
757# (server resource,s latency, bandwidth), so this hack is warranted. 823# (server resources, latency, bandwidth), so this hack is warranted.
758# the right fix is to make real tiled maps with an overview file 824# the right fix is to make real tiled maps with an overview file
759sub send_mapinfo { 825sub send_mapinfo {
760 my ($self, $data, $cb) = @_; 826 my ($self, $data, $cb) = @_;
761 827
762 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 828 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
787} 853}
788 854
789# this method does a "flood fill" into every tile direction 855# this method does a "flood fill" into every tile direction
790# it assumes that tiles are arranged in a rectangular grid, 856# it assumes that tiles are arranged in a rectangular grid,
791# i.e. a map is the same as the left of the right map etc. 857# i.e. a map is the same as the left of the right map etc.
792# failure to comply are harmless and result in display errors 858# failure to comply is harmless and results in display errors
793# at worst. 859# at worst.
794sub flood_fill { 860sub flood_fill {
795 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 861 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
796 862
797 # the server does not allow map paths > 6 863 # the server does not allow map paths > 6
833 return if $mode ne "spatial"; 899 return if $mode ne "spatial";
834 900
835 $x += $self->{map}->ox; 901 $x += $self->{map}->ox;
836 $y += $self->{map}->oy; 902 $y += $self->{map}->oy;
837 903
838 $self->load_map ($hash, $x, $y) 904 $self->load_map ($hash, $x, $y, $w, $h)
839 unless $self->{neigh_map}{$hash}[5]++;#d# 905 unless $self->{neigh_map}{$hash}[5]++;#d#
840 906
841 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 907 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
842 908
843 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 909 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
851 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 917 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
852 918
853 $self->flush_map; 919 $self->flush_map;
854 920
855 ++$self->{map_change_gen}; 921 ++$self->{map_change_gen};
856 $self->{map_cache_old} = delete $self->{map_cache_new}; 922 $self->{map_cache_old} = delete $self->{map_cache};
857 923
858 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 924 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
859 925
860 my $mapmapw = $self->{mapmap}->{w}; 926 my $mapmapw = $self->{mapmap}->{w};
861 my $mapmaph = $self->{mapmap}->{h}; 927 my $mapmaph = $self->{mapmap}->{h};
873 $self->{map_info} = [$hash, $x, $y, $w, $h]; 939 $self->{map_info} = [$hash, $x, $y, $w, $h];
874 940
875 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 941 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
876 $::STATWIDS->{map}->set_text ("Map: " . $map); 942 $::STATWIDS->{map}->set_text ("Map: " . $map);
877 943
878 $self->load_map ($hash, $x, $y); 944 $self->load_map ($hash, $x, $y, $w, $h);
879 $self->flood_fill (0, 0, 0, "", $hash, $flags); 945 $self->flood_fill (0, 0, 0, "", $hash, $flags);
880} 946}
881 947
882sub face_find { 948sub face_find {
883 my ($self, $facenum, $face, $cb) = @_; 949 my ($self, $facenum, $face, $cb) = @_;
954 1020
955 my $tex = $self->{texture}[$tile] ||= 1021 my $tex = $self->{texture}[$tile] ||=
956 new DC::Texture 1022 new DC::Texture
957 tile => $tile, 1023 tile => $tile,
958 image => $data, delete_image => 1, 1024 image => $data, delete_image => 1,
959 minify => 1, mipmap => 1; 1025 minify => 1;
960 1026
961 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1027 if (my $cbs = delete $self->{tile_cb}{$tile}) {
962 $_->($tex) for @$cbs; 1028 $_->($tex) for @$cbs;
963 } 1029 }
964} 1030}
969 my ($self, $num, $cb) = @_; 1035 my ($self, $num, $cb) = @_;
970 1036
971 push @{$self->{face_cb}{$num}}, $cb; 1037 push @{$self->{face_cb}{$num}}, $cb;
972 1038
973 defined wantarray 1039 defined wantarray
974 ? DC::guard { 1040 ? Guard::guard {
975 @{$self->{face_cb}{$num}} 1041 @{$self->{face_cb}{$num}}
976 = grep $_ != $cb, 1042 = grep $_ != $cb,
977 @{$self->{face_cb}{$num}}; 1043 @{$self->{face_cb}{$num}};
978 } 1044 }
979 : () 1045 : ()
1007 my ($self, $flags, $prompt) = @_; 1073 my ($self, $flags, $prompt) = @_;
1008 1074
1009 $prompt = $LAST_QUERY unless length $prompt; 1075 $prompt = $LAST_QUERY unless length $prompt;
1010 $LAST_QUERY = $prompt; 1076 $LAST_QUERY = $prompt;
1011 1077
1012 $self->{query}-> ($self, $flags, $prompt); 1078 $self->{query}->($self, $flags, $prompt);
1013} 1079}
1014 1080
1015sub sanitise_xml($) { 1081sub sanitise_xml($) {
1016 local $_ = shift; 1082 local $_ = shift;
1017 1083
1025 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g; 1091 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
1026 1092
1027 # handle some elements 1093 # handle some elements
1028 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1094 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1029 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; 1095 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1096
1097 s/\s+$//;
1030 1098
1031 $_ 1099 $_
1032} 1100}
1033 1101
1034our %NAME_TO_COLOR = ( 1102our %NAME_TO_COLOR = (
1077 $self->logprint ("msg: ", $text); 1145 $self->logprint ("msg: ", $text);
1078 return if $color < 0; # negative color == ignore if not understood 1146 return if $color < 0; # negative color == ignore if not understood
1079 1147
1080 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1148 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1081 1149
1082 ## try to create single paragraphs of multiple lines sent by the server
1083 # no longer neecssary with TRT servers
1084 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1085
1086 for (split /\n/, $text) {
1087 ::message ({ 1150 ::message ({
1088 fg => $fg, 1151 fg => $fg,
1089 markup => $_, 1152 markup => $text,
1090 type => $type, 1153 type => $type,
1091 extra => [@extra], 1154 extra => [@extra],
1092 color_flags => $color, #d# ugly, kill 1155 color_flags => $color, #d# ugly, kill
1093 }); 1156 });
1094 1157
1095 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1158# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1096 # actually, this is an ugly design. _we_ should control the channels, 1159# # actually, this is an ugly design. _we_ should control the channels,
1097 # not some random other widget, as the channels are clearly protocol-specific. 1160# # not some random other widget, as the channels are clearly protocol-specific.
1098 # then we could also react to flags such as CLEAR without resorting to 1161# # then we could also react to flags such as CLEAR without resorting to
1099 # hacks such as color_flags, above. 1162# # hacks such as color_flags, above.
1100 }
1101 1163
1102 $self->{statusbox}->add ($text, 1164 $self->{statusbox}->add ($text,
1103 group => $text, 1165 group => $text,
1104 fg => $fg, 1166 fg => $fg,
1105 timeout => $color >= 2 ? 180 : 10, 1167 timeout => $color >= 2 ? 180 : 10,
1170 $::FLOORBOX->clear; 1232 $::FLOORBOX->clear;
1171 1233
1172 my @add; 1234 my @add;
1173 1235
1174 my $row; 1236 my $row;
1175 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1237 for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
1238 next if $_->{tag} & 0x80000000;
1176 if ($row < 6) { 1239 if ($row < 6) {
1177 local $_->{face_widget}; # hack to force recreation of widget 1240 local $_->{face_widget}; # hack to force recreation of widget
1178 local $_->{desc_widget}; # hack to force recreation of widget 1241 local $_->{desc_widget}; # hack to force recreation of widget
1179 DC::Item::update_widgets $_; 1242 DC::Item::update_widgets $_;
1180 1243
1207sub set_opencont { 1270sub set_opencont {
1208 my ($conn, $tag, $name) = @_; 1271 my ($conn, $tag, $name) = @_;
1209 $conn->{open_container} = $tag; 1272 $conn->{open_container} = $tag;
1210 update_floorbox; 1273 update_floorbox;
1211 1274
1212 $::INVR_HB->clear (); 1275 $::INVR_HB->clear;
1213 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); 1276 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1214 1277
1215 if ($tag != 0) { # Floor isn't closable, is it? 1278 if ($tag != 0) { # Floor isn't closable, is it?
1216 $::INVR_HB->add (new DC::UI::Button 1279 $::INVR_HB->add (new DC::UI::Button
1217 text => "Close container", 1280 text => "Close container",
1273} 1336}
1274 1337
1275sub item_update { 1338sub item_update {
1276 my ($self, $item) = @_; 1339 my ($self, $item) = @_;
1277 1340
1278 #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; 1341 #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n";
1279 1342
1280 DC::Item::update_widgets $item; 1343 DC::Item::update_widgets $item;
1281 1344
1282 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1345 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1283 set_opencont ($::CONN, 0, "Floor"); 1346 set_opencont ($::CONN, 0, "Floor");
1284 1347
1285 } elsif ($item->{flags} & F_OPEN) { 1348 } elsif ($item->{flags} & F_OPEN) {
1286 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); 1349 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1311sub update_server_info { 1374sub update_server_info {
1312 my ($self) = @_; 1375 my ($self) = @_;
1313 1376
1314 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1377 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1315 1378
1379 my $version = JSON::XS->new->encode ($self->{s_version});
1380
1316 $::SERVER_INFO->set_markup ( 1381 $::SERVER_INFO->set_markup (
1317 "server <tt>$self->{host}:$self->{port}</tt>\n" 1382 "server <tt>$self->{host}:$self->{port}</tt>\n"
1318 . "protocol version <tt>$self->{version}</tt>\n" 1383 . "protocol version <tt>$version</tt>\n"
1319 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1320 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1321 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1322 . "editing support $yesno[!!$self->{editor_support}]\n" 1384 . "editing support $yesno[!!$self->{editor_support}]\n"
1323 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1324 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1325 . "client support $yesno[$self->{cfplus_ext} > 0]" 1385 . "client support $yesno[$self->{cfplus_ext} > 0]"
1326 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1386 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1327 . "map size $self->{mapw}×$self->{maph}\n" 1387 . "map size $self->{mapw}×$self->{maph}\n"
1328 ); 1388 );
1329 1389
1351 }); 1411 });
1352 1412
1353 $self->update_server_info; 1413 $self->update_server_info;
1354 1414
1355 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1415 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1356 $self->send_command ("pickup $::CFG->{pickup}"); 1416 $self->send_pickup ($::CFG->{pickup});
1357} 1417}
1358 1418
1359sub lookat { 1419sub lookat {
1360 my ($self, $x, $y) = @_; 1420 my ($self, $x, $y) = @_;
1361 1421
1363 $self->send_ext_req (lookat => $x, $y, sub { 1423 $self->send_ext_req (lookat => $x, $y, sub {
1364 my (%msg) = @_; 1424 my (%msg) = @_;
1365 1425
1366 if (exists $msg{npc_dialog}) { 1426 if (exists $msg{npc_dialog}) {
1367 # start npc chat dialog 1427 # start npc chat dialog
1368 $self->{npc_dialog} = new DC::NPCDialog:: 1428 $self->{w}{npc_dialog} = new DC::NPCDialog::
1369 token => $msg{npc_dialog}, 1429 token => $msg{npc_dialog},
1370 title => "$msg{npc_dialog}[0] (NPC)", 1430 title => "$msg{npc_dialog}[0] (NPC)",
1371 conn => $self, 1431 conn => $self,
1372 ; 1432 ;
1373 } 1433 }
1378} 1438}
1379 1439
1380sub destroy { 1440sub destroy {
1381 my ($self) = @_; 1441 my ($self) = @_;
1382 1442
1383 (delete $self->{npc_dialog})->destroy 1443 $_->destroy
1384 if $self->{npc_dialog}; 1444 for values %{ $self->{w} };
1385 1445
1386 $self->SUPER::destroy; 1446 $self->SUPER::destroy;
1387 1447
1388 %$self = (); 1448 %$self = ();
1389} 1449}
1525} 1585}
1526 1586
1527sub send { 1587sub send {
1528 my ($self, $msg) = @_; 1588 my ($self, $msg) = @_;
1529 1589
1530 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1590 $self->{textview}->add_paragraph ({
1591 markup =>
1592 "\n<span foreground='#ffff00'><b>"
1593 . (DC::asxml $msg)
1594 . "</b></span>"
1595 });
1531 $self->{textview}->scroll_to_bottom; 1596 $self->{textview}->scroll_to_bottom;
1532 1597
1533 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1598 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1534} 1599}
1535 1600
1538 1603
1539 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1604 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1540 1605
1541 if ($self->{conn}) { 1606 if ($self->{conn}) {
1542 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1607 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1543 delete $self->{conn}{npc_dialog}; 1608 delete $self->{conn}{w}{npc_dialog};
1544 $self->{conn}->disconnect_ext ($self->{id}); 1609 $self->{conn}->disconnect_ext ($self->{id});
1545 } 1610 }
1546 1611
1547 $self->SUPER::destroy; 1612 $self->SUPER::destroy;
1548} 1613}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines