ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/player-env.ext
Revision: 1.14
Committed: Thu Aug 30 08:34:40 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-2_2
Changes since 1.13: +18 -25 lines
Log Message:
the cfplus crashes were a result of overzealous face-nr caching inside the server

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