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.2 by root, Wed Jul 11 16:26:26 2007 UTC vs.
Revision 1.3 by root, Wed Jul 11 17:09:06 2007 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
6sub parse_facelist($$) {
7 my ($prefix, $list) = @_;
8
9 return undef
10 unless defined $list;
11
12 #TODO
13 [sort grep $_, map +(cf::face::find "$prefix$_"), split /\s*,\s*/, $list]
14}
5 15
6our %MUSIC_QUEUE; 16our %MUSIC_QUEUE;
7 17
8our $MUSIC_SCHEDULER = cf::async_ext { 18our $MUSIC_SCHEDULER = cf::async_ext {
9 while () { 19 while () {
10 for (keys %MUSIC_QUEUE) { 20 for (keys %MUSIC_QUEUE) {
11 delete $MUSIC_QUEUE{$_}; 21 delete $MUSIC_QUEUE{$_};
12 my $pl = cf::player::find_active $_ 22 my $pl = cf::player::find_active $_
13 or next; 23 or next;
14 24
25 my $faces;
26
15 my $map = $pl->ob->map 27 my $map = $pl->ob->map
16 or next; 28 or next;
17 29
18 # 1. update map-specific music info 30 # 1. update map-specific music info
19 unless (exists $map->{music}) { 31 unless (exists $map->{music_faces}) {
20 32 $map->{music_faces} = parse_facelist "music/", $map->{music};
21 } 33 }
22 34
35 my $faces = $map->{music_faces};
36
23 # 2. fall back to region if no map-specific music 37 # 2. fall back to region if no map-specific music
24 unless ($map->{music}) { 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};
25 } 54 }
55
56 warn "music for $pl is @$faces\n"
57 if $faces;
26 58
27 cf::cede_to_tick; 59 cf::cede_to_tick;
28 } 60 }
29 Coro::schedule unless %MUSIC_QUEUE; 61 Coro::schedule unless %MUSIC_QUEUE;
30 } 62 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines