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.10 by root, Mon Jul 23 21:02:50 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, 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}
5 20
6our %MUSIC_QUEUE; 21our %MUSIC_QUEUE;
7 22
8our $MUSIC_SCHEDULER = cf::async_ext { 23our $MUSIC_SCHEDULER = cf::async_ext {
9 while () { 24 while () {
10 for (keys %MUSIC_QUEUE) { 25 for (keys %MUSIC_QUEUE) {
11 delete $MUSIC_QUEUE{$_}; 26 delete $MUSIC_QUEUE{$_};
27
28 cf::get_slot 0.01, -10, "music scheduler";
29
12 my $pl = cf::player::find_active $_ 30 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
36 my $faces;
37
38 # 1. update map-specific music info
39 unless (exists $map->{music_faces}) {
40 $map->{music_faces} = parse_facelist "music/", $map->{music};
41 }
42
43 my $faces = $map->{music_faces};
44
45 # 2. fall back to region if no map-specific music
46 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 }
63
64 $faces
13 or next; 65 or next;
14 66
15 my $map = $pl->ob->map 67 my $facestr = join ",", @$faces;
68 $ns->{current_music_faces} ne $facestr
16 or next; 69 or next;
17 70
18 # 1. update map-specific music info 71 $ns->{current_music_faces} = $facestr;
19 unless (exists $map->{music}) {
20 72
73 my $msg = {
74 play => $faces,
21 } 75 };
22 76
23 # 2. fall back to region if no map-specific music 77 my $pri = 0;
24 unless ($map->{music}) { 78 push @{$msg->{faces}}, [$_, $pri++, cf::face::get_chksum $_]
25 } 79 for grep $ns->must_send_face ($_), @$faces;
26 80
27 cf::cede_to_tick; 81 $ns->ext_msg (music => %$msg);
28 } 82 }
29 Coro::schedule unless %MUSIC_QUEUE; 83 Coro::schedule unless %MUSIC_QUEUE;
30 } 84 }
31}; 85};
32 86

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines