ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/player-env.ext
Revision: 1.12
Committed: Tue Jul 31 00:56:58 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
Changes since 1.11: +1 -1 lines
Log Message:
rename music parameter

File Contents

# User Rev Content
1 root 1.1 #! perl # mandatory
2    
3     # this extension provides "environmental effects",
4     # meaning mostly background music and region messages right now.
5    
6 root 1.3 sub parse_facelist($$) {
7     my ($prefix, $list) = @_;
8    
9     return undef
10     unless defined $list;
11    
12 root 1.4 #TODO, sort by size (smallest first...)
13     [
14     sort { (cf::face::get_data_size $a) <=> (cf::face::get_data_size $b) }
15     grep $_,
16 root 1.5 map +(cf::face::find "$prefix$_" or ((warn "unable to find music file $_"), undef)),
17 root 1.4 split /\s*,\s*/, $list
18     ]
19 root 1.3 }
20    
21 root 1.2 our %MUSIC_QUEUE;
22    
23     our $MUSIC_SCHEDULER = cf::async_ext {
24     while () {
25     for (keys %MUSIC_QUEUE) {
26     delete $MUSIC_QUEUE{$_};
27 root 1.4
28 root 1.9 cf::get_slot 0.01, -10, "music scheduler";
29 root 1.8
30 root 1.6 my $pl = cf::player::find_active $_ or next;
31     $pl->ob->active or next;
32     my $ns = $pl->ns or next;
33     $ns->extcmd or next;
34     my $map = $pl->ob->map or next;
35 root 1.4
36 root 1.3 my $faces;
37    
38 root 1.2 # 1. update map-specific music info
39 root 1.3 unless (exists $map->{music_faces}) {
40     $map->{music_faces} = parse_facelist "music/", $map->{music};
41     }
42 root 1.2
43 root 1.3 my $faces = $map->{music_faces};
44 root 1.2
45     # 2. fall back to region if no map-specific music
46 root 1.3 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     }
57    
58     $rgn->{music_faces} = parse_facelist "music/", $par->{music};
59     }
60    
61     $faces = $rgn->{music_faces};
62 root 1.2 }
63    
64 root 1.4 $faces
65     or next;
66    
67     my $facestr = join ",", @$faces;
68     $ns->{current_music_faces} ne $facestr
69     or next;
70    
71     $ns->{current_music_faces} = $facestr;
72    
73 root 1.6 my $pri = 0;
74 root 1.11 $ns->send_face ($_, --$pri - 110)
75     for @$faces;
76     $ns->flush_fx;
77 root 1.4
78 root 1.12 $ns->ext_msg (music => { ambient => $faces });
79 root 1.2 }
80     Coro::schedule unless %MUSIC_QUEUE;
81     }
82     };
83    
84 root 1.1 cf::player->attach (
85     on_region_change => sub {
86     my ($pl, $new, $old) = @_;
87    
88     $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname);
89 root 1.2
90     $MUSIC_QUEUE{$pl->ob->name} = undef;
91     $MUSIC_SCHEDULER->ready;
92     },
93     on_map_change => sub {
94     my ($pl, $new) = @_;
95    
96     $MUSIC_QUEUE{$pl->ob->name} = undef;
97     $MUSIC_SCHEDULER->ready;
98 root 1.1 },
99     );
100    
101