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.202 by root, Sat Aug 4 03:29:03 2007 UTC vs.
Revision 1.215 by root, Fri Aug 17 21:18:01 2007 UTC

113our $CONN; 113our $CONN;
114our $PROFILE; # current profile 114our $PROFILE; # current profile
115our $FAST; # fast, low-quality mode, possibly useful for software-rendering 115our $FAST; # fast, low-quality mode, possibly useful for software-rendering
116 116
117our $WANT_REFRESH; 117our $WANT_REFRESH;
118our $CAN_REFRESH;
119 118
120our @SDL_MODES; 119our @SDL_MODES;
121our $WIDTH; 120our $WIDTH;
122our $HEIGHT; 121our $HEIGHT;
123our $FULLSCREEN; 122our $FULLSCREEN;
168our $STATUSBOX; 167our $STATUSBOX;
169our $DEBUG_STATUS; 168our $DEBUG_STATUS;
170 169
171our $INV; 170our $INV;
172our $INVR; 171our $INVR;
173our $INV_RIGHT_HB; 172our $INVR_HB;
174
175our $PICKUP_CFG;
176 173
177############################################################################# 174#############################################################################
178 175
179sub status { 176sub status {
180 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 177 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
217 my ($face) = @_; 214 my ($face) = @_;
218 215
219 $CFG->{effects_enable} 216 $CFG->{effects_enable}
220 or return; 217 or return;
221 218
219 $AUDIO_PLAY{$face}
220 or return;
221
222 if (my $chunk = $AUDIO_CHUNK{$face}) { 222 if (my $chunk = $AUDIO_CHUNK{$face}) {
223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
224 my (undef, $dx, $dy, $vol) = @$_; 224 my (undef, $dx, $dy, $vol) = @$_;
225 225
226 my $channel = CFPlus::Channel::find; 226 my $channel = CFPlus::Channel::find;
227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); 227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
228 $dx = $dx / 10 * 255;
229 $channel->set_panning (255 - $dx, 255 + $dx);
230
231# my $angle = $dx ? : $dx < 0 ?
232# my $distance = -$vol;
233# $channel->set_position ($angle, $distance); 228 $channel->set_position_r ($dx, $dy, 20);
234
235 $chunk->play ($channel); 229 $chunk->play ($channel);
236 } 230 }
237 } else { 231 } else {
238 # sound_meta not set means data is in flight either way 232 # sound_meta not set means data is in flight either way
239 my $meta = $CONN->{sound_meta}{$face} 233 my $meta = $CONN->{sound_meta}{$face}
240 or return; 234 or return;
241 235
242 # if its a jingle, play it as ambient music 236 # if its a jingle, play it as ambient music
243 if ($meta->{meta}{jingle}) { 237 if ($meta->{meta}{jingle}) {
244 delete $AUDIO_PLAY{$face}; # take the jingle out of the sound queue 238 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
245 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 239 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
246 &audio_music_push ($face); 240 &audio_music_push ($face);
241 }
247 } else { 242 } else {
248 # fetch from database 243 # fetch from database
249 CFPlus::DB::get res_data => $meta->{name}, sub { 244 CFPlus::DB::get res_data => $meta->{name}, sub {
250 my $rwops = new CFPlus::RW $_[0]; 245 my $rwops = new CFPlus::RW $_[0];
251 my $chunk = new CFPlus::MixChunk $rwops; 246 my $chunk = new CFPlus::MixChunk $rwops
247 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
252 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 248 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
253 $AUDIO_CHUNK{$face} = $chunk; 249 $AUDIO_CHUNK{$face} = $chunk;
254 250
255 audio_sound_push ($face); 251 audio_sound_push ($face);
256 }; 252 };
265 or return; 261 or return;
266 $CFG->{effects_enable} 262 $CFG->{effects_enable}
267 or return; 263 or return;
268 264
269 my $queue = $AUDIO_PLAY{$face} ||= []; 265 my $queue = $AUDIO_PLAY{$face} ||= [];
270 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s 266 push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
271 audio_sound_push $face 267 audio_sound_push $face
272 unless @$queue > 1; 268 unless @$queue > 1;
273} 269}
274 270
275sub audio_music_set_meta { 271sub audio_music_set_meta {
308 my $rwops = $meta->{path} 304 my $rwops = $meta->{path}
309 ? new_from_file CFPlus::RW $meta->{path} 305 ? new_from_file CFPlus::RW $meta->{path}
310 : new CFPlus::RW $$MUSIC_PLAYING_DATA; 306 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
311 307
312 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops 308 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
313 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error 309 or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
314 310
315 my $NOW = time; 311 my $NOW = time;
316 312
317 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 313 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
318 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 314 my $pos = $MUSIC_PLAYING_META->{stop_pos};
417 413
418sub audio_shutdown { 414sub audio_shutdown {
419 undef $MUSIC_PLAYER; 415 undef $MUSIC_PLAYER;
420 undef $MUSIC_PLAYING_META; 416 undef $MUSIC_PLAYING_META;
421 undef $MUSIC_PLAYING_DATA; 417 undef $MUSIC_PLAYING_DATA;
422
423 audio_music_set_meta { };
424 418
425 $MUSIC_WANT = []; 419 $MUSIC_WANT = [];
426 @MUSIC_JINGLE = (); 420 @MUSIC_JINGLE = ();
427 %AUDIO_PLAY = (); 421 %AUDIO_PLAY = ();
428 %AUDIO_CHUNK = (); 422 %AUDIO_CHUNK = ();
773 state => $CFG->{fullscreen}, 767 state => $CFG->{fullscreen},
774 tooltip => "Bring the client into fullscreen mode.", 768 tooltip => "Bring the client into fullscreen mode.",
775 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 769 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
776 ); 770 );
777 771
772 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1");
773 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
774 state => $CFG->{opengl11},
775 tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in "
776 . "higher memory usage and slower performance. It will, however, help tremendously on "
777 . "cards that claim to support a feature but fall back to software rendering. "
778 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
779 . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you "
780 . "experience extremely low framerates and your card should do better, try this option.</b>",
781 on_changed => sub { my ($self, $value) = @_; $CFG->{opengl11} = $value; 0 }
782 );
783
778 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 784 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
779 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 785 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
780 state => $CFG->{fast}, 786 state => $CFG->{fast},
781 tooltip => "Lower the visual quality considerably to speed up rendering.", 787 tooltip => "Lower the visual quality considerably to speed up rendering.",
782 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 788 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
808 814
809 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); 815 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing");
810 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 816 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
811 state => $CFG->{map_smoothing}, 817 state => $CFG->{map_smoothing},
812 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " 818 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. "
813 . "This increases load on the graphics subsystem and works only with 2.x servers. " 819 . "This increases load on the graphics subsystem and works only with TRT servers. "
814 . "Changes take effect at next connection only.", 820 . "Changes take effect at next login only.",
815 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 821 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
816 ); 822 );
817 823
818 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); 824 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
819 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 825 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
830 ); 836 );
831 837
832 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 838 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
833 $table->add_at (1, $row++, new CFPlus::UI::Slider 839 $table->add_at (1, $row++, new CFPlus::UI::Slider
834 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 840 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
835 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 841 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, "
842 . "but you still need to press apply to correctly re-layout the widget.",
836 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 843 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
837 ); 844 );
838 845
839 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 846 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
840 $table->add_at (1, $row++, new CFPlus::UI::Slider 847 $table->add_at (1, $row++, new CFPlus::UI::Slider
877# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 884# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
878# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { 885# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
879# $CFG->{effects_volume} = $_[1]; 886# $CFG->{effects_volume} = $_[1];
880# }); 887# });
881 888
882 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 889 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects");
883 $table->add_at (1, $row, new CFPlus::UI::CheckBox 890 $table->add_at (1, $row, new CFPlus::UI::CheckBox
884 expand => 1, state => $CFG->{effects_enable}, 891 expand => 1, state => $CFG->{effects_enable},
885 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", 892 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
893 on_changed => sub {
886 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } 894 $CFG->{effects_enable} = $_[1];
895 $CONN->update_fx_want if $CONN;
896 0
897 }
887 ); 898 );
888 $table->add_at (2, $row++, new CFPlus::UI::Slider 899 $table->add_at (2, $row++, new CFPlus::UI::Slider
889 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], 900 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 " 901 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.", 902 . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
892 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } 903 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
893 ); 904 );
894 905
895 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 906 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
896 $table->add_at (1, $row, new CFPlus::UI::CheckBox 907 $table->add_at (1, $row, new CFPlus::UI::CheckBox
897 expand => 1, state => $CFG->{bgm_enable}, 908 expand => 1, state => $CFG->{bgm_enable},
898 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 909 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
899 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 910 on_changed => sub {
911 $CFG->{bgm_enable} = $_[1];
912 $CONN->update_fx_want if $CONN;
913 0
914 }
900 ); 915 );
901 $table->add_at (2, $row++, new CFPlus::UI::Slider 916 $table->add_at (2, $row++, new CFPlus::UI::Slider
902 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 917 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
903 tooltip => "The volume of the background music. Changes are instant.", 918 tooltip => "The volume of the background music. Changes are instant.",
904 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 919 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
1593 $sw1->add ($INV = new CFPlus::UI::Inventory); 1608 $sw1->add ($INV = new CFPlus::UI::Inventory);
1594 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1609 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1595 1610
1596 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1611 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1597 1612
1598 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1613 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1599 1614
1600 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1615 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1601 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1616 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1602 1617
1603 # XXX: Call after $INVR = ... because set_opencont sets the items 1618 # XXX: Call after $INVR = ... because set_opencont sets the items
1858 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1873 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1859 ); 1874 );
1860 $hb->add (new CFPlus::UI::Button 1875 $hb->add (new CFPlus::UI::Button
1861 text => "Quit anyway", 1876 text => "Quit anyway",
1862 expand => 1, 1877 expand => 1,
1863 on_activate => sub { exit }, 1878 on_activate => sub { Event::unloop_all },
1864 ); 1879 );
1865 } 1880 }
1866 1881
1867 $QUIT_DIALOG->show; 1882 $QUIT_DIALOG->show;
1868 $QUIT_DIALOG->grab_focus; 1883 $QUIT_DIALOG->grab_focus;
2062 tooltip => "Terminates the program", 2077 tooltip => "Terminates the program",
2063 on_activate => sub { 2078 on_activate => sub {
2064 if ($CONN) { 2079 if ($CONN) {
2065 open_quit_dialog; 2080 open_quit_dialog;
2066 } else { 2081 } else {
2067 exit; 2082 Event::unloop_all;
2068 } 2083 }
2069 0 2084 0
2070 }, 2085 },
2071 ); 2086 );
2072 2087
2073 $BUTTONBAR->show; 2088 $BUTTONBAR->show;
2074 $SETUP_DIALOG->show; 2089 $SETUP_DIALOG->show;
2090 $MESSAGE_WINDOW->show;
2075 } 2091 }
2076 2092
2077 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 2093 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2078} 2094}
2079 2095
2087my $animate_timer; 2103my $animate_timer;
2088 2104
2089my $fps = 9; 2105my $fps = 9;
2090 2106
2091sub force_refresh { 2107sub force_refresh {
2108 if ($ENV{CFPLUS_DEBUG} & 4) {
2092 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2109 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2093 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2110 debug sprintf "%3.2f", $fps;
2111 }
2094 2112
2095 $CFPlus::UI::ROOT->draw; 2113 $CFPlus::UI::ROOT->draw;
2096 2114 CFPlus::SDL_GL_SwapBuffers;
2097 $WANT_REFRESH = 0;
2098 $CAN_REFRESH = 0;
2099 $LAST_REFRESH = $NOW; 2115 $LAST_REFRESH = $NOW;
2100 2116 $WANT_REFRESH->stop;
2101 CFPlus::SDL_GL_SwapBuffers;
2102} 2117}
2103 2118
2119$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2120
2104my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { 2121my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub {
2105 $NOW = time; 2122 $NOW = time;
2106 2123
2107 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2124 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2108 for CFPlus::poll_events; 2125 for CFPlus::poll_events;
2109 2126
2110 if (%animate_object) { 2127 if (%animate_object) {
2111 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2128 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2112 ++$WANT_REFRESH; 2129 $WANT_REFRESH->start;
2113 }
2114
2115 if ($WANT_REFRESH) {
2116 force_refresh;
2117 } else {
2118 $CAN_REFRESH = 1;
2119 } 2130 }
2120}); 2131});
2121 2132
2122sub animation_start { 2133sub animation_start {
2123 my ($widget) = @_; 2134 my ($widget) = @_;
2181 2192
2182 my %DEF_CFG = ( 2193 my %DEF_CFG = (
2183 sdl_mode => 0, 2194 sdl_mode => 0,
2184 fullscreen => 0, 2195 fullscreen => 0,
2185 fast => 0, 2196 fast => 0,
2197 opengl11 => 0,
2186 map_scale => 1, 2198 map_scale => 1,
2187 fow_enable => 1, 2199 fow_enable => 1,
2188 fow_intensity => 0, 2200 fow_intensity => 0,
2189 map_smoothing => 1, 2201 map_smoothing => 1,
2190 gui_fontsize => 1, 2202 gui_fontsize => 1,
2279} 2291}
2280 2292
2281show_tip_of_the_day if $CFG->{show_tips}; 2293show_tip_of_the_day if $CFG->{show_tips};
2282 2294
2283Event::loop; 2295Event::loop;
2296
2297#video_shutdown;
2298#audio_shutdown;
2284#CFPlus::SDL_Quit; 2299CFPlus::SDL_Quit;
2285#CFPlus::_exit 0;
2286
2287END {
2288 CFPlus::SDL_Quit;
2289 CFPlus::DB::Server::stop; 2300CFPlus::DB::Server::stop;
2290}
2291 2301
2292=head1 NAME 2302=head1 NAME
2293 2303
2294cfplus - A Crossfire+ and Crossfire game client 2304cfplus - A Crossfire TRT and Crossfire game client
2295 2305
2296=head1 SYNOPSIS 2306=head1 SYNOPSIS
2297 2307
2298Just run it - no commandline arguments are supported. 2308Just run it - no commandline arguments are supported.
2299 2309
2300=head1 USAGE 2310=head1 USAGE
2301 2311
2302cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used 2312cfplus utilises OpenGL for all UI elements and the game. It is supposed to
2303fullscreen and interactively. 2313be used in fullscreen mode and interactively.
2304 2314
2305=head1 DEBUGGING 2315=head1 DEBUGGING
2306 2316
2307 2317
2308CFPLUS_DEBUG - environment variable 2318CFPLUS_DEBUG - environment variable

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines