1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
4 | |
|
|
5 | use Guard (); |
5 | |
6 | |
6 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
7 | |
8 | |
8 | use DC; |
9 | use DC; |
9 | use DC::DB; |
10 | use DC::DB; |
… | |
… | |
11 | use DC::Pod; |
12 | use DC::Pod; |
12 | use DC::Macro; |
13 | use DC::Macro; |
13 | use DC::Item; |
14 | use DC::Item; |
14 | |
15 | |
15 | use base 'Deliantra::Protocol::Base'; |
16 | use base 'Deliantra::Protocol::Base'; |
|
|
17 | |
|
|
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
|
|
19 | "dialogue.png", minify => 1, mipmap => 1; |
|
|
20 | |
|
|
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
|
|
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
23 | |
|
|
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
16 | |
25 | |
17 | sub new { |
26 | sub 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, |
… | |
… | |
67 | for values %{delete $ws->{w} || {}}; |
76 | for values %{delete $ws->{w} || {}}; |
68 | } |
77 | } |
69 | |
78 | |
70 | delete $self->{items}; |
79 | delete $self->{items}; |
71 | $::INV->clear; |
80 | $::INV->clear; |
|
|
81 | $::INVR->clear; |
72 | $::INVR_HB->clear; |
82 | $::INVR_HB->clear; |
73 | $::FLOORBOX->clear; |
83 | $::FLOORBOX->clear; |
74 | }); |
84 | }); |
75 | |
85 | |
76 | $self->{map_widget}->add_command (@$_) |
86 | $self->{map_widget}->add_command (@$_) |
77 | for @cmd_help; |
87 | for @cmd_help; |
78 | |
88 | |
79 | { |
89 | { |
80 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
90 | $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}}); |
91 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
83 | } |
92 | } |
84 | |
93 | |
85 | { |
94 | { |
86 | $self->{noface} = my $tex = new_from_file DC::Texture |
95 | $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}}); |
96 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
89 | } |
97 | } |
|
|
98 | |
|
|
99 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
100 | # $self->{expire_w} = EV::timer 1, 1, sub { |
|
|
101 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
102 | # |
|
|
103 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
104 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
105 | # $self->{texture}[$_]->unload; |
|
|
106 | # warn "expire texture $_\n";#d# |
|
|
107 | # } |
|
|
108 | # |
|
|
109 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
110 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
111 | # warn "count is $count\n";#d# |
|
|
112 | # }; |
90 | |
113 | |
91 | $self->{open_container} = 0; |
114 | $self->{open_container} = 0; |
92 | |
115 | |
93 | # per server |
116 | # per server |
94 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
117 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
255 | my %wkw = ( |
278 | my %wkw = ( |
256 | root => $DC::UI::ROOT, |
279 | root => $DC::UI::ROOT, |
257 | tooltip => $DC::UI::TOOLTIP, |
280 | tooltip => $DC::UI::TOOLTIP, |
258 | |
281 | |
259 | mapwidget => $::MAPWIDGET, |
282 | mapwidget => $::MAPWIDGET, |
|
|
283 | menubar => $::MENUBAR, |
|
|
284 | menupopup => $::MENUPOPUP, |
|
|
285 | pickup_enable => $::PICKUP_ENABLE, |
260 | buttonbar => $::BUTTONBAR, |
286 | buttonbar => $::BUTTONBAR, |
261 | metaserver => $::METASERVER, |
287 | metaserver => $::METASERVER, |
262 | buttonbar => $::BUTTONBAR, |
288 | buttonbar => $::BUTTONBAR, |
263 | login_button => $::LOGIN_BUTTON, |
289 | login_button => $::LOGIN_BUTTON, |
264 | quit_dialog => $::QUIT_DIALOG, |
290 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
281 | |
307 | |
282 | floorbox => $::FLOORBOX, |
308 | floorbox => $::FLOORBOX, |
283 | help_window => $::HELP_WINDOW, |
309 | help_window => $::HELP_WINDOW, |
284 | message_window => $::MESSAGE_WINDOW, |
310 | message_window => $::MESSAGE_WINDOW, |
285 | message_dist => $::MESSAGE_DIST, |
311 | message_dist => $::MESSAGE_DIST, |
286 | statusbox => $::SDTATUSBOX, |
312 | statusbox => $::STATUSBOX, |
287 | |
313 | |
288 | inv => $::INV, |
314 | inv => $::INV, |
289 | invr => $::INVR, |
315 | invr => $::INVR, |
290 | invr_hb => $::INVR_HB, |
316 | invr_hb => $::INVR_HB, |
291 | ); |
317 | ); |
… | |
… | |
375 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
401 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
376 | : () |
402 | : () |
377 | } |
403 | } |
378 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
404 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
379 | |
405 | |
380 | join "", @diff |
406 | "\u$name: " . (join ", ", @diff) |
381 | } |
407 | } |
382 | |
408 | |
383 | # all stats that are chacked against changes |
409 | # all stats that are chacked against changes |
384 | my @statchange = ( |
410 | my @statchange = ( |
385 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
411 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
440 | } |
466 | } |
441 | |
467 | |
442 | if ( |
468 | if ( |
443 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
469 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
444 | ) { |
470 | ) { |
445 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
471 | 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); |
472 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
447 | } |
473 | } |
448 | |
474 | |
449 | $self->update_stats_window ($stats, $prev); |
475 | $self->update_stats_window ($stats, $prev); |
450 | |
476 | |
… | |
… | |
488 | |
514 | |
489 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
515 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
490 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
516 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
491 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
517 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
492 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
518 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
493 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
519 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
494 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
520 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
495 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
521 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
496 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
522 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
497 | my $title = $stats->{+CS_STAT_TITLE}; |
523 | my $title = $stats->{+CS_STAT_TITLE}; |
498 | $title =~ s/^Player: //; |
524 | $title =~ s/^Player: //; |
499 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
525 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
500 | |
526 | |
… | |
… | |
512 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
538 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
513 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
539 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
514 | |
540 | |
515 | $self->update_weight; |
541 | $self->update_weight; |
516 | |
542 | |
517 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
543 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
518 | for keys %RES_TBL; |
544 | for keys %RES_TBL; |
519 | |
545 | |
520 | my $sktbl = $::STATWIDS->{skill_tbl}; |
546 | my $sktbl = $::STATWIDS->{skill_tbl}; |
521 | my @skills = keys %{ $self->{skill_info} }; |
547 | my @skills = keys %{ $self->{skill_info} }; |
522 | |
548 | |
… | |
… | |
541 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
567 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
542 | ]; |
568 | ]; |
543 | |
569 | |
544 | my @add = @$sw; |
570 | my @add = @$sw; |
545 | |
571 | |
546 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
572 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
547 | |
573 | |
548 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
574 | 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); |
575 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
550 | |
576 | |
551 | my ($x, $y) = (0, 1); |
577 | my ($x, $y) = (0, 1); |
… | |
… | |
613 | my $sw = $self->{skillwid}{$idx}; |
639 | my $sw = $self->{skillwid}{$idx}; |
614 | $sw->[0]->set_text (::formsep ($val->[1])); |
640 | $sw->[0]->set_text (::formsep ($val->[1])); |
615 | $sw->[1]->set_text ($val->[0] * 1); |
641 | $sw->[1]->set_text ($val->[0] * 1); |
616 | $sw->[2]->set_value (@$val); |
642 | $sw->[2]->set_value (@$val); |
617 | |
643 | |
618 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
644 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
619 | $::GAUGES->{sklprg}->set_value (@$val); |
645 | $::GAUGES->{skillexp}->set_value (@$val); |
620 | } |
646 | } |
621 | } |
647 | } |
622 | |
648 | |
623 | sub user_send { |
649 | sub user_send { |
624 | my ($self, $command) = @_; |
650 | my ($self, $command) = @_; |
… | |
… | |
637 | } |
663 | } |
638 | |
664 | |
639 | sub map_scroll { |
665 | sub map_scroll { |
640 | my ($self, $dx, $dy) = @_; |
666 | my ($self, $dx, $dy) = @_; |
641 | |
667 | |
642 | $self->{map}->scroll ($dx, $dy); |
668 | $self->{map_widget}->scroll ($dx, $dy); |
643 | } |
669 | } |
644 | |
670 | |
645 | sub feed_map1a { |
671 | sub feed_map1a { |
646 | my ($self, $data) = @_; |
672 | my ($self, $data) = @_; |
647 | |
673 | |
… | |
… | |
651 | for my $tile (@$missing) { |
677 | for my $tile (@$missing) { |
652 | next if $self->{delay}{$tile}; |
678 | next if $self->{delay}{$tile}; |
653 | |
679 | |
654 | $delay = 1; |
680 | $delay = 1; |
655 | |
681 | |
656 | if (my $tex = $::CONN->{texture}[$tile]) { |
682 | if (my $tex = $self->{texture}[$tile]) { |
657 | $tex->upload; |
683 | $tex->upload; |
658 | } else { |
684 | } else { |
659 | $self->{delay}{$tile} = 1; |
685 | $self->{delay}{$tile} = 1; |
660 | |
686 | |
661 | # we assume the face is in-flight and will eventually come |
687 | # we assume the face is in-flight and will eventually arrive |
662 | push @{$self->{tile_cb}{$tile}}, sub { |
688 | push @{$self->{tile_cb}{$tile}}, sub { |
663 | delete $self->{delay}{$tile}; |
689 | delete $self->{delay}{$tile}; |
664 | $_[0]->upload; |
690 | $_[0]->upload; |
665 | }; |
691 | }; |
666 | } |
692 | } |
667 | } |
693 | } |
668 | |
694 | |
669 | if ($delay) { |
695 | if ($delay) { |
670 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
696 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
671 | EV::once undef, 0, 0.03, sub { |
697 | EV::once undef, 0, 0.03, sub { |
672 | $self->{map_widget}->update |
698 | $self->{map_widget}->update |
673 | if $self->{map_widget}; |
699 | if $self->{map_widget}; |
674 | }; |
700 | }; |
675 | } else { |
701 | } else { |
… | |
… | |
684 | } |
710 | } |
685 | |
711 | |
686 | sub flush_map { |
712 | sub flush_map { |
687 | my ($self) = @_; |
713 | my ($self) = @_; |
688 | |
714 | |
689 | my $map_info = delete $self->{map_info} |
715 | return unless $self->{map_info}; |
690 | or return; |
|
|
691 | |
716 | |
|
|
717 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
692 | my ($hash, $x, $y, $w, $h) = @$map_info; |
718 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
693 | |
719 | |
694 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
720 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
695 | $self->{map_cache_new}{$hash} = \$data; |
721 | |
|
|
722 | if ($data ne $$rdata) { |
|
|
723 | $map_info->[1] = \$data; |
|
|
724 | my $cdata = Compress::LZF::compress $data; |
696 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
725 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
726 | } |
|
|
727 | } |
697 | } |
728 | } |
698 | |
729 | |
699 | sub map_clear { |
730 | sub map_clear { |
700 | my ($self) = @_; |
731 | my ($self) = @_; |
701 | |
732 | |
702 | $self->flush_map; |
733 | $self->flush_map; |
|
|
734 | delete $self->{map_info}; |
703 | delete $self->{neigh_map}; |
735 | delete $self->{neigh_map}; |
704 | |
736 | |
705 | $self->{map}->clear; |
737 | $self->{map}->clear; |
706 | delete $self->{map_widget}{magicmap}; |
738 | delete $self->{map_widget}{magicmap}; |
707 | } |
739 | } |
… | |
… | |
728 | |
760 | |
729 | $self->bg_fetch; |
761 | $self->bg_fetch; |
730 | }; |
762 | }; |
731 | } |
763 | } |
732 | |
764 | |
733 | sub load_map($$$) { |
765 | sub load_map($$$$$$) { |
734 | my ($self, $hash, $x, $y) = @_; |
766 | my ($self, $hash, $x, $y, $w, $h) = @_; |
735 | |
767 | |
736 | my $gen = $self->{map_change_gen}; |
768 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
737 | |
769 | |
738 | my $cb = sub { |
770 | my $cb = sub { |
739 | return unless $gen == $self->{map_change_gen}; |
771 | $map_info->[1] = \$_[0]; |
740 | |
772 | |
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} || [] }; |
773 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
749 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
774 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
750 | $self->bg_fetch unless $inprogress; |
775 | $self->bg_fetch unless $inprogress; |
751 | } |
|
|
752 | }; |
776 | }; |
753 | |
777 | |
754 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
778 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
755 | $cb->($$rdata); |
779 | $cb->(${ $map_info->[1] }); |
756 | } else { |
780 | } else { |
|
|
781 | my $gen = $self->{map_change_gen}; |
|
|
782 | |
757 | DC::DB::get $self->{mapcache} => $hash, $cb; |
783 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
784 | return unless $gen == $self->{map_change_gen}; |
|
|
785 | return unless defined $_[0]; |
|
|
786 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
787 | }; |
758 | } |
788 | } |
759 | } |
789 | } |
760 | |
790 | |
761 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
791 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
762 | # (server resource,s latency, bandwidth), so this hack is warranted. |
792 | # (server resources, latency, bandwidth), so this hack is warranted. |
763 | # the right fix is to make real tiled maps with an overview file |
793 | # the right fix is to make real tiled maps with an overview file |
764 | sub send_mapinfo { |
794 | sub send_mapinfo { |
765 | my ($self, $data, $cb) = @_; |
795 | my ($self, $data, $cb) = @_; |
766 | |
796 | |
767 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
797 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
792 | } |
822 | } |
793 | |
823 | |
794 | # this method does a "flood fill" into every tile direction |
824 | # this method does a "flood fill" into every tile direction |
795 | # it assumes that tiles are arranged in a rectangular grid, |
825 | # 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. |
826 | # 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 |
827 | # failure to comply is harmless and results in display errors |
798 | # at worst. |
828 | # at worst. |
799 | sub flood_fill { |
829 | sub flood_fill { |
800 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
830 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
801 | |
831 | |
802 | # the server does not allow map paths > 6 |
832 | # the server does not allow map paths > 6 |
… | |
… | |
838 | return if $mode ne "spatial"; |
868 | return if $mode ne "spatial"; |
839 | |
869 | |
840 | $x += $self->{map}->ox; |
870 | $x += $self->{map}->ox; |
841 | $y += $self->{map}->oy; |
871 | $y += $self->{map}->oy; |
842 | |
872 | |
843 | $self->load_map ($hash, $x, $y) |
873 | $self->load_map ($hash, $x, $y, $w, $h) |
844 | unless $self->{neigh_map}{$hash}[5]++;#d# |
874 | unless $self->{neigh_map}{$hash}[5]++;#d# |
845 | |
875 | |
846 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
876 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
847 | |
877 | |
848 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
878 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
856 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
886 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
857 | |
887 | |
858 | $self->flush_map; |
888 | $self->flush_map; |
859 | |
889 | |
860 | ++$self->{map_change_gen}; |
890 | ++$self->{map_change_gen}; |
861 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
891 | $self->{map_cache_old} = delete $self->{map_cache}; |
862 | |
892 | |
863 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
893 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
864 | |
894 | |
865 | my $mapmapw = $self->{mapmap}->{w}; |
895 | my $mapmapw = $self->{mapmap}->{w}; |
866 | my $mapmaph = $self->{mapmap}->{h}; |
896 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
878 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
908 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
879 | |
909 | |
880 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
910 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
881 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
911 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
882 | |
912 | |
883 | $self->load_map ($hash, $x, $y); |
913 | $self->load_map ($hash, $x, $y, $w, $h); |
884 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
914 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
885 | } |
915 | } |
886 | |
916 | |
887 | sub face_find { |
917 | sub face_find { |
888 | my ($self, $facenum, $face, $cb) = @_; |
918 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
959 | |
989 | |
960 | my $tex = $self->{texture}[$tile] ||= |
990 | my $tex = $self->{texture}[$tile] ||= |
961 | new DC::Texture |
991 | new DC::Texture |
962 | tile => $tile, |
992 | tile => $tile, |
963 | image => $data, delete_image => 1, |
993 | image => $data, delete_image => 1, |
964 | minify => 1, mipmap => 1; |
994 | minify => 1; |
965 | |
995 | |
966 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
996 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
967 | $_->($tex) for @$cbs; |
997 | $_->($tex) for @$cbs; |
968 | } |
998 | } |
969 | } |
999 | } |
… | |
… | |
974 | my ($self, $num, $cb) = @_; |
1004 | my ($self, $num, $cb) = @_; |
975 | |
1005 | |
976 | push @{$self->{face_cb}{$num}}, $cb; |
1006 | push @{$self->{face_cb}{$num}}, $cb; |
977 | |
1007 | |
978 | defined wantarray |
1008 | defined wantarray |
979 | ? DC::guard { |
1009 | ? Guard::guard { |
980 | @{$self->{face_cb}{$num}} |
1010 | @{$self->{face_cb}{$num}} |
981 | = grep $_ != $cb, |
1011 | = grep $_ != $cb, |
982 | @{$self->{face_cb}{$num}}; |
1012 | @{$self->{face_cb}{$num}}; |
983 | } |
1013 | } |
984 | : () |
1014 | : () |
… | |
… | |
1088 | |
1118 | |
1089 | ## try to create single paragraphs of multiple lines sent by the server |
1119 | ## try to create single paragraphs of multiple lines sent by the server |
1090 | # no longer neecssary with TRT servers |
1120 | # no longer neecssary with TRT servers |
1091 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1121 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1092 | |
1122 | |
1093 | for (split /\n/, $text) { |
|
|
1094 | ::message ({ |
1123 | ::message ({ |
1095 | fg => $fg, |
1124 | fg => $fg, |
1096 | markup => $_, |
1125 | markup => $text, |
1097 | type => $type, |
1126 | type => $type, |
1098 | extra => [@extra], |
1127 | extra => [@extra], |
1099 | color_flags => $color, #d# ugly, kill |
1128 | color_flags => $color, #d# ugly, kill |
1100 | }); |
1129 | }); |
1101 | |
1130 | |
1102 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1131 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1103 | # actually, this is an ugly design. _we_ should control the channels, |
1132 | # # actually, this is an ugly design. _we_ should control the channels, |
1104 | # not some random other widget, as the channels are clearly protocol-specific. |
1133 | # # 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 |
1134 | # # then we could also react to flags such as CLEAR without resorting to |
1106 | # hacks such as color_flags, above. |
1135 | # # hacks such as color_flags, above. |
1107 | } |
|
|
1108 | |
1136 | |
1109 | $self->{statusbox}->add ($text, |
1137 | $self->{statusbox}->add ($text, |
1110 | group => $text, |
1138 | group => $text, |
1111 | fg => $fg, |
1139 | fg => $fg, |
1112 | timeout => $color >= 2 ? 180 : 10, |
1140 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1319 | sub update_server_info { |
1347 | sub update_server_info { |
1320 | my ($self) = @_; |
1348 | my ($self) = @_; |
1321 | |
1349 | |
1322 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1350 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1323 | |
1351 | |
|
|
1352 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1353 | |
1324 | $::SERVER_INFO->set_markup ( |
1354 | $::SERVER_INFO->set_markup ( |
1325 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1355 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1326 | . "protocol version <tt>$self->{version}</tt>\n" |
1356 | . "protocol version <tt>$version</tt>\n" |
1327 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1357 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1328 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1358 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1329 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1359 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1330 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1360 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1331 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1361 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
… | |
… | |
1359 | }); |
1389 | }); |
1360 | |
1390 | |
1361 | $self->update_server_info; |
1391 | $self->update_server_info; |
1362 | |
1392 | |
1363 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1393 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1364 | $self->send_command ("pickup $::CFG->{pickup}"); |
1394 | $self->send_pickup ($::CFG->{pickup}); |
1365 | } |
1395 | } |
1366 | |
1396 | |
1367 | sub lookat { |
1397 | sub lookat { |
1368 | my ($self, $x, $y) = @_; |
1398 | my ($self, $x, $y) = @_; |
1369 | |
1399 | |
… | |
… | |
1533 | } |
1563 | } |
1534 | |
1564 | |
1535 | sub send { |
1565 | sub send { |
1536 | my ($self, $msg) = @_; |
1566 | my ($self, $msg) = @_; |
1537 | |
1567 | |
1538 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1568 | $self->{textview}->add_paragraph ({ |
|
|
1569 | markup => |
|
|
1570 | "\n<span foreground='#ffff00'><b>" |
|
|
1571 | . (DC::asxml $msg) |
|
|
1572 | . "</b></span>" |
|
|
1573 | }); |
1539 | $self->{textview}->scroll_to_bottom; |
1574 | $self->{textview}->scroll_to_bottom; |
1540 | |
1575 | |
1541 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1576 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1542 | } |
1577 | } |
1543 | |
1578 | |