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.188 by root, Sun Jul 29 03:58:26 2007 UTC vs.
Revision 1.190 by root, Sun Jul 29 18:56:03 2007 UTC

162 162
163our $SDL_MIXER; 163our $SDL_MIXER;
164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; 164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
165our @MUSIC_WANT; 165our @MUSIC_WANT;
166our $MUSIC_START; 166our $MUSIC_START;
167our $MUSIC_PLAYING; 167our $MUSIC_PLAYING_DATA;
168our $MUSIC_PLAYING_META;
168our $MUSIC_PLAYER; 169our $MUSIC_PLAYER;
169our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 170our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
170our @SOUNDS; # event => file mapping 171our @SOUNDS; # event => file mapping
171our %AUDIO_CHUNKS; # audio files 172our %AUDIO_CHUNKS; # audio files
172 173
1121 . "but you also increase bandwidth requirements and latency. " 1122 . "but you also increase bandwidth requirements and latency. "
1122 . "This option is only used once at log-in.", 1123 . "This option is only used once at log-in.",
1123 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, 1124 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 },
1124 ); 1125 );
1125 1126
1126 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Face Prefetch");
1127 $table->add_at (1, 8, new CFPlus::UI::CheckBox
1128 state => $CFG->{face_prefetch},
1129 tooltip => "<b>Background Image Prefetch</b>\n\n"
1130 . "If enabled, the client automatically pre-fetches images from the server. "
1131 . "This might increase or create lag, but increases the chances "
1132 . "of faces being ready for display when you encounter them. "
1133 . "It also uses up server bandwidth on every connect, "
1134 . "so only set it if you really need to prefetch images. "
1135 . "This option can be set and unset any time.",
1136 on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 },
1137 );
1138
1139 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); 1127 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1140 $table->add_at (1, 9, new CFPlus::UI::Entry 1128 $table->add_at (1, 8, new CFPlus::UI::Entry
1141 text => $CFG->{output_rate}, 1129 text => $CFG->{output_rate},
1142 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " 1130 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed "
1143 . "when sending images, to ensure interactiveness. When 0 or unset, the server " 1131 . "when sending images, to ensure interactiveness. When 0 or unset, the server "
1144 . "default will be used, which is usually around 100kb/s.", 1132 . "default will be used, which is usually around 100kb/s.",
1145 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, 1133 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 },
1146 ); 1134 );
1147 1135
1148 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); 1136 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1149 $table->add_at (1, 10, new CFPlus::UI::Entry 1137 $table->add_at (1, 9, new CFPlus::UI::Entry
1150 text => $CFG->{output_count}, 1138 text => $CFG->{output_count},
1151 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1139 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1152 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1140 on_changed => sub { $CFG->{output_count} = $_[1]; 0 },
1153 ); 1141 );
1154 1142
1155 $table->add_at (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1143 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1156 $table->add_at (1, 11, new CFPlus::UI::Entry 1144 $table->add_at (1, 10, new CFPlus::UI::Entry
1157 text => $CFG->{output_sync}, 1145 text => $CFG->{output_sync},
1158 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1146 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1159 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1147 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 },
1160 ); 1148 );
1161 1149
1162 $table->add_at (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button 1150 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1163 expand => 1, 1151 expand => 1,
1164 align => 0, 1152 align => 0,
1165 text => "Login", 1153 text => "Login",
1166 on_activate => sub { 1154 on_activate => sub {
1167 $CONN ? stop_game 1155 $CONN ? stop_game
1830 &audio_music_changed (); 1818 &audio_music_changed ();
1831 } 1819 }
1832} 1820}
1833 1821
1834sub audio_music_start { 1822sub audio_music_start {
1835 my $path = $MUSIC_PLAYING->{path} 1823 my $meta = $MUSIC_PLAYING_META;
1836 or return;
1837 1824
1838 CFPlus::DB::prefetch_file $path, 1024_000, sub { 1825 CFPlus::DB::get res_data => $meta->{name}, sub {
1839 return unless $SDL_MIXER; 1826 return unless $SDL_MIXER;
1840 1827
1841 # music might have changed... 1828 # music might have changed...
1842 $path eq $MUSIC_PLAYING->{path} 1829 $meta eq $MUSIC_PLAYING_META
1843 or return &audio_music_start (); 1830 or return &audio_music_start ();
1844 1831
1845 my $rwops = new_from_file CFPlus::RW $path; 1832 $MUSIC_PLAYING_DATA = \$_[0];
1833
1834 my $rwops = $meta->{path}
1835 ? new_from_file CFPlus::RW $meta->{path}
1836 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
1837
1846 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops; 1838 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
1839 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
1847 1840
1848 my $NOW = time; 1841 my $NOW = time;
1849 1842
1850 if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { 1843 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
1851 my $pos = $MUSIC_PLAYING->{stop_pos}; 1844 my $pos = $MUSIC_PLAYING_META->{stop_pos};
1852 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 1845 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
1853 $MUSIC_START = time - $pos; 1846 $MUSIC_START = time - $pos;
1854 } else { 1847 } else {
1855 $MUSIC_PLAYER->play (0); 1848 $MUSIC_PLAYER->play (0);
1856 $MUSIC_START = time; 1849 $MUSIC_START = time;
1857 } 1850 }
1858 1851
1859 delete $MUSIC_PLAYING->{stop_time}; 1852 delete $MUSIC_PLAYING_META->{stop_time};
1860 delete $MUSIC_PLAYING->{stop_pos}; 1853 delete $MUSIC_PLAYING_META->{stop_pos};
1861 } 1854 }
1862} 1855}
1863 1856
1864sub audio_music_changed { 1857sub audio_music_changed {
1865 return unless $CFG->{bgm_enable}; 1858 return unless $CFG->{bgm_enable};
1867 1860
1868 # default MUSIC_WANT == MUSIC_DEFAULT 1861 # default MUSIC_WANT == MUSIC_DEFAULT
1869 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; 1862 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
1870 1863
1871 # if the currently playing song is acceptable, let it continue 1864 # if the currently playing song is acceptable, let it continue
1872 return if $MUSIC_PLAYING 1865 return if $MUSIC_PLAYING_META
1873 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; 1866 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT;
1874 1867
1875 my $NOW = time; 1868 my $NOW = time;
1876 1869
1877 if ($MUSIC_PLAYING) { 1870 if ($MUSIC_PLAYING_META) {
1878 $MUSIC_PLAYING->{stop_time} = $NOW; 1871 $MUSIC_PLAYING_META->{stop_time} = $NOW;
1879 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; 1872 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
1880 CFPlus::MixMusic::fade_out 1000; 1873 CFPlus::MixMusic::fade_out 1000;
1881 } else { 1874 } else {
1882 # sort by stop time, oldest first 1875 # sort by stop time, oldest first
1883 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; 1876 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
1884 1877
1885 # if the most recently-played piece played very recently, 1878 # if the most recently-played piece played very recently,
1886 # resume it, else choose the oldest piece for rotation. 1879 # resume it, else choose the oldest piece for rotation.
1887 $MUSIC_PLAYING = 1880 $MUSIC_PLAYING_META =
1888 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME 1881 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
1889 ? $MUSIC_WANT[-1] 1882 ? $MUSIC_WANT[-1]
1890 : $MUSIC_WANT[0]; 1883 : $MUSIC_WANT[0];
1891 1884
1892 audio_music_start; 1885 audio_music_start;
1893 } 1886 }
1894} 1887}
1895 1888
1896sub audio_music_finished { 1889sub audio_music_finished {
1897 $MUSIC_PLAYING = undef;
1898 undef $MUSIC_PLAYER; 1890 undef $MUSIC_PLAYER;
1891 undef $MUSIC_PLAYING_META;
1892 undef $MUSIC_PLAYING_DATA;
1899 1893
1900 audio_music_changed; 1894 audio_music_changed;
1901} 1895}
1902 1896
1903sub audio_init { 1897sub audio_init {
1992 1986
1993sub animation_stop { 1987sub animation_stop {
1994 my ($widget) = @_; 1988 my ($widget) = @_;
1995 delete $animate_object{$widget}; 1989 delete $animate_object{$widget};
1996} 1990}
1997
1998# check once/second for faces that need to be prefetched
1999# this should, of course, only run on demand, but
2000# SDL forces worse things on us....
2001
2002Event->timer (after => 1, interval => 0.25, cb => sub {
2003 $CONN->face_prefetch
2004 if $CONN;
2005});
2006 1991
2007%SDL_CB = ( 1992%SDL_CB = (
2008 CFPlus::SDL_QUIT => sub { 1993 CFPlus::SDL_QUIT => sub {
2009 exit; 1994 exit;
2010 }, 1995 },
2071 stat_fontsize => 0.7, 2056 stat_fontsize => 0.7,
2072 mapsize => 100, 2057 mapsize => 100,
2073 audio_enable => 1, 2058 audio_enable => 1,
2074 bgm_enable => 1, 2059 bgm_enable => 1,
2075 bgm_volume => 0.25, 2060 bgm_volume => 0.25,
2076 face_prefetch => 0,
2077 output_sync => 1, 2061 output_sync => 1,
2078 output_count => 1, 2062 output_count => 1,
2079 output_rate => "", 2063 output_rate => "",
2080 pickup => 0, 2064 pickup => 0,
2081 inv_sort => "mtime", 2065 inv_sort => "mtime",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines