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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines