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.15 by root, Wed Sep 19 21:56:30 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 5
6sub parse_facelist($$) {
7 my ($prefix, $list) = @_;
8
9 return undef
10 unless defined $list;
11
12 #TODO, sort by size (smallest first...)
13 [
14 sort { (cf::face::get_data_size $a) <=> (cf::face::get_data_size $b) }
15 grep $_,
16 map +(cf::face::find "$prefix$_" or ((warn "unable to find music file $_"), undef)),
17 split /\s*,\s*/, $list
18 ]
19}
20
6our %MUSIC_QUEUE; 21our %MUSIC_QUEUE;
22our %MUSIC_FACE_CACHE; # cleared by reload_facedata
7 23
8our $MUSIC_SCHEDULER = cf::async_ext { 24our $MUSIC_SCHEDULER = cf::async_ext {
25 $Coro::current->{desc} = "music scheduler";
26
9 while () { 27 while () {
10 for (keys %MUSIC_QUEUE) { 28 for (keys %MUSIC_QUEUE) {
11 delete $MUSIC_QUEUE{$_}; 29 delete $MUSIC_QUEUE{$_};
30
31 cf::get_slot 0.01, -10, "music scheduler";
32
12 my $pl = cf::player::find_active $_ 33 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
39 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
54 parse_facelist "music/", $par->{music}
55 }
56 ;
57 };
58
59 $faces
13 or next; 60 or next;
14 61
15 my $map = $pl->ob->map 62 my $facestr = join ",", @$faces;
63 $ns->{current_music_faces} ne $facestr
16 or next; 64 or next;
17 65
18 # 1. update map-specific music info 66 $ns->{current_music_faces} = $facestr;
19 unless (exists $map->{music}) {
20 67
21 } 68 my $pri = 0;
69 $ns->send_face ($_, --$pri - 110)
70 for @$faces;
71 $ns->flush_fx;
22 72
23 # 2. fall back to region if no map-specific music 73 $ns->ext_msg (ambient_music => $faces);
24 unless ($map->{music}) {
25 }
26
27 cf::cede_to_tick;
28 } 74 }
29 Coro::schedule unless %MUSIC_QUEUE; 75 Coro::schedule unless %MUSIC_QUEUE;
30 } 76 }
31}; 77};
32 78

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines