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.190 by root, Sun Jul 29 18:56:03 2007 UTC vs.
Revision 1.192 by root, Mon Jul 30 02:16:16 2007 UTC

71unshift @INC, $ENV{PAR_TEMP} 71unshift @INC, $ENV{PAR_TEMP}
72 if %PAR::LibCache; 72 if %PAR::LibCache;
73 73
74use Time::HiRes 'time'; 74use Time::HiRes 'time';
75use Event; 75use Event;
76use List::Util qw(max min);
76 77
77use Crossfire; 78use Crossfire;
78use Crossfire::Protocol::Constants; 79use Crossfire::Protocol::Constants;
79 80
80use Compress::LZF; 81use Compress::LZF;
459 mapmap => $MAPMAP, 460 mapmap => $MAPMAP,
460 query => \&server_query, 461 query => \&server_query,
461 462
462 setup_req => { 463 setup_req => {
463 smoothing => $CFG->{map_smoothing}*1, 464 smoothing => $CFG->{map_smoothing}*1,
464 },
465
466 sound_play => sub {
467 my ($x, $y, $soundnum, $type) = @_;
468
469 $SDL_MIXER
470 or return;
471
472 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
473 or return;
474
475 $chunk->play;
476 }, 465 },
477 }; 466 };
478 467
479 if ($CONN) { 468 if ($CONN) {
480 CFPlus::lowdelay fileno $CONN->{fh}; 469 CFPlus::lowdelay fileno $CONN->{fh};
1082 text => $CFG->{profile}{default}{host}, 1071 text => $CFG->{profile}{default}{host},
1083 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", 1072 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
1084 on_changed => sub { 1073 on_changed => sub {
1085 my ($self, $value) = @_; 1074 my ($self, $value) = @_;
1086 $CFG->{profile}{default}{host} = $value; 1075 $CFG->{profile}{default}{host} = $value;
1087 0 1076 1
1088 } 1077 }
1089 ); 1078 );
1090 1079
1091 $vbox->add (new CFPlus::UI::Button 1080 $vbox->add (new CFPlus::UI::Button
1092 expand => 1, 1081 expand => 1,
1093 text => "Server List", 1082 text => "Server List",
1094 other => $METASERVER, 1083 other => $METASERVER,
1095 tooltip => "Show a list of available crossfire servers", 1084 tooltip => "Show a list of available crossfire servers",
1096 on_activate => sub { $METASERVER->toggle_visibility; 0 }, 1085 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1097 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 0 }, 1086 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1098 ); 1087 );
1099 } 1088 }
1100 1089
1101 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username"); 1090 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username");
1102 $table->add_at (1, 4, new CFPlus::UI::Entry 1091 $table->add_at (1, 4, new CFPlus::UI::Entry
1103 text => $CFG->{profile}{default}{user}, 1092 text => $CFG->{profile}{default}{user},
1104 tooltip => "The name of your character on the server", 1093 tooltip => "The name of your character on the server",
1105 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value } 1094 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 }
1106 ); 1095 );
1107 1096
1108 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password"); 1097 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password");
1109 $table->add_at (1, 5, new CFPlus::UI::Entry 1098 $table->add_at (1, 5, new CFPlus::UI::Entry
1110 text => $CFG->{profile}{default}{password}, 1099 text => $CFG->{profile}{default}{password},
1111 hidden => 1, 1100 hidden => 1,
1112 tooltip => "The password for your character", 1101 tooltip => "The password for your character",
1113 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value } 1102 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value; 1 }
1114 ); 1103 );
1115 1104
1116 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); 1105 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size");
1117 $table->add_at (1, 7, new CFPlus::UI::Slider 1106 $table->add_at (1, 7, new CFPlus::UI::Slider
1118 force_w => 100, 1107 force_w => 100,
1119 range => [$CFG->{mapsize}, 10, 100, 0, 1], 1108 range => [$CFG->{mapsize}, 10, 100, 0, 1],
1120 tooltip => "This is the size of the portion of the map update the server sends you. " 1109 tooltip => "This is the size of the portion of the map update the server sends you. "
1121 . "If you set this to a high value you will be able to see further, " 1110 . "If you set this to a high value you will be able to see further, "
1122 . "but you also increase bandwidth requirements and latency. " 1111 . "but you also increase bandwidth requirements and latency. "
1123 . "This option is only used once at log-in.", 1112 . "This option is only used once at log-in.",
1124 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, 1113 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 },
1125 ); 1114 );
1126 1115
1127 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); 1116 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1128 $table->add_at (1, 8, new CFPlus::UI::Entry 1117 $table->add_at (1, 8, new CFPlus::UI::Entry
1129 text => $CFG->{output_rate}, 1118 text => $CFG->{output_rate},
1130 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " 1119 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1131 . "when sending images, to ensure interactiveness. When 0 or unset, the server " 1120 . "when sending data. When 0 or unset, the server "
1132 . "default will be used, which is usually around 100kb/s.", 1121 . "default will be used, which is usually around 100kb/s. Most servers will "
1122 . "dynamically find an optimal rate, so adjust this only when necessary.",
1133 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, 1123 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1134 ); 1124 );
1135 1125
1136 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); 1126 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1137 $table->add_at (1, 9, new CFPlus::UI::Entry 1127 $table->add_at (1, 9, new CFPlus::UI::Entry
1138 text => $CFG->{output_count}, 1128 text => $CFG->{output_count},
1139 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1129 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1140 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1130 on_changed => sub { $CFG->{output_count} = $_[1]; 1 },
1141 ); 1131 );
1142 1132
1143 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1133 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1144 $table->add_at (1, 10, new CFPlus::UI::Entry 1134 $table->add_at (1, 10, new CFPlus::UI::Entry
1145 text => $CFG->{output_sync}, 1135 text => $CFG->{output_sync},
1146 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1136 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1147 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1137 on_changed => sub { $CFG->{output_sync} = $_[1]; 1 },
1148 ); 1138 );
1149 1139
1150 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button 1140 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1151 expand => 1, 1141 expand => 1,
1152 align => 0, 1142 align => 0,
1153 text => "Login", 1143 text => "Login",
1154 on_activate => sub { 1144 on_activate => sub {
1155 $CONN ? stop_game 1145 $CONN ? stop_game
1156 : start_game; 1146 : start_game;
1157 0 1147 1
1158 }, 1148 },
1159 ); 1149 );
1160 1150
1161 $vbox->add (new CFPlus::UI::FancyFrame 1151 $vbox->add (new CFPlus::UI::FancyFrame
1162 label => "Server Info", 1152 label => "Server Info",
1800} 1790}
1801 1791
1802sub audio_channel_finished { 1792sub audio_channel_finished {
1803 my ($channel) = @_; 1793 my ($channel) = @_;
1804 1794
1805 #warn "channel $channel finished\n";#d# 1795# warn "channel $channel finished\n";#d#
1796}
1797
1798our %AUDIO_PLAY;
1799our %AUDIO_CHUNK;
1800
1801sub audio_sound_push($) {
1802 my ($face) = @_;
1803
1804 if (my $chunk = $AUDIO_CHUNK{$face}) {
1805 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
1806 my (undef, $dx, $dy, $vol) = @$_;
1807
1808 my $channel = $chunk->play
1809 or return;
1810
1811 $channel->volume (128 + $vol);
1812 $dx = $dx / 10 * 255;
1813 $channel->set_panning ((min 255, 255 - $dx), (min 255, 255 + $dx));
1814# my $angle = $dx ? : $dx < 0 ?
1815# my $distance = -$vol;
1816# $channel->set_position ($angle, $distance);
1817 }
1818 } else {
1819 # sound_meta not set means data is in flight either way
1820 my $meta = $CONN->{sound_meta}{$face}
1821 or return;
1822
1823 # fetch from database
1824 CFPlus::DB::get res_data => $meta->{name}, sub {
1825 my $vol = $meta->{meta}{volume} || 100;
1826 my $rwops = new CFPlus::RW $_[0];
1827 my $chunk = new CFPlus::MixChunk $rwops;
1828 $chunk->volume ($vol * 128 / 100);
1829 $AUDIO_CHUNK{$face} = $chunk;
1830
1831 audio_sound_push ($face);
1832 };
1833 }
1834}
1835
1836sub audio_sound_play {
1837 my ($face, $dx, $dy, $vol) = @_;
1838
1839 $SDL_MIXER
1840 or return;
1841
1842 my $queue = $AUDIO_PLAY{$face} ||= [];
1843 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
1844 audio_sound_push $face
1845 unless @$queue > 1;
1806} 1846}
1807 1847
1808sub audio_music_set { 1848sub audio_music_set {
1809 my ($songs) = @_; 1849 my ($songs) = @_;
1810 1850
1894 audio_music_changed; 1934 audio_music_changed;
1895} 1935}
1896 1936
1897sub audio_init { 1937sub audio_init {
1898 if ($CFG->{audio_enable}) { 1938 if ($CFG->{audio_enable}) {
1899 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") {
1900 $ENV{MIX_EFFECTSMAXSPEED} = 1; 1939 $ENV{MIX_EFFECTSMAXSPEED} = 1;
1901 $SDL_MIXER = !CFPlus::Mix_OpenAudio; 1940 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
1902 1941
1903 unless ($SDL_MIXER) { 1942 unless ($SDL_MIXER) {
1904 status "Unable to open sound device: there will be no sound"; 1943 status "Unable to open sound device: there will be no sound";
1905 return; 1944 return;
1906 }
1907
1908 CFPlus::Mix_AllocateChannels 8;
1909 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1910
1911 audio_music_finished;
1912
1913 local $_;
1914 while (<$fh>) {
1915 next if /^\s*#/;
1916 next if /^\s*$/;
1917
1918 my ($file, $volume, $event) = split /\s+/, $_, 3;
1919
1920 push @SOUNDS, "$volume,$file";
1921
1922 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
1923 my $rwops = new_from_file CFPlus::RW CFPlus::find_rcfile "sounds/$file";
1924 my $chunk = new CFPlus::MixChunk $rwops;
1925 $chunk->volume ($volume * 128 / 100);
1926 $chunk
1927 };
1928 }
1929 } else {
1930 status "unable to open sound config: $!";
1931 } 1945 }
1946
1947 CFPlus::Mix_AllocateChannels 16;
1948 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1949
1950 audio_music_finished;
1932 } else { 1951 } else {
1933 undef $SDL_MIXER; 1952 undef $SDL_MIXER;
1934 } 1953 }
1935} 1954}
1936 1955

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines