… | |
… | |
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 | |
|
|
56 | &::audio_music_set_ambient ($self->{songs} = $ev->{ambient}) |
55 | &::audio_music_set_ambient ($songs); |
57 | if $ev->{ambient}; |
|
|
58 | }); |
56 | }); |
59 | |
57 | |
60 | $self->connect_ext (capabilities => sub { |
58 | $self->connect_ext (capabilities => sub { |
61 | my (%cap) = @_; |
59 | my (%cap) = @_; |
62 | |
60 | |
63 | #$self->send ("setup sound 0"); # we use a different protocol |
61 | #$self->send ("setup sound 0"); # we use a different protocol |
64 | |
62 | $self->update_fx_want; |
65 | $self->send_exti_msg (fx_want => { |
|
|
66 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
|
|
67 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
|
|
68 | }); |
|
|
69 | |
63 | |
70 | if (my $ts = $cap{tileset}) { |
64 | if (my $ts = $cap{tileset}) { |
71 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
65 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
72 | $self->{tileset} = $default; |
66 | $self->{tileset} = $default; |
73 | $self->{tilesize} = $default->[3]; |
67 | $self->{tilesize} = $default->[3]; |
… | |
… | |
225 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
219 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
226 | |
220 | |
227 | $self |
221 | $self |
228 | } |
222 | } |
229 | |
223 | |
|
|
224 | sub update_fx_want { |
|
|
225 | my ($self) = @_; |
|
|
226 | |
|
|
227 | $self->send_exti_msg (fx_want => { |
|
|
228 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
|
|
229 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
|
|
230 | }); |
|
|
231 | } |
|
|
232 | |
230 | sub logprint { |
233 | sub logprint { |
231 | my ($self, @a) = @_; |
234 | my ($self, @a) = @_; |
232 | |
235 | |
233 | $self->{log_fh} ||= do { |
236 | CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; |
234 | my $path = "$Crossfire::VARDIR/log.$self->{host}"; |
|
|
235 | |
|
|
236 | open my $fh, ">>:utf8", $path |
|
|
237 | or die "Couldn't open logfile $path: $!"; |
|
|
238 | |
|
|
239 | $fh->autoflush (1); |
|
|
240 | |
|
|
241 | $fh; |
|
|
242 | }; |
|
|
243 | |
|
|
244 | my ($sec, $min, $hour, $mday, $mon, $year) = localtime time; |
|
|
245 | |
|
|
246 | my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
|
|
247 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec; |
|
|
248 | |
|
|
249 | print {$self->{log_fh}} "$ts ", @a, "\n"; |
|
|
250 | } |
237 | } |
251 | |
238 | |
252 | sub _stat_numdiff { |
239 | sub _stat_numdiff { |
253 | my ($self, $name, $old, $new) = @_; |
240 | my ($self, $name, $old, $new) = @_; |
254 | |
241 | |
… | |
… | |
519 | } |
506 | } |
520 | |
507 | |
521 | sub feed_map1a { |
508 | sub feed_map1a { |
522 | my ($self, $data) = @_; |
509 | my ($self, $data) = @_; |
523 | |
510 | |
524 | $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
511 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
|
|
512 | my $delay; |
|
|
513 | |
|
|
514 | for my $tile (@$missing) { |
|
|
515 | next if $self->{delay}{$tile}; |
|
|
516 | |
|
|
517 | $delay = 1; |
|
|
518 | |
|
|
519 | if (my $tex = $::CONN->{texture}[$tile]) { |
|
|
520 | $tex->upload; |
|
|
521 | } else { |
|
|
522 | $self->{delay}{$tile} = 1; |
|
|
523 | |
|
|
524 | # we assume the face is in-flight and will eventually come |
|
|
525 | push @{$self->{face_cb}{$tile}}, sub { |
|
|
526 | delete $self->{delay}{$tile}; |
|
|
527 | $_[0]->upload; |
|
|
528 | }; |
|
|
529 | } |
|
|
530 | } |
|
|
531 | |
|
|
532 | if ($delay) { |
|
|
533 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
|
|
534 | Event->timer (after => 0.03, cb => sub { |
|
|
535 | $_[0]->w->cancel; |
|
|
536 | $self->{map_widget}->update; |
|
|
537 | }); |
|
|
538 | } else { |
525 | $self->{map_widget}->update; |
539 | $self->{map_widget}->update; |
|
|
540 | } |
526 | } |
541 | } |
527 | |
542 | |
528 | sub magicmap { |
543 | sub magicmap { |
529 | my ($self, $w, $h, $x, $y, $data) = @_; |
544 | my ($self, $w, $h, $x, $y, $data) = @_; |
530 | |
545 | |
… | |
… | |
562 | do { |
577 | do { |
563 | $id = pop @{$self->{bg_fetch}} |
578 | $id = pop @{$self->{bg_fetch}} |
564 | or return; |
579 | or return; |
565 | } while $self->{texture}[$id]; |
580 | } while $self->{texture}[$id]; |
566 | |
581 | |
567 | CFPlus::DB::get tilecache => $id, sub { |
582 | CFPlus::DB::exists tilecache => $id, sub { |
568 | my ($data) = @_; |
583 | my ($exists) = @_; |
569 | |
584 | |
570 | return unless $self->{map}; # stop when destroyed |
585 | return unless $self->{map}; # stop when destroyed |
571 | |
586 | |
572 | $self->set_texture ($id => $data) |
587 | $self->have_tile ($id) |
573 | if defined $data; |
588 | if $exists; |
574 | |
589 | |
575 | $self->bg_fetch; |
590 | $self->bg_fetch; |
576 | }; |
591 | }; |
577 | } |
592 | } |
578 | |
593 | |
… | |
… | |
734 | $self->{map}->set_tileid ($facenum => $id); |
749 | $self->{map}->set_tileid ($facenum => $id); |
735 | |
750 | |
736 | CFPlus::DB::get tilecache => $id, $cb; |
751 | CFPlus::DB::get tilecache => $id, $cb; |
737 | |
752 | |
738 | } elsif ($face->{type} & 1) { # with metadata |
753 | } elsif ($face->{type} & 1) { # with metadata |
739 | #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
|
|
740 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
754 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
741 | } |
755 | } |
742 | } |
756 | } |
743 | |
757 | |
744 | sub face_update { |
758 | sub face_update { |
… | |
… | |
746 | |
760 | |
747 | if ($face->{type} == 0) { # FT_FACE |
761 | if ($face->{type} == 0) { # FT_FACE |
748 | CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
762 | CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
749 | if $changed; |
763 | if $changed; |
750 | |
764 | |
751 | $self->set_texture ($face->{id} => delete $face->{data}); |
765 | $self->have_tile ($face->{id}); |
752 | |
766 | |
753 | } elsif ($face->{type} & 1) { # split metadata |
767 | } elsif ($face->{type} & 1) { # split metadata |
754 | my $cb = sub { }; |
|
|
755 | |
|
|
756 | if ($face->{type} == 3) { # FT_MUSIC |
|
|
757 | $cb = sub { |
|
|
758 | $self->{music_meta}{$facenum} = $face; |
|
|
759 | |
|
|
760 | ::message ({ markup => "downloaded song #$facenum" }) |
|
|
761 | if $changed; |
|
|
762 | |
|
|
763 | &::audio_music_set_ambient ($self->{songs}); |
|
|
764 | }; |
|
|
765 | } elsif ($face->{type} == 5) { # FT_SOUND |
|
|
766 | $cb = sub { |
|
|
767 | $self->{sound_meta}{$facenum} = $face; |
|
|
768 | |
|
|
769 | ::message ({ markup => "downloaded sound #$facenum" }) |
|
|
770 | if $changed; |
|
|
771 | |
|
|
772 | &::audio_sound_push ($facenum); |
|
|
773 | }; |
|
|
774 | } |
|
|
775 | |
|
|
776 | if ($changed) { # new data |
768 | if ($changed) { # new data |
777 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
769 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
|
|
770 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
778 | |
771 | |
779 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
772 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
780 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { |
773 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { }; |
781 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
|
|
782 | $cb->(); |
|
|
783 | }; |
|
|
784 | |
|
|
785 | } else { |
774 | } else { |
786 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
775 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
787 | $cb->(); |
|
|
788 | } |
776 | } |
|
|
777 | |
|
|
778 | ::add_license ($face); |
|
|
779 | |
|
|
780 | if ($face->{type} == 3) { # FT_MUSIC |
|
|
781 | $self->{music_meta}{$facenum} = $face; |
|
|
782 | |
|
|
783 | ::message ({ markup => "downloaded song #$facenum" }) |
|
|
784 | if $changed; |
|
|
785 | |
|
|
786 | &::audio_music_push ($facenum); |
|
|
787 | } elsif ($face->{type} == 5) { # FT_SOUND |
|
|
788 | $self->{sound_meta}{$facenum} = $face; |
|
|
789 | |
|
|
790 | ::message ({ markup => "downloaded sound #$facenum" }) |
|
|
791 | if $changed; |
|
|
792 | |
|
|
793 | &::audio_sound_push ($facenum); |
|
|
794 | } |
|
|
795 | |
789 | } |
796 | } |
790 | } |
797 | } |
791 | |
798 | |
792 | sub smooth_update { |
799 | sub smooth_update { |
793 | my ($self, $facenum, $face) = @_; |
800 | my ($self, $facenum, $face) = @_; |
794 | |
801 | |
795 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
802 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
796 | } |
803 | } |
797 | |
804 | |
798 | sub set_texture { |
805 | sub have_tile { |
799 | my ($self, $id, $data) = @_; |
806 | my ($self, $tile) = @_; |
800 | |
807 | |
801 | return unless $self->{map}; |
808 | return unless $self->{map}; |
802 | |
809 | |
803 | $self->{texture}[$id] = my $tex = |
810 | my $tex = $self->{texture}[$tile] ||= |
804 | new_from_image CFPlus::Texture |
811 | new CFPlus::Texture |
805 | $data, minify => 1, mipmap => 1; |
812 | tile => $tile, minify => 1, mipmap => 1, delay => 1; |
806 | |
813 | |
807 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
808 | $self->{map_widget}->update; |
|
|
809 | |
|
|
810 | $_->() for @{(delete $self->{face_cb}{$id}) || []}; |
814 | $_->($tex) for @{(delete $self->{face_cb}{$tile}) || []}; |
811 | } |
815 | } |
812 | |
816 | |
813 | sub connect_face_update { |
817 | sub connect_face_update { |
814 | my ($self, $id, $cb) = @_; |
818 | my ($self, $id, $cb) = @_; |
815 | |
819 | |
… | |
… | |
1010 | } |
1014 | } |
1011 | |
1015 | |
1012 | $::FLOORBOX->add_at (@add); |
1016 | $::FLOORBOX->add_at (@add); |
1013 | }); |
1017 | }); |
1014 | |
1018 | |
1015 | $::WANT_REFRESH++; |
1019 | $::WANT_REFRESH->start; |
1016 | } |
1020 | } |
1017 | |
1021 | |
1018 | sub set_opencont { |
1022 | sub set_opencont { |
1019 | my ($conn, $tag, $name) = @_; |
1023 | my ($conn, $tag, $name) = @_; |
1020 | $conn->{open_container} = $tag; |
1024 | $conn->{open_container} = $tag; |