… | |
… | |
48 | sort { (length $a) <=> (length $b) } |
48 | sort { (length $a) <=> (length $b) } |
49 | @args |
49 | @args |
50 | } sort { $a->{par} <=> $b->{par} } |
50 | } sort { $a->{par} <=> $b->{par} } |
51 | CFPlus::Pod::find command => "*"; |
51 | CFPlus::Pod::find command => "*"; |
52 | |
52 | |
53 | $self->connect_ext (music => sub { |
53 | $self->connect_ext (ambient_music => sub { |
54 | my ($ev) = @_; |
54 | my ($songs) = @_; |
55 | |
55 | &::audio_music_set_ambient ($songs); |
56 | &::audio_music_set ($self->{songs} = $ev->{play}) |
|
|
57 | if $ev->{play}; |
|
|
58 | }); |
56 | }); |
59 | |
57 | |
60 | $self->connect_ext (capabilities => sub { |
58 | $self->connect_ext (capabilities => sub { |
61 | my (%cap) = @_; |
59 | my (%cap) = @_; |
|
|
60 | |
|
|
61 | #$self->send ("setup sound 0"); # we use a different protocol |
62 | |
62 | |
63 | $self->send_exti_msg (fx_want => { |
63 | $self->send_exti_msg (fx_want => { |
64 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
64 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
65 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
65 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
66 | }); |
66 | }); |
… | |
… | |
733 | |
733 | |
734 | CFPlus::DB::get tilecache => $id, $cb; |
734 | CFPlus::DB::get tilecache => $id, $cb; |
735 | |
735 | |
736 | } elsif ($face->{type} & 1) { # with metadata |
736 | } elsif ($face->{type} & 1) { # with metadata |
737 | #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
737 | #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
738 | CFPlus::DB::get "res-metadata" => $face->{name}, $cb; |
738 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
739 | } |
739 | } |
740 | } |
740 | } |
741 | |
741 | |
742 | sub face_update { |
742 | sub face_update { |
743 | my ($self, $facenum, $face, $changed) = @_; |
743 | my ($self, $facenum, $face, $changed) = @_; |
… | |
… | |
756 | $self->{music_meta}{$facenum} = $face; |
756 | $self->{music_meta}{$facenum} = $face; |
757 | |
757 | |
758 | ::message ({ markup => "downloaded song #$facenum" }) |
758 | ::message ({ markup => "downloaded song #$facenum" }) |
759 | if $changed; |
759 | if $changed; |
760 | |
760 | |
761 | &::audio_music_set ($self->{songs}); |
761 | &::audio_music_push ($facenum); |
|
|
762 | }; |
|
|
763 | } elsif ($face->{type} == 5) { # FT_SOUND |
|
|
764 | $cb = sub { |
|
|
765 | $self->{sound_meta}{$facenum} = $face; |
|
|
766 | |
|
|
767 | ::message ({ markup => "downloaded sound #$facenum" }) |
|
|
768 | if $changed; |
|
|
769 | |
|
|
770 | &::audio_sound_push ($facenum); |
762 | }; |
771 | }; |
763 | } |
772 | } |
764 | |
773 | |
765 | if ($changed) { # new data |
774 | if ($changed) { # new data |
766 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
775 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
767 | my $path = CFPlus::DB::path_of_res $face->{name}; |
|
|
768 | |
776 | |
769 | CFPlus::DB::write_file $path, $data, sub { |
777 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
770 | CFPlus::DB::put "res-metadata" => $face->{name} => $meta_json, sub { |
778 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { |
771 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
779 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
772 | $face->{path} = $path; |
|
|
773 | |
|
|
774 | $cb->(); |
780 | $cb->(); |
775 | }; |
|
|
776 | }; |
781 | }; |
|
|
782 | |
777 | } else { |
783 | } else { |
778 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
784 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
779 | $cb->(); |
785 | $cb->(); |
780 | } |
786 | } |
781 | } |
787 | } |
… | |
… | |
813 | @{$self->{face_cb}{$id}}; |
819 | @{$self->{face_cb}{$id}}; |
814 | } |
820 | } |
815 | } |
821 | } |
816 | |
822 | |
817 | sub sound_play { |
823 | sub sound_play { |
818 | my ($self, $x, $y, $soundnum, $type) = @_; |
824 | my ($self, $type, $face, $dx, $dy, $vol) = @_; |
819 | |
825 | |
820 | $self->{sound_play}->($x, $y, $soundnum, $type); |
826 | &::audio_sound_play ($face, $dx, $dy, $vol) |
|
|
827 | unless $type & 1; # odd types are silent for future expansion |
821 | } |
828 | } |
822 | |
829 | |
823 | my $LAST_QUERY; # server is stupid, stupid, stupid |
830 | my $LAST_QUERY; # server is stupid, stupid, stupid |
824 | |
831 | |
825 | sub query { |
832 | sub query { |
… | |
… | |
890 | $self->{$type} = $text; |
897 | $self->{$type} = $text; |
891 | } else { |
898 | } else { |
892 | $self->logprint ("msg: ", $text); |
899 | $self->logprint ("msg: ", $text); |
893 | return if $color < 0; # negative color == ignore if not understood |
900 | return if $color < 0; # negative color == ignore if not understood |
894 | |
901 | |
895 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
902 | my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; |
896 | |
903 | |
897 | ## try to create single paragraphs of multiple lines sent by the server |
904 | ## try to create single paragraphs of multiple lines sent by the server |
898 | # no longer neecssary with TRT servers |
905 | # no longer neecssary with TRT servers |
899 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
906 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
900 | |
907 | |
… | |
… | |
961 | my ($self) = @_; |
968 | my ($self) = @_; |
962 | |
969 | |
963 | $self->{map_widget}->clr_commands; |
970 | $self->{map_widget}->clr_commands; |
964 | |
971 | |
965 | ::stop_game (); |
972 | ::stop_game (); |
966 | } |
|
|
967 | |
|
|
968 | sub image_info { |
|
|
969 | my ($self, $numfaces) = @_; |
|
|
970 | |
|
|
971 | $self->{num_faces} = $numfaces; |
|
|
972 | $self->{face_prefetch} = [1 .. $numfaces]; |
|
|
973 | $self->face_prefetch; |
|
|
974 | } |
|
|
975 | |
|
|
976 | sub face_prefetch { |
|
|
977 | my ($self) = @_; |
|
|
978 | |
|
|
979 | return unless $::CFG->{face_prefetch}; |
|
|
980 | |
|
|
981 | if ($self->{num_faces}) { |
|
|
982 | return if @{ $self->{send_queue} || [] }; |
|
|
983 | my $todo = @{ $self->{face_prefetch} } |
|
|
984 | or return; |
|
|
985 | |
|
|
986 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
|
|
987 | |
|
|
988 | $self->send ("requestinfo image_sums $face $face"); |
|
|
989 | |
|
|
990 | $self->{statusbox}->add (CFPlus::asxml "prefetching $todo", |
|
|
991 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
|
|
992 | } elsif (!exists $self->{num_faces}) { |
|
|
993 | $self->send ("requestinfo image_info"); |
|
|
994 | |
|
|
995 | $self->{num_faces} = 0; |
|
|
996 | |
|
|
997 | $self->{statusbox}->add (CFPlus::asxml "starting to prefetch", |
|
|
998 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
|
|
999 | } |
|
|
1000 | } |
973 | } |
1001 | |
974 | |
1002 | sub update_floorbox { |
975 | sub update_floorbox { |
1003 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
976 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
1004 | return unless $::CONN; |
977 | return unless $::CONN; |