ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/cfplus
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/cfplus (file contents):
Revision 1.191 by root, Sun Jul 29 21:31:48 2007 UTC vs.
Revision 1.198 by root, Tue Jul 31 02:45:39 2007 UTC

159our $STATWIDS; 159our $STATWIDS;
160 160
161our $SDL_ACTIVE; 161our $SDL_ACTIVE;
162our %SDL_CB; 162our %SDL_CB;
163 163
164our $ALT_ENTER_MESSAGE;
165our $STATUSBOX;
166our $DEBUG_STATUS;
167
168our $INV;
169our $INVR;
170our $INV_RIGHT_HB;
171
172our $PICKUP_CFG;
173
174#############################################################################
175
176sub status {
177 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
178}
179
180sub debug {
181 $DEBUG_STATUS->set_text ($_[0]);
182}
183
184sub message {
185 my ($para) = @_;
186 $MESSAGE_WINDOW->message ($para);
187}
188
189#############################################################################
190#TODO: maybe move into own audio module...
191
164our $SDL_MIXER; 192our $SDL_MIXER;
193
165our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; 194our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
166our @MUSIC_WANT; 195our $MUSIC_WANT; # arryref of ambient music we want to play
196our @MUSIC_HAVE; # ambient music we have on disk
167our $MUSIC_START; 197our $MUSIC_START;
198our @MUSIC_JINGLE; # which jingles to play next
168our $MUSIC_PLAYING_DATA; 199our $MUSIC_PLAYING_DATA;
169our $MUSIC_PLAYING_META; 200our $MUSIC_PLAYING_META;
170our $MUSIC_PLAYER; 201our $MUSIC_PLAYER;
171our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 202our $MUSIC_RESUME = 30; # resume music when played less than these many seconds before
172our @SOUNDS; # event => file mapping 203
173our %AUDIO_CHUNKS; # audio files 204our %AUDIO_CHUNK; # audio "files"
205our %AUDIO_PLAY; # which audio faces should be played
174 206
175our $ALT_ENTER_MESSAGE; 207sub audio_channel_finished {
176our $STATUSBOX; 208 my ($channel) = @_;
177our $DEBUG_STATUS;
178 209
179our $INV; 210# warn "channel $channel finished\n";#d#
180our $INVR;
181our $INV_RIGHT_HB;
182
183our $PICKUP_CFG;
184
185sub status {
186 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
187} 211}
188 212
189sub debug { 213sub audio_sound_push($) {
190 $DEBUG_STATUS->set_text ($_[0]);
191}
192
193sub message {
194 my ($para) = @_; 214 my ($face) = @_;
195 $MESSAGE_WINDOW->message ($para); 215
216 if (my $chunk = $AUDIO_CHUNK{$face}) {
217 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
218 my (undef, $dx, $dy, $vol) = @$_;
219
220 my $channel = CFPlus::Channel::find;
221 $channel->volume ($vol * 128 / 255);
222 $dx = $dx / 10 * 255;
223 $channel->set_panning (255 - $dx, 255 + $dx);
224
225# my $angle = $dx ? : $dx < 0 ?
226# my $distance = -$vol;
227# $channel->set_position ($angle, $distance);
228
229 $chunk->play ($channel);
230 }
231 } else {
232 # sound_meta not set means data is in flight either way
233 my $meta = $CONN->{sound_meta}{$face}
234 or return;
235
236 # if its a jingle, play it as ambient music
237 if ($meta->{meta}{jingle}) {
238 delete $AUDIO_PLAY{$face}; # take the jingle out of the sound queue
239 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
240 &audio_music_push ($face);
241 } else {
242 # fetch from database
243 CFPlus::DB::get res_data => $meta->{name}, sub {
244 my $rwops = new CFPlus::RW $_[0];
245 my $chunk = new CFPlus::MixChunk $rwops;
246 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
247 $AUDIO_CHUNK{$face} = $chunk;
248
249 audio_sound_push ($face);
250 };
251 }
252 }
196} 253}
254
255sub audio_sound_play {
256 my ($face, $dx, $dy, $vol) = @_;
257
258 $SDL_MIXER
259 or return;
260
261 my $queue = $AUDIO_PLAY{$face} ||= [];
262 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
263 audio_sound_push $face
264 unless @$queue > 1;
265}
266
267sub audio_music_update_volume {
268 return unless $MUSIC_PLAYING_META;
269 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1;
270 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume};
271 CFPlus::MixMusic::volume $base * $volume * 128;
272}
273
274sub audio_music_start {
275 my $meta = $MUSIC_PLAYING_META;
276
277 CFPlus::DB::get res_data => $meta->{name}, sub {
278 return unless $SDL_MIXER;
279
280 # music might have changed...
281 $meta eq $MUSIC_PLAYING_META
282 or return &audio_music_start ();
283
284 audio_music_update_volume;
285
286 $MUSIC_PLAYING_DATA = \$_[0];
287
288 my $rwops = $meta->{path}
289 ? new_from_file CFPlus::RW $meta->{path}
290 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
291
292 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
293 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
294
295 my $NOW = time;
296
297 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
298 my $pos = $MUSIC_PLAYING_META->{stop_pos};
299 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
300 $MUSIC_START = time - $pos;
301 } else {
302 $MUSIC_PLAYER->play (0);
303 $MUSIC_START = time;
304 }
305
306 delete $MUSIC_PLAYING_META->{stop_time};
307 delete $MUSIC_PLAYING_META->{stop_pos};
308 }
309}
310
311sub audio_music_push {
312 return unless $SDL_MIXER;
313
314 my $fade_out;
315
316 if (@MUSIC_JINGLE) {
317 @MUSIC_HAVE = $MUSIC_JINGLE[0];
318 $fade_out = 333;
319 } else {
320 return unless $CFG->{bgm_enable};
321
322 my @have =
323 grep $_,
324 map $CONN->{music_meta}{$_},
325 @$MUSIC_WANT;
326
327 @MUSIC_HAVE = @have
328 if @have;
329
330 # default MUSIC_HAVE == MUSIC_DEFAULT
331 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
332 $fade_out = 1000;
333 }
334
335 # if the currently playing song is acceptable, let it continue
336 return if $MUSIC_PLAYING_META
337 && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
338
339 my $NOW = time;
340
341 if ($MUSIC_PLAYING_META) {
342 $MUSIC_PLAYING_META->{stop_time} = $NOW;
343 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
344 CFPlus::MixMusic::fade_out $fade_out;
345 } else {
346 # sort by stop time, oldest first
347 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
348
349 # if the most recently-played piece played very recently,
350 # resume it, else choose the oldest piece for rotation.
351 $MUSIC_PLAYING_META =
352 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
353 ? $MUSIC_HAVE[-1]
354 : $MUSIC_HAVE[0];
355
356 audio_music_start;
357 }
358}
359
360sub audio_music_set_ambient {
361 my ($songs) = @_;
362
363 $MUSIC_WANT = $songs;
364 audio_music_push;
365}
366
367sub audio_music_finished {
368 # we compress multiple jingles of the same type
369 shift @MUSIC_JINGLE
370 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
371
372 undef $MUSIC_PLAYER;
373 undef $MUSIC_PLAYING_META;
374 undef $MUSIC_PLAYING_DATA;
375
376 audio_music_push;
377}
378
379sub audio_init {
380 if ($CFG->{audio_enable}) {
381 $ENV{MIX_EFFECTSMAXSPEED} = 1;
382 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
383
384 unless ($SDL_MIXER) {
385 status "Unable to open sound device: there will be no sound";
386 return;
387 }
388
389 CFPlus::Mix_AllocateChannels 16;
390
391 audio_music_finished;
392 } else {
393 undef $SDL_MIXER;
394 }
395}
396
397sub audio_shutdown {
398 undef $MUSIC_PLAYER;
399 undef $MUSIC_PLAYING_META;
400 undef $MUSIC_PLAYING_DATA;
401
402 $MUSIC_WANT = [];
403 @MUSIC_JINGLE = ();
404 %AUDIO_PLAY = ();
405 %AUDIO_CHUNK = ();
406
407 CFPlus::Mix_CloseAudio if $SDL_MIXER;
408 undef $SDL_MIXER;
409}
410
411#############################################################################
197 412
198sub destroy_query_dialog { 413sub destroy_query_dialog {
199 (delete $_[0]{query_dialog})->destroy 414 (delete $_[0]{query_dialog})->destroy
200 if $_[0]{query_dialog}; 415 if $_[0]{query_dialog};
201} 416}
481 $SETUP_DIALOG->show; 696 $SETUP_DIALOG->show;
482 $PL_WINDOW->hide; 697 $PL_WINDOW->hide;
483 $SPELL_LIST->clear_spells; 698 $SPELL_LIST->clear_spells;
484 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); 699 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
485 700
486 &audio_music_set ([]); 701 &audio_music_set_ambient ([]);
487 702
488 return unless $CONN; 703 return unless $CONN;
489 704
490 status "connection closed"; 705 status "connection closed";
491 706
648 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 863 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 }
649 ); 864 );
650 $hbox->add (new CFPlus::UI::Slider 865 $hbox->add (new CFPlus::UI::Slider
651 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 866 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
652 tooltip => "The volume of the background music. Changes are instant.", 867 tooltip => "The volume of the background music. Changes are instant.",
653 on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFPlus::MixMusic::volume $_[1] * 128; 0 } 868 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
654 ); 869 );
655 870
656 $table->add_at (1, $row++, new CFPlus::UI::Button 871 $table->add_at (1, $row++, new CFPlus::UI::Button
657 expand => 1, align => 0, text => "Apply", 872 expand => 1, align => 0, text => "Apply",
658 tooltip => "Apply the audio settings", 873 tooltip => "Apply the audio settings",
1071 text => $CFG->{profile}{default}{host}, 1286 text => $CFG->{profile}{default}{host},
1072 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", 1287 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
1073 on_changed => sub { 1288 on_changed => sub {
1074 my ($self, $value) = @_; 1289 my ($self, $value) = @_;
1075 $CFG->{profile}{default}{host} = $value; 1290 $CFG->{profile}{default}{host} = $value;
1076 0 1291 1
1077 } 1292 }
1078 ); 1293 );
1079 1294
1080 $vbox->add (new CFPlus::UI::Button 1295 $vbox->add (new CFPlus::UI::Button
1081 expand => 1, 1296 expand => 1,
1082 text => "Server List", 1297 text => "Server List",
1083 other => $METASERVER, 1298 other => $METASERVER,
1084 tooltip => "Show a list of available crossfire servers", 1299 tooltip => "Show a list of available crossfire servers",
1085 on_activate => sub { $METASERVER->toggle_visibility; 0 }, 1300 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1086 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 0 }, 1301 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1087 ); 1302 );
1088 } 1303 }
1089 1304
1090 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username"); 1305 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username");
1091 $table->add_at (1, 4, new CFPlus::UI::Entry 1306 $table->add_at (1, 4, new CFPlus::UI::Entry
1092 text => $CFG->{profile}{default}{user}, 1307 text => $CFG->{profile}{default}{user},
1093 tooltip => "The name of your character on the server", 1308 tooltip => "The name of your character on the server",
1094 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value } 1309 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 }
1095 ); 1310 );
1096 1311
1097 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password"); 1312 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password");
1098 $table->add_at (1, 5, new CFPlus::UI::Entry 1313 $table->add_at (1, 5, new CFPlus::UI::Entry
1099 text => $CFG->{profile}{default}{password}, 1314 text => $CFG->{profile}{default}{password},
1100 hidden => 1, 1315 hidden => 1,
1101 tooltip => "The password for your character", 1316 tooltip => "The password for your character",
1102 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value } 1317 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value; 1 }
1103 ); 1318 );
1104 1319
1105 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); 1320 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size");
1106 $table->add_at (1, 7, new CFPlus::UI::Slider 1321 $table->add_at (1, 7, new CFPlus::UI::Slider
1107 force_w => 100, 1322 force_w => 100,
1108 range => [$CFG->{mapsize}, 10, 100, 0, 1], 1323 range => [$CFG->{mapsize}, 10, 100, 0, 1],
1109 tooltip => "This is the size of the portion of the map update the server sends you. " 1324 tooltip => "This is the size of the portion of the map update the server sends you. "
1110 . "If you set this to a high value you will be able to see further, " 1325 . "If you set this to a high value you will be able to see further, "
1111 . "but you also increase bandwidth requirements and latency. " 1326 . "but you also increase bandwidth requirements and latency. "
1112 . "This option is only used once at log-in.", 1327 . "This option is only used once at log-in.",
1113 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, 1328 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 },
1114 ); 1329 );
1115 1330
1116 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); 1331 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1117 $table->add_at (1, 8, new CFPlus::UI::Entry 1332 $table->add_at (1, 8, new CFPlus::UI::Entry
1118 text => $CFG->{output_rate}, 1333 text => $CFG->{output_rate},
1119 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " 1334 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1120 . "when sending images, to ensure interactiveness. When 0 or unset, the server " 1335 . "when sending data. When 0 or unset, the server "
1121 . "default will be used, which is usually around 100kb/s.", 1336 . "default will be used, which is usually around 100kb/s. Most servers will "
1337 . "dynamically find an optimal rate, so adjust this only when necessary.",
1122 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, 1338 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1123 ); 1339 );
1124 1340
1125 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); 1341 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1126 $table->add_at (1, 9, new CFPlus::UI::Entry 1342 $table->add_at (1, 9, new CFPlus::UI::Entry
1127 text => $CFG->{output_count}, 1343 text => $CFG->{output_count},
1128 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1344 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1129 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1345 on_changed => sub { $CFG->{output_count} = $_[1]; 1 },
1130 ); 1346 );
1131 1347
1132 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1348 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1133 $table->add_at (1, 10, new CFPlus::UI::Entry 1349 $table->add_at (1, 10, new CFPlus::UI::Entry
1134 text => $CFG->{output_sync}, 1350 text => $CFG->{output_sync},
1135 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1351 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1136 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1352 on_changed => sub { $CFG->{output_sync} = $_[1]; 1 },
1137 ); 1353 );
1138 1354
1139 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button 1355 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1140 expand => 1, 1356 expand => 1,
1141 align => 0, 1357 align => 0,
1142 text => "Login", 1358 text => "Login",
1143 on_activate => sub { 1359 on_activate => sub {
1144 $CONN ? stop_game 1360 $CONN ? stop_game
1145 : start_game; 1361 : start_game;
1146 0 1362 1
1147 }, 1363 },
1148 ); 1364 );
1149 1365
1150 $vbox->add (new CFPlus::UI::FancyFrame 1366 $vbox->add (new CFPlus::UI::FancyFrame
1151 label => "Server Info", 1367 label => "Server Info",
1786 CFPlus::OpenGL::shutdown; 2002 CFPlus::OpenGL::shutdown;
1787 2003
1788 undef $SDL_ACTIVE; 2004 undef $SDL_ACTIVE;
1789} 2005}
1790 2006
1791sub audio_channel_finished {
1792 my ($channel) = @_;
1793
1794# warn "channel $channel finished\n";#d#
1795}
1796
1797our %AUDIO_PLAY;
1798our %AUDIO_CHUNK;
1799
1800sub audio_sound_push($) {
1801 my ($face) = @_;
1802
1803 if (my $chunk = $AUDIO_CHUNK{$face}) {
1804 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
1805 my (undef, $dx, $dy, $vol) = @$_;
1806
1807 my $channel = $chunk->play
1808 or return;
1809
1810 $channel->volume (128 + $vol);
1811 $dx = $dx / 10 * 255;
1812 $channel->set_panning ((min 255, 255 - $dx), (min 255, 255 + $dx));
1813# my $angle = $dx ? : $dx < 0 ?
1814# my $distance = -$vol;
1815# $channel->set_position ($angle, $distance);
1816 }
1817 } else {
1818 # sound_meta not set means data is in flight either way
1819 my $meta = $CONN->{sound_meta}{$face}
1820 or return;
1821
1822 # fetch from database
1823 CFPlus::DB::get res_data => $meta->{name}, sub {
1824 my $vol = $meta->{meta}{volume} || 100;
1825 my $rwops = new CFPlus::RW $_[0];
1826 my $chunk = new CFPlus::MixChunk $rwops;
1827 $chunk->volume ($vol * 128 / 100);
1828 $AUDIO_CHUNK{$face} = $chunk;
1829
1830 audio_sound_push ($face);
1831 };
1832 }
1833}
1834
1835sub audio_sound_play {
1836 my ($face, $dx, $dy, $vol) = @_;
1837
1838 $SDL_MIXER
1839 or return;
1840
1841 my $queue = $AUDIO_PLAY{$face} ||= [];
1842 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
1843 audio_sound_push $face
1844 unless @$queue > 1;
1845}
1846
1847sub audio_music_set {
1848 my ($songs) = @_;
1849
1850 my @want =
1851 grep $_,
1852 map $CONN->{music_meta}{$_},
1853 @$songs;
1854
1855 if (@want) {
1856 @MUSIC_WANT = @want;
1857 &audio_music_changed ();
1858 }
1859}
1860
1861sub audio_music_start {
1862 my $meta = $MUSIC_PLAYING_META;
1863
1864 CFPlus::DB::get res_data => $meta->{name}, sub {
1865 return unless $SDL_MIXER;
1866
1867 # music might have changed...
1868 $meta eq $MUSIC_PLAYING_META
1869 or return &audio_music_start ();
1870
1871 $MUSIC_PLAYING_DATA = \$_[0];
1872
1873 my $rwops = $meta->{path}
1874 ? new_from_file CFPlus::RW $meta->{path}
1875 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
1876
1877 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
1878 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
1879
1880 my $NOW = time;
1881
1882 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
1883 my $pos = $MUSIC_PLAYING_META->{stop_pos};
1884 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
1885 $MUSIC_START = time - $pos;
1886 } else {
1887 $MUSIC_PLAYER->play (0);
1888 $MUSIC_START = time;
1889 }
1890
1891 delete $MUSIC_PLAYING_META->{stop_time};
1892 delete $MUSIC_PLAYING_META->{stop_pos};
1893 }
1894}
1895
1896sub audio_music_changed {
1897 return unless $CFG->{bgm_enable};
1898 return unless $SDL_MIXER;
1899
1900 # default MUSIC_WANT == MUSIC_DEFAULT
1901 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
1902
1903 # if the currently playing song is acceptable, let it continue
1904 return if $MUSIC_PLAYING_META
1905 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT;
1906
1907 my $NOW = time;
1908
1909 if ($MUSIC_PLAYING_META) {
1910 $MUSIC_PLAYING_META->{stop_time} = $NOW;
1911 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
1912 CFPlus::MixMusic::fade_out 1000;
1913 } else {
1914 # sort by stop time, oldest first
1915 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
1916
1917 # if the most recently-played piece played very recently,
1918 # resume it, else choose the oldest piece for rotation.
1919 $MUSIC_PLAYING_META =
1920 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
1921 ? $MUSIC_WANT[-1]
1922 : $MUSIC_WANT[0];
1923
1924 audio_music_start;
1925 }
1926}
1927
1928sub audio_music_finished {
1929 undef $MUSIC_PLAYER;
1930 undef $MUSIC_PLAYING_META;
1931 undef $MUSIC_PLAYING_DATA;
1932
1933 audio_music_changed;
1934}
1935
1936sub audio_init {
1937 if ($CFG->{audio_enable}) {
1938 $ENV{MIX_EFFECTSMAXSPEED} = 1;
1939 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
1940
1941 unless ($SDL_MIXER) {
1942 status "Unable to open sound device: there will be no sound";
1943 return;
1944 }
1945
1946 CFPlus::Mix_AllocateChannels 16;
1947 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1948
1949 audio_music_finished;
1950 } else {
1951 undef $SDL_MIXER;
1952 }
1953}
1954
1955sub audio_shutdown {
1956 CFPlus::Mix_CloseAudio if $SDL_MIXER;
1957 undef $SDL_MIXER;
1958 @SOUNDS = ();
1959 %AUDIO_CHUNKS = ();
1960}
1961
1962my %animate_object; 2007my %animate_object;
1963my $animate_timer; 2008my $animate_timer;
1964 2009
1965my $fps = 9; 2010my $fps = 9;
1966
1967my %demo;#d#
1968 2011
1969sub force_refresh { 2012sub force_refresh {
1970 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2013 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
1971 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2014 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4;
1972 2015
2057 2100
2058 CFPlus::UI::set_layout ($::CFG->{layout}); 2101 CFPlus::UI::set_layout ($::CFG->{layout});
2059 2102
2060 my %DEF_CFG = ( 2103 my %DEF_CFG = (
2061 sdl_mode => 0, 2104 sdl_mode => 0,
2062 width => 640,
2063 height => 480,
2064 fullscreen => 0, 2105 fullscreen => 0,
2065 fast => 0, 2106 fast => 0,
2066 map_scale => 1, 2107 map_scale => 1,
2067 fow_enable => 1, 2108 fow_enable => 1,
2068 fow_intensity => 0, 2109 fow_intensity => 0,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines