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.224 by root, Wed Nov 7 00:25:46 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 $exp_guard = $self->addme_guard;
40 my $skl_guard = $self->addme_guard;
41 my $spl_guard = $self->addme_guard;
42 $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub {
43 my ($exp, $skl, $spl) = @_;
44
45 $self->register_face_handler ($exp, sub {
46 my ($face) = @_;
47
48 undef $exp_guard;
49 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
50 $_->() for values %{ $self->{on_exp_update} };
51 });
52
53 $self->register_face_handler ($skl, sub {
54 my ($face) = @_;
55
56 undef $skl_guard;
57 my $info = $self->{json_coder}->decode (delete $face->{data});
58 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
59 });
60
61 $self->register_face_handler ($spl, sub {
62 my ($face) = @_;
63
64 undef $spl_guard;
65 my $info = $self->{json_coder}->decode (delete $face->{data});
66 $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info };
67 });
68
69 ()
70 });
28 71
29 $self->{map_widget}->clr_commands; 72 $self->{map_widget}->clr_commands;
30 73
31 my @cmd_help = map { 74 my @cmd_help = map {
32 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 75 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
67 for values %{delete $ws->{w} || {}}; 110 for values %{delete $ws->{w} || {}};
68 } 111 }
69 112
70 delete $self->{items}; 113 delete $self->{items};
71 $::INV->clear; 114 $::INV->clear;
115 $::INVR->clear;
72 $::INVR_HB->clear; 116 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 117 $::FLOORBOX->clear;
74 }); 118 });
75 119
76 $self->{map_widget}->add_command (@$_) 120 $self->{map_widget}->add_command (@$_)
77 for @cmd_help; 121 for @cmd_help;
78 122
79 { 123 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 124 $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}}); 125 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
83 } 126 }
84 127
85 { 128 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 129 $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}}); 130 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
89 } 131 }
132
133# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
134# $self->{expire_w} = AE::timer 1, 1, sub {
135# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
136#
137# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
138# warn DC::SvREFCNT $self->{texture}[$_];
139# $self->{texture}[$_]->unload;
140# warn "expire texture $_\n";#d#
141# }
142#
143# ($self->{expire_count} += $count) < @{ $self->{texture} }
144# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
145# warn "count is $count\n";#d#
146# };
90 147
91 $self->{open_container} = 0; 148 $self->{open_container} = 0;
92 149
93 # per server 150 # per server
94 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 151 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
106 }); 163 });
107} 164}
108 165
109sub ext_capabilities { 166sub ext_capabilities {
110 my ($self, %cap) = @_; 167 my ($self, %cap) = @_;
111
112 $self->update_fx_want;
113
114 $self->send_exti_req (resource => "exp_table", sub {
115 my ($exp_table) = @_;
116
117 $self->register_face_handler ($exp_table, sub {
118 my ($face) = @_;
119
120 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
121 $_->() for values %{ $self->{on_exp_update} || {} };
122 });
123
124 ()
125 });
126 168
127 if (my $ts = $cap{tileset}) { 169 if (my $ts = $cap{tileset}) {
128 if (my ($default) = grep $_->[2] & 1, @$ts) { 170 if (my ($default) = grep $_->[2] & 1, @$ts) {
129 $self->{tileset} = $default; 171 $self->{tileset} = $default;
130 $self->{tilesize} = $default->[3]; 172 $self->{tilesize} = $default->[3];
255 my %wkw = ( 297 my %wkw = (
256 root => $DC::UI::ROOT, 298 root => $DC::UI::ROOT,
257 tooltip => $DC::UI::TOOLTIP, 299 tooltip => $DC::UI::TOOLTIP,
258 300
259 mapwidget => $::MAPWIDGET, 301 mapwidget => $::MAPWIDGET,
302 menubar => $::MENUBAR,
303 menupopup => $::MENUPOPUP,
304 pickup_enable => $::PICKUP_ENABLE,
260 buttonbar => $::BUTTONBAR, 305 buttonbar => $::BUTTONBAR,
261 metaserver => $::METASERVER, 306 metaserver => $::METASERVER,
262 buttonbar => $::BUTTONBAR, 307 buttonbar => $::BUTTONBAR,
263 login_button => $::LOGIN_BUTTON, 308 login_button => $::LOGIN_BUTTON,
264 quit_dialog => $::QUIT_DIALOG, 309 quit_dialog => $::QUIT_DIALOG,
281 326
282 floorbox => $::FLOORBOX, 327 floorbox => $::FLOORBOX,
283 help_window => $::HELP_WINDOW, 328 help_window => $::HELP_WINDOW,
284 message_window => $::MESSAGE_WINDOW, 329 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST, 330 message_dist => $::MESSAGE_DIST,
286 statusbox => $::SDTATUSBOX, 331 statusbox => $::STATUSBOX,
287 332
288 inv => $::INV, 333 inv => $::INV,
289 invr => $::INVR, 334 invr => $::INVR,
290 invr_hb => $::INVR_HB, 335 invr_hb => $::INVR_HB,
291 ); 336 );
375 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 420 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
376 : () 421 : ()
377 } 422 }
378 sort { $a <=> $b } keys %{$self->{spell_paths}}; 423 sort { $a <=> $b } keys %{$self->{spell_paths}};
379 424
380 join "", @diff 425 "\u$name: " . (join ", ", @diff)
381} 426}
382 427
383# all stats that are chacked against changes 428# all stats that are chacked against changes
384my @statchange = ( 429my @statchange = (
385 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 430 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
428 473
429 if (my @diffs = 474 if (my @diffs =
430 ( 475 (
431 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 476 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
432 map { 477 map {
433 $stats->{$_} && $prev->{$_} 478 $stats->{$_} && $prev->{$_}
434 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 479 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
435 } sort { $a <=> $b } keys %{$self->{skill_info}} 480 } sort { $a <=> $b } keys %{$self->{skill_info}}
436 ) 481 )
437 ) { 482 ) {
438 my $msg = join " ", @diffs; 483 my $msg = join " ", @diffs;
440 } 485 }
441 486
442 if ( 487 if (
443 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 488 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
444 ) { 489 ) {
445 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 490 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
446 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); 491 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
447 } 492 }
448 493
449 $self->update_stats_window ($stats, $prev); 494 $self->update_stats_window ($stats, $prev);
450 495
488 533
489 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 534 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
490 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 535 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
491 $::GAUGES->{food} ->set_value ($fo, $fo_m); 536 $::GAUGES->{food} ->set_value ($fo, $fo_m);
492 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 537 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
493 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 538 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
494 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 539 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
495 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 540 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
496 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 541 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
497 my $title = $stats->{+CS_STAT_TITLE}; 542 my $title = $stats->{+CS_STAT_TITLE};
498 $title =~ s/^Player: //; 543 $title =~ s/^Player: //;
499 $::STATWIDS->{title} ->set_text ("Title: " . $title); 544 $::STATWIDS->{title} ->set_text ("Title: " . $title);
500 545
512 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 557 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
513 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 558 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
514 559
515 $self->update_weight; 560 $self->update_weight;
516 561
517 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 562 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
518 for keys %RES_TBL; 563 for keys %RES_TBL;
519 564
520 my $sktbl = $::STATWIDS->{skill_tbl}; 565 my $sktbl = $::STATWIDS->{skill_tbl};
521 my @skills = keys %{ $self->{skill_info} }; 566 my @skills = keys %{ $self->{skill_info} };
522 567
541 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 586 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
542 ]; 587 ];
543 588
544 my @add = @$sw; 589 my @add = @$sw;
545 590
546 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 591 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
547 592
548 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 593 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); 594 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
550 595
551 my ($x, $y) = (0, 1); 596 my ($x, $y) = (0, 1);
613 my $sw = $self->{skillwid}{$idx}; 658 my $sw = $self->{skillwid}{$idx};
614 $sw->[0]->set_text (::formsep ($val->[1])); 659 $sw->[0]->set_text (::formsep ($val->[1]));
615 $sw->[1]->set_text ($val->[0] * 1); 660 $sw->[1]->set_text ($val->[0] * 1);
616 $sw->[2]->set_value (@$val); 661 $sw->[2]->set_value (@$val);
617 662
618 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 663 $::GAUGES->{skillexp}->set_label ("$name %d%%");
619 $::GAUGES->{sklprg}->set_value (@$val); 664 $::GAUGES->{skillexp}->set_value (@$val);
620 } 665 }
621} 666}
622 667
623sub user_send { 668sub user_send {
624 my ($self, $command) = @_; 669 my ($self, $command) = @_;
637} 682}
638 683
639sub map_scroll { 684sub map_scroll {
640 my ($self, $dx, $dy) = @_; 685 my ($self, $dx, $dy) = @_;
641 686
642 $self->{map}->scroll ($dx, $dy); 687 $self->{map_widget}->scroll ($dx, $dy);
643} 688}
644 689
645sub feed_map1a { 690sub feed_map1a {
646 my ($self, $data) = @_; 691 my ($self, $data) = @_;
647 692
648 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 693 my $missing = $self->{map}->map1a_update ($data);
649 my $delay; 694 my $delay;
650 695
651 for my $tile (@$missing) { 696 for my $tile (@$missing) {
652 next if $self->{delay}{$tile}; 697 next if $self->{delay}{$tile};
653 698
654 $delay = 1; 699 $delay = 1;
655 700
656 if (my $tex = $::CONN->{texture}[$tile]) { 701 if (my $tex = $self->{texture}[$tile]) {
657 $tex->upload; 702 $tex->upload;
658 } else { 703 } else {
659 $self->{delay}{$tile} = 1; 704 $self->{delay}{$tile} = 1;
660 705
661 # we assume the face is in-flight and will eventually come 706 # we assume the face is in-flight and will eventually arrive
662 push @{$self->{tile_cb}{$tile}}, sub { 707 push @{$self->{tile_cb}{$tile}}, sub {
663 delete $self->{delay}{$tile}; 708 delete $self->{delay}{$tile};
664 $_[0]->upload; 709 $_[0]->upload;
665 }; 710 };
666 } 711 }
667 } 712 }
668 713
669 if ($delay) { 714 if ($delay) {
670 # delay the map drawing a tiny bit in the hope of getting the missing fetched 715 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
671 EV::once undef, 0, 0.03, sub { 716 EV::once undef, 0, 0.03, sub {
672 $self->{map_widget}->update 717 $self->{map_widget}->update
673 if $self->{map_widget}; 718 if $self->{map_widget};
674 }; 719 };
675 } else { 720 } else {
684} 729}
685 730
686sub flush_map { 731sub flush_map {
687 my ($self) = @_; 732 my ($self) = @_;
688 733
689 my $map_info = delete $self->{map_info} 734 return unless $self->{map_info};
690 or return;
691 735
736 for my $map_info (values %{ $self->{map_cache} || {} }) {
692 my ($hash, $x, $y, $w, $h) = @$map_info; 737 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
693 738
694 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 739 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
695 $self->{map_cache_new}{$hash} = \$data; 740
741 if ($data ne $$rdata) {
742 $map_info->[1] = \$data;
743 my $cdata = Compress::LZF::compress $data;
696 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 744 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
745 }
746 }
697} 747}
698 748
699sub map_clear { 749sub map_clear {
700 my ($self) = @_; 750 my ($self) = @_;
701 751
702 $self->flush_map; 752 $self->flush_map;
753 delete $self->{map_info};
703 delete $self->{neigh_map}; 754 delete $self->{neigh_map};
704 755
705 $self->{map}->clear; 756 $self->{map}->clear;
706 delete $self->{map_widget}{magicmap}; 757 delete $self->{map_widget}{magicmap};
707} 758}
728 779
729 $self->bg_fetch; 780 $self->bg_fetch;
730 }; 781 };
731} 782}
732 783
733sub load_map($$$) { 784sub load_map($$$$$$) {
734 my ($self, $hash, $x, $y) = @_; 785 my ($self, $hash, $x, $y, $w, $h) = @_;
735 786
736 my $gen = $self->{map_change_gen}; 787 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
737 788
738 my $cb = sub { 789 my $cb = sub {
739 return unless $gen == $self->{map_change_gen}; 790 $map_info->[1] = \$_[0];
740 791
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} || [] }; 792 my $inprogress = @{ $self->{bg_fetch} || [] };
749 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 793 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
750 $self->bg_fetch unless $inprogress; 794 $self->bg_fetch unless $inprogress;
751 }
752 }; 795 };
753 796
754 if (my $rdata = $self->{map_cache_old}{$hash}) { 797 if (my $map_info = $self->{map_cache_old}{$hash}) {
755 $cb->($$rdata); 798 $cb->(${ $map_info->[1] });
756 } else { 799 } else {
800 my $gen = $self->{map_change_gen};
801
757 DC::DB::get $self->{mapcache} => $hash, $cb; 802 DC::DB::get $self->{mapcache} => $hash, sub {
803 return unless $gen == $self->{map_change_gen};
804 return unless defined $_[0];
805 $cb->(Compress::LZF::decompress $_[0]);
806 };
758 } 807 }
759} 808}
760 809
761# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 810# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
762# (server resource,s latency, bandwidth), so this hack is warranted. 811# (server resources, latency, bandwidth), so this hack is warranted.
763# the right fix is to make real tiled maps with an overview file 812# the right fix is to make real tiled maps with an overview file
764sub send_mapinfo { 813sub send_mapinfo {
765 my ($self, $data, $cb) = @_; 814 my ($self, $data, $cb) = @_;
766 815
767 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 816 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
792} 841}
793 842
794# this method does a "flood fill" into every tile direction 843# this method does a "flood fill" into every tile direction
795# it assumes that tiles are arranged in a rectangular grid, 844# 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. 845# 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 846# failure to comply is harmless and results in display errors
798# at worst. 847# at worst.
799sub flood_fill { 848sub flood_fill {
800 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 849 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
801 850
802 # the server does not allow map paths > 6 851 # the server does not allow map paths > 6
838 return if $mode ne "spatial"; 887 return if $mode ne "spatial";
839 888
840 $x += $self->{map}->ox; 889 $x += $self->{map}->ox;
841 $y += $self->{map}->oy; 890 $y += $self->{map}->oy;
842 891
843 $self->load_map ($hash, $x, $y) 892 $self->load_map ($hash, $x, $y, $w, $h)
844 unless $self->{neigh_map}{$hash}[5]++;#d# 893 unless $self->{neigh_map}{$hash}[5]++;#d#
845 894
846 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 895 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
847 896
848 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 897 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
856 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 905 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
857 906
858 $self->flush_map; 907 $self->flush_map;
859 908
860 ++$self->{map_change_gen}; 909 ++$self->{map_change_gen};
861 $self->{map_cache_old} = delete $self->{map_cache_new}; 910 $self->{map_cache_old} = delete $self->{map_cache};
862 911
863 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 912 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
864 913
865 my $mapmapw = $self->{mapmap}->{w}; 914 my $mapmapw = $self->{mapmap}->{w};
866 my $mapmaph = $self->{mapmap}->{h}; 915 my $mapmaph = $self->{mapmap}->{h};
878 $self->{map_info} = [$hash, $x, $y, $w, $h]; 927 $self->{map_info} = [$hash, $x, $y, $w, $h];
879 928
880 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 929 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
881 $::STATWIDS->{map}->set_text ("Map: " . $map); 930 $::STATWIDS->{map}->set_text ("Map: " . $map);
882 931
883 $self->load_map ($hash, $x, $y); 932 $self->load_map ($hash, $x, $y, $w, $h);
884 $self->flood_fill (0, 0, 0, "", $hash, $flags); 933 $self->flood_fill (0, 0, 0, "", $hash, $flags);
885} 934}
886 935
887sub face_find { 936sub face_find {
888 my ($self, $facenum, $face, $cb) = @_; 937 my ($self, $facenum, $face, $cb) = @_;
959 1008
960 my $tex = $self->{texture}[$tile] ||= 1009 my $tex = $self->{texture}[$tile] ||=
961 new DC::Texture 1010 new DC::Texture
962 tile => $tile, 1011 tile => $tile,
963 image => $data, delete_image => 1, 1012 image => $data, delete_image => 1,
964 minify => 1, mipmap => 1; 1013 minify => 1;
965 1014
966 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1015 if (my $cbs = delete $self->{tile_cb}{$tile}) {
967 $_->($tex) for @$cbs; 1016 $_->($tex) for @$cbs;
968 } 1017 }
969} 1018}
974 my ($self, $num, $cb) = @_; 1023 my ($self, $num, $cb) = @_;
975 1024
976 push @{$self->{face_cb}{$num}}, $cb; 1025 push @{$self->{face_cb}{$num}}, $cb;
977 1026
978 defined wantarray 1027 defined wantarray
979 ? DC::guard { 1028 ? Guard::guard {
980 @{$self->{face_cb}{$num}} 1029 @{$self->{face_cb}{$num}}
981 = grep $_ != $cb, 1030 = grep $_ != $cb,
982 @{$self->{face_cb}{$num}}; 1031 @{$self->{face_cb}{$num}};
983 } 1032 }
984 : () 1033 : ()
1012 my ($self, $flags, $prompt) = @_; 1061 my ($self, $flags, $prompt) = @_;
1013 1062
1014 $prompt = $LAST_QUERY unless length $prompt; 1063 $prompt = $LAST_QUERY unless length $prompt;
1015 $LAST_QUERY = $prompt; 1064 $LAST_QUERY = $prompt;
1016 1065
1017 $self->{query}-> ($self, $flags, $prompt); 1066 $self->{query}->($self, $flags, $prompt);
1018} 1067}
1019 1068
1020sub sanitise_xml($) { 1069sub sanitise_xml($) {
1021 local $_ = shift; 1070 local $_ = shift;
1022 1071
1054 tan => 12, 1103 tan => 12,
1055); 1104);
1056 1105
1057our @CF_COLOR = ( 1106our @CF_COLOR = (
1058 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1107 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1059 [1.00, 1.00, 1.00], 1108 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1060 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 1109 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1061 [1.00, 0.00, 0.00], 1110 [1.00, 0.00, 0.00],
1062 [1.00, 0.54, 0.00], 1111 [1.00, 0.54, 0.00],
1063 [0.11, 0.56, 1.00], 1112 [0.11, 0.56, 1.00],
1064 [0.93, 0.46, 0.00], 1113 [0.93, 0.46, 0.00],
1065 [0.18, 0.54, 0.34], 1114 [0.18, 0.54, 0.34],
1084 $self->logprint ("msg: ", $text); 1133 $self->logprint ("msg: ", $text);
1085 return if $color < 0; # negative color == ignore if not understood 1134 return if $color < 0; # negative color == ignore if not understood
1086 1135
1087 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1136 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1088 1137
1089 ## try to create single paragraphs of multiple lines sent by the server
1090 # no longer neecssary with TRT servers
1091 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1092
1093 for (split /\n/, $text) {
1094 ::message ({ 1138 ::message ({
1095 fg => $fg, 1139 fg => $fg,
1096 markup => $_, 1140 markup => $text,
1097 type => $type, 1141 type => $type,
1098 extra => [@extra], 1142 extra => [@extra],
1099 color_flags => $color, #d# ugly, kill 1143 color_flags => $color, #d# ugly, kill
1100 }); 1144 });
1101 1145
1102 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1146# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1103 # actually, this is an ugly design. _we_ should control the channels, 1147# # actually, this is an ugly design. _we_ should control the channels,
1104 # not some random other widget, as the channels are clearly protocol-specific. 1148# # 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 1149# # then we could also react to flags such as CLEAR without resorting to
1106 # hacks such as color_flags, above. 1150# # hacks such as color_flags, above.
1107 }
1108 1151
1109 $self->{statusbox}->add ($text, 1152 $self->{statusbox}->add ($text,
1110 group => $text, 1153 group => $text,
1111 fg => $fg, 1154 fg => $fg,
1112 timeout => $color >= 2 ? 180 : 10, 1155 timeout => $color >= 2 ? 180 : 10,
1319sub update_server_info { 1362sub update_server_info {
1320 my ($self) = @_; 1363 my ($self) = @_;
1321 1364
1322 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1365 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1323 1366
1367 my $version = JSON::XS->new->encode ($self->{s_version});
1368
1324 $::SERVER_INFO->set_markup ( 1369 $::SERVER_INFO->set_markup (
1325 "server <tt>$self->{host}:$self->{port}</tt>\n" 1370 "server <tt>$self->{host}:$self->{port}</tt>\n"
1326 . "protocol version <tt>$self->{version}</tt>\n" 1371 . "protocol version <tt>$version</tt>\n"
1327 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1328 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1329 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1330 . "editing support $yesno[!!$self->{editor_support}]\n" 1372 . "editing support $yesno[!!$self->{editor_support}]\n"
1331 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1332 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1333 . "client support $yesno[$self->{cfplus_ext} > 0]" 1373 . "client support $yesno[$self->{cfplus_ext} > 0]"
1334 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1374 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1335 . "map size $self->{mapw}×$self->{maph}\n" 1375 . "map size $self->{mapw}×$self->{maph}\n"
1336 ); 1376 );
1337 1377
1359 }); 1399 });
1360 1400
1361 $self->update_server_info; 1401 $self->update_server_info;
1362 1402
1363 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1403 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1364 $self->send_command ("pickup $::CFG->{pickup}"); 1404 $self->send_pickup ($::CFG->{pickup});
1365} 1405}
1366 1406
1367sub lookat { 1407sub lookat {
1368 my ($self, $x, $y) = @_; 1408 my ($self, $x, $y) = @_;
1369 1409
1371 $self->send_ext_req (lookat => $x, $y, sub { 1411 $self->send_ext_req (lookat => $x, $y, sub {
1372 my (%msg) = @_; 1412 my (%msg) = @_;
1373 1413
1374 if (exists $msg{npc_dialog}) { 1414 if (exists $msg{npc_dialog}) {
1375 # start npc chat dialog 1415 # start npc chat dialog
1376 $self->{npc_dialog} = new DC::NPCDialog:: 1416 $self->{w}{npc_dialog} = new DC::NPCDialog::
1377 token => $msg{npc_dialog}, 1417 token => $msg{npc_dialog},
1378 title => "$msg{npc_dialog}[0] (NPC)", 1418 title => "$msg{npc_dialog}[0] (NPC)",
1379 conn => $self, 1419 conn => $self,
1380 ; 1420 ;
1381 } 1421 }
1386} 1426}
1387 1427
1388sub destroy { 1428sub destroy {
1389 my ($self) = @_; 1429 my ($self) = @_;
1390 1430
1391 (delete $self->{npc_dialog})->destroy 1431 $_->destroy
1392 if $self->{npc_dialog}; 1432 for values %{ $self->{w} };
1393 1433
1394 $self->SUPER::destroy; 1434 $self->SUPER::destroy;
1395 1435
1396 %$self = (); 1436 %$self = ();
1397} 1437}
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
1546 1591
1547 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1592 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1548 1593
1549 if ($self->{conn}) { 1594 if ($self->{conn}) {
1550 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1595 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1551 delete $self->{conn}{npc_dialog}; 1596 delete $self->{conn}{w}{npc_dialog};
1552 $self->{conn}->disconnect_ext ($self->{id}); 1597 $self->{conn}->disconnect_ext ($self->{id});
1553 } 1598 }
1554 1599
1555 $self->SUPER::destroy; 1600 $self->SUPER::destroy;
1556} 1601}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines