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.195 by root, Tue Jul 31 01:03:52 2007 UTC vs.
Revision 1.215 by root, Fri Aug 17 21:18:01 2007 UTC

113our $CONN; 113our $CONN;
114our $PROFILE; # current profile 114our $PROFILE; # current profile
115our $FAST; # fast, low-quality mode, possibly useful for software-rendering 115our $FAST; # fast, low-quality mode, possibly useful for software-rendering
116 116
117our $WANT_REFRESH; 117our $WANT_REFRESH;
118our $CAN_REFRESH;
119 118
120our @SDL_MODES; 119our @SDL_MODES;
121our $WIDTH; 120our $WIDTH;
122our $HEIGHT; 121our $HEIGHT;
123our $FULLSCREEN; 122our $FULLSCREEN;
144our $SETUP_KEYBOARD; 143our $SETUP_KEYBOARD;
145 144
146our $PL_NOTEBOOK; 145our $PL_NOTEBOOK;
147our $PL_WINDOW; 146our $PL_WINDOW;
148 147
148our $MUSIC_PLAYING_WIDGET;
149our $LICENSE_WIDGET;
150
149our $INVENTORY_PAGE; 151our $INVENTORY_PAGE;
150our $STATS_PAGE; 152our $STATS_PAGE;
151our $SKILL_PAGE; 153our $SKILL_PAGE;
152our $SPELL_PAGE; 154our $SPELL_PAGE;
153our $SPELL_LIST; 155our $SPELL_LIST;
159our $STATWIDS; 161our $STATWIDS;
160 162
161our $SDL_ACTIVE; 163our $SDL_ACTIVE;
162our %SDL_CB; 164our %SDL_CB;
163 165
166our $ALT_ENTER_MESSAGE;
167our $STATUSBOX;
168our $DEBUG_STATUS;
169
170our $INV;
171our $INVR;
172our $INVR_HB;
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_CHUNK; # audio files 204our %AUDIO_CHUNK; # audio "files"
174 205our %AUDIO_PLAY; # which audio faces should be played
175our $ALT_ENTER_MESSAGE;
176our $STATUSBOX;
177our $DEBUG_STATUS;
178
179our $INV;
180our $INVR;
181our $INV_RIGHT_HB;
182
183our $PICKUP_CFG;
184
185#############################################################################
186#TODO: maybe move into own audio module...
187 206
188sub audio_channel_finished { 207sub audio_channel_finished {
189 my ($channel) = @_; 208 my ($channel) = @_;
190 209
191# warn "channel $channel finished\n";#d# 210# warn "channel $channel finished\n";#d#
192} 211}
193 212
194our %AUDIO_PLAY;
195our %AUDIO_CHUNK;
196
197sub audio_sound_push($) { 213sub audio_sound_push($) {
198 my ($face) = @_; 214 my ($face) = @_;
215
216 $CFG->{effects_enable}
217 or return;
218
219 $AUDIO_PLAY{$face}
220 or return;
199 221
200 if (my $chunk = $AUDIO_CHUNK{$face}) { 222 if (my $chunk = $AUDIO_CHUNK{$face}) {
201 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
202 my (undef, $dx, $dy, $vol) = @$_; 224 my (undef, $dx, $dy, $vol) = @$_;
203 225
204 my $channel = CFPlus::Channel::find; 226 my $channel = CFPlus::Channel::find;
205 $channel->volume (128 + $vol); 227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
206 $dx = $dx / 10 * 255;
207 $channel->set_panning ((min 255, 255 - $dx), (min 255, 255 + $dx));
208
209# my $angle = $dx ? : $dx < 0 ?
210# my $distance = -$vol;
211# $channel->set_position ($angle, $distance); 228 $channel->set_position_r ($dx, $dy, 20);
212
213 $chunk->play ($channel); 229 $chunk->play ($channel);
214 } 230 }
215 } else { 231 } else {
216 # sound_meta not set means data is in flight either way 232 # sound_meta not set means data is in flight either way
217 my $meta = $CONN->{sound_meta}{$face} 233 my $meta = $CONN->{sound_meta}{$face}
218 or return; 234 or return;
219 235
236 # if its a jingle, play it as ambient music
237 if ($meta->{meta}{jingle}) {
238 if (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 }
242 } else {
220 # fetch from database 243 # fetch from database
221 CFPlus::DB::get res_data => $meta->{name}, sub { 244 CFPlus::DB::get res_data => $meta->{name}, sub {
222 my $vol = $meta->{meta}{volume} || 1;
223 my $rwops = new CFPlus::RW $_[0]; 245 my $rwops = new CFPlus::RW $_[0];
224 my $chunk = new CFPlus::MixChunk $rwops; 246 my $chunk = new CFPlus::MixChunk $rwops
225 $chunk->volume ($vol * 128); 247 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
248 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
226 $AUDIO_CHUNK{$face} = $chunk; 249 $AUDIO_CHUNK{$face} = $chunk;
227 250
228 audio_sound_push ($face); 251 audio_sound_push ($face);
252 };
229 }; 253 }
230 } 254 }
231} 255}
232 256
233sub audio_sound_play { 257sub audio_sound_play {
234 my ($face, $dx, $dy, $vol) = @_; 258 my ($face, $dx, $dy, $vol) = @_;
235 259
236 $SDL_MIXER 260 $SDL_MIXER
237 or return; 261 or return;
262 $CFG->{effects_enable}
263 or return;
238 264
239 my $queue = $AUDIO_PLAY{$face} ||= []; 265 my $queue = $AUDIO_PLAY{$face} ||= [];
240 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s 266 push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
241 audio_sound_push $face 267 audio_sound_push $face
242 unless @$queue > 1; 268 unless @$queue > 1;
269}
270
271sub audio_music_set_meta {
272 my ($meta) = @_;
273
274 $MUSIC_PLAYING_META = $meta;
275 $MUSIC_PLAYING_WIDGET->set_markup (
276 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n"
277 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n"
278 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n"
279 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license})
280 );
243} 281}
244 282
245sub audio_music_update_volume { 283sub audio_music_update_volume {
246 return unless $MUSIC_PLAYING_META; 284 return unless $MUSIC_PLAYING_META;
247 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 285 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1;
248 my $base = $CFG->{bgm_volume}; 286 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume};
249 CFPlus::MixMusic::volume $base * $volume * 128; 287 CFPlus::MixMusic::volume $base * $volume * 128;
250}
251
252sub audio_music_set_ambient {
253 my ($songs) = @_;
254
255 my @want =
256 grep $_,
257 map $CONN->{music_meta}{$_},
258 @$songs;
259
260 if (@want) {
261 @MUSIC_WANT = @want;
262 &audio_music_changed ();
263 }
264} 288}
265 289
266sub audio_music_start { 290sub audio_music_start {
267 my $meta = $MUSIC_PLAYING_META; 291 my $meta = $MUSIC_PLAYING_META;
268 292
280 my $rwops = $meta->{path} 304 my $rwops = $meta->{path}
281 ? new_from_file CFPlus::RW $meta->{path} 305 ? new_from_file CFPlus::RW $meta->{path}
282 : new CFPlus::RW $$MUSIC_PLAYING_DATA; 306 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
283 307
284 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops 308 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
285 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error 309 or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
286 310
287 my $NOW = time; 311 my $NOW = time;
288 312
289 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 313 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
290 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 314 my $pos = $MUSIC_PLAYING_META->{stop_pos};
293 } else { 317 } else {
294 $MUSIC_PLAYER->play (0); 318 $MUSIC_PLAYER->play (0);
295 $MUSIC_START = time; 319 $MUSIC_START = time;
296 } 320 }
297 321
298 delete $MUSIC_PLAYING_META->{stop_time}; 322 delete $meta->{stop_time};
299 delete $MUSIC_PLAYING_META->{stop_pos}; 323 delete $meta->{stop_pos};
300 } 324 }
301} 325}
302 326
303sub audio_music_changed { 327sub audio_music_push {
304 return unless $CFG->{bgm_enable};
305 return unless $SDL_MIXER; 328 return unless $SDL_MIXER;
306 329
330 my $fade_out;
331
332 if (@MUSIC_JINGLE) {
333 @MUSIC_HAVE = $MUSIC_JINGLE[0];
334 $fade_out = 333;
335 } else {
336 return unless $CFG->{bgm_enable};
337
338 my @have =
339 grep $_,
340 map $CONN->{music_meta}{$_},
341 @$MUSIC_WANT;
342
343 @MUSIC_HAVE = @have
344 if @have;
345
307 # default MUSIC_WANT == MUSIC_DEFAULT 346 # default MUSIC_HAVE == MUSIC_DEFAULT
308 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; 347 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
348 $fade_out = 1000;
349 }
309 350
310 # if the currently playing song is acceptable, let it continue 351 # if the currently playing song is acceptable, let it continue
311 return if $MUSIC_PLAYING_META
312 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT; 352 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
313 353
314 my $NOW = time; 354 my $NOW = time;
315 355
316 if ($MUSIC_PLAYING_META) { 356 if ($MUSIC_PLAYING_META) {
317 $MUSIC_PLAYING_META->{stop_time} = $NOW; 357 $MUSIC_PLAYING_META->{stop_time} = $NOW;
318 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START; 358 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
319 CFPlus::MixMusic::fade_out 1000; 359 CFPlus::MixMusic::fade_out $fade_out;
320 } else { 360 } else {
321 # sort by stop time, oldest first 361 # sort by stop time, oldest first
322 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; 362 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
323 363
324 # if the most recently-played piece played very recently, 364 # if the most recently-played piece played very recently,
325 # resume it, else choose the oldest piece for rotation. 365 # resume it, else choose the oldest piece for rotation.
326 $MUSIC_PLAYING_META = 366 audio_music_set_meta
327 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME 367 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
328 ? $MUSIC_WANT[-1] 368 ? $MUSIC_HAVE[-1]
329 : $MUSIC_WANT[0]; 369 : $MUSIC_HAVE[0];
330 370
331 audio_music_start; 371 audio_music_start;
332 } 372 }
333} 373}
334 374
375sub audio_music_set_ambient {
376 my ($songs) = @_;
377
378 $MUSIC_WANT = $songs;
379 audio_music_push;
380}
381
335sub audio_music_finished { 382sub audio_music_finished {
383 # we compress multiple jingles of the same type
384 shift @MUSIC_JINGLE
385 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
386
387 $MUSIC_PLAYING_WIDGET->clear;
388
336 undef $MUSIC_PLAYER; 389 undef $MUSIC_PLAYER;
337 undef $MUSIC_PLAYING_META; 390 undef $MUSIC_PLAYING_META;
338 undef $MUSIC_PLAYING_DATA; 391 undef $MUSIC_PLAYING_DATA;
339 392
340 audio_music_changed; 393 audio_music_push;
394}
395
396sub audio_init {
397 if ($CFG->{audio_enable}) {
398 $ENV{MIX_EFFECTSMAXSPEED} = 1;
399 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
400
401 unless ($SDL_MIXER) {
402 status "Unable to open sound device: there will be no sound";
403 return;
404 }
405
406 CFPlus::Mix_AllocateChannels 16;
407
408 audio_music_finished;
409 } else {
410 undef $SDL_MIXER;
411 }
412}
413
414sub audio_shutdown {
415 undef $MUSIC_PLAYER;
416 undef $MUSIC_PLAYING_META;
417 undef $MUSIC_PLAYING_DATA;
418
419 $MUSIC_WANT = [];
420 @MUSIC_JINGLE = ();
421 %AUDIO_PLAY = ();
422 %AUDIO_CHUNK = ();
423
424 CFPlus::Mix_CloseAudio if $SDL_MIXER;
425 undef $SDL_MIXER;
341} 426}
342 427
343############################################################################# 428#############################################################################
344
345sub status {
346 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
347}
348
349sub debug {
350 $DEBUG_STATUS->set_text ($_[0]);
351}
352
353sub message {
354 my ($para) = @_;
355 $MESSAGE_WINDOW->message ($para);
356}
357 429
358sub destroy_query_dialog { 430sub destroy_query_dialog {
359 (delete $_[0]{query_dialog})->destroy 431 (delete $_[0]{query_dialog})->destroy
360 if $_[0]{query_dialog}; 432 if $_[0]{query_dialog};
361} 433}
695 state => $CFG->{fullscreen}, 767 state => $CFG->{fullscreen},
696 tooltip => "Bring the client into fullscreen mode.", 768 tooltip => "Bring the client into fullscreen mode.",
697 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 769 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
698 ); 770 );
699 771
772 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1");
773 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
774 state => $CFG->{opengl11},
775 tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in "
776 . "higher memory usage and slower performance. It will, however, help tremendously on "
777 . "cards that claim to support a feature but fall back to software rendering. "
778 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
779 . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you "
780 . "experience extremely low framerates and your card should do better, try this option.</b>",
781 on_changed => sub { my ($self, $value) = @_; $CFG->{opengl11} = $value; 0 }
782 );
783
700 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 784 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
701 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 785 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
702 state => $CFG->{fast}, 786 state => $CFG->{fast},
703 tooltip => "Lower the visual quality considerably to speed up rendering.", 787 tooltip => "Lower the visual quality considerably to speed up rendering.",
704 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 788 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
730 814
731 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); 815 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing");
732 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 816 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
733 state => $CFG->{map_smoothing}, 817 state => $CFG->{map_smoothing},
734 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " 818 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. "
735 . "This increases load on the graphics subsystem and works only with 2.x servers. " 819 . "This increases load on the graphics subsystem and works only with TRT servers. "
736 . "Changes take effect at next connection only.", 820 . "Changes take effect at next login only.",
737 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 821 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
738 ); 822 );
739 823
740 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); 824 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
741 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 825 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
752 ); 836 );
753 837
754 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 838 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
755 $table->add_at (1, $row++, new CFPlus::UI::Slider 839 $table->add_at (1, $row++, new CFPlus::UI::Slider
756 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 840 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
757 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 841 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, "
842 . "but you still need to press apply to correctly re-layout the widget.",
758 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 843 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
759 ); 844 );
760 845
761 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 846 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
762 $table->add_at (1, $row++, new CFPlus::UI::Slider 847 $table->add_at (1, $row++, new CFPlus::UI::Slider
784} 869}
785 870
786sub audio_setup { 871sub audio_setup {
787 my $vbox = new CFPlus::UI::VBox; 872 my $vbox = new CFPlus::UI::VBox;
788 873
789 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); 874 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]);
790 875
791 my $row = 0; 876 my $row = 0;
792 877
793 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); 878 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable");
794 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 879 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
798 ); 883 );
799# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 884# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
800# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { 885# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
801# $CFG->{effects_volume} = $_[1]; 886# $CFG->{effects_volume} = $_[1];
802# }); 887# });
888
889 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects");
890 $table->add_at (1, $row, new CFPlus::UI::CheckBox
891 expand => 1, state => $CFG->{effects_enable},
892 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
893 on_changed => sub {
894 $CFG->{effects_enable} = $_[1];
895 $CONN->update_fx_want if $CONN;
896 0
897 }
898 );
899 $table->add_at (2, $row++, new CFPlus::UI::Slider
900 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
901 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
902 . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
903 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
904 );
905
803 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 906 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
804 $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox); 907 $table->add_at (1, $row, new CFPlus::UI::CheckBox
805 $hbox->add (new CFPlus::UI::CheckBox
806 expand => 1, state => $CFG->{bgm_enable}, 908 expand => 1, state => $CFG->{bgm_enable},
807 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 909 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
808 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 910 on_changed => sub {
911 $CFG->{bgm_enable} = $_[1];
912 $CONN->update_fx_want if $CONN;
913 0
914 }
809 ); 915 );
810 $hbox->add (new CFPlus::UI::Slider 916 $table->add_at (2, $row++, new CFPlus::UI::Slider
811 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 917 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
812 tooltip => "The volume of the background music. Changes are instant.", 918 tooltip => "The volume of the background music. Changes are instant.",
813 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 919 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
814 ); 920 );
815 921
816 $table->add_at (1, $row++, new CFPlus::UI::Button 922 $table->add_at (1, $row++, new CFPlus::UI::Button
817 expand => 1, align => 0, text => "Apply", 923 c_colspan => 2, expand => 1, align => 0, text => "Apply",
818 tooltip => "Apply the audio settings", 924 tooltip => "Apply the audio settings",
819 on_activate => sub { 925 on_activate => sub {
820 audio_shutdown (); 926 audio_shutdown ();
821 audio_init (); 927 audio_init ();
822 0 928 0
893 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); 999 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } );
894 1000
895 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# 1001 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
896 1002
897 $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0); 1003 $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0);
898 $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", rowspan => 1, colspan => 2); 1004 $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", c_rowspan => 1, c_colspan => 2);
899 $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1); 1005 $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1);
900 $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2); 1006 $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", c_rowspan => 1, c_colspan => 2);
901 $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, colspan => 1); 1007 $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1);
902 $t->add_at (1,1, new CFPlus::UI::Label text => "e"); 1008 $t->add_at (1,1, new CFPlus::UI::Label text => "e");
903 1009
904 $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas); 1010 $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas);
905 1011
906 $c->add_items ({ 1012 $c->add_items ({
1502 $sw1->add ($INV = new CFPlus::UI::Inventory); 1608 $sw1->add ($INV = new CFPlus::UI::Inventory);
1503 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1609 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1504 1610
1505 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1611 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1506 1612
1507 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1613 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1508 1614
1509 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1615 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1510 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1616 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1511 1617
1512 # XXX: Call after $INVR = ... because set_opencont sets the items 1618 # XXX: Call after $INVR = ... because set_opencont sets the items
1513 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); 1619 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor");
1514 1620
1515 $hb 1621 $hb
1622}
1623
1624sub media_window {
1625 my $vb = new CFPlus::UI::VBox;
1626
1627 $vb->add (new CFPlus::UI::FancyFrame
1628 label => "Currently playing music",
1629 child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
1630 child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8),
1631 );
1632
1633 $vb->add (new CFPlus::UI::FancyFrame
1634 label => "Other media used in this session",
1635 expand => 1,
1636 child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller
1637 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
1638 );
1639
1640 $vb
1641}
1642
1643sub add_license {
1644 my ($meta) = @_;
1645
1646 $meta = $meta->{meta}
1647 or return;
1648
1649 $meta->{license} || $meta->{author} || $meta->{source}
1650 or return;
1651
1652 $LICENSE_WIDGET->add_paragraph ({
1653 fg => [1, 1, 1, 1],
1654 markup => "<small>"
1655 . "<b>Name:</b> " . (CFPlus::asxml $meta->{name}) . "\n"
1656 . "<b>Author:</b> " . (CFPlus::asxml $meta->{author}) . "\n"
1657 . "<b>Source:</b> " . (CFPlus::asxml $meta->{source}) . "\n"
1658 . "<b>License:</b> " . (CFPlus::asxml $meta->{license}) . "\n"
1659 . "</small>",
1660 });
1661 $LICENSE_WIDGET->scroll_to_bottom;
1516} 1662}
1517 1663
1518sub toggle_player_page { 1664sub toggle_player_page {
1519 my ($widget) = @_; 1665 my ($widget) = @_;
1520 1666
1559 $ntb->add_tab ( 1705 $ntb->add_tab (
1560 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1706 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1561 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1707 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1562 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1708 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1563 ); 1709 );
1564 $ntb->add_tab (Pickup => autopickup_setup, 1710 $ntb->add_tab (Pickup => autopickup_setup,
1565 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1711 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1712
1713 $ntb->add_tab (Media => media_window,
1714 "License, Author and Source info for media sent by the server.");
1566 1715
1567 $ntb->set_current_page ($INVENTORY_PAGE); 1716 $ntb->set_current_page ($INVENTORY_PAGE);
1568 1717
1569 $plwin->add ($ntb); 1718 $plwin->add ($ntb);
1570 $plwin 1719 $plwin
1724 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1873 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1725 ); 1874 );
1726 $hb->add (new CFPlus::UI::Button 1875 $hb->add (new CFPlus::UI::Button
1727 text => "Quit anyway", 1876 text => "Quit anyway",
1728 expand => 1, 1877 expand => 1,
1729 on_activate => sub { exit }, 1878 on_activate => sub { Event::unloop_all },
1730 ); 1879 );
1731 } 1880 }
1732 1881
1733 $QUIT_DIALOG->show; 1882 $QUIT_DIALOG->show;
1734 $QUIT_DIALOG->grab_focus; 1883 $QUIT_DIALOG->grab_focus;
1928 tooltip => "Terminates the program", 2077 tooltip => "Terminates the program",
1929 on_activate => sub { 2078 on_activate => sub {
1930 if ($CONN) { 2079 if ($CONN) {
1931 open_quit_dialog; 2080 open_quit_dialog;
1932 } else { 2081 } else {
1933 exit; 2082 Event::unloop_all;
1934 } 2083 }
1935 0 2084 0
1936 }, 2085 },
1937 ); 2086 );
1938 2087
1939 $BUTTONBAR->show; 2088 $BUTTONBAR->show;
1940 $SETUP_DIALOG->show; 2089 $SETUP_DIALOG->show;
2090 $MESSAGE_WINDOW->show;
1941 } 2091 }
1942 2092
1943 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 2093 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
1944} 2094}
1945 2095
1947 CFPlus::OpenGL::shutdown; 2097 CFPlus::OpenGL::shutdown;
1948 2098
1949 undef $SDL_ACTIVE; 2099 undef $SDL_ACTIVE;
1950} 2100}
1951 2101
1952sub audio_init {
1953 if ($CFG->{audio_enable}) {
1954 $ENV{MIX_EFFECTSMAXSPEED} = 1;
1955 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
1956
1957 unless ($SDL_MIXER) {
1958 status "Unable to open sound device: there will be no sound";
1959 return;
1960 }
1961
1962 CFPlus::Mix_AllocateChannels 16;
1963
1964 audio_music_finished;
1965 } else {
1966 undef $SDL_MIXER;
1967 }
1968}
1969
1970sub audio_shutdown {
1971 CFPlus::Mix_CloseAudio if $SDL_MIXER;
1972 undef $SDL_MIXER;
1973 @SOUNDS = ();
1974 %AUDIO_CHUNK = ();
1975}
1976
1977my %animate_object; 2102my %animate_object;
1978my $animate_timer; 2103my $animate_timer;
1979 2104
1980my $fps = 9; 2105my $fps = 9;
1981 2106
1982sub force_refresh { 2107sub force_refresh {
2108 if ($ENV{CFPLUS_DEBUG} & 4) {
1983 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2109 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
1984 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2110 debug sprintf "%3.2f", $fps;
2111 }
1985 2112
1986 $CFPlus::UI::ROOT->draw; 2113 $CFPlus::UI::ROOT->draw;
1987 2114 CFPlus::SDL_GL_SwapBuffers;
1988 $WANT_REFRESH = 0;
1989 $CAN_REFRESH = 0;
1990 $LAST_REFRESH = $NOW; 2115 $LAST_REFRESH = $NOW;
1991 2116 $WANT_REFRESH->stop;
1992 CFPlus::SDL_GL_SwapBuffers;
1993} 2117}
1994 2118
2119$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2120
1995my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { 2121my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub {
1996 $NOW = time; 2122 $NOW = time;
1997 2123
1998 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2124 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
1999 for CFPlus::poll_events; 2125 for CFPlus::poll_events;
2000 2126
2001 if (%animate_object) { 2127 if (%animate_object) {
2002 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2128 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2003 ++$WANT_REFRESH; 2129 $WANT_REFRESH->start;
2004 }
2005
2006 if ($WANT_REFRESH) {
2007 force_refresh;
2008 } else {
2009 $CAN_REFRESH = 1;
2010 } 2130 }
2011}); 2131});
2012 2132
2013sub animation_start { 2133sub animation_start {
2014 my ($widget) = @_; 2134 my ($widget) = @_;
2072 2192
2073 my %DEF_CFG = ( 2193 my %DEF_CFG = (
2074 sdl_mode => 0, 2194 sdl_mode => 0,
2075 fullscreen => 0, 2195 fullscreen => 0,
2076 fast => 0, 2196 fast => 0,
2197 opengl11 => 0,
2077 map_scale => 1, 2198 map_scale => 1,
2078 fow_enable => 1, 2199 fow_enable => 1,
2079 fow_intensity => 0, 2200 fow_intensity => 0,
2080 map_smoothing => 1, 2201 map_smoothing => 1,
2081 gui_fontsize => 1, 2202 gui_fontsize => 1,
2083 gauge_fontsize => 1, 2204 gauge_fontsize => 1,
2084 gauge_size => 0.35, 2205 gauge_size => 0.35,
2085 stat_fontsize => 0.7, 2206 stat_fontsize => 0.7,
2086 mapsize => 100, 2207 mapsize => 100,
2087 audio_enable => 1, 2208 audio_enable => 1,
2209 effects_enable => 1,
2210 effects_volume => 1,
2088 bgm_enable => 1, 2211 bgm_enable => 1,
2089 bgm_volume => 0.25, 2212 bgm_volume => 0.5,
2090 output_sync => 1, 2213 output_sync => 1,
2091 output_count => 1, 2214 output_count => 1,
2092 output_rate => "", 2215 output_rate => "",
2093 pickup => 0, 2216 pickup => 0,
2094 inv_sort => "mtime", 2217 inv_sort => "mtime",
2168} 2291}
2169 2292
2170show_tip_of_the_day if $CFG->{show_tips}; 2293show_tip_of_the_day if $CFG->{show_tips};
2171 2294
2172Event::loop; 2295Event::loop;
2296
2297#video_shutdown;
2298#audio_shutdown;
2173#CFPlus::SDL_Quit; 2299CFPlus::SDL_Quit;
2174#CFPlus::_exit 0;
2175
2176END {
2177 CFPlus::SDL_Quit;
2178 CFPlus::DB::Server::stop; 2300CFPlus::DB::Server::stop;
2179}
2180 2301
2181=head1 NAME 2302=head1 NAME
2182 2303
2183cfplus - A Crossfire+ and Crossfire game client 2304cfplus - A Crossfire TRT and Crossfire game client
2184 2305
2185=head1 SYNOPSIS 2306=head1 SYNOPSIS
2186 2307
2187Just run it - no commandline arguments are supported. 2308Just run it - no commandline arguments are supported.
2188 2309
2189=head1 USAGE 2310=head1 USAGE
2190 2311
2191cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used 2312cfplus utilises OpenGL for all UI elements and the game. It is supposed to
2192fullscreen and interactively. 2313be used in fullscreen mode and interactively.
2193 2314
2194=head1 DEBUGGING 2315=head1 DEBUGGING
2195 2316
2196 2317
2197CFPLUS_DEBUG - environment variable 2318CFPLUS_DEBUG - environment variable

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines