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.190 by root, Sun Jul 29 18:56:03 2007 UTC vs.
Revision 1.197 by root, Tue Jul 31 02:25:52 2007 UTC

71unshift @INC, $ENV{PAR_TEMP} 71unshift @INC, $ENV{PAR_TEMP}
72 if %PAR::LibCache; 72 if %PAR::LibCache;
73 73
74use Time::HiRes 'time'; 74use Time::HiRes 'time';
75use Event; 75use Event;
76use List::Util qw(max min);
76 77
77use Crossfire; 78use Crossfire;
78use Crossfire::Protocol::Constants; 79use Crossfire::Protocol::Constants;
79 80
80use Compress::LZF; 81use Compress::LZF;
160our $SDL_ACTIVE; 161our $SDL_ACTIVE;
161our %SDL_CB; 162our %SDL_CB;
162 163
163our $SDL_MIXER; 164our $SDL_MIXER;
164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; 165our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
165our @MUSIC_WANT; 166our $MUSIC_WANT; # arryref of ambient music
167our @MUSIC_HAVE; # ambient music we want now
166our $MUSIC_START; 168our $MUSIC_START;
169our @MUSIC_JINGLE; # which jingles to play
167our $MUSIC_PLAYING_DATA; 170our $MUSIC_PLAYING_DATA;
168our $MUSIC_PLAYING_META; 171our $MUSIC_PLAYING_META;
169our $MUSIC_PLAYER; 172our $MUSIC_PLAYER;
170our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 173our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
171our @SOUNDS; # event => file mapping 174our @SOUNDS; # event => file mapping
172our %AUDIO_CHUNKS; # audio files 175our %AUDIO_CHUNK; # audio files
173 176
174our $ALT_ENTER_MESSAGE; 177our $ALT_ENTER_MESSAGE;
175our $STATUSBOX; 178our $STATUSBOX;
176our $DEBUG_STATUS; 179our $DEBUG_STATUS;
177 180
178our $INV; 181our $INV;
179our $INVR; 182our $INVR;
180our $INV_RIGHT_HB; 183our $INV_RIGHT_HB;
181 184
182our $PICKUP_CFG; 185our $PICKUP_CFG;
186
187#############################################################################
188#TODO: maybe move into own audio module...
189
190sub audio_channel_finished {
191 my ($channel) = @_;
192
193# warn "channel $channel finished\n";#d#
194}
195
196our %AUDIO_PLAY;
197our %AUDIO_CHUNK;
198
199sub audio_sound_push($) {
200 my ($face) = @_;
201
202 if (my $chunk = $AUDIO_CHUNK{$face}) {
203 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
204 my (undef, $dx, $dy, $vol) = @$_;
205
206 my $channel = CFPlus::Channel::find;
207 $channel->volume ($vol * 128 / 255);
208 $dx = $dx / 10 * 255;
209 $channel->set_panning (255 - $dx, 255 + $dx);
210
211# my $angle = $dx ? : $dx < 0 ?
212# my $distance = -$vol;
213# $channel->set_position ($angle, $distance);
214
215 $chunk->play ($channel);
216 }
217 } else {
218 # sound_meta not set means data is in flight either way
219 my $meta = $CONN->{sound_meta}{$face}
220 or return;
221
222 # if its a jingle, play it as ambient music
223 if ($meta->{meta}{jingle}) {
224 push @MUSIC_JINGLE, $meta;
225 delete $AUDIO_PLAY{$face};
226 &audio_music_push ($face);
227 } else {
228 # fetch from database
229 CFPlus::DB::get res_data => $meta->{name}, sub {
230 my $rwops = new CFPlus::RW $_[0];
231 my $chunk = new CFPlus::MixChunk $rwops;
232 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
233 $AUDIO_CHUNK{$face} = $chunk;
234
235 audio_sound_push ($face);
236 };
237 }
238 }
239}
240
241sub audio_sound_play {
242 my ($face, $dx, $dy, $vol) = @_;
243
244 $SDL_MIXER
245 or return;
246
247 my $queue = $AUDIO_PLAY{$face} ||= [];
248 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
249 audio_sound_push $face
250 unless @$queue > 1;
251}
252
253sub audio_music_update_volume {
254 return unless $MUSIC_PLAYING_META;
255 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1;
256 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume};
257 CFPlus::MixMusic::volume $base * $volume * 128;
258}
259
260sub audio_music_start {
261 my $meta = $MUSIC_PLAYING_META;
262
263 CFPlus::DB::get res_data => $meta->{name}, sub {
264 return unless $SDL_MIXER;
265
266 # music might have changed...
267 $meta eq $MUSIC_PLAYING_META
268 or return &audio_music_start ();
269
270 audio_music_update_volume;
271
272 $MUSIC_PLAYING_DATA = \$_[0];
273
274 my $rwops = $meta->{path}
275 ? new_from_file CFPlus::RW $meta->{path}
276 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
277
278 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
279 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
280
281 my $NOW = time;
282
283 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
284 my $pos = $MUSIC_PLAYING_META->{stop_pos};
285 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
286 $MUSIC_START = time - $pos;
287 } else {
288 $MUSIC_PLAYER->play (0);
289 $MUSIC_START = time;
290 }
291
292 delete $MUSIC_PLAYING_META->{stop_time};
293 delete $MUSIC_PLAYING_META->{stop_pos};
294 }
295}
296
297sub audio_music_push {
298 return unless $SDL_MIXER;
299
300 my $fade_out;
301
302 if (@MUSIC_JINGLE) {
303 @MUSIC_HAVE = $MUSIC_JINGLE[0];
304 $fade_out = 333;
305 } else {
306 return unless $CFG->{bgm_enable};
307
308 my @have =
309 grep $_,
310 map $CONN->{music_meta}{$_},
311 @$MUSIC_WANT;
312
313 @MUSIC_HAVE = @have
314 if @have;
315
316 # default MUSIC_HAVE == MUSIC_DEFAULT
317 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
318 $fade_out = 1000;
319 }
320
321 # if the currently playing song is acceptable, let it continue
322 return if $MUSIC_PLAYING_META
323 && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
324
325 my $NOW = time;
326
327 if ($MUSIC_PLAYING_META) {
328 $MUSIC_PLAYING_META->{stop_time} = $NOW;
329 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
330 CFPlus::MixMusic::fade_out $fade_out;
331 } else {
332 # sort by stop time, oldest first
333 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
334
335 # if the most recently-played piece played very recently,
336 # resume it, else choose the oldest piece for rotation.
337 $MUSIC_PLAYING_META =
338 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
339 ? $MUSIC_HAVE[-1]
340 : $MUSIC_HAVE[0];
341
342 audio_music_start;
343 }
344}
345
346sub audio_music_set_ambient {
347 my ($songs) = @_;
348
349 $MUSIC_WANT = $songs;
350 audio_music_push;
351}
352
353sub audio_music_finished {
354 shift @MUSIC_JINGLE
355 if $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
356
357 undef $MUSIC_PLAYER;
358 undef $MUSIC_PLAYING_META;
359 undef $MUSIC_PLAYING_DATA;
360
361 audio_music_push;
362}
363
364#############################################################################
183 365
184sub status { 366sub status {
185 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 367 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
186} 368}
187 369
460 query => \&server_query, 642 query => \&server_query,
461 643
462 setup_req => { 644 setup_req => {
463 smoothing => $CFG->{map_smoothing}*1, 645 smoothing => $CFG->{map_smoothing}*1,
464 }, 646 },
465
466 sound_play => sub {
467 my ($x, $y, $soundnum, $type) = @_;
468
469 $SDL_MIXER
470 or return;
471
472 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
473 or return;
474
475 $chunk->play;
476 },
477 }; 647 };
478 648
479 if ($CONN) { 649 if ($CONN) {
480 CFPlus::lowdelay fileno $CONN->{fh}; 650 CFPlus::lowdelay fileno $CONN->{fh};
481 651
492 $SETUP_DIALOG->show; 662 $SETUP_DIALOG->show;
493 $PL_WINDOW->hide; 663 $PL_WINDOW->hide;
494 $SPELL_LIST->clear_spells; 664 $SPELL_LIST->clear_spells;
495 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); 665 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
496 666
497 &audio_music_set ([]); 667 &audio_music_set_ambient ([]);
498 668
499 return unless $CONN; 669 return unless $CONN;
500 670
501 status "connection closed"; 671 status "connection closed";
502 672
659 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 829 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 }
660 ); 830 );
661 $hbox->add (new CFPlus::UI::Slider 831 $hbox->add (new CFPlus::UI::Slider
662 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 832 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
663 tooltip => "The volume of the background music. Changes are instant.", 833 tooltip => "The volume of the background music. Changes are instant.",
664 on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFPlus::MixMusic::volume $_[1] * 128; 0 } 834 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
665 ); 835 );
666 836
667 $table->add_at (1, $row++, new CFPlus::UI::Button 837 $table->add_at (1, $row++, new CFPlus::UI::Button
668 expand => 1, align => 0, text => "Apply", 838 expand => 1, align => 0, text => "Apply",
669 tooltip => "Apply the audio settings", 839 tooltip => "Apply the audio settings",
1082 text => $CFG->{profile}{default}{host}, 1252 text => $CFG->{profile}{default}{host},
1083 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", 1253 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
1084 on_changed => sub { 1254 on_changed => sub {
1085 my ($self, $value) = @_; 1255 my ($self, $value) = @_;
1086 $CFG->{profile}{default}{host} = $value; 1256 $CFG->{profile}{default}{host} = $value;
1087 0 1257 1
1088 } 1258 }
1089 ); 1259 );
1090 1260
1091 $vbox->add (new CFPlus::UI::Button 1261 $vbox->add (new CFPlus::UI::Button
1092 expand => 1, 1262 expand => 1,
1093 text => "Server List", 1263 text => "Server List",
1094 other => $METASERVER, 1264 other => $METASERVER,
1095 tooltip => "Show a list of available crossfire servers", 1265 tooltip => "Show a list of available crossfire servers",
1096 on_activate => sub { $METASERVER->toggle_visibility; 0 }, 1266 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1097 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 0 }, 1267 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1098 ); 1268 );
1099 } 1269 }
1100 1270
1101 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username"); 1271 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username");
1102 $table->add_at (1, 4, new CFPlus::UI::Entry 1272 $table->add_at (1, 4, new CFPlus::UI::Entry
1103 text => $CFG->{profile}{default}{user}, 1273 text => $CFG->{profile}{default}{user},
1104 tooltip => "The name of your character on the server", 1274 tooltip => "The name of your character on the server",
1105 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value } 1275 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 }
1106 ); 1276 );
1107 1277
1108 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password"); 1278 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password");
1109 $table->add_at (1, 5, new CFPlus::UI::Entry 1279 $table->add_at (1, 5, new CFPlus::UI::Entry
1110 text => $CFG->{profile}{default}{password}, 1280 text => $CFG->{profile}{default}{password},
1111 hidden => 1, 1281 hidden => 1,
1112 tooltip => "The password for your character", 1282 tooltip => "The password for your character",
1113 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value } 1283 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value; 1 }
1114 ); 1284 );
1115 1285
1116 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); 1286 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size");
1117 $table->add_at (1, 7, new CFPlus::UI::Slider 1287 $table->add_at (1, 7, new CFPlus::UI::Slider
1118 force_w => 100, 1288 force_w => 100,
1119 range => [$CFG->{mapsize}, 10, 100, 0, 1], 1289 range => [$CFG->{mapsize}, 10, 100, 0, 1],
1120 tooltip => "This is the size of the portion of the map update the server sends you. " 1290 tooltip => "This is the size of the portion of the map update the server sends you. "
1121 . "If you set this to a high value you will be able to see further, " 1291 . "If you set this to a high value you will be able to see further, "
1122 . "but you also increase bandwidth requirements and latency. " 1292 . "but you also increase bandwidth requirements and latency. "
1123 . "This option is only used once at log-in.", 1293 . "This option is only used once at log-in.",
1124 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, 1294 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 },
1125 ); 1295 );
1126 1296
1127 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); 1297 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1128 $table->add_at (1, 8, new CFPlus::UI::Entry 1298 $table->add_at (1, 8, new CFPlus::UI::Entry
1129 text => $CFG->{output_rate}, 1299 text => $CFG->{output_rate},
1130 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " 1300 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1131 . "when sending images, to ensure interactiveness. When 0 or unset, the server " 1301 . "when sending data. When 0 or unset, the server "
1132 . "default will be used, which is usually around 100kb/s.", 1302 . "default will be used, which is usually around 100kb/s. Most servers will "
1303 . "dynamically find an optimal rate, so adjust this only when necessary.",
1133 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, 1304 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1134 ); 1305 );
1135 1306
1136 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); 1307 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1137 $table->add_at (1, 9, new CFPlus::UI::Entry 1308 $table->add_at (1, 9, new CFPlus::UI::Entry
1138 text => $CFG->{output_count}, 1309 text => $CFG->{output_count},
1139 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1310 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1140 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1311 on_changed => sub { $CFG->{output_count} = $_[1]; 1 },
1141 ); 1312 );
1142 1313
1143 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1314 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1144 $table->add_at (1, 10, new CFPlus::UI::Entry 1315 $table->add_at (1, 10, new CFPlus::UI::Entry
1145 text => $CFG->{output_sync}, 1316 text => $CFG->{output_sync},
1146 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1317 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1147 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1318 on_changed => sub { $CFG->{output_sync} = $_[1]; 1 },
1148 ); 1319 );
1149 1320
1150 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button 1321 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1151 expand => 1, 1322 expand => 1,
1152 align => 0, 1323 align => 0,
1153 text => "Login", 1324 text => "Login",
1154 on_activate => sub { 1325 on_activate => sub {
1155 $CONN ? stop_game 1326 $CONN ? stop_game
1156 : start_game; 1327 : start_game;
1157 0 1328 1
1158 }, 1329 },
1159 ); 1330 );
1160 1331
1161 $vbox->add (new CFPlus::UI::FancyFrame 1332 $vbox->add (new CFPlus::UI::FancyFrame
1162 label => "Server Info", 1333 label => "Server Info",
1797 CFPlus::OpenGL::shutdown; 1968 CFPlus::OpenGL::shutdown;
1798 1969
1799 undef $SDL_ACTIVE; 1970 undef $SDL_ACTIVE;
1800} 1971}
1801 1972
1802sub audio_channel_finished {
1803 my ($channel) = @_;
1804
1805 #warn "channel $channel finished\n";#d#
1806}
1807
1808sub audio_music_set {
1809 my ($songs) = @_;
1810
1811 my @want =
1812 grep $_,
1813 map $CONN->{music_meta}{$_},
1814 @$songs;
1815
1816 if (@want) {
1817 @MUSIC_WANT = @want;
1818 &audio_music_changed ();
1819 }
1820}
1821
1822sub audio_music_start {
1823 my $meta = $MUSIC_PLAYING_META;
1824
1825 CFPlus::DB::get res_data => $meta->{name}, sub {
1826 return unless $SDL_MIXER;
1827
1828 # music might have changed...
1829 $meta eq $MUSIC_PLAYING_META
1830 or return &audio_music_start ();
1831
1832 $MUSIC_PLAYING_DATA = \$_[0];
1833
1834 my $rwops = $meta->{path}
1835 ? new_from_file CFPlus::RW $meta->{path}
1836 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
1837
1838 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
1839 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
1840
1841 my $NOW = time;
1842
1843 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
1844 my $pos = $MUSIC_PLAYING_META->{stop_pos};
1845 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
1846 $MUSIC_START = time - $pos;
1847 } else {
1848 $MUSIC_PLAYER->play (0);
1849 $MUSIC_START = time;
1850 }
1851
1852 delete $MUSIC_PLAYING_META->{stop_time};
1853 delete $MUSIC_PLAYING_META->{stop_pos};
1854 }
1855}
1856
1857sub audio_music_changed {
1858 return unless $CFG->{bgm_enable};
1859 return unless $SDL_MIXER;
1860
1861 # default MUSIC_WANT == MUSIC_DEFAULT
1862 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
1863
1864 # if the currently playing song is acceptable, let it continue
1865 return if $MUSIC_PLAYING_META
1866 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT;
1867
1868 my $NOW = time;
1869
1870 if ($MUSIC_PLAYING_META) {
1871 $MUSIC_PLAYING_META->{stop_time} = $NOW;
1872 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
1873 CFPlus::MixMusic::fade_out 1000;
1874 } else {
1875 # sort by stop time, oldest first
1876 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
1877
1878 # if the most recently-played piece played very recently,
1879 # resume it, else choose the oldest piece for rotation.
1880 $MUSIC_PLAYING_META =
1881 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
1882 ? $MUSIC_WANT[-1]
1883 : $MUSIC_WANT[0];
1884
1885 audio_music_start;
1886 }
1887}
1888
1889sub audio_music_finished {
1890 undef $MUSIC_PLAYER;
1891 undef $MUSIC_PLAYING_META;
1892 undef $MUSIC_PLAYING_DATA;
1893
1894 audio_music_changed;
1895}
1896
1897sub audio_init { 1973sub audio_init {
1898 if ($CFG->{audio_enable}) { 1974 if ($CFG->{audio_enable}) {
1899 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") {
1900 $ENV{MIX_EFFECTSMAXSPEED} = 1; 1975 $ENV{MIX_EFFECTSMAXSPEED} = 1;
1901 $SDL_MIXER = !CFPlus::Mix_OpenAudio; 1976 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
1902 1977
1903 unless ($SDL_MIXER) { 1978 unless ($SDL_MIXER) {
1904 status "Unable to open sound device: there will be no sound"; 1979 status "Unable to open sound device: there will be no sound";
1905 return; 1980 return;
1906 }
1907
1908 CFPlus::Mix_AllocateChannels 8;
1909 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1910
1911 audio_music_finished;
1912
1913 local $_;
1914 while (<$fh>) {
1915 next if /^\s*#/;
1916 next if /^\s*$/;
1917
1918 my ($file, $volume, $event) = split /\s+/, $_, 3;
1919
1920 push @SOUNDS, "$volume,$file";
1921
1922 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
1923 my $rwops = new_from_file CFPlus::RW CFPlus::find_rcfile "sounds/$file";
1924 my $chunk = new CFPlus::MixChunk $rwops;
1925 $chunk->volume ($volume * 128 / 100);
1926 $chunk
1927 };
1928 }
1929 } else {
1930 status "unable to open sound config: $!";
1931 } 1981 }
1982
1983 CFPlus::Mix_AllocateChannels 16;
1984
1985 audio_music_finished;
1932 } else { 1986 } else {
1933 undef $SDL_MIXER; 1987 undef $SDL_MIXER;
1934 } 1988 }
1935} 1989}
1936 1990
1937sub audio_shutdown { 1991sub audio_shutdown {
1938 CFPlus::Mix_CloseAudio if $SDL_MIXER; 1992 CFPlus::Mix_CloseAudio if $SDL_MIXER;
1939 undef $SDL_MIXER; 1993 undef $SDL_MIXER;
1940 @SOUNDS = (); 1994 @SOUNDS = ();
1941 %AUDIO_CHUNKS = (); 1995 %AUDIO_CHUNK = ();
1942} 1996}
1943 1997
1944my %animate_object; 1998my %animate_object;
1945my $animate_timer; 1999my $animate_timer;
1946 2000
1947my $fps = 9; 2001my $fps = 9;
1948
1949my %demo;#d#
1950 2002
1951sub force_refresh { 2003sub force_refresh {
1952 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2004 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
1953 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2005 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4;
1954 2006
2039 2091
2040 CFPlus::UI::set_layout ($::CFG->{layout}); 2092 CFPlus::UI::set_layout ($::CFG->{layout});
2041 2093
2042 my %DEF_CFG = ( 2094 my %DEF_CFG = (
2043 sdl_mode => 0, 2095 sdl_mode => 0,
2044 width => 640,
2045 height => 480,
2046 fullscreen => 0, 2096 fullscreen => 0,
2047 fast => 0, 2097 fast => 0,
2048 map_scale => 1, 2098 map_scale => 1,
2049 fow_enable => 1, 2099 fow_enable => 1,
2050 fow_intensity => 0, 2100 fow_intensity => 0,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines