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.11 by root, Tue Jul 24 04:55:34 2007 UTC vs.
Revision 1.17 by root, Thu Apr 29 07:52:02 2010 UTC

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