… | |
… | |
11 | use DC::Pod; |
11 | use DC::Pod; |
12 | use DC::Macro; |
12 | use DC::Macro; |
13 | use DC::Item; |
13 | use DC::Item; |
14 | |
14 | |
15 | use base 'Deliantra::Protocol::Base'; |
15 | use base 'Deliantra::Protocol::Base'; |
|
|
16 | |
|
|
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
|
|
18 | "dialogue.png", minify => 1, mipmap => 1; |
|
|
19 | |
|
|
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
|
|
21 | "noface.png", minify => 1, mipmap => 1; |
|
|
22 | |
|
|
23 | our $TEX_HIDDEN = new_from_resource DC::Texture |
|
|
24 | "hidden.png", minify => 1, mipmap => 1; |
|
|
25 | |
|
|
26 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
16 | |
27 | |
17 | sub new { |
28 | sub new { |
18 | my ($class, %arg) = @_; |
29 | my ($class, %arg) = @_; |
19 | |
30 | |
20 | my $self = $class->SUPER::new (%arg, |
31 | my $self = $class->SUPER::new (%arg, |
… | |
… | |
67 | for values %{delete $ws->{w} || {}}; |
78 | for values %{delete $ws->{w} || {}}; |
68 | } |
79 | } |
69 | |
80 | |
70 | delete $self->{items}; |
81 | delete $self->{items}; |
71 | $::INV->clear; |
82 | $::INV->clear; |
|
|
83 | $::INVR->clear; |
72 | $::INVR_HB->clear; |
84 | $::INVR_HB->clear; |
73 | $::FLOORBOX->clear; |
85 | $::FLOORBOX->clear; |
74 | }); |
86 | }); |
75 | |
87 | |
76 | $self->{map_widget}->add_command (@$_) |
88 | $self->{map_widget}->add_command (@$_) |
77 | for @cmd_help; |
89 | for @cmd_help; |
78 | |
90 | |
79 | { |
91 | { |
80 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
92 | $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}}); |
93 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
83 | } |
94 | } |
84 | |
95 | |
85 | { |
96 | { |
86 | $self->{noface} = my $tex = new_from_file DC::Texture |
97 | $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}}); |
98 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
89 | } |
99 | } |
|
|
100 | |
|
|
101 | { |
|
|
102 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
103 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
104 | } |
|
|
105 | |
|
|
106 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
107 | # $self->{expire_w} = EV::timer 1, 1, sub { |
|
|
108 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
109 | # |
|
|
110 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
111 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
112 | # $self->{texture}[$_]->unload; |
|
|
113 | # warn "expire texture $_\n";#d# |
|
|
114 | # } |
|
|
115 | # |
|
|
116 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
117 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
118 | # warn "count is $count\n";#d# |
|
|
119 | # }; |
90 | |
120 | |
91 | $self->{open_container} = 0; |
121 | $self->{open_container} = 0; |
92 | |
122 | |
93 | # per server |
123 | # per server |
94 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
124 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
541 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
571 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
542 | ]; |
572 | ]; |
543 | |
573 | |
544 | my @add = @$sw; |
574 | my @add = @$sw; |
545 | |
575 | |
546 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
576 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
547 | |
577 | |
548 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
578 | 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); |
579 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
550 | |
580 | |
551 | my ($x, $y) = (0, 1); |
581 | my ($x, $y) = (0, 1); |
… | |
… | |
637 | } |
667 | } |
638 | |
668 | |
639 | sub map_scroll { |
669 | sub map_scroll { |
640 | my ($self, $dx, $dy) = @_; |
670 | my ($self, $dx, $dy) = @_; |
641 | |
671 | |
642 | $self->{map}->scroll ($dx, $dy); |
672 | $self->{map_widget}->scroll ($dx, $dy); |
643 | } |
673 | } |
644 | |
674 | |
645 | sub feed_map1a { |
675 | sub feed_map1a { |
646 | my ($self, $data) = @_; |
676 | my ($self, $data) = @_; |
647 | |
677 | |
… | |
… | |
651 | for my $tile (@$missing) { |
681 | for my $tile (@$missing) { |
652 | next if $self->{delay}{$tile}; |
682 | next if $self->{delay}{$tile}; |
653 | |
683 | |
654 | $delay = 1; |
684 | $delay = 1; |
655 | |
685 | |
656 | if (my $tex = $::CONN->{texture}[$tile]) { |
686 | if (my $tex = $self->{texture}[$tile]) { |
657 | $tex->upload; |
687 | $tex->upload; |
658 | } else { |
688 | } else { |
659 | $self->{delay}{$tile} = 1; |
689 | $self->{delay}{$tile} = 1; |
660 | |
690 | |
661 | # we assume the face is in-flight and will eventually come |
691 | # we assume the face is in-flight and will eventually arrive |
662 | push @{$self->{tile_cb}{$tile}}, sub { |
692 | push @{$self->{tile_cb}{$tile}}, sub { |
663 | delete $self->{delay}{$tile}; |
693 | delete $self->{delay}{$tile}; |
664 | $_[0]->upload; |
694 | $_[0]->upload; |
665 | }; |
695 | }; |
666 | } |
696 | } |
667 | } |
697 | } |
668 | |
698 | |
669 | if ($delay) { |
699 | if ($delay) { |
670 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
700 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
671 | EV::once undef, 0, 0.03, sub { |
701 | EV::once undef, 0, 0.03, sub { |
672 | $self->{map_widget}->update |
702 | $self->{map_widget}->update |
673 | if $self->{map_widget}; |
703 | if $self->{map_widget}; |
674 | }; |
704 | }; |
675 | } else { |
705 | } else { |
… | |
… | |
684 | } |
714 | } |
685 | |
715 | |
686 | sub flush_map { |
716 | sub flush_map { |
687 | my ($self) = @_; |
717 | my ($self) = @_; |
688 | |
718 | |
689 | my $map_info = delete $self->{map_info} |
719 | return unless $self->{map_info}; |
690 | or return; |
|
|
691 | |
720 | |
|
|
721 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
692 | my ($hash, $x, $y, $w, $h) = @$map_info; |
722 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
693 | |
723 | |
694 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
724 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
695 | $self->{map_cache_new}{$hash} = \$data; |
725 | |
|
|
726 | if ($data ne $$rdata) { |
|
|
727 | $map_info->[1] = \$data; |
|
|
728 | my $cdata = Compress::LZF::compress $data; |
696 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
729 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
730 | } |
|
|
731 | } |
697 | } |
732 | } |
698 | |
733 | |
699 | sub map_clear { |
734 | sub map_clear { |
700 | my ($self) = @_; |
735 | my ($self) = @_; |
701 | |
736 | |
702 | $self->flush_map; |
737 | $self->flush_map; |
|
|
738 | delete $self->{map_info}; |
703 | delete $self->{neigh_map}; |
739 | delete $self->{neigh_map}; |
704 | |
740 | |
705 | $self->{map}->clear; |
741 | $self->{map}->clear; |
706 | delete $self->{map_widget}{magicmap}; |
742 | delete $self->{map_widget}{magicmap}; |
707 | } |
743 | } |
… | |
… | |
728 | |
764 | |
729 | $self->bg_fetch; |
765 | $self->bg_fetch; |
730 | }; |
766 | }; |
731 | } |
767 | } |
732 | |
768 | |
733 | sub load_map($$$) { |
769 | sub load_map($$$$$$) { |
734 | my ($self, $hash, $x, $y) = @_; |
770 | my ($self, $hash, $x, $y, $w, $h) = @_; |
735 | |
771 | |
736 | my $gen = $self->{map_change_gen}; |
772 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
737 | |
773 | |
738 | my $cb = sub { |
774 | my $cb = sub { |
739 | return unless $gen == $self->{map_change_gen}; |
775 | $map_info->[1] = \$_[0]; |
740 | |
776 | |
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} || [] }; |
777 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
749 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
778 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
750 | $self->bg_fetch unless $inprogress; |
779 | $self->bg_fetch unless $inprogress; |
751 | } |
|
|
752 | }; |
780 | }; |
753 | |
781 | |
754 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
782 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
755 | $cb->($$rdata); |
783 | $cb->(${ $map_info->[1] }); |
756 | } else { |
784 | } else { |
|
|
785 | my $gen = $self->{map_change_gen}; |
|
|
786 | |
757 | DC::DB::get $self->{mapcache} => $hash, $cb; |
787 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
788 | return unless $gen == $self->{map_change_gen}; |
|
|
789 | return unless defined $_[0]; |
|
|
790 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
791 | }; |
758 | } |
792 | } |
759 | } |
793 | } |
760 | |
794 | |
761 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
795 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
762 | # (server resource,s latency, bandwidth), so this hack is warranted. |
796 | # (server resources, latency, bandwidth), so this hack is warranted. |
763 | # the right fix is to make real tiled maps with an overview file |
797 | # the right fix is to make real tiled maps with an overview file |
764 | sub send_mapinfo { |
798 | sub send_mapinfo { |
765 | my ($self, $data, $cb) = @_; |
799 | my ($self, $data, $cb) = @_; |
766 | |
800 | |
767 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
801 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
792 | } |
826 | } |
793 | |
827 | |
794 | # this method does a "flood fill" into every tile direction |
828 | # this method does a "flood fill" into every tile direction |
795 | # it assumes that tiles are arranged in a rectangular grid, |
829 | # 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. |
830 | # 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 |
831 | # failure to comply is harmless and results in display errors |
798 | # at worst. |
832 | # at worst. |
799 | sub flood_fill { |
833 | sub flood_fill { |
800 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
834 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
801 | |
835 | |
802 | # the server does not allow map paths > 6 |
836 | # the server does not allow map paths > 6 |
… | |
… | |
838 | return if $mode ne "spatial"; |
872 | return if $mode ne "spatial"; |
839 | |
873 | |
840 | $x += $self->{map}->ox; |
874 | $x += $self->{map}->ox; |
841 | $y += $self->{map}->oy; |
875 | $y += $self->{map}->oy; |
842 | |
876 | |
843 | $self->load_map ($hash, $x, $y) |
877 | $self->load_map ($hash, $x, $y, $w, $h) |
844 | unless $self->{neigh_map}{$hash}[5]++;#d# |
878 | unless $self->{neigh_map}{$hash}[5]++;#d# |
845 | |
879 | |
846 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
880 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
847 | |
881 | |
848 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
882 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
856 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
890 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
857 | |
891 | |
858 | $self->flush_map; |
892 | $self->flush_map; |
859 | |
893 | |
860 | ++$self->{map_change_gen}; |
894 | ++$self->{map_change_gen}; |
861 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
895 | $self->{map_cache_old} = delete $self->{map_cache}; |
862 | |
896 | |
863 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
897 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
864 | |
898 | |
865 | my $mapmapw = $self->{mapmap}->{w}; |
899 | my $mapmapw = $self->{mapmap}->{w}; |
866 | my $mapmaph = $self->{mapmap}->{h}; |
900 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
878 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
912 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
879 | |
913 | |
880 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
914 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
881 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
915 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
882 | |
916 | |
883 | $self->load_map ($hash, $x, $y); |
917 | $self->load_map ($hash, $x, $y, $w, $h); |
884 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
918 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
885 | } |
919 | } |
886 | |
920 | |
887 | sub face_find { |
921 | sub face_find { |
888 | my ($self, $facenum, $face, $cb) = @_; |
922 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
1088 | |
1122 | |
1089 | ## try to create single paragraphs of multiple lines sent by the server |
1123 | ## try to create single paragraphs of multiple lines sent by the server |
1090 | # no longer neecssary with TRT servers |
1124 | # no longer neecssary with TRT servers |
1091 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1125 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1092 | |
1126 | |
1093 | for (split /\n/, $text) { |
|
|
1094 | ::message ({ |
1127 | ::message ({ |
1095 | fg => $fg, |
1128 | fg => $fg, |
1096 | markup => $_, |
1129 | markup => $text, |
1097 | type => $type, |
1130 | type => $type, |
1098 | extra => [@extra], |
1131 | extra => [@extra], |
1099 | color_flags => $color, #d# ugly, kill |
1132 | color_flags => $color, #d# ugly, kill |
1100 | }); |
1133 | }); |
1101 | |
1134 | |
1102 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1135 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1103 | # actually, this is an ugly design. _we_ should control the channels, |
1136 | # # actually, this is an ugly design. _we_ should control the channels, |
1104 | # not some random other widget, as the channels are clearly protocol-specific. |
1137 | # # 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 |
1138 | # # then we could also react to flags such as CLEAR without resorting to |
1106 | # hacks such as color_flags, above. |
1139 | # # hacks such as color_flags, above. |
1107 | } |
|
|
1108 | |
1140 | |
1109 | $self->{statusbox}->add ($text, |
1141 | $self->{statusbox}->add ($text, |
1110 | group => $text, |
1142 | group => $text, |
1111 | fg => $fg, |
1143 | fg => $fg, |
1112 | timeout => $color >= 2 ? 180 : 10, |
1144 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1360 | |
1392 | |
1361 | $self->update_server_info; |
1393 | $self->update_server_info; |
1362 | |
1394 | |
1363 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1395 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1364 | $self->send_command ("pickup $::CFG->{pickup}"); |
1396 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
1397 | |
|
|
1398 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1399 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
1365 | } |
1400 | } |
1366 | |
1401 | |
1367 | sub lookat { |
1402 | sub lookat { |
1368 | my ($self, $x, $y) = @_; |
1403 | my ($self, $x, $y) = @_; |
1369 | |
1404 | |
… | |
… | |
1533 | } |
1568 | } |
1534 | |
1569 | |
1535 | sub send { |
1570 | sub send { |
1536 | my ($self, $msg) = @_; |
1571 | my ($self, $msg) = @_; |
1537 | |
1572 | |
1538 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1573 | $self->{textview}->add_paragraph ({ |
|
|
1574 | markup => |
|
|
1575 | "\n<span foreground='#ffff00'><b>" |
|
|
1576 | . (DC::asxml $msg) |
|
|
1577 | . "</b></span>" |
|
|
1578 | }); |
1539 | $self->{textview}->scroll_to_bottom; |
1579 | $self->{textview}->scroll_to_bottom; |
1540 | |
1580 | |
1541 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1581 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1542 | } |
1582 | } |
1543 | |
1583 | |