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.187 by elmex, Fri Jul 27 18:04:43 2007 UTC vs.
Revision 1.196 by root, Tue Jul 31 02:03:13 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;
167our $MUSIC_PLAYING; 169our $MUSIC_PLAYING_DATA;
170our $MUSIC_PLAYING_META;
168our $MUSIC_PLAYER; 171our $MUSIC_PLAYER;
169our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 172our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
170our @SOUNDS; # event => file mapping 173our @SOUNDS; # event => file mapping
171our %AUDIO_CHUNKS; # audio files 174our %AUDIO_CHUNK; # audio files
172 175
173our $ALT_ENTER_MESSAGE; 176our $ALT_ENTER_MESSAGE;
174our $STATUSBOX; 177our $STATUSBOX;
175our $DEBUG_STATUS; 178our $DEBUG_STATUS;
176 179
177our $INV; 180our $INV;
178our $INVR; 181our $INVR;
179our $INV_RIGHT_HB; 182our $INV_RIGHT_HB;
180 183
181our $PICKUP_CFG; 184our $PICKUP_CFG;
185
186#############################################################################
187#TODO: maybe move into own audio module...
188
189sub audio_channel_finished {
190 my ($channel) = @_;
191
192# warn "channel $channel finished\n";#d#
193}
194
195our %AUDIO_PLAY;
196our %AUDIO_CHUNK;
197
198sub audio_sound_push($) {
199 my ($face) = @_;
200
201 if (my $chunk = $AUDIO_CHUNK{$face}) {
202 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
203 my (undef, $dx, $dy, $vol) = @$_;
204
205 my $channel = CFPlus::Channel::find;
206 $channel->volume ($vol * 128 / 255);
207 $dx = $dx / 10 * 255;
208 $channel->set_panning (255 - $dx, 255 + $dx);
209
210# my $angle = $dx ? : $dx < 0 ?
211# my $distance = -$vol;
212# $channel->set_position ($angle, $distance);
213
214 $chunk->play ($channel);
215 }
216 } else {
217 # sound_meta not set means data is in flight either way
218 my $meta = $CONN->{sound_meta}{$face}
219 or return;
220
221 # fetch from database
222 CFPlus::DB::get res_data => $meta->{name}, sub {
223 my $rwops = new CFPlus::RW $_[0];
224 my $chunk = new CFPlus::MixChunk $rwops;
225 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
226 $AUDIO_CHUNK{$face} = $chunk;
227
228 audio_sound_push ($face);
229 };
230 }
231}
232
233sub audio_sound_play {
234 my ($face, $dx, $dy, $vol) = @_;
235
236 $SDL_MIXER
237 or return;
238
239 my $queue = $AUDIO_PLAY{$face} ||= [];
240 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
241 audio_sound_push $face
242 unless @$queue > 1;
243}
244
245sub audio_music_update_volume {
246 return unless $MUSIC_PLAYING_META;
247 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1;
248 my $base = $CFG->{bgm_volume};
249 CFPlus::MixMusic::volume $base * $volume * 128;
250}
251
252sub audio_music_push {
253 my @have =
254 grep $_,
255 map $CONN->{music_meta}{$_},
256 @$MUSIC_WANT;
257
258 if (@have) {
259 @MUSIC_HAVE = @have;
260 &audio_music_changed ();
261 }
262}
263
264sub audio_music_set_ambient {
265 my ($songs) = @_;
266
267 $MUSIC_WANT = $songs;
268
269 audio_music_push;
270}
271
272sub audio_music_start {
273 my $meta = $MUSIC_PLAYING_META;
274
275 CFPlus::DB::get res_data => $meta->{name}, sub {
276 return unless $SDL_MIXER;
277
278 # music might have changed...
279 $meta eq $MUSIC_PLAYING_META
280 or return &audio_music_start ();
281
282 audio_music_update_volume;
283
284 $MUSIC_PLAYING_DATA = \$_[0];
285
286 my $rwops = $meta->{path}
287 ? new_from_file CFPlus::RW $meta->{path}
288 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
289
290 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
291 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
292
293 my $NOW = time;
294
295 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
296 my $pos = $MUSIC_PLAYING_META->{stop_pos};
297 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
298 $MUSIC_START = time - $pos;
299 } else {
300 $MUSIC_PLAYER->play (0);
301 $MUSIC_START = time;
302 }
303
304 delete $MUSIC_PLAYING_META->{stop_time};
305 delete $MUSIC_PLAYING_META->{stop_pos};
306 }
307}
308
309sub audio_music_changed {
310 return unless $CFG->{bgm_enable};
311 return unless $SDL_MIXER;
312
313 # default MUSIC_HAVE == MUSIC_DEFAULT
314 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
315
316 # if the currently playing song is acceptable, let it continue
317 return if $MUSIC_PLAYING_META
318 && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
319
320 my $NOW = time;
321
322 if ($MUSIC_PLAYING_META) {
323 $MUSIC_PLAYING_META->{stop_time} = $NOW;
324 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
325 CFPlus::MixMusic::fade_out 1000;
326 } else {
327 # sort by stop time, oldest first
328 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
329
330 # if the most recently-played piece played very recently,
331 # resume it, else choose the oldest piece for rotation.
332 $MUSIC_PLAYING_META =
333 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
334 ? $MUSIC_HAVE[-1]
335 : $MUSIC_HAVE[0];
336
337 audio_music_start;
338 }
339}
340
341sub audio_music_finished {
342 undef $MUSIC_PLAYER;
343 undef $MUSIC_PLAYING_META;
344 undef $MUSIC_PLAYING_DATA;
345
346 audio_music_changed;
347}
348
349#############################################################################
182 350
183sub status { 351sub status {
184 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 352 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
185} 353}
186 354
459 query => \&server_query, 627 query => \&server_query,
460 628
461 setup_req => { 629 setup_req => {
462 smoothing => $CFG->{map_smoothing}*1, 630 smoothing => $CFG->{map_smoothing}*1,
463 }, 631 },
464
465 sound_play => sub {
466 my ($x, $y, $soundnum, $type) = @_;
467
468 $SDL_MIXER
469 or return;
470
471 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
472 or return;
473
474 $chunk->play;
475 },
476 }; 632 };
477 633
478 if ($CONN) { 634 if ($CONN) {
479 CFPlus::lowdelay fileno $CONN->{fh}; 635 CFPlus::lowdelay fileno $CONN->{fh};
480 636
491 $SETUP_DIALOG->show; 647 $SETUP_DIALOG->show;
492 $PL_WINDOW->hide; 648 $PL_WINDOW->hide;
493 $SPELL_LIST->clear_spells; 649 $SPELL_LIST->clear_spells;
494 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); 650 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
495 651
496 &audio_music_set ([]); 652 &audio_music_set_ambient ([]);
497 653
498 return unless $CONN; 654 return unless $CONN;
499 655
500 status "connection closed"; 656 status "connection closed";
501 657
658 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 814 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 }
659 ); 815 );
660 $hbox->add (new CFPlus::UI::Slider 816 $hbox->add (new CFPlus::UI::Slider
661 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 817 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
662 tooltip => "The volume of the background music. Changes are instant.", 818 tooltip => "The volume of the background music. Changes are instant.",
663 on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFPlus::MixMusic::volume $_[1] * 128; 0 } 819 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
664 ); 820 );
665 821
666 $table->add_at (1, $row++, new CFPlus::UI::Button 822 $table->add_at (1, $row++, new CFPlus::UI::Button
667 expand => 1, align => 0, text => "Apply", 823 expand => 1, align => 0, text => "Apply",
668 tooltip => "Apply the audio settings", 824 tooltip => "Apply the audio settings",
1081 text => $CFG->{profile}{default}{host}, 1237 text => $CFG->{profile}{default}{host},
1082 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", 1238 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
1083 on_changed => sub { 1239 on_changed => sub {
1084 my ($self, $value) = @_; 1240 my ($self, $value) = @_;
1085 $CFG->{profile}{default}{host} = $value; 1241 $CFG->{profile}{default}{host} = $value;
1086 0 1242 1
1087 } 1243 }
1088 ); 1244 );
1089 1245
1090 $vbox->add (new CFPlus::UI::Button 1246 $vbox->add (new CFPlus::UI::Button
1091 expand => 1, 1247 expand => 1,
1092 text => "Server List", 1248 text => "Server List",
1093 other => $METASERVER, 1249 other => $METASERVER,
1094 tooltip => "Show a list of available crossfire servers", 1250 tooltip => "Show a list of available crossfire servers",
1095 on_activate => sub { $METASERVER->toggle_visibility; 0 }, 1251 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1096 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 0 }, 1252 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1097 ); 1253 );
1098 } 1254 }
1099 1255
1100 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username"); 1256 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username");
1101 $table->add_at (1, 4, new CFPlus::UI::Entry 1257 $table->add_at (1, 4, new CFPlus::UI::Entry
1102 text => $CFG->{profile}{default}{user}, 1258 text => $CFG->{profile}{default}{user},
1103 tooltip => "The name of your character on the server", 1259 tooltip => "The name of your character on the server",
1104 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value } 1260 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 }
1105 ); 1261 );
1106 1262
1107 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password"); 1263 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password");
1108 $table->add_at (1, 5, new CFPlus::UI::Entry 1264 $table->add_at (1, 5, new CFPlus::UI::Entry
1109 text => $CFG->{profile}{default}{password}, 1265 text => $CFG->{profile}{default}{password},
1110 hidden => 1, 1266 hidden => 1,
1111 tooltip => "The password for your character", 1267 tooltip => "The password for your character",
1112 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value } 1268 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value; 1 }
1113 ); 1269 );
1114 1270
1115 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); 1271 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size");
1116 $table->add_at (1, 7, new CFPlus::UI::Slider 1272 $table->add_at (1, 7, new CFPlus::UI::Slider
1117 force_w => 100, 1273 force_w => 100,
1118 range => [$CFG->{mapsize}, 10, 100, 0, 1], 1274 range => [$CFG->{mapsize}, 10, 100, 0, 1],
1119 tooltip => "This is the size of the portion of the map update the server sends you. " 1275 tooltip => "This is the size of the portion of the map update the server sends you. "
1120 . "If you set this to a high value you will be able to see further, " 1276 . "If you set this to a high value you will be able to see further, "
1121 . "but you also increase bandwidth requirements and latency. " 1277 . "but you also increase bandwidth requirements and latency. "
1122 . "This option is only used once at log-in.", 1278 . "This option is only used once at log-in.",
1123 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, 1279 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 },
1124 ); 1280 );
1125 1281
1126 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Face Prefetch");
1127 $table->add_at (1, 8, new CFPlus::UI::CheckBox
1128 state => $CFG->{face_prefetch},
1129 tooltip => "<b>Background Image Prefetch</b>\n\n"
1130 . "If enabled, the client automatically pre-fetches images from the server. "
1131 . "This might increase or create lag, but increases the chances "
1132 . "of faces being ready for display when you encounter them. "
1133 . "It also uses up server bandwidth on every connect, "
1134 . "so only set it if you really need to prefetch images. "
1135 . "This option can be set and unset any time.",
1136 on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 },
1137 );
1138
1139 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); 1282 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1283 $table->add_at (1, 8, new CFPlus::UI::Entry
1284 text => $CFG->{output_rate},
1285 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1286 . "when sending data. When 0 or unset, the server "
1287 . "default will be used, which is usually around 100kb/s. Most servers will "
1288 . "dynamically find an optimal rate, so adjust this only when necessary.",
1289 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1290 );
1291
1292 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1140 $table->add_at (1, 9, new CFPlus::UI::Entry 1293 $table->add_at (1, 9, new CFPlus::UI::Entry
1141 text => $CFG->{output_rate},
1142 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed "
1143 . "when sending images, to ensure interactiveness. When 0 or unset, the server "
1144 . "default will be used, which is usually around 100kb/s.",
1145 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 },
1146 );
1147
1148 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1149 $table->add_at (1, 10, new CFPlus::UI::Entry
1150 text => $CFG->{output_count}, 1294 text => $CFG->{output_count},
1151 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1295 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1152 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1296 on_changed => sub { $CFG->{output_count} = $_[1]; 1 },
1153 ); 1297 );
1154 1298
1155 $table->add_at (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1299 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1156 $table->add_at (1, 11, new CFPlus::UI::Entry 1300 $table->add_at (1, 10, new CFPlus::UI::Entry
1157 text => $CFG->{output_sync}, 1301 text => $CFG->{output_sync},
1158 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1302 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1159 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1303 on_changed => sub { $CFG->{output_sync} = $_[1]; 1 },
1160 ); 1304 );
1161 1305
1162 $table->add_at (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button 1306 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1163 expand => 1, 1307 expand => 1,
1164 align => 0, 1308 align => 0,
1165 text => "Login", 1309 text => "Login",
1166 on_activate => sub { 1310 on_activate => sub {
1167 $CONN ? stop_game 1311 $CONN ? stop_game
1168 : start_game; 1312 : start_game;
1169 0 1313 1
1170 }, 1314 },
1171 ); 1315 );
1172 1316
1173 $vbox->add (new CFPlus::UI::FancyFrame 1317 $vbox->add (new CFPlus::UI::FancyFrame
1174 label => "Server Info", 1318 label => "Server Info",
1809 CFPlus::OpenGL::shutdown; 1953 CFPlus::OpenGL::shutdown;
1810 1954
1811 undef $SDL_ACTIVE; 1955 undef $SDL_ACTIVE;
1812} 1956}
1813 1957
1814sub audio_channel_finished {
1815 my ($channel) = @_;
1816
1817 #warn "channel $channel finished\n";#d#
1818}
1819
1820sub audio_music_set {
1821 my ($songs) = @_;
1822
1823 my @want =
1824 grep $_,
1825 map $CONN->{music_meta}{$_},
1826 @$songs;
1827
1828 if (@want) {
1829 @MUSIC_WANT = @want;
1830 &audio_music_changed ();
1831 }
1832}
1833
1834sub audio_music_start {
1835 my $path = $MUSIC_PLAYING->{path}
1836 or return;
1837
1838 CFPlus::DB::prefetch_file $path, 1024_000, sub {
1839 return unless $SDL_MIXER;
1840
1841 # music might have changed...
1842 $path eq $MUSIC_PLAYING->{path}
1843 or return &audio_music_start ();
1844
1845 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path;
1846
1847 my $NOW = time;
1848
1849 if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) {
1850 my $pos = $MUSIC_PLAYING->{stop_pos};
1851 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
1852 $MUSIC_START = time - $pos;
1853 } else {
1854 $MUSIC_PLAYER->play (0);
1855 $MUSIC_START = time;
1856 }
1857
1858 delete $MUSIC_PLAYING->{stop_time};
1859 delete $MUSIC_PLAYING->{stop_pos};
1860 }
1861}
1862
1863sub audio_music_changed {
1864 return unless $CFG->{bgm_enable};
1865 return unless $SDL_MIXER;
1866
1867 # default MUSIC_WANT == MUSIC_DEFAULT
1868 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
1869
1870 # if the currently playing song is acceptable, let it continue
1871 return if $MUSIC_PLAYING
1872 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT;
1873
1874 my $NOW = time;
1875
1876 if ($MUSIC_PLAYING) {
1877 $MUSIC_PLAYING->{stop_time} = $NOW;
1878 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START;
1879 CFPlus::MixMusic::fade_out 1000;
1880 } else {
1881 # sort by stop time, oldest first
1882 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
1883
1884 # if the most recently-played piece played very recently,
1885 # resume it, else choose the oldest piece for rotation.
1886 $MUSIC_PLAYING =
1887 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
1888 ? $MUSIC_WANT[-1]
1889 : $MUSIC_WANT[0];
1890
1891 audio_music_start;
1892 }
1893}
1894
1895sub audio_music_finished {
1896 $MUSIC_PLAYING = undef;
1897 undef $MUSIC_PLAYER;
1898
1899 audio_music_changed;
1900}
1901
1902sub audio_init { 1958sub audio_init {
1903 if ($CFG->{audio_enable}) { 1959 if ($CFG->{audio_enable}) {
1904 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { 1960 $ENV{MIX_EFFECTSMAXSPEED} = 1;
1905 $SDL_MIXER = !CFPlus::Mix_OpenAudio; 1961 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
1906 1962
1907 unless ($SDL_MIXER) { 1963 unless ($SDL_MIXER) {
1908 status "Unable to open sound device: there will be no sound"; 1964 status "Unable to open sound device: there will be no sound";
1909 return; 1965 return;
1910 }
1911
1912 CFPlus::Mix_AllocateChannels 8;
1913 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1914
1915 audio_music_finished;
1916
1917 local $_;
1918 while (<$fh>) {
1919 next if /^\s*#/;
1920 next if /^\s*$/;
1921
1922 my ($file, $volume, $event) = split /\s+/, $_, 3;
1923
1924 push @SOUNDS, "$volume,$file";
1925
1926 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
1927 my $chunk = new_from_file CFPlus::MixChunk CFPlus::find_rcfile "sounds/$file";
1928 $chunk->volume ($volume * 128 / 100);
1929 $chunk
1930 };
1931 }
1932 } else {
1933 status "unable to open sound config: $!";
1934 } 1966 }
1967
1968 CFPlus::Mix_AllocateChannels 16;
1969
1970 audio_music_finished;
1935 } else { 1971 } else {
1936 undef $SDL_MIXER; 1972 undef $SDL_MIXER;
1937 } 1973 }
1938} 1974}
1939 1975
1940sub audio_shutdown { 1976sub audio_shutdown {
1941 CFPlus::Mix_CloseAudio if $SDL_MIXER; 1977 CFPlus::Mix_CloseAudio if $SDL_MIXER;
1942 undef $SDL_MIXER; 1978 undef $SDL_MIXER;
1943 @SOUNDS = (); 1979 @SOUNDS = ();
1944 %AUDIO_CHUNKS = (); 1980 %AUDIO_CHUNK = ();
1945} 1981}
1946 1982
1947my %animate_object; 1983my %animate_object;
1948my $animate_timer; 1984my $animate_timer;
1949 1985
1950my $fps = 9; 1986my $fps = 9;
1951
1952my %demo;#d#
1953 1987
1954sub force_refresh { 1988sub force_refresh {
1955 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 1989 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
1956 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 1990 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4;
1957 1991
1989 2023
1990sub animation_stop { 2024sub animation_stop {
1991 my ($widget) = @_; 2025 my ($widget) = @_;
1992 delete $animate_object{$widget}; 2026 delete $animate_object{$widget};
1993} 2027}
1994
1995# check once/second for faces that need to be prefetched
1996# this should, of course, only run on demand, but
1997# SDL forces worse things on us....
1998
1999Event->timer (after => 1, interval => 0.25, cb => sub {
2000 $CONN->face_prefetch
2001 if $CONN;
2002});
2003 2028
2004%SDL_CB = ( 2029%SDL_CB = (
2005 CFPlus::SDL_QUIT => sub { 2030 CFPlus::SDL_QUIT => sub {
2006 exit; 2031 exit;
2007 }, 2032 },
2051 2076
2052 CFPlus::UI::set_layout ($::CFG->{layout}); 2077 CFPlus::UI::set_layout ($::CFG->{layout});
2053 2078
2054 my %DEF_CFG = ( 2079 my %DEF_CFG = (
2055 sdl_mode => 0, 2080 sdl_mode => 0,
2056 width => 640,
2057 height => 480,
2058 fullscreen => 0, 2081 fullscreen => 0,
2059 fast => 0, 2082 fast => 0,
2060 map_scale => 1, 2083 map_scale => 1,
2061 fow_enable => 1, 2084 fow_enable => 1,
2062 fow_intensity => 0, 2085 fow_intensity => 0,
2068 stat_fontsize => 0.7, 2091 stat_fontsize => 0.7,
2069 mapsize => 100, 2092 mapsize => 100,
2070 audio_enable => 1, 2093 audio_enable => 1,
2071 bgm_enable => 1, 2094 bgm_enable => 1,
2072 bgm_volume => 0.25, 2095 bgm_volume => 0.25,
2073 face_prefetch => 0,
2074 output_sync => 1, 2096 output_sync => 1,
2075 output_count => 1, 2097 output_count => 1,
2076 output_rate => "", 2098 output_rate => "",
2077 pickup => 0, 2099 pickup => 0,
2078 inv_sort => "mtime", 2100 inv_sort => "mtime",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines