ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/player-env.ext
(Generate patch)

Comparing deliantra/server/ext/player-env.ext (file contents):
Revision 1.3 by root, Wed Jul 11 17:09:06 2007 UTC vs.
Revision 1.16 by root, Thu Apr 8 18:27:17 2010 UTC

7 my ($prefix, $list) = @_; 7 my ($prefix, $list) = @_;
8 8
9 return undef 9 return undef
10 unless defined $list; 10 unless defined $list;
11 11
12 #TODO 12 #TODO, sort by size (smallest first...)
13 [sort grep $_, map +(cf::face::find "$prefix$_"), split /\s*,\s*/, $list] 13 [
14 sort { (cf::face::get_data_size $a) <=> (cf::face::get_data_size $b) }
15 grep $_,
16 map +(cf::face::find "$prefix$_" or ((warn "unable to find music file $_"), undef)),
17 split /\s*,\s*/, $list
18 ]
14} 19}
15 20
16our %MUSIC_QUEUE; 21our %MUSIC_QUEUE;
22our %MUSIC_FACE_CACHE; # cleared by reload_facedata
17 23
18our $MUSIC_SCHEDULER = cf::async_ext { 24our $MUSIC_SCHEDULER = cf::async_ext {
25 $Coro::current->{desc} = "music scheduler";
26
19 while () { 27 while () {
20 for (keys %MUSIC_QUEUE) { 28 for (keys %MUSIC_QUEUE) {
21 delete $MUSIC_QUEUE{$_}; 29 delete $MUSIC_QUEUE{$_};
30
31 cf::get_slot 0.01, -10, "music scheduler";
32
22 my $pl = cf::player::find_active $_ 33 my $pl = cf::player::find_active $_ or next;
34 $pl->ob->active or next;
35 my $ns = $pl->ns or next;
36 $ns->extcmd or next;
37 my $map = $pl->ob->map or next;
38
39 my $faces = delete $ns->{music_play_once};
40 $faces ||= $MUSIC_FACE_CACHE{$map} ||= do {
41 # 1. map-specific music info
42 parse_facelist "music/", $map->{music}
43 or do {
44 # 2. fall back to region if no map-specific music
45 my $rgn = $pl->ob->region
46 or next;
47
48 my $par = $rgn;
49 while () {
50 last if exists $par->{music};
51 $par = $par->parent
52 or last;
53 }
54
55 parse_facelist "music/", $par->{music}
56 }
57 ;
58 };
59
60 $faces
23 or next; 61 or next;
24 62
25 my $faces; 63 my $facestr = join ",", @$faces;
26 64 $ns->{current_music_faces} ne $facestr
27 my $map = $pl->ob->map
28 or next; 65 or next;
29 66
30 # 1. update map-specific music info 67 $ns->{current_music_faces} = $facestr;
31 unless (exists $map->{music_faces}) {
32 $map->{music_faces} = parse_facelist "music/", $map->{music};
33 }
34 68
35 my $faces = $map->{music_faces}; 69 my $pri = 0;
70 $ns->send_face ($_, --$pri - 110)
71 for @$faces;
72 $ns->flush_fx;
36 73
37 # 2. fall back to region if no map-specific music 74 $ns->ext_msg (ambient_music => $faces);
38 unless ($faces) {
39 my $rgn = $pl->ob->region
40 or next;
41
42 unless (exists $rgn->{music_faces}) {
43 my $par = $rgn;
44 while () {
45 last if exists $par->{music};
46 $par = $par->parent
47 or last;
48 }
49
50 $rgn->{music_faces} = parse_facelist "music/", $par->{music};
51 }
52
53 $faces = $rgn->{music_faces};
54 }
55
56 warn "music for $pl is @$faces\n"
57 if $faces;
58
59 cf::cede_to_tick;
60 } 75 }
61 Coro::schedule unless %MUSIC_QUEUE; 76 Coro::schedule unless %MUSIC_QUEUE;
62 } 77 }
63}; 78};
64 79
66 on_region_change => sub { 81 on_region_change => sub {
67 my ($pl, $new, $old) = @_; 82 my ($pl, $new, $old) = @_;
68 83
69 $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname); 84 $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname);
70 85
71 $MUSIC_QUEUE{$pl->ob->name} = undef; 86 undef $MUSIC_QUEUE{$pl->ob->name};
72 $MUSIC_SCHEDULER->ready; 87 $MUSIC_SCHEDULER->ready;
73 }, 88 },
74 on_map_change => sub { 89 on_map_change => sub {
75 my ($pl, $new) = @_; 90 my ($pl, $new) = @_;
76 91
77 $MUSIC_QUEUE{$pl->ob->name} = undef; 92 undef $MUSIC_QUEUE{$pl->ob->name};
78 $MUSIC_SCHEDULER->ready; 93 $MUSIC_SCHEDULER->ready;
79 }, 94 },
80); 95);
81 96
97sub play_music_once {
98 my ($pl, $music) = @_;
82 99
100 $pl->ns->{music_play_once} = parse_facelist "music/", $music;
101
102 undef $MUSIC_QUEUE{$pl->ob->name};
103 $MUSIC_SCHEDULER->ready;
104}
105

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines