ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/player-env.ext
Revision: 1.15
Committed: Wed Sep 19 21:56:30 2007 UTC (16 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81, rel-2_80, rel-2_6, rel-2_7, rel-2_4, rel-2_5, rel-2_3, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_54, rel-2_55, rel-2_56, rel-2_79, rel-2_52, rel-2_53, rel-2_32, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61, rel-2_43, rel-2_42, rel-2_41
Changes since 1.14: +2 -0 lines
Log Message:
name your coroutines

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 root 1.14 our %MUSIC_FACE_CACHE; # cleared by reload_facedata
23 root 1.2
24     our $MUSIC_SCHEDULER = cf::async_ext {
25 root 1.15 $Coro::current->{desc} = "music scheduler";
26    
27 root 1.2 while () {
28     for (keys %MUSIC_QUEUE) {
29     delete $MUSIC_QUEUE{$_};
30 root 1.4
31 root 1.9 cf::get_slot 0.01, -10, "music scheduler";
32 root 1.8
33 root 1.6 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 root 1.4
39 root 1.14 my $faces = $MUSIC_FACE_CACHE{$map} ||= do {
40     # 1. map-specific music info
41     parse_facelist "music/", $map->{music}
42     or do {
43     # 2. fall back to region if no map-specific music
44     my $rgn = $pl->ob->region
45     or next;
46    
47     my $par = $rgn;
48     while () {
49     last if exists $par->{music};
50     $par = $par->parent
51     or last;
52     }
53 root 1.3
54 root 1.14 parse_facelist "music/", $par->{music}
55 root 1.3 }
56 root 1.14 ;
57     };
58 root 1.2
59 root 1.4 $faces
60     or next;
61    
62     my $facestr = join ",", @$faces;
63     $ns->{current_music_faces} ne $facestr
64     or next;
65    
66     $ns->{current_music_faces} = $facestr;
67    
68 root 1.6 my $pri = 0;
69 root 1.11 $ns->send_face ($_, --$pri - 110)
70     for @$faces;
71     $ns->flush_fx;
72 root 1.4
73 root 1.13 $ns->ext_msg (ambient_music => $faces);
74 root 1.2 }
75     Coro::schedule unless %MUSIC_QUEUE;
76     }
77     };
78    
79 root 1.1 cf::player->attach (
80     on_region_change => sub {
81     my ($pl, $new, $old) = @_;
82    
83     $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname);
84 root 1.2
85     $MUSIC_QUEUE{$pl->ob->name} = undef;
86     $MUSIC_SCHEDULER->ready;
87     },
88     on_map_change => sub {
89     my ($pl, $new) = @_;
90    
91     $MUSIC_QUEUE{$pl->ob->name} = undef;
92     $MUSIC_SCHEDULER->ready;
93 root 1.1 },
94     );
95    
96