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.5 by root, Thu Jul 12 18:56:33 2007 UTC vs.
Revision 1.16 by root, Thu Apr 8 18:27:17 2010 UTC

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{$_};
27 my $pl = cf::player::find_active $_
28 or next;
29 30
30 my $ns = $pl->ns 31 cf::get_slot 0.01, -10, "music scheduler";
31 or next;
32 32
33 my $pl = cf::player::find_active $_ or next;
34 $pl->ob->active or next;
35 my $ns = $pl->ns or next;
33 $ns->extcmd 36 $ns->extcmd or next;
34 or next; 37 my $map = $pl->ob->map or next;
35 38
36 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;
37 47
38 my $map = $pl->ob->map 48 my $par = $rgn;
39 or next; 49 while () {
50 last if exists $par->{music};
51 $par = $par->parent
52 or last;
53 }
40 54
41 # 1. update map-specific music info
42 unless (exists $map->{music_faces}) {
43 $map->{music_faces} = parse_facelist "music/", $map->{music}; 55 parse_facelist "music/", $par->{music}
44 }
45
46 my $faces = $map->{music_faces};
47
48 # 2. fall back to region if no map-specific music
49 unless ($faces) {
50 my $rgn = $pl->ob->region
51 or next;
52
53 unless (exists $rgn->{music_faces}) {
54 my $par = $rgn;
55 while () {
56 last if exists $par->{music};
57 $par = $par->parent
58 or last;
59 } 56 }
60
61 $rgn->{music_faces} = parse_facelist "music/", $par->{music};
62 } 57 ;
63
64 $faces = $rgn->{music_faces};
65 } 58 };
66 59
67 $faces 60 $faces
68 or next; 61 or next;
69 62
70 my $facestr = join ",", @$faces; 63 my $facestr = join ",", @$faces;
71 $ns->{current_music_faces} ne $facestr 64 $ns->{current_music_faces} ne $facestr
72 or next; 65 or next;
73 66
74 $ns->{current_music_faces} = $facestr; 67 $ns->{current_music_faces} = $facestr;
75 68
76 my $msg = { 69 my $pri = 0;
77 faces => $faces, 70 $ns->send_face ($_, --$pri - 110)
78 }; 71 for @$faces;
72 $ns->flush_fx;
79 73
80 $msg->{chksum}{$_} = cf::face::get_chksum $_
81 for grep $ns->must_send_face ($_), @$faces;
82
83 $ns->ext_event (music => %$msg); 74 $ns->ext_msg (ambient_music => $faces);
84
85 cf::cede_to_tick;
86 } 75 }
87 Coro::schedule unless %MUSIC_QUEUE; 76 Coro::schedule unless %MUSIC_QUEUE;
88 } 77 }
89}; 78};
90 79
92 on_region_change => sub { 81 on_region_change => sub {
93 my ($pl, $new, $old) = @_; 82 my ($pl, $new, $old) = @_;
94 83
95 $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);
96 85
97 $MUSIC_QUEUE{$pl->ob->name} = undef; 86 undef $MUSIC_QUEUE{$pl->ob->name};
98 $MUSIC_SCHEDULER->ready; 87 $MUSIC_SCHEDULER->ready;
99 }, 88 },
100 on_map_change => sub { 89 on_map_change => sub {
101 my ($pl, $new) = @_; 90 my ($pl, $new) = @_;
102 91
103 $MUSIC_QUEUE{$pl->ob->name} = undef; 92 undef $MUSIC_QUEUE{$pl->ob->name};
104 $MUSIC_SCHEDULER->ready; 93 $MUSIC_SCHEDULER->ready;
105 }, 94 },
106); 95);
107 96
97sub play_music_once {
98 my ($pl, $music) = @_;
108 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