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.7 by root, Thu Jul 12 19:36:57 2007 UTC vs.
Revision 1.17 by root, Thu Apr 29 07:52:02 2010 UTC

11 11
12 #TODO, sort by size (smallest first...) 12 #TODO, sort by size (smallest first...)
13 [ 13 [
14 sort { (cf::face::get_data_size $a) <=> (cf::face::get_data_size $b) } 14 sort { (cf::face::get_data_size $a) <=> (cf::face::get_data_size $b) }
15 grep $_, 15 grep $_,
16 map +(cf::face::find "$prefix$_" or ((warn "unable to find music file $_"), undef)), 16 map +(cf::face::find "$prefix$_" or ((cf::error "unable to find music file $_"), undef)),
17 split /\s*,\s*/, $list 17 split /\s*,\s*/, $list
18 ] 18 ]
19} 19}
20 20
21our %MUSIC_QUEUE; 21our %MUSIC_QUEUE;
22our %MUSIC_FACE_CACHE; # cleared by reload_facedata
22 23
23our $MUSIC_SCHEDULER = cf::async_ext { 24our $MUSIC_SCHEDULER = cf::async_ext {
25 $Coro::current->{desc} = "music scheduler";
26
24 while () { 27 while () {
25 for (keys %MUSIC_QUEUE) { 28 for (keys %MUSIC_QUEUE) {
26 delete $MUSIC_QUEUE{$_}; 29 delete $MUSIC_QUEUE{$_};
30
31 cf::get_slot 0.01, -10, "music scheduler";
27 32
28 my $pl = cf::player::find_active $_ or next; 33 my $pl = cf::player::find_active $_ or next;
29 $pl->ob->active or next; 34 $pl->ob->active or next;
30 my $ns = $pl->ns or next; 35 my $ns = $pl->ns or next;
31 $ns->extcmd or next; 36 $ns->extcmd or next;
32 my $map = $pl->ob->map or next; 37 my $map = $pl->ob->map or next;
33 38
34 my $faces; 39 my $faces = delete $ns->{music_play_once};
40 $faces ||= $MUSIC_FACE_CACHE{$map} ||= do {
41 # 1. map-specific music info
42 parse_facelist "music/", $map->{music}
43 or do {
44 # 2. fall back to region if no map-specific music
45 my $rgn = $pl->ob->region
46 or next;
35 47
36 # 1. update map-specific music info 48 my $par = $rgn;
37 unless (exists $map->{music_faces}) { 49 while () {
38 $map->{music_faces} = parse_facelist "music/", $map->{music}; 50 last if exists $par->{music};
39 } 51 $par = $par->parent
52 or last;
53 }
40 54
41 my $faces = $map->{music_faces}; 55 parse_facelist "music/", $par->{music}
42
43 # 2. fall back to region if no map-specific music
44 unless ($faces) {
45 my $rgn = $pl->ob->region
46 or next;
47
48 unless (exists $rgn->{music_faces}) {
49 my $par = $rgn;
50 while () {
51 last if exists $par->{music};
52 $par = $par->parent
53 or last;
54 } 56 }
55
56 $rgn->{music_faces} = parse_facelist "music/", $par->{music};
57 } 57 ;
58
59 $faces = $rgn->{music_faces};
60 } 58 };
61 59
62 $faces 60 $faces
63 or next; 61 or next;
64 62
65 my $facestr = join ",", @$faces; 63 my $facestr = join ",", @$faces;
66 $ns->{current_music_faces} ne $facestr 64 $ns->{current_music_faces} ne $facestr
67 or next; 65 or next;
68 66
69 $ns->{current_music_faces} = $facestr; 67 $ns->{current_music_faces} = $facestr;
70 68
71 my $msg = { 69 my $pri = 0;
72 play => $faces, 70 $ns->send_face ($_, --$pri - 110)
73 }; 71 for @$faces;
72 $ns->flush_fx;
74 73
75 my $pri = 0;
76 push @{$msg->{faces}}, [$_, $pri++, cf::face::get_chksum $_]
77 for grep $ns->must_send_face ($_), @$faces;
78
79 $ns->ext_event (music => %$msg); 74 $ns->ext_msg (ambient_music => $faces);
80
81 cf::cede_to_tick;
82 } 75 }
83 Coro::schedule unless %MUSIC_QUEUE; 76 Coro::schedule unless %MUSIC_QUEUE;
84 } 77 }
85}; 78};
86 79
88 on_region_change => sub { 81 on_region_change => sub {
89 my ($pl, $new, $old) = @_; 82 my ($pl, $new, $old) = @_;
90 83
91 $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname); 84 $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname);
92 85
93 $MUSIC_QUEUE{$pl->ob->name} = undef; 86 undef $MUSIC_QUEUE{$pl->ob->name};
94 $MUSIC_SCHEDULER->ready; 87 $MUSIC_SCHEDULER->ready;
95 }, 88 },
96 on_map_change => sub { 89 on_map_change => sub {
97 my ($pl, $new) = @_; 90 my ($pl, $new) = @_;
98 91
99 $MUSIC_QUEUE{$pl->ob->name} = undef; 92 undef $MUSIC_QUEUE{$pl->ob->name};
100 $MUSIC_SCHEDULER->ready; 93 $MUSIC_SCHEDULER->ready;
101 }, 94 },
102); 95);
103 96
97sub play_music_once {
98 my ($pl, $music) = @_;
104 99
100 $pl->ns->{music_play_once} = parse_facelist "music/", $music;
101
102 undef $MUSIC_QUEUE{$pl->ob->name};
103 $MUSIC_SCHEDULER->ready;
104}
105

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines