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.194 by root, Tue Jul 31 00:50:04 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;
167our $MUSIC_PLAYING_DATA; 168our $MUSIC_PLAYING_DATA;
168our $MUSIC_PLAYING_META; 169our $MUSIC_PLAYING_META;
169our $MUSIC_PLAYER; 170our $MUSIC_PLAYER;
170our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 171our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
171our @SOUNDS; # event => file mapping 172our @SOUNDS; # event => file mapping
172our %AUDIO_CHUNKS; # audio files 173our %AUDIO_CHUNK; # audio files
173 174
174our $ALT_ENTER_MESSAGE; 175our $ALT_ENTER_MESSAGE;
175our $STATUSBOX; 176our $STATUSBOX;
176our $DEBUG_STATUS; 177our $DEBUG_STATUS;
177 178
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 },
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 },
477 }; 466 };
478 467
479 if ($CONN) { 468 if ($CONN) {
480 CFPlus::lowdelay fileno $CONN->{fh}; 469 CFPlus::lowdelay fileno $CONN->{fh};
481 470
492 $SETUP_DIALOG->show; 481 $SETUP_DIALOG->show;
493 $PL_WINDOW->hide; 482 $PL_WINDOW->hide;
494 $SPELL_LIST->clear_spells; 483 $SPELL_LIST->clear_spells;
495 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); 484 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
496 485
497 &audio_music_set ([]); 486 &audio_music_set_ambient ([]);
498 487
499 return unless $CONN; 488 return unless $CONN;
500 489
501 status "connection closed"; 490 status "connection closed";
502 491
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#
1806} 1796}
1807 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 = CFPlus::Channel::find;
1809 $channel->volume (128 + $vol);
1810 $dx = $dx / 10 * 255;
1811 $channel->set_panning ((min 255, 255 - $dx), (min 255, 255 + $dx));
1812
1813# my $angle = $dx ? : $dx < 0 ?
1814# my $distance = -$vol;
1815# $channel->set_position ($angle, $distance);
1816
1817 $chunk->play ($channel);
1818 }
1819 } else {
1820 # sound_meta not set means data is in flight either way
1821 my $meta = $CONN->{sound_meta}{$face}
1822 or return;
1823
1824 # fetch from database
1825 CFPlus::DB::get res_data => $meta->{name}, sub {
1826 my $vol = $meta->{meta}{volume} || 1;
1827 my $rwops = new CFPlus::RW $_[0];
1828 my $chunk = new CFPlus::MixChunk $rwops;
1829 $chunk->volume ($vol * 128);
1830 $AUDIO_CHUNK{$face} = $chunk;
1831
1832 audio_sound_push ($face);
1833 };
1834 }
1835}
1836
1837sub audio_sound_play {
1838 my ($face, $dx, $dy, $vol) = @_;
1839
1840 $SDL_MIXER
1841 or return;
1842
1843 my $queue = $AUDIO_PLAY{$face} ||= [];
1844 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
1845 audio_sound_push $face
1846 unless @$queue > 1;
1847}
1848
1808sub audio_music_set { 1849sub audio_music_set_ambient {
1809 my ($songs) = @_; 1850 my ($songs) = @_;
1810 1851
1811 my @want = 1852 my @want =
1812 grep $_, 1853 grep $_,
1813 map $CONN->{music_meta}{$_}, 1854 map $CONN->{music_meta}{$_},
1894 audio_music_changed; 1935 audio_music_changed;
1895} 1936}
1896 1937
1897sub audio_init { 1938sub audio_init {
1898 if ($CFG->{audio_enable}) { 1939 if ($CFG->{audio_enable}) {
1899 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") {
1900 $ENV{MIX_EFFECTSMAXSPEED} = 1; 1940 $ENV{MIX_EFFECTSMAXSPEED} = 1;
1901 $SDL_MIXER = !CFPlus::Mix_OpenAudio; 1941 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
1902 1942
1903 unless ($SDL_MIXER) { 1943 unless ($SDL_MIXER) {
1904 status "Unable to open sound device: there will be no sound"; 1944 status "Unable to open sound device: there will be no sound";
1905 return; 1945 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 } 1946 }
1947
1948 CFPlus::Mix_AllocateChannels 16;
1949 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1950
1951 audio_music_finished;
1932 } else { 1952 } else {
1933 undef $SDL_MIXER; 1953 undef $SDL_MIXER;
1934 } 1954 }
1935} 1955}
1936 1956
1937sub audio_shutdown { 1957sub audio_shutdown {
1938 CFPlus::Mix_CloseAudio if $SDL_MIXER; 1958 CFPlus::Mix_CloseAudio if $SDL_MIXER;
1939 undef $SDL_MIXER; 1959 undef $SDL_MIXER;
1940 @SOUNDS = (); 1960 @SOUNDS = ();
1941 %AUDIO_CHUNKS = (); 1961 %AUDIO_CHUNK = ();
1942} 1962}
1943 1963
1944my %animate_object; 1964my %animate_object;
1945my $animate_timer; 1965my $animate_timer;
1946 1966
1947my $fps = 9; 1967my $fps = 9;
1948
1949my %demo;#d#
1950 1968
1951sub force_refresh { 1969sub force_refresh {
1952 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 1970 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
1953 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 1971 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4;
1954 1972
2039 2057
2040 CFPlus::UI::set_layout ($::CFG->{layout}); 2058 CFPlus::UI::set_layout ($::CFG->{layout});
2041 2059
2042 my %DEF_CFG = ( 2060 my %DEF_CFG = (
2043 sdl_mode => 0, 2061 sdl_mode => 0,
2044 width => 640,
2045 height => 480,
2046 fullscreen => 0, 2062 fullscreen => 0,
2047 fast => 0, 2063 fast => 0,
2048 map_scale => 1, 2064 map_scale => 1,
2049 fow_enable => 1, 2065 fow_enable => 1,
2050 fow_intensity => 0, 2066 fow_intensity => 0,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines