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.225 by root, Fri Aug 31 08:03:10 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;
147our $PL_WINDOW; 147our $PL_WINDOW;
148 148
149our $MUSIC_PLAYING_WIDGET; 149our $MUSIC_PLAYING_WIDGET;
150our $LICENSE_WIDGET; 150our $LICENSE_WIDGET;
151 151
152our $PICKUP_PAGE;
152our $INVENTORY_PAGE; 153our $INVENTORY_PAGE;
153our $STATS_PAGE; 154our $STATS_PAGE;
154our $SKILL_PAGE; 155our $SKILL_PAGE;
155our $SPELL_PAGE; 156our $SPELL_PAGE;
156our $SPELL_LIST; 157our $SPELL_LIST;
168our $STATUSBOX; 169our $STATUSBOX;
169our $DEBUG_STATUS; 170our $DEBUG_STATUS;
170 171
171our $INV; 172our $INV;
172our $INVR; 173our $INVR;
173our $INV_RIGHT_HB; 174our $INVR_HB;
174
175our $PICKUP_CFG;
176 175
177############################################################################# 176#############################################################################
178 177
179sub status { 178sub status {
180 $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]);
183sub debug { 182sub debug {
184 $DEBUG_STATUS->set_text ($_[0]); 183 $DEBUG_STATUS->set_text ($_[0]);
185} 184}
186 185
187sub message { 186sub message {
188 my ($para) = @_;
189 $MESSAGE_WINDOW->message ($para); 187 $MESSAGE_WINDOW->message (@_);
190} 188}
191 189
192############################################################################# 190#############################################################################
193#TODO: maybe move into own audio module... 191#TODO: maybe move into own audio module...
194 192
217 my ($face) = @_; 215 my ($face) = @_;
218 216
219 $CFG->{effects_enable} 217 $CFG->{effects_enable}
220 or return; 218 or return;
221 219
220 $AUDIO_PLAY{$face}
221 or return;
222
222 if (my $chunk = $AUDIO_CHUNK{$face}) { 223 if (my $chunk = $AUDIO_CHUNK{$face}) {
223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 224 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
224 my (undef, $dx, $dy, $vol) = @$_; 225 my (undef, $dx, $dy, $vol) = @$_;
225 226
226 my $channel = CFPlus::Channel::find; 227 my $channel = CFPlus::Channel::find;
227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); 228 $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); 229 $channel->set_position_r ($dx, $dy, 20);
234
235 $chunk->play ($channel); 230 $chunk->play ($channel);
236 } 231 }
237 } else { 232 } else {
238 # sound_meta not set means data is in flight either way 233 # sound_meta not set means data is in flight either way
239 my $meta = $CONN->{sound_meta}{$face} 234 my $meta = $CONN->{face}[$face]
240 or return; 235 or return;
241 236
237 $meta->{data}
238 or return;
239
242 # if its a jingle, play it as ambient music 240 # if its a jingle, play it as ambient music
243 if ($meta->{meta}{jingle}) { 241 if ($meta->{data}{jingle}) {
244 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue 242 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 243 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
246 &audio_music_push ($face); 244 &audio_music_push ($face);
247 } 245 }
248 } else { 246 } else {
249 # fetch from database 247 # fetch from database
250 CFPlus::DB::get res_data => $meta->{name}, sub { 248 CFPlus::DB::get res_data => $meta->{name}, sub {
251 my $rwops = new CFPlus::RW $_[0]; 249 my $rwops = new CFPlus::RW $_[0];
252 my $chunk = new CFPlus::MixChunk $rwops 250 my $chunk = new CFPlus::MixChunk $rwops
253 or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError; 251 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
254 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 252 $chunk->volume (($meta->{data}{volume} || 1) * 128);
255 $AUDIO_CHUNK{$face} = $chunk; 253 $AUDIO_CHUNK{$face} = $chunk;
256 254
257 audio_sound_push ($face); 255 audio_sound_push ($face);
258 }; 256 };
259 } 257 }
267 or return; 265 or return;
268 $CFG->{effects_enable} 266 $CFG->{effects_enable}
269 or return; 267 or return;
270 268
271 my $queue = $AUDIO_PLAY{$face} ||= []; 269 my $queue = $AUDIO_PLAY{$face} ||= [];
272 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s 270 push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
273 audio_sound_push $face 271 audio_sound_push $face
274 unless @$queue > 1; 272 unless @$queue > 1;
275} 273}
276 274
277sub audio_music_set_meta { 275sub audio_music_set_meta {
278 my ($meta) = @_; 276 my ($meta) = @_;
279 277
280 $MUSIC_PLAYING_META = $meta; 278 $MUSIC_PLAYING_META = $meta;
281 $MUSIC_PLAYING_WIDGET->set_markup ( 279 $MUSIC_PLAYING_WIDGET->set_markup (
282 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" 280 "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
283 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" 281 . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
284 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" 282 . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
285 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) 283 . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license})
286 ); 284 );
287} 285}
288 286
289sub audio_music_update_volume { 287sub audio_music_update_volume {
290 return unless $MUSIC_PLAYING_META; 288 return unless $MUSIC_PLAYING_META;
291 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 289 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
292 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; 290 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
293 CFPlus::MixMusic::volume $base * $volume * 128; 291 CFPlus::MixMusic::volume $base * $volume * 128;
294} 292}
295 293
296sub audio_music_start { 294sub audio_music_start {
297 my $meta = $MUSIC_PLAYING_META; 295 my $meta = $MUSIC_PLAYING_META;
316 314
317 my $NOW = time; 315 my $NOW = time;
318 316
319 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 317 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
320 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 318 my $pos = $MUSIC_PLAYING_META->{stop_pos};
321 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 319 $MUSIC_PLAYER->fade_in_pos (0, 700, $pos);
322 $MUSIC_START = time - $pos; 320 $MUSIC_START = time - $pos;
323 } else { 321 } else {
324 $MUSIC_PLAYER->play (0); 322 $MUSIC_PLAYER->play (0);
325 $MUSIC_START = time; 323 $MUSIC_START = time;
326 } 324 }
340 $fade_out = 333; 338 $fade_out = 333;
341 } else { 339 } else {
342 return unless $CFG->{bgm_enable}; 340 return unless $CFG->{bgm_enable};
343 341
344 my @have = 342 my @have =
345 grep $_, 343 grep $_ && $_->{data},
346 map $CONN->{music_meta}{$_}, 344 map $CONN->{face}[$_],
347 @$MUSIC_WANT; 345 @$MUSIC_WANT;
346
347 # randomize music a bit so that the order is not always the same
348 $_->{stop_time} ||= rand for @have;
348 349
349 @MUSIC_HAVE = @have 350 @MUSIC_HAVE = @have
350 if @have; 351 if @have;
351 352
352 # default MUSIC_HAVE == MUSIC_DEFAULT 353 # default MUSIC_HAVE == MUSIC_DEFAULT
353 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 354 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
354 $fade_out = 1000; 355 $fade_out = 700;
355 } 356 }
356 357
357 # if the currently playing song is acceptable, let it continue 358 # if the currently playing song is acceptable, let it continue
358 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 359 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
359 360
368 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 369 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
369 370
370 # if the most recently-played piece played very recently, 371 # if the most recently-played piece played very recently,
371 # resume it, else choose the oldest piece for rotation. 372 # resume it, else choose the oldest piece for rotation.
372 audio_music_set_meta 373 audio_music_set_meta
373 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 374 $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
374 ? $MUSIC_HAVE[-1] 375 ? $MUSIC_HAVE[-1]
375 : $MUSIC_HAVE[0]; 376 : $MUSIC_HAVE[0];
376 377
377 audio_music_start; 378 audio_music_start;
378 } 379 }
384 $MUSIC_WANT = $songs; 385 $MUSIC_WANT = $songs;
385 audio_music_push; 386 audio_music_push;
386} 387}
387 388
388sub audio_music_finished { 389sub audio_music_finished {
390 if ($MUSIC_PLAYING_META) {
391 $MUSIC_PLAYING_META->{stop_time} = time;
392 }
393
389 # we compress multiple jingles of the same type 394 # we compress multiple jingles of the same type
390 shift @MUSIC_JINGLE 395 shift @MUSIC_JINGLE
391 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 396 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
392 397
393 $MUSIC_PLAYING_WIDGET->clear; 398 $MUSIC_PLAYING_WIDGET->clear;
419 424
420sub audio_shutdown { 425sub audio_shutdown {
421 undef $MUSIC_PLAYER; 426 undef $MUSIC_PLAYER;
422 undef $MUSIC_PLAYING_META; 427 undef $MUSIC_PLAYING_META;
423 undef $MUSIC_PLAYING_DATA; 428 undef $MUSIC_PLAYING_DATA;
424
425 audio_music_set_meta { };
426 429
427 $MUSIC_WANT = []; 430 $MUSIC_WANT = [];
428 @MUSIC_JINGLE = (); 431 @MUSIC_JINGLE = ();
429 %AUDIO_PLAY = (); 432 %AUDIO_PLAY = ();
430 %AUDIO_CHUNK = (); 433 %AUDIO_CHUNK = ();
775 state => $CFG->{fullscreen}, 778 state => $CFG->{fullscreen},
776 tooltip => "Bring the client into fullscreen mode.", 779 tooltip => "Bring the client into fullscreen mode.",
777 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 780 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
778 ); 781 );
779 782
783 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1");
784 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
785 state => $CFG->{force_opengl11},
786 tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in "
787 . "higher memory usage and slower performance. It will, however, help tremendously on "
788 . "cards that claim to support a feature but fall back to software rendering. "
789 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
790 . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you "
791 . "experience extremely low framerates and your card should do better, try this option.</b>",
792 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
793 );
794
795 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures");
796 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
797 state => $CFG->{texture_compression},
798 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
799 . "will save a lot of memory and increase performance. The compression algorithm "
800 . "can differ form card to card, so your mileage may vary. This setting is ignored in "
801 . "forced OpenGL 1.1 mode.",
802 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
803 );
804
780 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 805 $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 806 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
782 state => $CFG->{fast}, 807 state => $CFG->{fast},
783 tooltip => "Lower the visual quality considerably to speed up rendering.", 808 tooltip => "Lower the visual quality considerably to speed up rendering.",
784 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 809 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
810 835
811 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); 836 $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 837 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
813 state => $CFG->{map_smoothing}, 838 state => $CFG->{map_smoothing},
814 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " 839 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. " 840 . "This increases load on the graphics subsystem and works only with TRT servers. "
816 . "Changes take effect at next connection only.", 841 . "Changes take effect at next login only.",
817 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 842 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
818 ); 843 );
819 844
820 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); 845 $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 846 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
832 ); 857 );
833 858
834 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 859 $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 860 $table->add_at (1, $row++, new CFPlus::UI::Slider
836 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 861 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.", 862 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, "
863 . "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 }, 864 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
839 ); 865 );
840 866
841 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 867 $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 868 $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"); 905# $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 { 906# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
881# $CFG->{effects_volume} = $_[1]; 907# $CFG->{effects_volume} = $_[1];
882# }); 908# });
883 909
884 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 910 $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 911 $table->add_at (1, $row, new CFPlus::UI::CheckBox
886 expand => 1, state => $CFG->{effects_enable}, 912 expand => 1, state => $CFG->{effects_enable},
887 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", 913 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
914 on_changed => sub {
888 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } 915 $CFG->{effects_enable} = $_[1];
916 $CONN->update_fx_want if $CONN;
917 0
918 }
889 ); 919 );
890 $table->add_at (2, $row++, new CFPlus::UI::Slider 920 $table->add_at (2, $row++, new CFPlus::UI::Slider
891 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], 921 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 " 922 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.", 923 . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
894 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } 924 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
895 ); 925 );
896 926
897 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 927 $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 928 $table->add_at (1, $row, new CFPlus::UI::CheckBox
899 expand => 1, state => $CFG->{bgm_enable}, 929 expand => 1, state => $CFG->{bgm_enable},
900 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 930 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 } 931 on_changed => sub {
932 $CFG->{bgm_enable} = $_[1];
933 $CONN->update_fx_want if $CONN;
934 audio_music_push;
935 0
936 }
902 ); 937 );
903 $table->add_at (2, $row++, new CFPlus::UI::Slider 938 $table->add_at (2, $row++, new CFPlus::UI::Slider
904 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 939 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
905 tooltip => "The volume of the background music. Changes are instant.", 940 tooltip => "The volume of the background music. Changes are instant.",
906 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 941 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
957 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); 992 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health");
958 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); 993 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana");
959 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); 994 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace");
960 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); 995 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food");
961 996
962 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); 997 $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 $prg = new CFPlus::UI::ExperienceProgress);
999 $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress);
963 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); 1000 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
964 1001
965 $GAUGES = { 1002 $GAUGES = {
1003 exp => $exp, prg => $prg, sklprg => $sklprg,
966 exp => $exp, win => $win, range => $rng, 1004 win => $win, range => $rng,
967 food => $fg, mana => $mg, hp => $hg, grace => $gg 1005 hp => $hg, mana => $mg, grace => $gg, food => $fg,
968 }; 1006 };
969 1007
970 &set_gauge_window_fontsize; 1008 &set_gauge_window_fontsize;
971 1009
972 $win 1010 $win
1173 $r 1211 $r
1174} 1212}
1175 1213
1176sub skill_window { 1214sub skill_window {
1177 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); 1215 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
1216
1178 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); 1217 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1218
1179 $sw 1219 $sw
1180} 1220}
1181 1221
1182sub formsep($) { 1222sub formsep($) {
1183 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 1223 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1595 $sw1->add ($INV = new CFPlus::UI::Inventory); 1635 $sw1->add ($INV = new CFPlus::UI::Inventory);
1596 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1636 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1597 1637
1598 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1638 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1599 1639
1600 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1640 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1601 1641
1602 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1642 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1603 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1643 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1604 1644
1605 # XXX: Call after $INVR = ... because set_opencont sets the items 1645 # XXX: Call after $INVR = ... because set_opencont sets the items
1628} 1668}
1629 1669
1630sub add_license { 1670sub add_license {
1631 my ($meta) = @_; 1671 my ($meta) = @_;
1632 1672
1633 $meta = $meta->{meta} 1673 $meta = $meta->{data}
1634 or return; 1674 or return;
1635 1675
1636 $meta->{license} || $meta->{author} || $meta->{source} 1676 $meta->{license} || $meta->{author} || $meta->{source}
1637 or return; 1677 or return;
1638 1678
1692 $ntb->add_tab ( 1732 $ntb->add_tab (
1693 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1733 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1694 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1734 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1695 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1735 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1696 ); 1736 );
1697 $ntb->add_tab (Pickup => autopickup_setup, 1737 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1698 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1738 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1699 1739
1700 $ntb->add_tab (Media => media_window, 1740 $ntb->add_tab (Media => media_window,
1701 "License, Author and Source info for media sent by the server."); 1741 "License, Author and Source info for media sent by the server.");
1702 1742
1860 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1900 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1861 ); 1901 );
1862 $hb->add (new CFPlus::UI::Button 1902 $hb->add (new CFPlus::UI::Button
1863 text => "Quit anyway", 1903 text => "Quit anyway",
1864 expand => 1, 1904 expand => 1,
1865 on_activate => sub { exit }, 1905 on_activate => sub { Event::unloop_all },
1866 ); 1906 );
1867 } 1907 }
1868 1908
1869 $QUIT_DIALOG->show; 1909 $QUIT_DIALOG->show;
1870 $QUIT_DIALOG->grab_focus; 1910 $QUIT_DIALOG->grab_focus;
1943 1983
1944 $SDL_ACTIVE = 1; 1984 $SDL_ACTIVE = 1;
1945 $LAST_REFRESH = time - 0.01; 1985 $LAST_REFRESH = time - 0.01;
1946 1986
1947 CFPlus::OpenGL::init; 1987 CFPlus::OpenGL::init;
1988 CFPlus::Macro::init;
1948 1989
1949 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 1990 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
1950 1991
1951 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 1992 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
1952 1993
1953 ############################################################################# 1994 #############################################################################
1954 1995
1955 if ($DEBUG_STATUS) { 1996 if ($DEBUG_STATUS) {
1956 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; 1997 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
1957 } else { 1998 } else {
1958 # create the widgets 1999 # create/configure the widgets
2000
2001 $CFPlus::UI::ROOT->connect (key_down => sub {
2002 my (undef, $ev) = @_;
2003
2004 if (my @macros = CFPlus::Macro::find $ev) {
2005 CFPlus::Macro::execute $_ for @macros;
2006
2007 return 1;
2008 }
2009
2010 0
2011 });
1959 2012
1960 $DEBUG_STATUS = new CFPlus::UI::Label 2013 $DEBUG_STATUS = new CFPlus::UI::Label
1961 padding => 0, 2014 padding => 0,
1962 z => 100, 2015 z => 100,
1963 force_x => "max", 2016 force_x => "max",
1993 $MESSAGE_WINDOW->activate_console ($preset) 2046 $MESSAGE_WINDOW->activate_console ($preset)
1994 if $MESSAGE_WINDOW; 2047 if $MESSAGE_WINDOW;
1995 }); 2048 });
1996 $MAPWIDGET->show; 2049 $MAPWIDGET->show;
1997 $MAPWIDGET->grab_focus; 2050 $MAPWIDGET->grab_focus;
2051
2052 $COMPLETER = new CFPlus::MapWidget::Command::
2053 command => { },
2054 tooltip => "#completer_help",
2055 ;
1998 2056
1999 $SETUP_DIALOG = new CFPlus::UI::Toplevel 2057 $SETUP_DIALOG = new CFPlus::UI::Toplevel
2000 title => "Setup", 2058 title => "Setup",
2001 name => "setup_dialog", 2059 name => "setup_dialog",
2002 x => 'center', 2060 x => 'center',
2064 tooltip => "Terminates the program", 2122 tooltip => "Terminates the program",
2065 on_activate => sub { 2123 on_activate => sub {
2066 if ($CONN) { 2124 if ($CONN) {
2067 open_quit_dialog; 2125 open_quit_dialog;
2068 } else { 2126 } else {
2069 exit; 2127 Event::unloop_all;
2070 } 2128 }
2071 0 2129 0
2072 }, 2130 },
2073 ); 2131 );
2074 2132
2075 $BUTTONBAR->show; 2133 $BUTTONBAR->show;
2076 $SETUP_DIALOG->show; 2134 $SETUP_DIALOG->show;
2135 $MESSAGE_WINDOW->show;
2077 } 2136 }
2078 2137
2079 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 2138 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2080} 2139}
2081 2140
2089my $animate_timer; 2148my $animate_timer;
2090 2149
2091my $fps = 9; 2150my $fps = 9;
2092 2151
2093sub force_refresh { 2152sub force_refresh {
2153 if ($ENV{CFPLUS_DEBUG} & 4) {
2094 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2154 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2095 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2155 debug sprintf "%3.2f", $fps;
2156 }
2096 2157
2097 $CFPlus::UI::ROOT->draw; 2158 $CFPlus::UI::ROOT->draw;
2098 2159 CFPlus::SDL_GL_SwapBuffers;
2099 $WANT_REFRESH = 0;
2100 $CAN_REFRESH = 0;
2101 $LAST_REFRESH = $NOW; 2160 $LAST_REFRESH = $NOW;
2102 2161 $WANT_REFRESH->stop;
2103 CFPlus::SDL_GL_SwapBuffers;
2104} 2162}
2105 2163
2164$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2165
2106my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { 2166my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub {
2107 $NOW = time; 2167 $NOW = time;
2108 2168
2109 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2169 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2110 for CFPlus::poll_events; 2170 for CFPlus::poll_events;
2111 2171
2112 if (%animate_object) { 2172 if (%animate_object) {
2113 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2173 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2114 ++$WANT_REFRESH; 2174 $WANT_REFRESH->start;
2115 }
2116
2117 if ($WANT_REFRESH) {
2118 force_refresh;
2119 } else {
2120 $CAN_REFRESH = 1;
2121 } 2175 }
2122}); 2176});
2123 2177
2124sub animation_start { 2178sub animation_start {
2125 my ($widget) = @_; 2179 my ($widget) = @_;
2131 delete $animate_object{$widget}; 2185 delete $animate_object{$widget};
2132} 2186}
2133 2187
2134%SDL_CB = ( 2188%SDL_CB = (
2135 CFPlus::SDL_QUIT => sub { 2189 CFPlus::SDL_QUIT => sub {
2136 exit; 2190 Event::unloop_all;
2137 }, 2191 },
2138 CFPlus::SDL_VIDEORESIZE => sub { 2192 CFPlus::SDL_VIDEORESIZE => sub {
2139 }, 2193 },
2140 CFPlus::SDL_VIDEOEXPOSE => sub { 2194 CFPlus::SDL_VIDEOEXPOSE => sub {
2141 CFPlus::UI::full_refresh; 2195 CFPlus::UI::full_refresh;
2180 CFPlus::DB::Server::run; 2234 CFPlus::DB::Server::run;
2181 2235
2182 CFPlus::UI::set_layout ($::CFG->{layout}); 2236 CFPlus::UI::set_layout ($::CFG->{layout});
2183 2237
2184 my %DEF_CFG = ( 2238 my %DEF_CFG = (
2185 sdl_mode => 0, 2239 sdl_mode => 0,
2186 fullscreen => 0, 2240 fullscreen => 0,
2187 fast => 0, 2241 fast => 0,
2242 force_opengl11 => undef,
2243 texture_compression => 1,
2188 map_scale => 1, 2244 map_scale => 1,
2189 fow_enable => 1, 2245 fow_enable => 1,
2190 fow_intensity => 0, 2246 fow_intensity => 0,
2191 map_smoothing => 1, 2247 map_smoothing => 1,
2192 gui_fontsize => 1, 2248 gui_fontsize => 1,
2193 log_fontsize => 0.7, 2249 log_fontsize => 0.7,
2194 gauge_fontsize => 1, 2250 gauge_fontsize => 1,
2195 gauge_size => 0.35, 2251 gauge_size => 0.35,
2196 stat_fontsize => 0.7, 2252 stat_fontsize => 0.7,
2197 mapsize => 100, 2253 mapsize => 100,
2198 audio_enable => 1, 2254 audio_enable => 1,
2199 effects_enable => 1, 2255 effects_enable => 1,
2200 effects_volume => 1, 2256 effects_volume => 1,
2201 bgm_enable => 1, 2257 bgm_enable => 1,
2202 bgm_volume => 0.5, 2258 bgm_volume => 0.5,
2203 output_sync => 1, 2259 output_sync => 1,
2204 output_count => 1, 2260 output_count => 1,
2205 output_rate => "", 2261 output_rate => "",
2206 pickup => 0, 2262 pickup => 0,
2207 inv_sort => "mtime", 2263 inv_sort => "mtime",
2208 default => "profile", # default profile 2264 default => "profile", # default profile
2209 show_tips => 1, 2265 show_tips => 1,
2210 logview_max_par => 1000, 2266 logview_max_par => 1000,
2211 ); 2267 );
2212 2268
2213 while (my ($k, $v) = each %DEF_CFG) { 2269 while (my ($k, $v) = each %DEF_CFG) {
2214 $CFG->{$k} = $v unless exists $CFG->{$k}; 2270 $CFG->{$k} = $v unless exists $CFG->{$k};
2215 } 2271 }
2272# } 2328# }
2273# my $t2 = Time::HiRes::time; 2329# my $t2 = Time::HiRes::time;
2274# warn $t2-$t1; 2330# warn $t2-$t1;
2275# } 2331# }
2276 2332
2277 $startup_done->();
2278
2279 video_init; 2333 video_init;
2280 audio_init; 2334 audio_init;
2281} 2335}
2282 2336
2283show_tip_of_the_day if $CFG->{show_tips}; 2337show_tip_of_the_day if $CFG->{show_tips};
2284 2338
2339Event->idle (cb => sub {
2340 $_[0]->w->cancel;
2341 $startup_done->();
2342});
2343
2285Event::loop; 2344Event::loop;
2345
2346#video_shutdown;
2347#audio_shutdown;
2286#CFPlus::SDL_Quit; 2348CFPlus::SDL_Quit;
2287#CFPlus::_exit 0;
2288
2289END {
2290 CFPlus::SDL_Quit;
2291 CFPlus::DB::Server::stop; 2349CFPlus::DB::Server::stop;
2292}
2293 2350
2294=head1 NAME 2351=head1 NAME
2295 2352
2296cfplus - A Crossfire+ and Crossfire game client 2353cfplus - A Crossfire TRT and Crossfire game client
2297 2354
2298=head1 SYNOPSIS 2355=head1 SYNOPSIS
2299 2356
2300Just run it - no commandline arguments are supported. 2357Just run it - no commandline arguments are supported.
2301 2358
2302=head1 USAGE 2359=head1 USAGE
2303 2360
2304cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used 2361cfplus utilises OpenGL for all UI elements and the game. It is supposed to
2305fullscreen and interactively. 2362be used in fullscreen mode and interactively.
2306 2363
2307=head1 DEBUGGING 2364=head1 DEBUGGING
2308 2365
2309 2366
2310CFPLUS_DEBUG - environment variable 2367CFPLUS_DEBUG - environment variable

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines