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.199 by root, Wed Aug 1 14:27:21 2007 UTC vs.
Revision 1.224 by root, Thu Aug 30 07:57:59 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;
127our $FONT_FIXED; 126our $FONT_FIXED;
128 127
129our $MAP; 128our $MAP;
130our $MAPMAP; 129our $MAPMAP;
131our $MAPWIDGET; 130our $MAPWIDGET;
131our $COMPLETER;
132our $BUTTONBAR; 132our $BUTTONBAR;
133our $METASERVER; 133our $METASERVER;
134our $LOGIN_BUTTON; 134our $LOGIN_BUTTON;
135our $QUIT_DIALOG; 135our $QUIT_DIALOG;
136our $HOST_ENTRY; 136our $HOST_ENTRY;
144our $SETUP_KEYBOARD; 144our $SETUP_KEYBOARD;
145 145
146our $PL_NOTEBOOK; 146our $PL_NOTEBOOK;
147our $PL_WINDOW; 147our $PL_WINDOW;
148 148
149our $MUSIC_PLAYING_WIDGET;
150our $LICENSE_WIDGET;
151
152our $PICKUP_PAGE;
149our $INVENTORY_PAGE; 153our $INVENTORY_PAGE;
150our $STATS_PAGE; 154our $STATS_PAGE;
151our $SKILL_PAGE; 155our $SKILL_PAGE;
152our $SPELL_PAGE; 156our $SPELL_PAGE;
153our $SPELL_LIST; 157our $SPELL_LIST;
165our $STATUSBOX; 169our $STATUSBOX;
166our $DEBUG_STATUS; 170our $DEBUG_STATUS;
167 171
168our $INV; 172our $INV;
169our $INVR; 173our $INVR;
170our $INV_RIGHT_HB; 174our $INVR_HB;
171
172our $PICKUP_CFG;
173 175
174############################################################################# 176#############################################################################
175 177
176sub status { 178sub status {
177 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 179 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
214 my ($face) = @_; 216 my ($face) = @_;
215 217
216 $CFG->{effects_enable} 218 $CFG->{effects_enable}
217 or return; 219 or return;
218 220
221 $AUDIO_PLAY{$face}
222 or return;
223
219 if (my $chunk = $AUDIO_CHUNK{$face}) { 224 if (my $chunk = $AUDIO_CHUNK{$face}) {
220 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 225 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
221 my (undef, $dx, $dy, $vol) = @$_; 226 my (undef, $dx, $dy, $vol) = @$_;
222 227
223 my $channel = CFPlus::Channel::find; 228 my $channel = CFPlus::Channel::find;
224 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); 229 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
225 $dx = $dx / 10 * 255;
226 $channel->set_panning (255 - $dx, 255 + $dx);
227
228# my $angle = $dx ? : $dx < 0 ?
229# my $distance = -$vol;
230# $channel->set_position ($angle, $distance); 230 $channel->set_position_r ($dx, $dy, 20);
231
232 $chunk->play ($channel); 231 $chunk->play ($channel);
233 } 232 }
234 } else { 233 } else {
235 # sound_meta not set means data is in flight either way 234 # sound_meta not set means data is in flight either way
236 my $meta = $CONN->{sound_meta}{$face} 235 my $meta = $CONN->{face}[$face]
237 or return; 236 or return;
238 237
238 $meta->{data}
239 or return;
240
239 # if its a jingle, play it as ambient music 241 # if its a jingle, play it as ambient music
240 if ($meta->{meta}{jingle}) { 242 if ($meta->{data}{jingle}) {
241 delete $AUDIO_PLAY{$face}; # take the jingle out of the sound queue 243 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
242 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 244 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
243 &audio_music_push ($face); 245 &audio_music_push ($face);
246 }
244 } else { 247 } else {
245 # fetch from database 248 # fetch from database
246 CFPlus::DB::get res_data => $meta->{name}, sub { 249 CFPlus::DB::get res_data => $meta->{name}, sub {
247 my $rwops = new CFPlus::RW $_[0]; 250 my $rwops = new CFPlus::RW $_[0];
248 my $chunk = new CFPlus::MixChunk $rwops; 251 my $chunk = new CFPlus::MixChunk $rwops
252 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
249 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 253 $chunk->volume (($meta->{data}{volume} || 1) * 128);
250 $AUDIO_CHUNK{$face} = $chunk; 254 $AUDIO_CHUNK{$face} = $chunk;
251 255
252 audio_sound_push ($face); 256 audio_sound_push ($face);
253 }; 257 };
254 } 258 }
262 or return; 266 or return;
263 $CFG->{effects_enable} 267 $CFG->{effects_enable}
264 or return; 268 or return;
265 269
266 my $queue = $AUDIO_PLAY{$face} ||= []; 270 my $queue = $AUDIO_PLAY{$face} ||= [];
267 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s 271 push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
268 audio_sound_push $face 272 audio_sound_push $face
269 unless @$queue > 1; 273 unless @$queue > 1;
270} 274}
271 275
276sub audio_music_set_meta {
277 my ($meta) = @_;
278
279 $MUSIC_PLAYING_META = $meta;
280 $MUSIC_PLAYING_WIDGET->set_markup (
281 "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
282 . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
283 . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
284 . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license})
285 );
286}
287
272sub audio_music_update_volume { 288sub audio_music_update_volume {
273 return unless $MUSIC_PLAYING_META; 289 return unless $MUSIC_PLAYING_META;
274 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 290 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
275 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; 291 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
276 CFPlus::MixMusic::volume $base * $volume * 128; 292 CFPlus::MixMusic::volume $base * $volume * 128;
277} 293}
278 294
279sub audio_music_start { 295sub audio_music_start {
280 my $meta = $MUSIC_PLAYING_META; 296 my $meta = $MUSIC_PLAYING_META;
293 my $rwops = $meta->{path} 309 my $rwops = $meta->{path}
294 ? new_from_file CFPlus::RW $meta->{path} 310 ? new_from_file CFPlus::RW $meta->{path}
295 : new CFPlus::RW $$MUSIC_PLAYING_DATA; 311 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
296 312
297 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops 313 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
298 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error 314 or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
299 315
300 my $NOW = time; 316 my $NOW = time;
301 317
302 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 318 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
303 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 319 my $pos = $MUSIC_PLAYING_META->{stop_pos};
304 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 320 $MUSIC_PLAYER->fade_in_pos (0, 700, $pos);
305 $MUSIC_START = time - $pos; 321 $MUSIC_START = time - $pos;
306 } else { 322 } else {
307 $MUSIC_PLAYER->play (0); 323 $MUSIC_PLAYER->play (0);
308 $MUSIC_START = time; 324 $MUSIC_START = time;
309 } 325 }
310 326
311 delete $MUSIC_PLAYING_META->{stop_time}; 327 delete $meta->{stop_time};
312 delete $MUSIC_PLAYING_META->{stop_pos}; 328 delete $meta->{stop_pos};
313 } 329 }
314} 330}
315 331
316sub audio_music_push { 332sub audio_music_push {
317 return unless $SDL_MIXER; 333 return unless $SDL_MIXER;
323 $fade_out = 333; 339 $fade_out = 333;
324 } else { 340 } else {
325 return unless $CFG->{bgm_enable}; 341 return unless $CFG->{bgm_enable};
326 342
327 my @have = 343 my @have =
328 grep $_, 344 grep $_ && $_->{data},
329 map $CONN->{music_meta}{$_}, 345 map $CONN->{face}[$_],
330 @$MUSIC_WANT; 346 @$MUSIC_WANT;
347
348 # randomize music a bit so that the order is not always the same
349 $_->{stop_time} ||= rand for @have;
331 350
332 @MUSIC_HAVE = @have 351 @MUSIC_HAVE = @have
333 if @have; 352 if @have;
334 353
335 # default MUSIC_HAVE == MUSIC_DEFAULT 354 # default MUSIC_HAVE == MUSIC_DEFAULT
336 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 355 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
337 $fade_out = 1000; 356 $fade_out = 700;
338 } 357 }
339 358
340 # if the currently playing song is acceptable, let it continue 359 # if the currently playing song is acceptable, let it continue
341 return if $MUSIC_PLAYING_META
342 && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 360 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
343 361
344 my $NOW = time; 362 my $NOW = time;
345 363
346 if ($MUSIC_PLAYING_META) { 364 if ($MUSIC_PLAYING_META) {
347 $MUSIC_PLAYING_META->{stop_time} = $NOW; 365 $MUSIC_PLAYING_META->{stop_time} = $NOW;
351 # sort by stop time, oldest first 369 # sort by stop time, oldest first
352 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 370 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
353 371
354 # if the most recently-played piece played very recently, 372 # if the most recently-played piece played very recently,
355 # resume it, else choose the oldest piece for rotation. 373 # resume it, else choose the oldest piece for rotation.
356 $MUSIC_PLAYING_META = 374 audio_music_set_meta
357 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 375 $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
358 ? $MUSIC_HAVE[-1] 376 ? $MUSIC_HAVE[-1]
359 : $MUSIC_HAVE[0]; 377 : $MUSIC_HAVE[0];
360 378
361 audio_music_start; 379 audio_music_start;
362 } 380 }
368 $MUSIC_WANT = $songs; 386 $MUSIC_WANT = $songs;
369 audio_music_push; 387 audio_music_push;
370} 388}
371 389
372sub audio_music_finished { 390sub audio_music_finished {
391 if ($MUSIC_PLAYING_META) {
392 $MUSIC_PLAYING_META->{stop_time} = time;
393 }
394
373 # we compress multiple jingles of the same type 395 # we compress multiple jingles of the same type
374 shift @MUSIC_JINGLE 396 shift @MUSIC_JINGLE
375 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 397 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
398
399 $MUSIC_PLAYING_WIDGET->clear;
376 400
377 undef $MUSIC_PLAYER; 401 undef $MUSIC_PLAYER;
378 undef $MUSIC_PLAYING_META; 402 undef $MUSIC_PLAYING_META;
379 undef $MUSIC_PLAYING_DATA; 403 undef $MUSIC_PLAYING_DATA;
380 404
755 state => $CFG->{fullscreen}, 779 state => $CFG->{fullscreen},
756 tooltip => "Bring the client into fullscreen mode.", 780 tooltip => "Bring the client into fullscreen mode.",
757 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 781 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
758 ); 782 );
759 783
784 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1");
785 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
786 state => $CFG->{force_opengl11},
787 tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in "
788 . "higher memory usage and slower performance. It will, however, help tremendously on "
789 . "cards that claim to support a feature but fall back to software rendering. "
790 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
791 . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you "
792 . "experience extremely low framerates and your card should do better, try this option.</b>",
793 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
794 );
795
796 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures");
797 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
798 state => $CFG->{texture_compression},
799 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
800 . "will save a lot of memory and increase performance. The compression algorithm "
801 . "can differ form card to card, so your mileage may vary. This setting is ignored in "
802 . "forced OpenGL 1.1 mode.",
803 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
804 );
805
760 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 806 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
761 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 807 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
762 state => $CFG->{fast}, 808 state => $CFG->{fast},
763 tooltip => "Lower the visual quality considerably to speed up rendering.", 809 tooltip => "Lower the visual quality considerably to speed up rendering.",
764 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 810 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
790 836
791 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); 837 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing");
792 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 838 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
793 state => $CFG->{map_smoothing}, 839 state => $CFG->{map_smoothing},
794 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " 840 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. "
795 . "This increases load on the graphics subsystem and works only with 2.x servers. " 841 . "This increases load on the graphics subsystem and works only with TRT servers. "
796 . "Changes take effect at next connection only.", 842 . "Changes take effect at next login only.",
797 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 843 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
798 ); 844 );
799 845
800 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); 846 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
801 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 847 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
812 ); 858 );
813 859
814 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 860 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
815 $table->add_at (1, $row++, new CFPlus::UI::Slider 861 $table->add_at (1, $row++, new CFPlus::UI::Slider
816 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 862 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
817 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 863 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, "
864 . "but you still need to press apply to correctly re-layout the widget.",
818 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 865 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
819 ); 866 );
820 867
821 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 868 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
822 $table->add_at (1, $row++, new CFPlus::UI::Slider 869 $table->add_at (1, $row++, new CFPlus::UI::Slider
859# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 906# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
860# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { 907# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
861# $CFG->{effects_volume} = $_[1]; 908# $CFG->{effects_volume} = $_[1];
862# }); 909# });
863 910
864 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 911 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects");
865 $table->add_at (1, $row, new CFPlus::UI::CheckBox 912 $table->add_at (1, $row, new CFPlus::UI::CheckBox
866 expand => 1, state => $CFG->{effects_enable}, 913 expand => 1, state => $CFG->{effects_enable},
867 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", 914 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
915 on_changed => sub {
868 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } 916 $CFG->{effects_enable} = $_[1];
917 $CONN->update_fx_want if $CONN;
918 0
919 }
869 ); 920 );
870 $table->add_at (2, $row++, new CFPlus::UI::Slider 921 $table->add_at (2, $row++, new CFPlus::UI::Slider
871 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], 922 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
872 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " 923 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
873 . "is set highest and you use your operating system volume setting. Changes are instant.", 924 . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
874 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } 925 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
875 ); 926 );
876 927
877 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 928 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
878 $table->add_at (1, $row, new CFPlus::UI::CheckBox 929 $table->add_at (1, $row, new CFPlus::UI::CheckBox
879 expand => 1, state => $CFG->{bgm_enable}, 930 expand => 1, state => $CFG->{bgm_enable},
880 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 931 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
881 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 932 on_changed => sub {
933 $CFG->{bgm_enable} = $_[1];
934 $CONN->update_fx_want if $CONN;
935 audio_music_push;
936 0
937 }
882 ); 938 );
883 $table->add_at (2, $row++, new CFPlus::UI::Slider 939 $table->add_at (2, $row++, new CFPlus::UI::Slider
884 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 940 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
885 tooltip => "The volume of the background music. Changes are instant.", 941 tooltip => "The volume of the background music. Changes are instant.",
886 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 942 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
937 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); 993 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health");
938 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); 994 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana");
939 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); 995 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace");
940 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); 996 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food");
941 997
942 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); 998 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
999 $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress);
1000 $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress);
943 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); 1001 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
944 1002
945 $GAUGES = { 1003 $GAUGES = {
1004 exp => $exp, prg => $prg, sklprg => $sklprg,
946 exp => $exp, win => $win, range => $rng, 1005 win => $win, range => $rng,
947 food => $fg, mana => $mg, hp => $hg, grace => $gg 1006 hp => $hg, mana => $mg, grace => $gg, food => $fg,
948 }; 1007 };
949 1008
950 &set_gauge_window_fontsize; 1009 &set_gauge_window_fontsize;
951 1010
952 $win 1011 $win
1153 $r 1212 $r
1154} 1213}
1155 1214
1156sub skill_window { 1215sub skill_window {
1157 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); 1216 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
1217
1158 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); 1218 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1219
1159 $sw 1220 $sw
1160} 1221}
1161 1222
1162sub formsep($) { 1223sub formsep($) {
1163 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 1224 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1575 $sw1->add ($INV = new CFPlus::UI::Inventory); 1636 $sw1->add ($INV = new CFPlus::UI::Inventory);
1576 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1637 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1577 1638
1578 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1639 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1579 1640
1580 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1641 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1581 1642
1582 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1643 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1583 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1644 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1584 1645
1585 # XXX: Call after $INVR = ... because set_opencont sets the items 1646 # XXX: Call after $INVR = ... because set_opencont sets the items
1586 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); 1647 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor");
1587 1648
1588 $hb 1649 $hb
1650}
1651
1652sub media_window {
1653 my $vb = new CFPlus::UI::VBox;
1654
1655 $vb->add (new CFPlus::UI::FancyFrame
1656 label => "Currently playing music",
1657 child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
1658 child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8),
1659 );
1660
1661 $vb->add (new CFPlus::UI::FancyFrame
1662 label => "Other media used in this session",
1663 expand => 1,
1664 child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller
1665 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
1666 );
1667
1668 $vb
1669}
1670
1671sub add_license {
1672 my ($meta) = @_;
1673
1674 $meta = $meta->{data}
1675 or return;
1676
1677 $meta->{license} || $meta->{author} || $meta->{source}
1678 or return;
1679
1680 $LICENSE_WIDGET->add_paragraph ({
1681 fg => [1, 1, 1, 1],
1682 markup => "<small>"
1683 . "<b>Name:</b> " . (CFPlus::asxml $meta->{name}) . "\n"
1684 . "<b>Author:</b> " . (CFPlus::asxml $meta->{author}) . "\n"
1685 . "<b>Source:</b> " . (CFPlus::asxml $meta->{source}) . "\n"
1686 . "<b>License:</b> " . (CFPlus::asxml $meta->{license}) . "\n"
1687 . "</small>",
1688 });
1689 $LICENSE_WIDGET->scroll_to_bottom;
1589} 1690}
1590 1691
1591sub toggle_player_page { 1692sub toggle_player_page {
1592 my ($widget) = @_; 1693 my ($widget) = @_;
1593 1694
1632 $ntb->add_tab ( 1733 $ntb->add_tab (
1633 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1734 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1634 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1735 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1635 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1736 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1636 ); 1737 );
1637 $ntb->add_tab (Pickup => autopickup_setup, 1738 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1638 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1739 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1740
1741 $ntb->add_tab (Media => media_window,
1742 "License, Author and Source info for media sent by the server.");
1639 1743
1640 $ntb->set_current_page ($INVENTORY_PAGE); 1744 $ntb->set_current_page ($INVENTORY_PAGE);
1641 1745
1642 $plwin->add ($ntb); 1746 $plwin->add ($ntb);
1643 $plwin 1747 $plwin
1797 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1901 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1798 ); 1902 );
1799 $hb->add (new CFPlus::UI::Button 1903 $hb->add (new CFPlus::UI::Button
1800 text => "Quit anyway", 1904 text => "Quit anyway",
1801 expand => 1, 1905 expand => 1,
1802 on_activate => sub { exit }, 1906 on_activate => sub { Event::unloop_all },
1803 ); 1907 );
1804 } 1908 }
1805 1909
1806 $QUIT_DIALOG->show; 1910 $QUIT_DIALOG->show;
1807 $QUIT_DIALOG->grab_focus; 1911 $QUIT_DIALOG->grab_focus;
1880 1984
1881 $SDL_ACTIVE = 1; 1985 $SDL_ACTIVE = 1;
1882 $LAST_REFRESH = time - 0.01; 1986 $LAST_REFRESH = time - 0.01;
1883 1987
1884 CFPlus::OpenGL::init; 1988 CFPlus::OpenGL::init;
1989 CFPlus::Macro::init;
1885 1990
1886 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 1991 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
1887 1992
1888 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 1993 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
1889 1994
1890 ############################################################################# 1995 #############################################################################
1891 1996
1892 if ($DEBUG_STATUS) { 1997 if ($DEBUG_STATUS) {
1893 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; 1998 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
1894 } else { 1999 } else {
1895 # create the widgets 2000 # create/configure the widgets
2001
2002 $CFPlus::UI::ROOT->connect (key_down => sub {
2003 my (undef, $ev) = @_;
2004
2005 if (my @macros = CFPlus::Macro::find $ev) {
2006 CFPlus::Macro::execute $_ for @macros;
2007
2008 return 1;
2009 }
2010
2011 0
2012 });
1896 2013
1897 $DEBUG_STATUS = new CFPlus::UI::Label 2014 $DEBUG_STATUS = new CFPlus::UI::Label
1898 padding => 0, 2015 padding => 0,
1899 z => 100, 2016 z => 100,
1900 force_x => "max", 2017 force_x => "max",
1930 $MESSAGE_WINDOW->activate_console ($preset) 2047 $MESSAGE_WINDOW->activate_console ($preset)
1931 if $MESSAGE_WINDOW; 2048 if $MESSAGE_WINDOW;
1932 }); 2049 });
1933 $MAPWIDGET->show; 2050 $MAPWIDGET->show;
1934 $MAPWIDGET->grab_focus; 2051 $MAPWIDGET->grab_focus;
2052
2053 $COMPLETER = new CFPlus::MapWidget::Command::
2054 command => { },
2055 tooltip => "#completer_help",
2056 ;
1935 2057
1936 $SETUP_DIALOG = new CFPlus::UI::Toplevel 2058 $SETUP_DIALOG = new CFPlus::UI::Toplevel
1937 title => "Setup", 2059 title => "Setup",
1938 name => "setup_dialog", 2060 name => "setup_dialog",
1939 x => 'center', 2061 x => 'center',
2001 tooltip => "Terminates the program", 2123 tooltip => "Terminates the program",
2002 on_activate => sub { 2124 on_activate => sub {
2003 if ($CONN) { 2125 if ($CONN) {
2004 open_quit_dialog; 2126 open_quit_dialog;
2005 } else { 2127 } else {
2006 exit; 2128 Event::unloop_all;
2007 } 2129 }
2008 0 2130 0
2009 }, 2131 },
2010 ); 2132 );
2011 2133
2012 $BUTTONBAR->show; 2134 $BUTTONBAR->show;
2013 $SETUP_DIALOG->show; 2135 $SETUP_DIALOG->show;
2136 $MESSAGE_WINDOW->show;
2014 } 2137 }
2015 2138
2016 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 2139 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2017} 2140}
2018 2141
2026my $animate_timer; 2149my $animate_timer;
2027 2150
2028my $fps = 9; 2151my $fps = 9;
2029 2152
2030sub force_refresh { 2153sub force_refresh {
2154 if ($ENV{CFPLUS_DEBUG} & 4) {
2031 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2155 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2032 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2156 debug sprintf "%3.2f", $fps;
2157 }
2033 2158
2034 $CFPlus::UI::ROOT->draw; 2159 $CFPlus::UI::ROOT->draw;
2035 2160 CFPlus::SDL_GL_SwapBuffers;
2036 $WANT_REFRESH = 0;
2037 $CAN_REFRESH = 0;
2038 $LAST_REFRESH = $NOW; 2161 $LAST_REFRESH = $NOW;
2039 2162 $WANT_REFRESH->stop;
2040 CFPlus::SDL_GL_SwapBuffers;
2041} 2163}
2042 2164
2165$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2166
2043my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { 2167my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub {
2044 $NOW = time; 2168 $NOW = time;
2045 2169
2046 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2170 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2047 for CFPlus::poll_events; 2171 for CFPlus::poll_events;
2048 2172
2049 if (%animate_object) { 2173 if (%animate_object) {
2050 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2174 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2051 ++$WANT_REFRESH; 2175 $WANT_REFRESH->start;
2052 }
2053
2054 if ($WANT_REFRESH) {
2055 force_refresh;
2056 } else {
2057 $CAN_REFRESH = 1;
2058 } 2176 }
2059}); 2177});
2060 2178
2061sub animation_start { 2179sub animation_start {
2062 my ($widget) = @_; 2180 my ($widget) = @_;
2068 delete $animate_object{$widget}; 2186 delete $animate_object{$widget};
2069} 2187}
2070 2188
2071%SDL_CB = ( 2189%SDL_CB = (
2072 CFPlus::SDL_QUIT => sub { 2190 CFPlus::SDL_QUIT => sub {
2073 exit; 2191 Event::unloop_all;
2074 }, 2192 },
2075 CFPlus::SDL_VIDEORESIZE => sub { 2193 CFPlus::SDL_VIDEORESIZE => sub {
2076 }, 2194 },
2077 CFPlus::SDL_VIDEOEXPOSE => sub { 2195 CFPlus::SDL_VIDEOEXPOSE => sub {
2078 CFPlus::UI::full_refresh; 2196 CFPlus::UI::full_refresh;
2117 CFPlus::DB::Server::run; 2235 CFPlus::DB::Server::run;
2118 2236
2119 CFPlus::UI::set_layout ($::CFG->{layout}); 2237 CFPlus::UI::set_layout ($::CFG->{layout});
2120 2238
2121 my %DEF_CFG = ( 2239 my %DEF_CFG = (
2122 sdl_mode => 0, 2240 sdl_mode => 0,
2123 fullscreen => 0, 2241 fullscreen => 0,
2124 fast => 0, 2242 fast => 0,
2243 force_opengl11 => undef,
2244 texture_compression => 1,
2125 map_scale => 1, 2245 map_scale => 1,
2126 fow_enable => 1, 2246 fow_enable => 1,
2127 fow_intensity => 0, 2247 fow_intensity => 0,
2128 map_smoothing => 1, 2248 map_smoothing => 1,
2129 gui_fontsize => 1, 2249 gui_fontsize => 1,
2130 log_fontsize => 0.7, 2250 log_fontsize => 0.7,
2131 gauge_fontsize => 1, 2251 gauge_fontsize => 1,
2132 gauge_size => 0.35, 2252 gauge_size => 0.35,
2133 stat_fontsize => 0.7, 2253 stat_fontsize => 0.7,
2134 mapsize => 100, 2254 mapsize => 100,
2135 audio_enable => 1, 2255 audio_enable => 1,
2136 effects_enable => 1, 2256 effects_enable => 1,
2137 effects_volume => 1, 2257 effects_volume => 1,
2138 bgm_enable => 1, 2258 bgm_enable => 1,
2139 bgm_volume => 0.5, 2259 bgm_volume => 0.5,
2140 output_sync => 1, 2260 output_sync => 1,
2141 output_count => 1, 2261 output_count => 1,
2142 output_rate => "", 2262 output_rate => "",
2143 pickup => 0, 2263 pickup => 0,
2144 inv_sort => "mtime", 2264 inv_sort => "mtime",
2145 default => "profile", # default profile 2265 default => "profile", # default profile
2146 show_tips => 1, 2266 show_tips => 1,
2147 logview_max_par => 1000, 2267 logview_max_par => 1000,
2148 ); 2268 );
2149 2269
2150 while (my ($k, $v) = each %DEF_CFG) { 2270 while (my ($k, $v) = each %DEF_CFG) {
2151 $CFG->{$k} = $v unless exists $CFG->{$k}; 2271 $CFG->{$k} = $v unless exists $CFG->{$k};
2152 } 2272 }
2209# } 2329# }
2210# my $t2 = Time::HiRes::time; 2330# my $t2 = Time::HiRes::time;
2211# warn $t2-$t1; 2331# warn $t2-$t1;
2212# } 2332# }
2213 2333
2214 $startup_done->();
2215
2216 video_init; 2334 video_init;
2217 audio_init; 2335 audio_init;
2218} 2336}
2219 2337
2220show_tip_of_the_day if $CFG->{show_tips}; 2338show_tip_of_the_day if $CFG->{show_tips};
2221 2339
2340Event->idle (cb => sub {
2341 $_[0]->w->cancel;
2342 $startup_done->();
2343});
2344
2222Event::loop; 2345Event::loop;
2346
2347#video_shutdown;
2348#audio_shutdown;
2223#CFPlus::SDL_Quit; 2349CFPlus::SDL_Quit;
2224#CFPlus::_exit 0;
2225
2226END {
2227 CFPlus::SDL_Quit;
2228 CFPlus::DB::Server::stop; 2350CFPlus::DB::Server::stop;
2229}
2230 2351
2231=head1 NAME 2352=head1 NAME
2232 2353
2233cfplus - A Crossfire+ and Crossfire game client 2354cfplus - A Crossfire TRT and Crossfire game client
2234 2355
2235=head1 SYNOPSIS 2356=head1 SYNOPSIS
2236 2357
2237Just run it - no commandline arguments are supported. 2358Just run it - no commandline arguments are supported.
2238 2359
2239=head1 USAGE 2360=head1 USAGE
2240 2361
2241cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used 2362cfplus utilises OpenGL for all UI elements and the game. It is supposed to
2242fullscreen and interactively. 2363be used in fullscreen mode and interactively.
2243 2364
2244=head1 DEBUGGING 2365=head1 DEBUGGING
2245 2366
2246 2367
2247CFPLUS_DEBUG - environment variable 2368CFPLUS_DEBUG - environment variable

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines