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.203 by root, Mon Aug 6 02:11:45 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}
248 } else { 242 } else {
249 # fetch from database 243 # fetch from database
250 CFPlus::DB::get res_data => $meta->{name}, sub { 244 CFPlus::DB::get res_data => $meta->{name}, sub {
251 my $rwops = new CFPlus::RW $_[0]; 245 my $rwops = new CFPlus::RW $_[0];
252 my $chunk = new CFPlus::MixChunk $rwops 246 my $chunk = new CFPlus::MixChunk $rwops
253 or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError; 247 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
254 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 248 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
255 $AUDIO_CHUNK{$face} = $chunk; 249 $AUDIO_CHUNK{$face} = $chunk;
256 250
257 audio_sound_push ($face); 251 audio_sound_push ($face);
258 }; 252 };
267 or return; 261 or return;
268 $CFG->{effects_enable} 262 $CFG->{effects_enable}
269 or return; 263 or return;
270 264
271 my $queue = $AUDIO_PLAY{$face} ||= []; 265 my $queue = $AUDIO_PLAY{$face} ||= [];
272 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
273 audio_sound_push $face 267 audio_sound_push $face
274 unless @$queue > 1; 268 unless @$queue > 1;
275} 269}
276 270
277sub audio_music_set_meta { 271sub audio_music_set_meta {
419 413
420sub audio_shutdown { 414sub audio_shutdown {
421 undef $MUSIC_PLAYER; 415 undef $MUSIC_PLAYER;
422 undef $MUSIC_PLAYING_META; 416 undef $MUSIC_PLAYING_META;
423 undef $MUSIC_PLAYING_DATA; 417 undef $MUSIC_PLAYING_DATA;
424
425 audio_music_set_meta { };
426 418
427 $MUSIC_WANT = []; 419 $MUSIC_WANT = [];
428 @MUSIC_JINGLE = (); 420 @MUSIC_JINGLE = ();
429 %AUDIO_PLAY = (); 421 %AUDIO_PLAY = ();
430 %AUDIO_CHUNK = (); 422 %AUDIO_CHUNK = ();
775 state => $CFG->{fullscreen}, 767 state => $CFG->{fullscreen},
776 tooltip => "Bring the client into fullscreen mode.", 768 tooltip => "Bring the client into fullscreen mode.",
777 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 769 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
778 ); 770 );
779 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
780 $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");
781 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 785 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
782 state => $CFG->{fast}, 786 state => $CFG->{fast},
783 tooltip => "Lower the visual quality considerably to speed up rendering.", 787 tooltip => "Lower the visual quality considerably to speed up rendering.",
784 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 788 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
810 814
811 $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");
812 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 816 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
813 state => $CFG->{map_smoothing}, 817 state => $CFG->{map_smoothing},
814 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. "
815 . "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. "
816 . "Changes take effect at next connection only.", 820 . "Changes take effect at next login only.",
817 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 821 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
818 ); 822 );
819 823
820 $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");
821 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 825 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
832 ); 836 );
833 837
834 $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");
835 $table->add_at (1, $row++, new CFPlus::UI::Slider 839 $table->add_at (1, $row++, new CFPlus::UI::Slider
836 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 840 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
837 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.",
838 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 },
839 ); 844 );
840 845
841 $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");
842 $table->add_at (1, $row++, new CFPlus::UI::Slider 847 $table->add_at (1, $row++, new CFPlus::UI::Slider
879# $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");
880# $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 {
881# $CFG->{effects_volume} = $_[1]; 886# $CFG->{effects_volume} = $_[1];
882# }); 887# });
883 888
884 $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");
885 $table->add_at (1, $row, new CFPlus::UI::CheckBox 890 $table->add_at (1, $row, new CFPlus::UI::CheckBox
886 expand => 1, state => $CFG->{effects_enable}, 891 expand => 1, state => $CFG->{effects_enable},
887 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 {
888 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } 894 $CFG->{effects_enable} = $_[1];
895 $CONN->update_fx_want if $CONN;
896 0
897 }
889 ); 898 );
890 $table->add_at (2, $row++, new CFPlus::UI::Slider 899 $table->add_at (2, $row++, new CFPlus::UI::Slider
891 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], 900 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
892 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 "
893 . "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.",
894 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } 903 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
895 ); 904 );
896 905
897 $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");
898 $table->add_at (1, $row, new CFPlus::UI::CheckBox 907 $table->add_at (1, $row, new CFPlus::UI::CheckBox
899 expand => 1, state => $CFG->{bgm_enable}, 908 expand => 1, state => $CFG->{bgm_enable},
900 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.",
901 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 }
902 ); 915 );
903 $table->add_at (2, $row++, new CFPlus::UI::Slider 916 $table->add_at (2, $row++, new CFPlus::UI::Slider
904 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 917 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
905 tooltip => "The volume of the background music. Changes are instant.", 918 tooltip => "The volume of the background music. Changes are instant.",
906 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 }
1595 $sw1->add ($INV = new CFPlus::UI::Inventory); 1608 $sw1->add ($INV = new CFPlus::UI::Inventory);
1596 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1609 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1597 1610
1598 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1611 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1599 1612
1600 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1613 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1601 1614
1602 $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);
1603 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1616 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1604 1617
1605 # XXX: Call after $INVR = ... because set_opencont sets the items 1618 # XXX: Call after $INVR = ... because set_opencont sets the items
1860 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1873 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1861 ); 1874 );
1862 $hb->add (new CFPlus::UI::Button 1875 $hb->add (new CFPlus::UI::Button
1863 text => "Quit anyway", 1876 text => "Quit anyway",
1864 expand => 1, 1877 expand => 1,
1865 on_activate => sub { exit }, 1878 on_activate => sub { Event::unloop_all },
1866 ); 1879 );
1867 } 1880 }
1868 1881
1869 $QUIT_DIALOG->show; 1882 $QUIT_DIALOG->show;
1870 $QUIT_DIALOG->grab_focus; 1883 $QUIT_DIALOG->grab_focus;
2064 tooltip => "Terminates the program", 2077 tooltip => "Terminates the program",
2065 on_activate => sub { 2078 on_activate => sub {
2066 if ($CONN) { 2079 if ($CONN) {
2067 open_quit_dialog; 2080 open_quit_dialog;
2068 } else { 2081 } else {
2069 exit; 2082 Event::unloop_all;
2070 } 2083 }
2071 0 2084 0
2072 }, 2085 },
2073 ); 2086 );
2074 2087
2075 $BUTTONBAR->show; 2088 $BUTTONBAR->show;
2076 $SETUP_DIALOG->show; 2089 $SETUP_DIALOG->show;
2090 $MESSAGE_WINDOW->show;
2077 } 2091 }
2078 2092
2079 $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]);
2080} 2094}
2081 2095
2089my $animate_timer; 2103my $animate_timer;
2090 2104
2091my $fps = 9; 2105my $fps = 9;
2092 2106
2093sub force_refresh { 2107sub force_refresh {
2108 if ($ENV{CFPLUS_DEBUG} & 4) {
2094 $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;
2095 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2110 debug sprintf "%3.2f", $fps;
2111 }
2096 2112
2097 $CFPlus::UI::ROOT->draw; 2113 $CFPlus::UI::ROOT->draw;
2098 2114 CFPlus::SDL_GL_SwapBuffers;
2099 $WANT_REFRESH = 0;
2100 $CAN_REFRESH = 0;
2101 $LAST_REFRESH = $NOW; 2115 $LAST_REFRESH = $NOW;
2102 2116 $WANT_REFRESH->stop;
2103 CFPlus::SDL_GL_SwapBuffers;
2104} 2117}
2105 2118
2119$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2120
2106my $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 {
2107 $NOW = time; 2122 $NOW = time;
2108 2123
2109 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2124 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2110 for CFPlus::poll_events; 2125 for CFPlus::poll_events;
2111 2126
2112 if (%animate_object) { 2127 if (%animate_object) {
2113 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2128 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2114 ++$WANT_REFRESH; 2129 $WANT_REFRESH->start;
2115 }
2116
2117 if ($WANT_REFRESH) {
2118 force_refresh;
2119 } else {
2120 $CAN_REFRESH = 1;
2121 } 2130 }
2122}); 2131});
2123 2132
2124sub animation_start { 2133sub animation_start {
2125 my ($widget) = @_; 2134 my ($widget) = @_;
2183 2192
2184 my %DEF_CFG = ( 2193 my %DEF_CFG = (
2185 sdl_mode => 0, 2194 sdl_mode => 0,
2186 fullscreen => 0, 2195 fullscreen => 0,
2187 fast => 0, 2196 fast => 0,
2197 opengl11 => 0,
2188 map_scale => 1, 2198 map_scale => 1,
2189 fow_enable => 1, 2199 fow_enable => 1,
2190 fow_intensity => 0, 2200 fow_intensity => 0,
2191 map_smoothing => 1, 2201 map_smoothing => 1,
2192 gui_fontsize => 1, 2202 gui_fontsize => 1,
2281} 2291}
2282 2292
2283show_tip_of_the_day if $CFG->{show_tips}; 2293show_tip_of_the_day if $CFG->{show_tips};
2284 2294
2285Event::loop; 2295Event::loop;
2296
2297#video_shutdown;
2298#audio_shutdown;
2286#CFPlus::SDL_Quit; 2299CFPlus::SDL_Quit;
2287#CFPlus::_exit 0;
2288
2289END {
2290 CFPlus::SDL_Quit;
2291 CFPlus::DB::Server::stop; 2300CFPlus::DB::Server::stop;
2292}
2293 2301
2294=head1 NAME 2302=head1 NAME
2295 2303
2296cfplus - A Crossfire+ and Crossfire game client 2304cfplus - A Crossfire TRT and Crossfire game client
2297 2305
2298=head1 SYNOPSIS 2306=head1 SYNOPSIS
2299 2307
2300Just run it - no commandline arguments are supported. 2308Just run it - no commandline arguments are supported.
2301 2309
2302=head1 USAGE 2310=head1 USAGE
2303 2311
2304cfplus 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
2305fullscreen and interactively. 2313be used in fullscreen mode and interactively.
2306 2314
2307=head1 DEBUGGING 2315=head1 DEBUGGING
2308 2316
2309 2317
2310CFPLUS_DEBUG - environment variable 2318CFPLUS_DEBUG - environment variable

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines