… | |
… | |
71 | unshift @INC, $ENV{PAR_TEMP} |
71 | unshift @INC, $ENV{PAR_TEMP} |
72 | if %PAR::LibCache; |
72 | if %PAR::LibCache; |
73 | |
73 | |
74 | use Time::HiRes 'time'; |
74 | use Time::HiRes 'time'; |
75 | use Event; |
75 | use Event; |
|
|
76 | use List::Util qw(max min); |
76 | |
77 | |
77 | use Crossfire; |
78 | use Crossfire; |
78 | use Crossfire::Protocol::Constants; |
79 | use Crossfire::Protocol::Constants; |
79 | |
80 | |
80 | use Compress::LZF; |
81 | use Compress::LZF; |
… | |
… | |
158 | our $STATWIDS; |
159 | our $STATWIDS; |
159 | |
160 | |
160 | our $SDL_ACTIVE; |
161 | our $SDL_ACTIVE; |
161 | our %SDL_CB; |
162 | our %SDL_CB; |
162 | |
163 | |
163 | our $SDL_MIXER; |
|
|
164 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
|
|
165 | our @MUSIC_WANT; |
|
|
166 | our $MUSIC_START; |
|
|
167 | our $MUSIC_PLAYING; |
|
|
168 | our $MUSIC_PLAYER; |
|
|
169 | our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before |
|
|
170 | our @SOUNDS; # event => file mapping |
|
|
171 | our %AUDIO_CHUNKS; # audio files |
|
|
172 | |
|
|
173 | our $ALT_ENTER_MESSAGE; |
164 | our $ALT_ENTER_MESSAGE; |
174 | our $STATUSBOX; |
165 | our $STATUSBOX; |
175 | our $DEBUG_STATUS; |
166 | our $DEBUG_STATUS; |
176 | |
167 | |
177 | our $INV; |
168 | our $INV; |
178 | our $INVR; |
169 | our $INVR; |
179 | our $INV_RIGHT_HB; |
170 | our $INV_RIGHT_HB; |
180 | |
171 | |
181 | our $PICKUP_CFG; |
172 | our $PICKUP_CFG; |
182 | |
173 | |
|
|
174 | ############################################################################# |
|
|
175 | |
183 | sub status { |
176 | sub status { |
184 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
177 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
185 | } |
178 | } |
186 | |
179 | |
187 | sub debug { |
180 | sub debug { |
… | |
… | |
190 | |
183 | |
191 | sub message { |
184 | sub message { |
192 | my ($para) = @_; |
185 | my ($para) = @_; |
193 | $MESSAGE_WINDOW->message ($para); |
186 | $MESSAGE_WINDOW->message ($para); |
194 | } |
187 | } |
|
|
188 | |
|
|
189 | ############################################################################# |
|
|
190 | #TODO: maybe move into own audio module... |
|
|
191 | |
|
|
192 | our $SDL_MIXER; |
|
|
193 | |
|
|
194 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
|
|
195 | our $MUSIC_WANT; # arryref of ambient music we want to play |
|
|
196 | our @MUSIC_HAVE; # ambient music we have on disk |
|
|
197 | our $MUSIC_START; |
|
|
198 | our @MUSIC_JINGLE; # which jingles to play next |
|
|
199 | our $MUSIC_PLAYING_DATA; |
|
|
200 | our $MUSIC_PLAYING_META; |
|
|
201 | our $MUSIC_PLAYER; |
|
|
202 | our $MUSIC_RESUME = 30; # resume music when played less than these many seconds before |
|
|
203 | |
|
|
204 | our %AUDIO_CHUNK; # audio "files" |
|
|
205 | our %AUDIO_PLAY; # which audio faces should be played |
|
|
206 | |
|
|
207 | sub audio_channel_finished { |
|
|
208 | my ($channel) = @_; |
|
|
209 | |
|
|
210 | # warn "channel $channel finished\n";#d# |
|
|
211 | } |
|
|
212 | |
|
|
213 | sub audio_sound_push($) { |
|
|
214 | my ($face) = @_; |
|
|
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 | } |
|
|
253 | } |
|
|
254 | |
|
|
255 | sub 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 | |
|
|
267 | sub 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 | |
|
|
274 | sub 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 | |
|
|
311 | sub 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 | |
|
|
360 | sub audio_music_set_ambient { |
|
|
361 | my ($songs) = @_; |
|
|
362 | |
|
|
363 | $MUSIC_WANT = $songs; |
|
|
364 | audio_music_push; |
|
|
365 | } |
|
|
366 | |
|
|
367 | sub 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 | |
|
|
379 | sub 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 | |
|
|
397 | sub 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 | ############################################################################# |
195 | |
412 | |
196 | sub destroy_query_dialog { |
413 | sub destroy_query_dialog { |
197 | (delete $_[0]{query_dialog})->destroy |
414 | (delete $_[0]{query_dialog})->destroy |
198 | if $_[0]{query_dialog}; |
415 | if $_[0]{query_dialog}; |
199 | } |
416 | } |
… | |
… | |
459 | query => \&server_query, |
676 | query => \&server_query, |
460 | |
677 | |
461 | setup_req => { |
678 | setup_req => { |
462 | smoothing => $CFG->{map_smoothing}*1, |
679 | smoothing => $CFG->{map_smoothing}*1, |
463 | }, |
680 | }, |
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 | }; |
681 | }; |
477 | |
682 | |
478 | if ($CONN) { |
683 | if ($CONN) { |
479 | CFPlus::lowdelay fileno $CONN->{fh}; |
684 | CFPlus::lowdelay fileno $CONN->{fh}; |
480 | |
685 | |
… | |
… | |
491 | $SETUP_DIALOG->show; |
696 | $SETUP_DIALOG->show; |
492 | $PL_WINDOW->hide; |
697 | $PL_WINDOW->hide; |
493 | $SPELL_LIST->clear_spells; |
698 | $SPELL_LIST->clear_spells; |
494 | $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); |
699 | $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); |
495 | |
700 | |
496 | &audio_music_set ([]); |
701 | &audio_music_set_ambient ([]); |
497 | |
702 | |
498 | return unless $CONN; |
703 | return unless $CONN; |
499 | |
704 | |
500 | status "connection closed"; |
705 | status "connection closed"; |
501 | |
706 | |
… | |
… | |
658 | on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } |
863 | on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } |
659 | ); |
864 | ); |
660 | $hbox->add (new CFPlus::UI::Slider |
865 | $hbox->add (new CFPlus::UI::Slider |
661 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
866 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
662 | tooltip => "The volume of the background music. Changes are instant.", |
867 | tooltip => "The volume of the background music. Changes are instant.", |
663 | 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 } |
664 | ); |
869 | ); |
665 | |
870 | |
666 | $table->add_at (1, $row++, new CFPlus::UI::Button |
871 | $table->add_at (1, $row++, new CFPlus::UI::Button |
667 | expand => 1, align => 0, text => "Apply", |
872 | expand => 1, align => 0, text => "Apply", |
668 | tooltip => "Apply the audio settings", |
873 | tooltip => "Apply the audio settings", |
… | |
… | |
1081 | text => $CFG->{profile}{default}{host}, |
1286 | text => $CFG->{profile}{default}{host}, |
1082 | 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", |
1083 | on_changed => sub { |
1288 | on_changed => sub { |
1084 | my ($self, $value) = @_; |
1289 | my ($self, $value) = @_; |
1085 | $CFG->{profile}{default}{host} = $value; |
1290 | $CFG->{profile}{default}{host} = $value; |
1086 | 0 |
1291 | 1 |
1087 | } |
1292 | } |
1088 | ); |
1293 | ); |
1089 | |
1294 | |
1090 | $vbox->add (new CFPlus::UI::Button |
1295 | $vbox->add (new CFPlus::UI::Button |
1091 | expand => 1, |
1296 | expand => 1, |
1092 | text => "Server List", |
1297 | text => "Server List", |
1093 | other => $METASERVER, |
1298 | other => $METASERVER, |
1094 | tooltip => "Show a list of available crossfire servers", |
1299 | tooltip => "Show a list of available crossfire servers", |
1095 | on_activate => sub { $METASERVER->toggle_visibility; 0 }, |
1300 | on_activate => sub { $METASERVER->toggle_visibility; 0 }, |
1096 | on_visibility_change => sub { $METASERVER->hide unless $_[1]; 0 }, |
1301 | on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 }, |
1097 | ); |
1302 | ); |
1098 | } |
1303 | } |
1099 | |
1304 | |
1100 | $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"); |
1101 | $table->add_at (1, 4, new CFPlus::UI::Entry |
1306 | $table->add_at (1, 4, new CFPlus::UI::Entry |
1102 | text => $CFG->{profile}{default}{user}, |
1307 | text => $CFG->{profile}{default}{user}, |
1103 | tooltip => "The name of your character on the server", |
1308 | tooltip => "The name of your character on the server", |
1104 | on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value } |
1309 | on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 } |
1105 | ); |
1310 | ); |
1106 | |
1311 | |
1107 | $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"); |
1108 | $table->add_at (1, 5, new CFPlus::UI::Entry |
1313 | $table->add_at (1, 5, new CFPlus::UI::Entry |
1109 | text => $CFG->{profile}{default}{password}, |
1314 | text => $CFG->{profile}{default}{password}, |
1110 | hidden => 1, |
1315 | hidden => 1, |
1111 | tooltip => "The password for your character", |
1316 | tooltip => "The password for your character", |
1112 | on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value } |
1317 | on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value; 1 } |
1113 | ); |
1318 | ); |
1114 | |
1319 | |
1115 | $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"); |
1116 | $table->add_at (1, 7, new CFPlus::UI::Slider |
1321 | $table->add_at (1, 7, new CFPlus::UI::Slider |
1117 | force_w => 100, |
1322 | force_w => 100, |
1118 | range => [$CFG->{mapsize}, 10, 100, 0, 1], |
1323 | range => [$CFG->{mapsize}, 10, 100, 0, 1], |
1119 | 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. " |
1120 | . "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, " |
1121 | . "but you also increase bandwidth requirements and latency. " |
1326 | . "but you also increase bandwidth requirements and latency. " |
1122 | . "This option is only used once at log-in.", |
1327 | . "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 }, |
1328 | on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 }, |
1124 | ); |
1329 | ); |
1125 | |
1330 | |
1126 | $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"); |
1127 | $table->add_at (1, 8, new CFPlus::UI::Entry |
1332 | $table->add_at (1, 8, new CFPlus::UI::Entry |
1128 | text => $CFG->{output_rate}, |
1333 | text => $CFG->{output_rate}, |
1129 | 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 " |
1130 | . "when sending images, to ensure interactiveness. When 0 or unset, the server " |
1335 | . "when sending data. When 0 or unset, the server " |
1131 | . "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.", |
1132 | on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, |
1338 | on_changed => sub { $CFG->{output_rate} = $_[1]; 1 }, |
1133 | ); |
1339 | ); |
1134 | |
1340 | |
1135 | $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"); |
1136 | $table->add_at (1, 9, new CFPlus::UI::Entry |
1342 | $table->add_at (1, 9, new CFPlus::UI::Entry |
1137 | text => $CFG->{output_count}, |
1343 | text => $CFG->{output_count}, |
1138 | 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.", |
1139 | on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, |
1345 | on_changed => sub { $CFG->{output_count} = $_[1]; 1 }, |
1140 | ); |
1346 | ); |
1141 | |
1347 | |
1142 | $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"); |
1143 | $table->add_at (1, 10, new CFPlus::UI::Entry |
1349 | $table->add_at (1, 10, new CFPlus::UI::Entry |
1144 | text => $CFG->{output_sync}, |
1350 | text => $CFG->{output_sync}, |
1145 | 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.", |
1146 | on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, |
1352 | on_changed => sub { $CFG->{output_sync} = $_[1]; 1 }, |
1147 | ); |
1353 | ); |
1148 | |
1354 | |
1149 | $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button |
1355 | $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button |
1150 | expand => 1, |
1356 | expand => 1, |
1151 | align => 0, |
1357 | align => 0, |
1152 | text => "Login", |
1358 | text => "Login", |
1153 | on_activate => sub { |
1359 | on_activate => sub { |
1154 | $CONN ? stop_game |
1360 | $CONN ? stop_game |
1155 | : start_game; |
1361 | : start_game; |
1156 | 0 |
1362 | 1 |
1157 | }, |
1363 | }, |
1158 | ); |
1364 | ); |
1159 | |
1365 | |
1160 | $vbox->add (new CFPlus::UI::FancyFrame |
1366 | $vbox->add (new CFPlus::UI::FancyFrame |
1161 | label => "Server Info", |
1367 | label => "Server Info", |
… | |
… | |
1796 | CFPlus::OpenGL::shutdown; |
2002 | CFPlus::OpenGL::shutdown; |
1797 | |
2003 | |
1798 | undef $SDL_ACTIVE; |
2004 | undef $SDL_ACTIVE; |
1799 | } |
2005 | } |
1800 | |
2006 | |
1801 | sub audio_channel_finished { |
|
|
1802 | my ($channel) = @_; |
|
|
1803 | |
|
|
1804 | #warn "channel $channel finished\n";#d# |
|
|
1805 | } |
|
|
1806 | |
|
|
1807 | sub audio_music_set { |
|
|
1808 | my ($songs) = @_; |
|
|
1809 | |
|
|
1810 | my @want = |
|
|
1811 | grep $_, |
|
|
1812 | map $CONN->{music_meta}{$_}, |
|
|
1813 | @$songs; |
|
|
1814 | |
|
|
1815 | if (@want) { |
|
|
1816 | @MUSIC_WANT = @want; |
|
|
1817 | &audio_music_changed (); |
|
|
1818 | } |
|
|
1819 | } |
|
|
1820 | |
|
|
1821 | sub audio_music_start { |
|
|
1822 | my $path = $MUSIC_PLAYING->{path} |
|
|
1823 | or return; |
|
|
1824 | |
|
|
1825 | CFPlus::DB::prefetch_file $path, 1024_000, sub { |
|
|
1826 | return unless $SDL_MIXER; |
|
|
1827 | |
|
|
1828 | # music might have changed... |
|
|
1829 | $path eq $MUSIC_PLAYING->{path} |
|
|
1830 | or return &audio_music_start (); |
|
|
1831 | |
|
|
1832 | my $rwops = new_from_file CFPlus::RW $path; |
|
|
1833 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops; |
|
|
1834 | |
|
|
1835 | my $NOW = time; |
|
|
1836 | |
|
|
1837 | if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { |
|
|
1838 | my $pos = $MUSIC_PLAYING->{stop_pos}; |
|
|
1839 | $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); |
|
|
1840 | $MUSIC_START = time - $pos; |
|
|
1841 | } else { |
|
|
1842 | $MUSIC_PLAYER->play (0); |
|
|
1843 | $MUSIC_START = time; |
|
|
1844 | } |
|
|
1845 | |
|
|
1846 | delete $MUSIC_PLAYING->{stop_time}; |
|
|
1847 | delete $MUSIC_PLAYING->{stop_pos}; |
|
|
1848 | } |
|
|
1849 | } |
|
|
1850 | |
|
|
1851 | sub audio_music_changed { |
|
|
1852 | return unless $CFG->{bgm_enable}; |
|
|
1853 | return unless $SDL_MIXER; |
|
|
1854 | |
|
|
1855 | # default MUSIC_WANT == MUSIC_DEFAULT |
|
|
1856 | @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; |
|
|
1857 | |
|
|
1858 | # if the currently playing song is acceptable, let it continue |
|
|
1859 | return if $MUSIC_PLAYING |
|
|
1860 | && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; |
|
|
1861 | |
|
|
1862 | my $NOW = time; |
|
|
1863 | |
|
|
1864 | if ($MUSIC_PLAYING) { |
|
|
1865 | $MUSIC_PLAYING->{stop_time} = $NOW; |
|
|
1866 | $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; |
|
|
1867 | CFPlus::MixMusic::fade_out 1000; |
|
|
1868 | } else { |
|
|
1869 | # sort by stop time, oldest first |
|
|
1870 | @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; |
|
|
1871 | |
|
|
1872 | # if the most recently-played piece played very recently, |
|
|
1873 | # resume it, else choose the oldest piece for rotation. |
|
|
1874 | $MUSIC_PLAYING = |
|
|
1875 | $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME |
|
|
1876 | ? $MUSIC_WANT[-1] |
|
|
1877 | : $MUSIC_WANT[0]; |
|
|
1878 | |
|
|
1879 | audio_music_start; |
|
|
1880 | } |
|
|
1881 | } |
|
|
1882 | |
|
|
1883 | sub audio_music_finished { |
|
|
1884 | $MUSIC_PLAYING = undef; |
|
|
1885 | undef $MUSIC_PLAYER; |
|
|
1886 | |
|
|
1887 | audio_music_changed; |
|
|
1888 | } |
|
|
1889 | |
|
|
1890 | sub audio_init { |
|
|
1891 | if ($CFG->{audio_enable}) { |
|
|
1892 | if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { |
|
|
1893 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
|
|
1894 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
|
|
1895 | |
|
|
1896 | unless ($SDL_MIXER) { |
|
|
1897 | status "Unable to open sound device: there will be no sound"; |
|
|
1898 | return; |
|
|
1899 | } |
|
|
1900 | |
|
|
1901 | CFPlus::Mix_AllocateChannels 8; |
|
|
1902 | CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128; |
|
|
1903 | |
|
|
1904 | audio_music_finished; |
|
|
1905 | |
|
|
1906 | local $_; |
|
|
1907 | while (<$fh>) { |
|
|
1908 | next if /^\s*#/; |
|
|
1909 | next if /^\s*$/; |
|
|
1910 | |
|
|
1911 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
1912 | |
|
|
1913 | push @SOUNDS, "$volume,$file"; |
|
|
1914 | |
|
|
1915 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
1916 | my $rwops = new_from_file CFPlus::RW CFPlus::find_rcfile "sounds/$file"; |
|
|
1917 | my $chunk = new CFPlus::MixChunk $rwops; |
|
|
1918 | $chunk->volume ($volume * 128 / 100); |
|
|
1919 | $chunk |
|
|
1920 | }; |
|
|
1921 | } |
|
|
1922 | } else { |
|
|
1923 | status "unable to open sound config: $!"; |
|
|
1924 | } |
|
|
1925 | } else { |
|
|
1926 | undef $SDL_MIXER; |
|
|
1927 | } |
|
|
1928 | } |
|
|
1929 | |
|
|
1930 | sub audio_shutdown { |
|
|
1931 | CFPlus::Mix_CloseAudio if $SDL_MIXER; |
|
|
1932 | undef $SDL_MIXER; |
|
|
1933 | @SOUNDS = (); |
|
|
1934 | %AUDIO_CHUNKS = (); |
|
|
1935 | } |
|
|
1936 | |
|
|
1937 | my %animate_object; |
2007 | my %animate_object; |
1938 | my $animate_timer; |
2008 | my $animate_timer; |
1939 | |
2009 | |
1940 | my $fps = 9; |
2010 | my $fps = 9; |
1941 | |
|
|
1942 | my %demo;#d# |
|
|
1943 | |
2011 | |
1944 | sub force_refresh { |
2012 | sub force_refresh { |
1945 | $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; |
1946 | debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; |
2014 | debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; |
1947 | |
2015 | |
… | |
… | |
2032 | |
2100 | |
2033 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2101 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2034 | |
2102 | |
2035 | my %DEF_CFG = ( |
2103 | my %DEF_CFG = ( |
2036 | sdl_mode => 0, |
2104 | sdl_mode => 0, |
2037 | width => 640, |
|
|
2038 | height => 480, |
|
|
2039 | fullscreen => 0, |
2105 | fullscreen => 0, |
2040 | fast => 0, |
2106 | fast => 0, |
2041 | map_scale => 1, |
2107 | map_scale => 1, |
2042 | fow_enable => 1, |
2108 | fow_enable => 1, |
2043 | fow_intensity => 0, |
2109 | fow_intensity => 0, |