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.17 by root, Thu Apr 29 07:52:02 2010 UTC vs.
Revision 1.18 by root, Fri May 14 22:56:47 2010 UTC

1#! perl # mandatory 1#! perl # mandatory
2 2
3# this extension provides "environmental effects", 3# this extension provides "environmental effects",
4# meaning mostly background music and region messages right now. 4# meaning mostly background music and region messages right now.
5 5
6our %MUSIC_GROUP;
7
8sub reload {
9 cf::trace "loading music config from $DATADIR/music\n";
10
11 0 < Coro::AIO::aio_load "$DATADIR/music", my $data
12 or die "$DATADIR/music $!";
13
14 my $conf = JSON::XS->new->utf8->relaxed->decode ($data);
15 %MUSIC_GROUP = %{ $conf->{group} };
16}
17
18cf::post_init {
19 $_[0] ? cf::async { reload } : reload
20};
21
6sub parse_facelist($$) { 22sub parse_musiclist($) {
7 my ($prefix, $list) = @_; 23 my ($list) = @_;
8 24
9 return undef 25 return undef
10 unless defined $list; 26 unless defined $list;
11 27
12 #TODO, sort by size (smallest first...) 28 my @name = split /\s*,\s*/, $list;
29 my @face;
30
31 while (@name) {
32 my $name = shift @name;
33
34 if ($name =~ /^\@(.*)$/) {
35 my $group = $MUSIC_GROUP{$1}
36 or cf::error "music group $1 does not exist (referenced in '$list')";
37
38 unshift @name, @$group;
39 } else {
40 my $face = cf::face::find "music/$name"
41 or "unable to find music face $name (referenced in '$list')";
42
43 push @face, $face
44 if $face;
45 }
13 [ 46 }
47
48 # sort by size, smallest first, because it'S the fastest to download...
14 sort { (cf::face::get_data_size $a) <=> (cf::face::get_data_size $b) } 49 [ sort { (cf::face::get_data_size $a) <=> (cf::face::get_data_size $b) } @face ]
15 grep $_,
16 map +(cf::face::find "$prefix$_" or ((cf::error "unable to find music file $_"), undef)),
17 split /\s*,\s*/, $list
18 ]
19} 50}
20 51
21our %MUSIC_QUEUE; 52our %MUSIC_QUEUE;
22our %MUSIC_FACE_CACHE; # cleared by reload_facedata 53our %MUSIC_FACE_CACHE; # cleared by reload_facedata
23 54
37 my $map = $pl->ob->map or next; 68 my $map = $pl->ob->map or next;
38 69
39 my $faces = delete $ns->{music_play_once}; 70 my $faces = delete $ns->{music_play_once};
40 $faces ||= $MUSIC_FACE_CACHE{$map} ||= do { 71 $faces ||= $MUSIC_FACE_CACHE{$map} ||= do {
41 # 1. map-specific music info 72 # 1. map-specific music info
42 parse_facelist "music/", $map->{music} 73 parse_musiclist $map->{music}
43 or do { 74 or do {
44 # 2. fall back to region if no map-specific music 75 # 2. fall back to region if no map-specific music
45 my $rgn = $pl->ob->region 76 my $rgn = $pl->ob->region
46 or next; 77 or next;
47 78
50 last if exists $par->{music}; 81 last if exists $par->{music};
51 $par = $par->parent 82 $par = $par->parent
52 or last; 83 or last;
53 } 84 }
54 85
55 parse_facelist "music/", $par->{music} 86 parse_musiclist $par->{music}
56 } 87 }
57 ; 88 ;
58 }; 89 };
59 90
60 $faces 91 $faces
95); 126);
96 127
97sub play_music_once { 128sub play_music_once {
98 my ($pl, $music) = @_; 129 my ($pl, $music) = @_;
99 130
100 $pl->ns->{music_play_once} = parse_facelist "music/", $music; 131 $pl->ns->{music_play_once} = parse_musiclist $music;
101 132
102 undef $MUSIC_QUEUE{$pl->ob->name}; 133 undef $MUSIC_QUEUE{$pl->ob->name};
103 $MUSIC_SCHEDULER->ready; 134 $MUSIC_SCHEDULER->ready;
104} 135}
105 136

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines