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.198 by root, Tue Jul 31 02:45:39 2007 UTC vs.
Revision 1.204 by root, Mon Aug 6 05:06:33 2007 UTC

144our $SETUP_KEYBOARD; 144our $SETUP_KEYBOARD;
145 145
146our $PL_NOTEBOOK; 146our $PL_NOTEBOOK;
147our $PL_WINDOW; 147our $PL_WINDOW;
148 148
149our $MUSIC_PLAYING_WIDGET;
150our $LICENSE_WIDGET;
151
149our $INVENTORY_PAGE; 152our $INVENTORY_PAGE;
150our $STATS_PAGE; 153our $STATS_PAGE;
151our $SKILL_PAGE; 154our $SKILL_PAGE;
152our $SPELL_PAGE; 155our $SPELL_PAGE;
153our $SPELL_LIST; 156our $SPELL_LIST;
211} 214}
212 215
213sub audio_sound_push($) { 216sub audio_sound_push($) {
214 my ($face) = @_; 217 my ($face) = @_;
215 218
219 $CFG->{effects_enable}
220 or return;
221
216 if (my $chunk = $AUDIO_CHUNK{$face}) { 222 if (my $chunk = $AUDIO_CHUNK{$face}) {
217 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
218 my (undef, $dx, $dy, $vol) = @$_; 224 my (undef, $dx, $dy, $vol) = @$_;
219 225
220 my $channel = CFPlus::Channel::find; 226 my $channel = CFPlus::Channel::find;
221 $channel->volume ($vol * 128 / 255); 227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
222 $dx = $dx / 10 * 255; 228 $dx = $dx / 10 * 255;
223 $channel->set_panning (255 - $dx, 255 + $dx); 229 $channel->set_panning (255 - $dx, 255 + $dx);
224 230
225# my $angle = $dx ? : $dx < 0 ? 231# my $angle = $dx ? : $dx < 0 ?
226# my $distance = -$vol; 232# my $distance = -$vol;
233 my $meta = $CONN->{sound_meta}{$face} 239 my $meta = $CONN->{sound_meta}{$face}
234 or return; 240 or return;
235 241
236 # if its a jingle, play it as ambient music 242 # if its a jingle, play it as ambient music
237 if ($meta->{meta}{jingle}) { 243 if ($meta->{meta}{jingle}) {
238 delete $AUDIO_PLAY{$face}; # take the jingle out of the sound queue 244 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 245 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
240 &audio_music_push ($face); 246 &audio_music_push ($face);
247 }
241 } else { 248 } else {
242 # fetch from database 249 # fetch from database
243 CFPlus::DB::get res_data => $meta->{name}, sub { 250 CFPlus::DB::get res_data => $meta->{name}, sub {
244 my $rwops = new CFPlus::RW $_[0]; 251 my $rwops = new CFPlus::RW $_[0];
245 my $chunk = new CFPlus::MixChunk $rwops; 252 my $chunk = new CFPlus::MixChunk $rwops
253 or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
246 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 254 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
247 $AUDIO_CHUNK{$face} = $chunk; 255 $AUDIO_CHUNK{$face} = $chunk;
248 256
249 audio_sound_push ($face); 257 audio_sound_push ($face);
250 }; 258 };
255sub audio_sound_play { 263sub audio_sound_play {
256 my ($face, $dx, $dy, $vol) = @_; 264 my ($face, $dx, $dy, $vol) = @_;
257 265
258 $SDL_MIXER 266 $SDL_MIXER
259 or return; 267 or return;
268 $CFG->{effects_enable}
269 or return;
260 270
261 my $queue = $AUDIO_PLAY{$face} ||= []; 271 my $queue = $AUDIO_PLAY{$face} ||= [];
262 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s 272 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
263 audio_sound_push $face 273 audio_sound_push $face
264 unless @$queue > 1; 274 unless @$queue > 1;
275}
276
277sub audio_music_set_meta {
278 my ($meta) = @_;
279
280 $MUSIC_PLAYING_META = $meta;
281 $MUSIC_PLAYING_WIDGET->set_markup (
282 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n"
283 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n"
284 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n"
285 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license})
286 );
265} 287}
266 288
267sub audio_music_update_volume { 289sub audio_music_update_volume {
268 return unless $MUSIC_PLAYING_META; 290 return unless $MUSIC_PLAYING_META;
269 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 291 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1;
288 my $rwops = $meta->{path} 310 my $rwops = $meta->{path}
289 ? new_from_file CFPlus::RW $meta->{path} 311 ? new_from_file CFPlus::RW $meta->{path}
290 : new CFPlus::RW $$MUSIC_PLAYING_DATA; 312 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
291 313
292 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops 314 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
293 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error 315 or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
294 316
295 my $NOW = time; 317 my $NOW = time;
296 318
297 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 319 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
298 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 320 my $pos = $MUSIC_PLAYING_META->{stop_pos};
301 } else { 323 } else {
302 $MUSIC_PLAYER->play (0); 324 $MUSIC_PLAYER->play (0);
303 $MUSIC_START = time; 325 $MUSIC_START = time;
304 } 326 }
305 327
306 delete $MUSIC_PLAYING_META->{stop_time}; 328 delete $meta->{stop_time};
307 delete $MUSIC_PLAYING_META->{stop_pos}; 329 delete $meta->{stop_pos};
308 } 330 }
309} 331}
310 332
311sub audio_music_push { 333sub audio_music_push {
312 return unless $SDL_MIXER; 334 return unless $SDL_MIXER;
331 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 353 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
332 $fade_out = 1000; 354 $fade_out = 1000;
333 } 355 }
334 356
335 # if the currently playing song is acceptable, let it continue 357 # if the currently playing song is acceptable, let it continue
336 return if $MUSIC_PLAYING_META
337 && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 358 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
338 359
339 my $NOW = time; 360 my $NOW = time;
340 361
341 if ($MUSIC_PLAYING_META) { 362 if ($MUSIC_PLAYING_META) {
342 $MUSIC_PLAYING_META->{stop_time} = $NOW; 363 $MUSIC_PLAYING_META->{stop_time} = $NOW;
346 # sort by stop time, oldest first 367 # sort by stop time, oldest first
347 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 368 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
348 369
349 # if the most recently-played piece played very recently, 370 # if the most recently-played piece played very recently,
350 # resume it, else choose the oldest piece for rotation. 371 # resume it, else choose the oldest piece for rotation.
351 $MUSIC_PLAYING_META = 372 audio_music_set_meta
352 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 373 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
353 ? $MUSIC_HAVE[-1] 374 ? $MUSIC_HAVE[-1]
354 : $MUSIC_HAVE[0]; 375 : $MUSIC_HAVE[0];
355 376
356 audio_music_start; 377 audio_music_start;
366 387
367sub audio_music_finished { 388sub audio_music_finished {
368 # we compress multiple jingles of the same type 389 # we compress multiple jingles of the same type
369 shift @MUSIC_JINGLE 390 shift @MUSIC_JINGLE
370 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 391 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
392
393 $MUSIC_PLAYING_WIDGET->clear;
371 394
372 undef $MUSIC_PLAYER; 395 undef $MUSIC_PLAYER;
373 undef $MUSIC_PLAYING_META; 396 undef $MUSIC_PLAYING_META;
374 undef $MUSIC_PLAYING_DATA; 397 undef $MUSIC_PLAYING_DATA;
375 398
839} 862}
840 863
841sub audio_setup { 864sub audio_setup {
842 my $vbox = new CFPlus::UI::VBox; 865 my $vbox = new CFPlus::UI::VBox;
843 866
844 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); 867 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]);
845 868
846 my $row = 0; 869 my $row = 0;
847 870
848 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); 871 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable");
849 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 872 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
853 ); 876 );
854# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 877# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
855# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { 878# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
856# $CFG->{effects_volume} = $_[1]; 879# $CFG->{effects_volume} = $_[1];
857# }); 880# });
881
882 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
883 $table->add_at (1, $row, new CFPlus::UI::CheckBox
884 expand => 1, state => $CFG->{effects_enable},
885 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
886 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 }
887 );
888 $table->add_at (2, $row++, new CFPlus::UI::Slider
889 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
890 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
891 . "is set highest and you use your operating system volume setting. Changes are instant.",
892 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
893 );
894
858 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 895 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
859 $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox); 896 $table->add_at (1, $row, new CFPlus::UI::CheckBox
860 $hbox->add (new CFPlus::UI::CheckBox
861 expand => 1, state => $CFG->{bgm_enable}, 897 expand => 1, state => $CFG->{bgm_enable},
862 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 898 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
863 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 899 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 }
864 ); 900 );
865 $hbox->add (new CFPlus::UI::Slider 901 $table->add_at (2, $row++, new CFPlus::UI::Slider
866 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 902 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
867 tooltip => "The volume of the background music. Changes are instant.", 903 tooltip => "The volume of the background music. Changes are instant.",
868 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 904 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
869 ); 905 );
870 906
871 $table->add_at (1, $row++, new CFPlus::UI::Button 907 $table->add_at (1, $row++, new CFPlus::UI::Button
872 expand => 1, align => 0, text => "Apply", 908 c_colspan => 2, expand => 1, align => 0, text => "Apply",
873 tooltip => "Apply the audio settings", 909 tooltip => "Apply the audio settings",
874 on_activate => sub { 910 on_activate => sub {
875 audio_shutdown (); 911 audio_shutdown ();
876 audio_init (); 912 audio_init ();
877 0 913 0
948 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); 984 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } );
949 985
950 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# 986 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
951 987
952 $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0); 988 $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0);
953 $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", rowspan => 1, colspan => 2); 989 $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", c_rowspan => 1, c_colspan => 2);
954 $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1); 990 $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1);
955 $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2); 991 $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", c_rowspan => 1, c_colspan => 2);
956 $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, colspan => 1); 992 $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1);
957 $t->add_at (1,1, new CFPlus::UI::Label text => "e"); 993 $t->add_at (1,1, new CFPlus::UI::Label text => "e");
958 994
959 $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas); 995 $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas);
960 996
961 $c->add_items ({ 997 $c->add_items ({
1568 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); 1604 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor");
1569 1605
1570 $hb 1606 $hb
1571} 1607}
1572 1608
1609sub media_window {
1610 my $vb = new CFPlus::UI::VBox;
1611
1612 $vb->add (new CFPlus::UI::FancyFrame
1613 label => "Currently playing music",
1614 child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
1615 child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8),
1616 );
1617
1618 $vb->add (new CFPlus::UI::FancyFrame
1619 label => "Other media used in this session",
1620 expand => 1,
1621 child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller
1622 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
1623 );
1624
1625 $vb
1626}
1627
1628sub add_license {
1629 my ($meta) = @_;
1630
1631 $meta = $meta->{meta}
1632 or return;
1633
1634 $meta->{license} || $meta->{author} || $meta->{source}
1635 or return;
1636
1637 $LICENSE_WIDGET->add_paragraph ({
1638 fg => [1, 1, 1, 1],
1639 markup => "<small>"
1640 . "<b>Name:</b> " . (CFPlus::asxml $meta->{name}) . "\n"
1641 . "<b>Author:</b> " . (CFPlus::asxml $meta->{author}) . "\n"
1642 . "<b>Source:</b> " . (CFPlus::asxml $meta->{source}) . "\n"
1643 . "<b>License:</b> " . (CFPlus::asxml $meta->{license}) . "\n"
1644 . "</small>",
1645 });
1646 $LICENSE_WIDGET->scroll_to_bottom;
1647}
1648
1573sub toggle_player_page { 1649sub toggle_player_page {
1574 my ($widget) = @_; 1650 my ($widget) = @_;
1575 1651
1576 if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) { 1652 if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) {
1577 $PL_WINDOW->hide; 1653 $PL_WINDOW->hide;
1614 $ntb->add_tab ( 1690 $ntb->add_tab (
1615 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1691 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1616 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1692 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1617 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1693 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1618 ); 1694 );
1619 $ntb->add_tab (Pickup => autopickup_setup, 1695 $ntb->add_tab (Pickup => autopickup_setup,
1620 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1696 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1697
1698 $ntb->add_tab (Media => media_window,
1699 "License, Author and Source info for media sent by the server.");
1621 1700
1622 $ntb->set_current_page ($INVENTORY_PAGE); 1701 $ntb->set_current_page ($INVENTORY_PAGE);
1623 1702
1624 $plwin->add ($ntb); 1703 $plwin->add ($ntb);
1625 $plwin 1704 $plwin
2113 gauge_fontsize => 1, 2192 gauge_fontsize => 1,
2114 gauge_size => 0.35, 2193 gauge_size => 0.35,
2115 stat_fontsize => 0.7, 2194 stat_fontsize => 0.7,
2116 mapsize => 100, 2195 mapsize => 100,
2117 audio_enable => 1, 2196 audio_enable => 1,
2197 effects_enable => 1,
2198 effects_volume => 1,
2118 bgm_enable => 1, 2199 bgm_enable => 1,
2119 bgm_volume => 0.25, 2200 bgm_volume => 0.5,
2120 output_sync => 1, 2201 output_sync => 1,
2121 output_count => 1, 2202 output_count => 1,
2122 output_rate => "", 2203 output_rate => "",
2123 pickup => 0, 2204 pickup => 0,
2124 inv_sort => "mtime", 2205 inv_sort => "mtime",
2202Event::loop; 2283Event::loop;
2203#CFPlus::SDL_Quit; 2284#CFPlus::SDL_Quit;
2204#CFPlus::_exit 0; 2285#CFPlus::_exit 0;
2205 2286
2206END { 2287END {
2288 video_shutdown;
2289 audio_shutdown;
2207 CFPlus::SDL_Quit; 2290 CFPlus::SDL_Quit;
2208 CFPlus::DB::Server::stop; 2291 CFPlus::DB::Server::stop;
2209} 2292}
2210 2293
2211=head1 NAME 2294=head1 NAME
2212 2295
2213cfplus - A Crossfire+ and Crossfire game client 2296cfplus - A Crossfire TRT and Crossfire game client
2214 2297
2215=head1 SYNOPSIS 2298=head1 SYNOPSIS
2216 2299
2217Just run it - no commandline arguments are supported. 2300Just run it - no commandline arguments are supported.
2218 2301
2219=head1 USAGE 2302=head1 USAGE
2220 2303
2221cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used 2304cfplus utilises OpenGL for all UI elements and the game. It is supposed to
2222fullscreen and interactively. 2305be used in fullscreen mode and interactively.
2223 2306
2224=head1 DEBUGGING 2307=head1 DEBUGGING
2225 2308
2226 2309
2227CFPLUS_DEBUG - environment variable 2310CFPLUS_DEBUG - environment variable

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines