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.206 by root, Thu Aug 9 03:40:44 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
226 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 224 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
227 my (undef, $dx, $dy, $vol) = @$_; 225 my (undef, $dx, $dy, $vol) = @$_;
228 226
229 my $channel = CFPlus::Channel::find; 227 my $channel = CFPlus::Channel::find;
230 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); 228 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
231 $dx = $dx / 10 * 255;
232 $channel->set_panning (255 - $dx, 255 + $dx);
233
234# my $angle = $dx ? : $dx < 0 ?
235# my $distance = -$vol;
236# $channel->set_position ($angle, $distance); 229 $channel->set_position_r ($dx, $dy, 20);
237
238 $chunk->play ($channel); 230 $chunk->play ($channel);
239 } 231 }
240 } else { 232 } else {
241 # sound_meta not set means data is in flight either way 233 # sound_meta not set means data is in flight either way
242 my $meta = $CONN->{sound_meta}{$face} 234 my $meta = $CONN->{face}[$face]
243 or return; 235 or return;
244 236
237 $meta->{data}
238 or return;
239
245 # if its a jingle, play it as ambient music 240 # if its a jingle, play it as ambient music
246 if ($meta->{meta}{jingle}) { 241 if ($meta->{data}{jingle}) {
247 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
248 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 243 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
249 &audio_music_push ($face); 244 &audio_music_push ($face);
250 } 245 }
251 } else { 246 } else {
252 # fetch from database 247 # fetch from database
253 CFPlus::DB::get res_data => $meta->{name}, sub { 248 CFPlus::DB::get res_data => $meta->{name}, sub {
254 my $rwops = new CFPlus::RW $_[0]; 249 my $rwops = new CFPlus::RW $_[0];
255 my $chunk = new CFPlus::MixChunk $rwops 250 my $chunk = new CFPlus::MixChunk $rwops
256 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; 251 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
257 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 252 $chunk->volume (($meta->{data}{volume} || 1) * 128);
258 $AUDIO_CHUNK{$face} = $chunk; 253 $AUDIO_CHUNK{$face} = $chunk;
259 254
260 audio_sound_push ($face); 255 audio_sound_push ($face);
261 }; 256 };
262 } 257 }
270 or return; 265 or return;
271 $CFG->{effects_enable} 266 $CFG->{effects_enable}
272 or return; 267 or return;
273 268
274 my $queue = $AUDIO_PLAY{$face} ||= []; 269 my $queue = $AUDIO_PLAY{$face} ||= [];
275 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
276 audio_sound_push $face 271 audio_sound_push $face
277 unless @$queue > 1; 272 unless @$queue > 1;
278} 273}
279 274
280sub audio_music_set_meta { 275sub audio_music_set_meta {
281 my ($meta) = @_; 276 my ($meta) = @_;
282 277
283 $MUSIC_PLAYING_META = $meta; 278 $MUSIC_PLAYING_META = $meta;
284 $MUSIC_PLAYING_WIDGET->set_markup ( 279 $MUSIC_PLAYING_WIDGET->set_markup (
285 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" 280 "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
286 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" 281 . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
287 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" 282 . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
288 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) 283 . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license})
289 ); 284 );
290} 285}
291 286
292sub audio_music_update_volume { 287sub audio_music_update_volume {
293 return unless $MUSIC_PLAYING_META; 288 return unless $MUSIC_PLAYING_META;
294 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 289 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
295 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; 290 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
296 CFPlus::MixMusic::volume $base * $volume * 128; 291 CFPlus::MixMusic::volume $base * $volume * 128;
297} 292}
298 293
299sub audio_music_start { 294sub audio_music_start {
300 my $meta = $MUSIC_PLAYING_META; 295 my $meta = $MUSIC_PLAYING_META;
319 314
320 my $NOW = time; 315 my $NOW = time;
321 316
322 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 317 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
323 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 318 my $pos = $MUSIC_PLAYING_META->{stop_pos};
324 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 319 $MUSIC_PLAYER->fade_in_pos (0, 700, $pos);
325 $MUSIC_START = time - $pos; 320 $MUSIC_START = time - $pos;
326 } else { 321 } else {
327 $MUSIC_PLAYER->play (0); 322 $MUSIC_PLAYER->play (0);
328 $MUSIC_START = time; 323 $MUSIC_START = time;
329 } 324 }
343 $fade_out = 333; 338 $fade_out = 333;
344 } else { 339 } else {
345 return unless $CFG->{bgm_enable}; 340 return unless $CFG->{bgm_enable};
346 341
347 my @have = 342 my @have =
348 grep $_, 343 grep $_ && $_->{data},
349 map $CONN->{music_meta}{$_}, 344 map $CONN->{face}[$_],
350 @$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;
351 349
352 @MUSIC_HAVE = @have 350 @MUSIC_HAVE = @have
353 if @have; 351 if @have;
354 352
355 # default MUSIC_HAVE == MUSIC_DEFAULT 353 # default MUSIC_HAVE == MUSIC_DEFAULT
356 @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;
357 $fade_out = 1000; 355 $fade_out = 700;
358 } 356 }
359 357
360 # if the currently playing song is acceptable, let it continue 358 # if the currently playing song is acceptable, let it continue
361 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 359 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
362 360
371 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 369 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
372 370
373 # if the most recently-played piece played very recently, 371 # if the most recently-played piece played very recently,
374 # resume it, else choose the oldest piece for rotation. 372 # resume it, else choose the oldest piece for rotation.
375 audio_music_set_meta 373 audio_music_set_meta
376 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 374 $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
377 ? $MUSIC_HAVE[-1] 375 ? $MUSIC_HAVE[-1]
378 : $MUSIC_HAVE[0]; 376 : $MUSIC_HAVE[0];
379 377
380 audio_music_start; 378 audio_music_start;
381 } 379 }
387 $MUSIC_WANT = $songs; 385 $MUSIC_WANT = $songs;
388 audio_music_push; 386 audio_music_push;
389} 387}
390 388
391sub audio_music_finished { 389sub audio_music_finished {
390 if ($MUSIC_PLAYING_META) {
391 $MUSIC_PLAYING_META->{stop_time} = time;
392 }
393
392 # we compress multiple jingles of the same type 394 # we compress multiple jingles of the same type
393 shift @MUSIC_JINGLE 395 shift @MUSIC_JINGLE
394 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 396 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
395 397
396 $MUSIC_PLAYING_WIDGET->clear; 398 $MUSIC_PLAYING_WIDGET->clear;
776 state => $CFG->{fullscreen}, 778 state => $CFG->{fullscreen},
777 tooltip => "Bring the client into fullscreen mode.", 779 tooltip => "Bring the client into fullscreen mode.",
778 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 780 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
779 ); 781 );
780 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
781 $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");
782 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 806 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
783 state => $CFG->{fast}, 807 state => $CFG->{fast},
784 tooltip => "Lower the visual quality considerably to speed up rendering.", 808 tooltip => "Lower the visual quality considerably to speed up rendering.",
785 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 809 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
811 835
812 $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");
813 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 837 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
814 state => $CFG->{map_smoothing}, 838 state => $CFG->{map_smoothing},
815 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. "
816 . "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. "
817 . "Changes take effect at next connection only.", 841 . "Changes take effect at next login only.",
818 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 842 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
819 ); 843 );
820 844
821 $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");
822 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 846 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
833 ); 857 );
834 858
835 $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");
836 $table->add_at (1, $row++, new CFPlus::UI::Slider 860 $table->add_at (1, $row++, new CFPlus::UI::Slider
837 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 861 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
838 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.",
839 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 },
840 ); 865 );
841 866
842 $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");
843 $table->add_at (1, $row++, new CFPlus::UI::Slider 868 $table->add_at (1, $row++, new CFPlus::UI::Slider
904 expand => 1, state => $CFG->{bgm_enable}, 929 expand => 1, state => $CFG->{bgm_enable},
905 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.",
906 on_changed => sub { 931 on_changed => sub {
907 $CFG->{bgm_enable} = $_[1]; 932 $CFG->{bgm_enable} = $_[1];
908 $CONN->update_fx_want if $CONN; 933 $CONN->update_fx_want if $CONN;
934 audio_music_push;
909 0 935 0
910 } 936 }
911 ); 937 );
912 $table->add_at (2, $row++, new CFPlus::UI::Slider 938 $table->add_at (2, $row++, new CFPlus::UI::Slider
913 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 939 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
966 $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");
967 $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");
968 $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");
969 $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");
970 996
971 $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);
972 $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");
973 1001
974 $GAUGES = { 1002 $GAUGES = {
1003 exp => $exp, prg => $prg, sklprg => $sklprg,
975 exp => $exp, win => $win, range => $rng, 1004 win => $win, range => $rng,
976 food => $fg, mana => $mg, hp => $hg, grace => $gg 1005 hp => $hg, mana => $mg, grace => $gg, food => $fg,
977 }; 1006 };
978 1007
979 &set_gauge_window_fontsize; 1008 &set_gauge_window_fontsize;
980 1009
981 $win 1010 $win
1182 $r 1211 $r
1183} 1212}
1184 1213
1185sub skill_window { 1214sub skill_window {
1186 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); 1215 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
1216
1187 $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
1188 $sw 1219 $sw
1189} 1220}
1190 1221
1191sub formsep($) { 1222sub formsep($) {
1192 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 1223 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1604 $sw1->add ($INV = new CFPlus::UI::Inventory); 1635 $sw1->add ($INV = new CFPlus::UI::Inventory);
1605 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1636 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1606 1637
1607 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1638 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1608 1639
1609 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1640 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1610 1641
1611 $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);
1612 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1643 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1613 1644
1614 # XXX: Call after $INVR = ... because set_opencont sets the items 1645 # XXX: Call after $INVR = ... because set_opencont sets the items
1637} 1668}
1638 1669
1639sub add_license { 1670sub add_license {
1640 my ($meta) = @_; 1671 my ($meta) = @_;
1641 1672
1642 $meta = $meta->{meta} 1673 $meta = $meta->{data}
1643 or return; 1674 or return;
1644 1675
1645 $meta->{license} || $meta->{author} || $meta->{source} 1676 $meta->{license} || $meta->{author} || $meta->{source}
1646 or return; 1677 or return;
1647 1678
1701 $ntb->add_tab ( 1732 $ntb->add_tab (
1702 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1733 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1703 "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 :). "
1704 . "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."
1705 ); 1736 );
1706 $ntb->add_tab (Pickup => autopickup_setup, 1737 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1707 "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.");
1708 1739
1709 $ntb->add_tab (Media => media_window, 1740 $ntb->add_tab (Media => media_window,
1710 "License, Author and Source info for media sent by the server."); 1741 "License, Author and Source info for media sent by the server.");
1711 1742
1869 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1900 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1870 ); 1901 );
1871 $hb->add (new CFPlus::UI::Button 1902 $hb->add (new CFPlus::UI::Button
1872 text => "Quit anyway", 1903 text => "Quit anyway",
1873 expand => 1, 1904 expand => 1,
1874 on_activate => sub { exit }, 1905 on_activate => sub { Event::unloop_all },
1875 ); 1906 );
1876 } 1907 }
1877 1908
1878 $QUIT_DIALOG->show; 1909 $QUIT_DIALOG->show;
1879 $QUIT_DIALOG->grab_focus; 1910 $QUIT_DIALOG->grab_focus;
1952 1983
1953 $SDL_ACTIVE = 1; 1984 $SDL_ACTIVE = 1;
1954 $LAST_REFRESH = time - 0.01; 1985 $LAST_REFRESH = time - 0.01;
1955 1986
1956 CFPlus::OpenGL::init; 1987 CFPlus::OpenGL::init;
1988 CFPlus::Macro::init;
1957 1989
1958 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 1990 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
1959 1991
1960 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 1992 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
1961 1993
1962 ############################################################################# 1994 #############################################################################
1963 1995
1964 if ($DEBUG_STATUS) { 1996 if ($DEBUG_STATUS) {
1965 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; 1997 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
1966 } else { 1998 } else {
1967 # 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 });
1968 2012
1969 $DEBUG_STATUS = new CFPlus::UI::Label 2013 $DEBUG_STATUS = new CFPlus::UI::Label
1970 padding => 0, 2014 padding => 0,
1971 z => 100, 2015 z => 100,
1972 force_x => "max", 2016 force_x => "max",
2002 $MESSAGE_WINDOW->activate_console ($preset) 2046 $MESSAGE_WINDOW->activate_console ($preset)
2003 if $MESSAGE_WINDOW; 2047 if $MESSAGE_WINDOW;
2004 }); 2048 });
2005 $MAPWIDGET->show; 2049 $MAPWIDGET->show;
2006 $MAPWIDGET->grab_focus; 2050 $MAPWIDGET->grab_focus;
2051
2052 $COMPLETER = new CFPlus::MapWidget::Command::
2053 command => { },
2054 tooltip => "#completer_help",
2055 ;
2007 2056
2008 $SETUP_DIALOG = new CFPlus::UI::Toplevel 2057 $SETUP_DIALOG = new CFPlus::UI::Toplevel
2009 title => "Setup", 2058 title => "Setup",
2010 name => "setup_dialog", 2059 name => "setup_dialog",
2011 x => 'center', 2060 x => 'center',
2073 tooltip => "Terminates the program", 2122 tooltip => "Terminates the program",
2074 on_activate => sub { 2123 on_activate => sub {
2075 if ($CONN) { 2124 if ($CONN) {
2076 open_quit_dialog; 2125 open_quit_dialog;
2077 } else { 2126 } else {
2078 exit; 2127 Event::unloop_all;
2079 } 2128 }
2080 0 2129 0
2081 }, 2130 },
2082 ); 2131 );
2083 2132
2084 $BUTTONBAR->show; 2133 $BUTTONBAR->show;
2085 $SETUP_DIALOG->show; 2134 $SETUP_DIALOG->show;
2135 $MESSAGE_WINDOW->show;
2086 } 2136 }
2087 2137
2088 $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]);
2089} 2139}
2090 2140
2098my $animate_timer; 2148my $animate_timer;
2099 2149
2100my $fps = 9; 2150my $fps = 9;
2101 2151
2102sub force_refresh { 2152sub force_refresh {
2153 if ($ENV{CFPLUS_DEBUG} & 4) {
2103 $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;
2104 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2155 debug sprintf "%3.2f", $fps;
2156 }
2105 2157
2106 $CFPlus::UI::ROOT->draw; 2158 $CFPlus::UI::ROOT->draw;
2107 2159 CFPlus::SDL_GL_SwapBuffers;
2108 $WANT_REFRESH = 0;
2109 $CAN_REFRESH = 0;
2110 $LAST_REFRESH = $NOW; 2160 $LAST_REFRESH = $NOW;
2111 2161 $WANT_REFRESH->stop;
2112 CFPlus::SDL_GL_SwapBuffers;
2113} 2162}
2114 2163
2164$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2165
2115my $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 {
2116 $NOW = time; 2167 $NOW = time;
2117 2168
2118 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2169 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2119 for CFPlus::poll_events; 2170 for CFPlus::poll_events;
2120 2171
2121 if (%animate_object) { 2172 if (%animate_object) {
2122 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2173 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2123 ++$WANT_REFRESH; 2174 $WANT_REFRESH->start;
2124 }
2125
2126 if ($WANT_REFRESH) {
2127 force_refresh;
2128 } else {
2129 $CAN_REFRESH = 1;
2130 } 2175 }
2131}); 2176});
2132 2177
2133sub animation_start { 2178sub animation_start {
2134 my ($widget) = @_; 2179 my ($widget) = @_;
2140 delete $animate_object{$widget}; 2185 delete $animate_object{$widget};
2141} 2186}
2142 2187
2143%SDL_CB = ( 2188%SDL_CB = (
2144 CFPlus::SDL_QUIT => sub { 2189 CFPlus::SDL_QUIT => sub {
2145 exit; 2190 Event::unloop_all;
2146 }, 2191 },
2147 CFPlus::SDL_VIDEORESIZE => sub { 2192 CFPlus::SDL_VIDEORESIZE => sub {
2148 }, 2193 },
2149 CFPlus::SDL_VIDEOEXPOSE => sub { 2194 CFPlus::SDL_VIDEOEXPOSE => sub {
2150 CFPlus::UI::full_refresh; 2195 CFPlus::UI::full_refresh;
2189 CFPlus::DB::Server::run; 2234 CFPlus::DB::Server::run;
2190 2235
2191 CFPlus::UI::set_layout ($::CFG->{layout}); 2236 CFPlus::UI::set_layout ($::CFG->{layout});
2192 2237
2193 my %DEF_CFG = ( 2238 my %DEF_CFG = (
2194 sdl_mode => 0, 2239 sdl_mode => 0,
2195 fullscreen => 0, 2240 fullscreen => 0,
2196 fast => 0, 2241 fast => 0,
2242 force_opengl11 => undef,
2243 texture_compression => 1,
2197 map_scale => 1, 2244 map_scale => 1,
2198 fow_enable => 1, 2245 fow_enable => 1,
2199 fow_intensity => 0, 2246 fow_intensity => 0,
2200 map_smoothing => 1, 2247 map_smoothing => 1,
2201 gui_fontsize => 1, 2248 gui_fontsize => 1,
2202 log_fontsize => 0.7, 2249 log_fontsize => 0.7,
2203 gauge_fontsize => 1, 2250 gauge_fontsize => 1,
2204 gauge_size => 0.35, 2251 gauge_size => 0.35,
2205 stat_fontsize => 0.7, 2252 stat_fontsize => 0.7,
2206 mapsize => 100, 2253 mapsize => 100,
2207 audio_enable => 1, 2254 audio_enable => 1,
2208 effects_enable => 1, 2255 effects_enable => 1,
2209 effects_volume => 1, 2256 effects_volume => 1,
2210 bgm_enable => 1, 2257 bgm_enable => 1,
2211 bgm_volume => 0.5, 2258 bgm_volume => 0.5,
2212 output_sync => 1, 2259 output_sync => 1,
2213 output_count => 1, 2260 output_count => 1,
2214 output_rate => "", 2261 output_rate => "",
2215 pickup => 0, 2262 pickup => 0,
2216 inv_sort => "mtime", 2263 inv_sort => "mtime",
2217 default => "profile", # default profile 2264 default => "profile", # default profile
2218 show_tips => 1, 2265 show_tips => 1,
2219 logview_max_par => 1000, 2266 logview_max_par => 1000,
2220 ); 2267 );
2221 2268
2222 while (my ($k, $v) = each %DEF_CFG) { 2269 while (my ($k, $v) = each %DEF_CFG) {
2223 $CFG->{$k} = $v unless exists $CFG->{$k}; 2270 $CFG->{$k} = $v unless exists $CFG->{$k};
2224 } 2271 }
2281# } 2328# }
2282# my $t2 = Time::HiRes::time; 2329# my $t2 = Time::HiRes::time;
2283# warn $t2-$t1; 2330# warn $t2-$t1;
2284# } 2331# }
2285 2332
2286 $startup_done->();
2287
2288 video_init; 2333 video_init;
2289 audio_init; 2334 audio_init;
2290} 2335}
2291 2336
2292show_tip_of_the_day if $CFG->{show_tips}; 2337show_tip_of_the_day if $CFG->{show_tips};
2293 2338
2339Event->idle (cb => sub {
2340 $_[0]->w->cancel;
2341 $startup_done->();
2342});
2343
2294Event::loop; 2344Event::loop;
2345
2346#video_shutdown;
2347#audio_shutdown;
2295#CFPlus::SDL_Quit; 2348CFPlus::SDL_Quit;
2296#CFPlus::_exit 0;
2297
2298END {
2299 video_shutdown;
2300 audio_shutdown;
2301 CFPlus::SDL_Quit;
2302 CFPlus::DB::Server::stop; 2349CFPlus::DB::Server::stop;
2303}
2304 2350
2305=head1 NAME 2351=head1 NAME
2306 2352
2307cfplus - A Crossfire TRT and Crossfire game client 2353cfplus - A Crossfire TRT and Crossfire game client
2308 2354

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines