… | |
… | |
17 | split /\s*,\s*/, $list |
17 | split /\s*,\s*/, $list |
18 | ] |
18 | ] |
19 | } |
19 | } |
20 | |
20 | |
21 | our %MUSIC_QUEUE; |
21 | our %MUSIC_QUEUE; |
|
|
22 | our %MUSIC_FACE_CACHE; # cleared by reload_facedata |
22 | |
23 | |
23 | our $MUSIC_SCHEDULER = cf::async_ext { |
24 | our $MUSIC_SCHEDULER = cf::async_ext { |
|
|
25 | $Coro::current->{desc} = "music scheduler"; |
|
|
26 | |
24 | while () { |
27 | while () { |
25 | for (keys %MUSIC_QUEUE) { |
28 | for (keys %MUSIC_QUEUE) { |
26 | delete $MUSIC_QUEUE{$_}; |
29 | delete $MUSIC_QUEUE{$_}; |
|
|
30 | |
|
|
31 | cf::get_slot 0.01, -10, "music scheduler"; |
27 | |
32 | |
28 | my $pl = cf::player::find_active $_ or next; |
33 | my $pl = cf::player::find_active $_ or next; |
29 | $pl->ob->active or next; |
34 | $pl->ob->active or next; |
30 | my $ns = $pl->ns or next; |
35 | my $ns = $pl->ns or next; |
31 | $ns->extcmd or next; |
36 | $ns->extcmd or next; |
32 | my $map = $pl->ob->map or next; |
37 | my $map = $pl->ob->map or next; |
33 | |
38 | |
34 | my $faces; |
39 | my $faces = $MUSIC_FACE_CACHE{$map} ||= do { |
|
|
40 | # 1. map-specific music info |
|
|
41 | parse_facelist "music/", $map->{music} |
|
|
42 | or do { |
|
|
43 | # 2. fall back to region if no map-specific music |
|
|
44 | my $rgn = $pl->ob->region |
|
|
45 | or next; |
35 | |
46 | |
36 | # 1. update map-specific music info |
47 | my $par = $rgn; |
37 | unless (exists $map->{music_faces}) { |
48 | while () { |
38 | $map->{music_faces} = parse_facelist "music/", $map->{music}; |
49 | last if exists $par->{music}; |
39 | } |
50 | $par = $par->parent |
|
|
51 | or last; |
|
|
52 | } |
40 | |
53 | |
41 | my $faces = $map->{music_faces}; |
54 | parse_facelist "music/", $par->{music} |
42 | |
|
|
43 | # 2. fall back to region if no map-specific music |
|
|
44 | unless ($faces) { |
|
|
45 | my $rgn = $pl->ob->region |
|
|
46 | or next; |
|
|
47 | |
|
|
48 | unless (exists $rgn->{music_faces}) { |
|
|
49 | my $par = $rgn; |
|
|
50 | while () { |
|
|
51 | last if exists $par->{music}; |
|
|
52 | $par = $par->parent |
|
|
53 | or last; |
|
|
54 | } |
55 | } |
55 | |
|
|
56 | $rgn->{music_faces} = parse_facelist "music/", $par->{music}; |
|
|
57 | } |
56 | ; |
58 | |
|
|
59 | $faces = $rgn->{music_faces}; |
|
|
60 | } |
57 | }; |
61 | |
58 | |
62 | $faces |
59 | $faces |
63 | or next; |
60 | or next; |
64 | |
61 | |
65 | my $facestr = join ",", @$faces; |
62 | my $facestr = join ",", @$faces; |
66 | $ns->{current_music_faces} ne $facestr |
63 | $ns->{current_music_faces} ne $facestr |
67 | or next; |
64 | or next; |
68 | |
65 | |
69 | warn "MUSIC CHANGE <$ns->{current_music_faces}> <$facestr>\n";#d# |
|
|
70 | |
|
|
71 | $ns->{current_music_faces} = $facestr; |
66 | $ns->{current_music_faces} = $facestr; |
72 | |
67 | |
73 | my $msg = { |
68 | my $pri = 0; |
74 | play => $faces, |
69 | $ns->send_face ($_, --$pri - 110) |
75 | }; |
70 | for @$faces; |
|
|
71 | $ns->flush_fx; |
76 | |
72 | |
77 | my $pri = 0; |
|
|
78 | push @{$msg->{faces}}, [$_, $pri++, cf::face::get_chksum $_] |
|
|
79 | for grep $ns->must_send_face ($_), @$faces; |
|
|
80 | |
|
|
81 | $ns->ext_event (music => %$msg); |
73 | $ns->ext_msg (ambient_music => $faces); |
82 | |
|
|
83 | cf::cede_to_tick; |
|
|
84 | } |
74 | } |
85 | Coro::schedule unless %MUSIC_QUEUE; |
75 | Coro::schedule unless %MUSIC_QUEUE; |
86 | } |
76 | } |
87 | }; |
77 | }; |
88 | |
78 | |