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.204 by root, Mon Aug 6 05:06:33 2007 UTC vs.
Revision 1.223 by root, Tue Aug 28 01:23:47 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]);
217 my ($face) = @_; 216 my ($face) = @_;
218 217
219 $CFG->{effects_enable} 218 $CFG->{effects_enable}
220 or return; 219 or return;
221 220
221 $AUDIO_PLAY{$face}
222 or return;
223
222 if (my $chunk = $AUDIO_CHUNK{$face}) { 224 if (my $chunk = $AUDIO_CHUNK{$face}) {
223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 225 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
224 my (undef, $dx, $dy, $vol) = @$_; 226 my (undef, $dx, $dy, $vol) = @$_;
225 227
226 my $channel = CFPlus::Channel::find; 228 my $channel = CFPlus::Channel::find;
227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); 229 $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); 230 $channel->set_position_r ($dx, $dy, 20);
234
235 $chunk->play ($channel); 231 $chunk->play ($channel);
236 } 232 }
237 } else { 233 } else {
238 # sound_meta not set means data is in flight either way 234 # sound_meta not set means data is in flight either way
239 my $meta = $CONN->{sound_meta}{$face} 235 my $meta = $CONN->{face}[$face]
240 or return; 236 or return;
241 237
238 $meta->{data}
239 or return;
240
242 # if its a jingle, play it as ambient music 241 # if its a jingle, play it as ambient music
243 if ($meta->{meta}{jingle}) { 242 if ($meta->{data}{jingle}) {
244 if (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
245 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 244 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
246 &audio_music_push ($face); 245 &audio_music_push ($face);
247 } 246 }
248 } else { 247 } else {
249 # fetch from database 248 # fetch from database
250 CFPlus::DB::get res_data => $meta->{name}, sub { 249 CFPlus::DB::get res_data => $meta->{name}, sub {
251 my $rwops = new CFPlus::RW $_[0]; 250 my $rwops = new CFPlus::RW $_[0];
252 my $chunk = new CFPlus::MixChunk $rwops 251 my $chunk = new CFPlus::MixChunk $rwops
253 or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError; 252 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
254 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 253 $chunk->volume (($meta->{data}{volume} || 1) * 128);
255 $AUDIO_CHUNK{$face} = $chunk; 254 $AUDIO_CHUNK{$face} = $chunk;
256 255
257 audio_sound_push ($face); 256 audio_sound_push ($face);
258 }; 257 };
259 } 258 }
267 or return; 266 or return;
268 $CFG->{effects_enable} 267 $CFG->{effects_enable}
269 or return; 268 or return;
270 269
271 my $queue = $AUDIO_PLAY{$face} ||= []; 270 my $queue = $AUDIO_PLAY{$face} ||= [];
272 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
273 audio_sound_push $face 272 audio_sound_push $face
274 unless @$queue > 1; 273 unless @$queue > 1;
275} 274}
276 275
277sub audio_music_set_meta { 276sub audio_music_set_meta {
278 my ($meta) = @_; 277 my ($meta) = @_;
279 278
280 $MUSIC_PLAYING_META = $meta; 279 $MUSIC_PLAYING_META = $meta;
281 $MUSIC_PLAYING_WIDGET->set_markup ( 280 $MUSIC_PLAYING_WIDGET->set_markup (
282 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" 281 "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
283 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" 282 . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
284 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" 283 . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
285 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) 284 . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license})
286 ); 285 );
287} 286}
288 287
289sub audio_music_update_volume { 288sub audio_music_update_volume {
290 return unless $MUSIC_PLAYING_META; 289 return unless $MUSIC_PLAYING_META;
291 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 290 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
292 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; 291 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
293 CFPlus::MixMusic::volume $base * $volume * 128; 292 CFPlus::MixMusic::volume $base * $volume * 128;
294} 293}
295 294
296sub audio_music_start { 295sub audio_music_start {
297 my $meta = $MUSIC_PLAYING_META; 296 my $meta = $MUSIC_PLAYING_META;
340 $fade_out = 333; 339 $fade_out = 333;
341 } else { 340 } else {
342 return unless $CFG->{bgm_enable}; 341 return unless $CFG->{bgm_enable};
343 342
344 my @have = 343 my @have =
345 grep $_, 344 grep $_ && $_->{data},
346 map $CONN->{music_meta}{$_}, 345 map $CONN->{face}[$_],
347 @$MUSIC_WANT; 346 @$MUSIC_WANT;
348 347
349 @MUSIC_HAVE = @have 348 @MUSIC_HAVE = @have
350 if @have; 349 if @have;
351 350
773 state => $CFG->{fullscreen}, 772 state => $CFG->{fullscreen},
774 tooltip => "Bring the client into fullscreen mode.", 773 tooltip => "Bring the client into fullscreen mode.",
775 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 774 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
776 ); 775 );
777 776
777 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1");
778 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
779 state => $CFG->{force_opengl11},
780 tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in "
781 . "higher memory usage and slower performance. It will, however, help tremendously on "
782 . "cards that claim to support a feature but fall back to software rendering. "
783 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
784 . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you "
785 . "experience extremely low framerates and your card should do better, try this option.</b>",
786 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
787 );
788
789 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures");
790 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
791 state => $CFG->{texture_compression},
792 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
793 . "will save a lot of memory and increase performance. The compression algorithm "
794 . "can differ form card to card, so your mileage may vary. This setting is ignored in "
795 . "forced OpenGL 1.1 mode.",
796 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
797 );
798
778 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 799 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
779 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 800 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
780 state => $CFG->{fast}, 801 state => $CFG->{fast},
781 tooltip => "Lower the visual quality considerably to speed up rendering.", 802 tooltip => "Lower the visual quality considerably to speed up rendering.",
782 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 803 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
808 829
809 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); 830 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing");
810 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 831 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
811 state => $CFG->{map_smoothing}, 832 state => $CFG->{map_smoothing},
812 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " 833 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. "
813 . "This increases load on the graphics subsystem and works only with 2.x servers. " 834 . "This increases load on the graphics subsystem and works only with TRT servers. "
814 . "Changes take effect at next connection only.", 835 . "Changes take effect at next login only.",
815 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 836 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
816 ); 837 );
817 838
818 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); 839 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
819 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 840 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
830 ); 851 );
831 852
832 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 853 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
833 $table->add_at (1, $row++, new CFPlus::UI::Slider 854 $table->add_at (1, $row++, new CFPlus::UI::Slider
834 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 855 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
835 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 856 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, "
857 . "but you still need to press apply to correctly re-layout the widget.",
836 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 858 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
837 ); 859 );
838 860
839 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 861 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
840 $table->add_at (1, $row++, new CFPlus::UI::Slider 862 $table->add_at (1, $row++, new CFPlus::UI::Slider
877# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 899# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
878# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { 900# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
879# $CFG->{effects_volume} = $_[1]; 901# $CFG->{effects_volume} = $_[1];
880# }); 902# });
881 903
882 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 904 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects");
883 $table->add_at (1, $row, new CFPlus::UI::CheckBox 905 $table->add_at (1, $row, new CFPlus::UI::CheckBox
884 expand => 1, state => $CFG->{effects_enable}, 906 expand => 1, state => $CFG->{effects_enable},
885 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", 907 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
908 on_changed => sub {
886 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } 909 $CFG->{effects_enable} = $_[1];
910 $CONN->update_fx_want if $CONN;
911 0
912 }
887 ); 913 );
888 $table->add_at (2, $row++, new CFPlus::UI::Slider 914 $table->add_at (2, $row++, new CFPlus::UI::Slider
889 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], 915 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
890 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " 916 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
891 . "is set highest and you use your operating system volume setting. Changes are instant.", 917 . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
892 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } 918 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
893 ); 919 );
894 920
895 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 921 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
896 $table->add_at (1, $row, new CFPlus::UI::CheckBox 922 $table->add_at (1, $row, new CFPlus::UI::CheckBox
897 expand => 1, state => $CFG->{bgm_enable}, 923 expand => 1, state => $CFG->{bgm_enable},
898 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 924 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
899 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 925 on_changed => sub {
926 $CFG->{bgm_enable} = $_[1];
927 $CONN->update_fx_want if $CONN;
928 audio_music_push;
929 0
930 }
900 ); 931 );
901 $table->add_at (2, $row++, new CFPlus::UI::Slider 932 $table->add_at (2, $row++, new CFPlus::UI::Slider
902 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 933 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
903 tooltip => "The volume of the background music. Changes are instant.", 934 tooltip => "The volume of the background music. Changes are instant.",
904 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 935 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
955 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); 986 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health");
956 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); 987 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana");
957 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); 988 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace");
958 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); 989 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food");
959 990
960 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); 991 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
992 $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress);
993 $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress);
961 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); 994 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
962 995
963 $GAUGES = { 996 $GAUGES = {
997 exp => $exp, prg => $prg, sklprg => $sklprg,
964 exp => $exp, win => $win, range => $rng, 998 win => $win, range => $rng,
965 food => $fg, mana => $mg, hp => $hg, grace => $gg 999 hp => $hg, mana => $mg, grace => $gg, food => $fg,
966 }; 1000 };
967 1001
968 &set_gauge_window_fontsize; 1002 &set_gauge_window_fontsize;
969 1003
970 $win 1004 $win
1171 $r 1205 $r
1172} 1206}
1173 1207
1174sub skill_window { 1208sub skill_window {
1175 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); 1209 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
1210
1176 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); 1211 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1212
1177 $sw 1213 $sw
1178} 1214}
1179 1215
1180sub formsep($) { 1216sub formsep($) {
1181 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 1217 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1593 $sw1->add ($INV = new CFPlus::UI::Inventory); 1629 $sw1->add ($INV = new CFPlus::UI::Inventory);
1594 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1630 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1595 1631
1596 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1632 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1597 1633
1598 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1634 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1599 1635
1600 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1636 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1601 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1637 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1602 1638
1603 # XXX: Call after $INVR = ... because set_opencont sets the items 1639 # XXX: Call after $INVR = ... because set_opencont sets the items
1626} 1662}
1627 1663
1628sub add_license { 1664sub add_license {
1629 my ($meta) = @_; 1665 my ($meta) = @_;
1630 1666
1631 $meta = $meta->{meta} 1667 $meta = $meta->{data}
1632 or return; 1668 or return;
1633 1669
1634 $meta->{license} || $meta->{author} || $meta->{source} 1670 $meta->{license} || $meta->{author} || $meta->{source}
1635 or return; 1671 or return;
1636 1672
1690 $ntb->add_tab ( 1726 $ntb->add_tab (
1691 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1727 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1692 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1728 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1693 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1729 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1694 ); 1730 );
1695 $ntb->add_tab (Pickup => autopickup_setup, 1731 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1696 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1732 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1697 1733
1698 $ntb->add_tab (Media => media_window, 1734 $ntb->add_tab (Media => media_window,
1699 "License, Author and Source info for media sent by the server."); 1735 "License, Author and Source info for media sent by the server.");
1700 1736
1858 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1894 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1859 ); 1895 );
1860 $hb->add (new CFPlus::UI::Button 1896 $hb->add (new CFPlus::UI::Button
1861 text => "Quit anyway", 1897 text => "Quit anyway",
1862 expand => 1, 1898 expand => 1,
1863 on_activate => sub { exit }, 1899 on_activate => sub { Event::unloop_all },
1864 ); 1900 );
1865 } 1901 }
1866 1902
1867 $QUIT_DIALOG->show; 1903 $QUIT_DIALOG->show;
1868 $QUIT_DIALOG->grab_focus; 1904 $QUIT_DIALOG->grab_focus;
1941 1977
1942 $SDL_ACTIVE = 1; 1978 $SDL_ACTIVE = 1;
1943 $LAST_REFRESH = time - 0.01; 1979 $LAST_REFRESH = time - 0.01;
1944 1980
1945 CFPlus::OpenGL::init; 1981 CFPlus::OpenGL::init;
1982 CFPlus::Macro::init;
1946 1983
1947 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 1984 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
1948 1985
1949 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 1986 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
1950 1987
1951 ############################################################################# 1988 #############################################################################
1952 1989
1953 if ($DEBUG_STATUS) { 1990 if ($DEBUG_STATUS) {
1954 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; 1991 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
1955 } else { 1992 } else {
1956 # create the widgets 1993 # create/configure the widgets
1994
1995 $CFPlus::UI::ROOT->connect (key_down => sub {
1996 my (undef, $ev) = @_;
1997
1998 if (my @macros = CFPlus::Macro::find $ev) {
1999 CFPlus::Macro::execute $_ for @macros;
2000
2001 return 1;
2002 }
2003
2004 0
2005 });
1957 2006
1958 $DEBUG_STATUS = new CFPlus::UI::Label 2007 $DEBUG_STATUS = new CFPlus::UI::Label
1959 padding => 0, 2008 padding => 0,
1960 z => 100, 2009 z => 100,
1961 force_x => "max", 2010 force_x => "max",
1991 $MESSAGE_WINDOW->activate_console ($preset) 2040 $MESSAGE_WINDOW->activate_console ($preset)
1992 if $MESSAGE_WINDOW; 2041 if $MESSAGE_WINDOW;
1993 }); 2042 });
1994 $MAPWIDGET->show; 2043 $MAPWIDGET->show;
1995 $MAPWIDGET->grab_focus; 2044 $MAPWIDGET->grab_focus;
2045
2046 $COMPLETER = new CFPlus::MapWidget::Command::
2047 command => { },
2048 tooltip => "#completer_help",
2049 ;
1996 2050
1997 $SETUP_DIALOG = new CFPlus::UI::Toplevel 2051 $SETUP_DIALOG = new CFPlus::UI::Toplevel
1998 title => "Setup", 2052 title => "Setup",
1999 name => "setup_dialog", 2053 name => "setup_dialog",
2000 x => 'center', 2054 x => 'center',
2062 tooltip => "Terminates the program", 2116 tooltip => "Terminates the program",
2063 on_activate => sub { 2117 on_activate => sub {
2064 if ($CONN) { 2118 if ($CONN) {
2065 open_quit_dialog; 2119 open_quit_dialog;
2066 } else { 2120 } else {
2067 exit; 2121 Event::unloop_all;
2068 } 2122 }
2069 0 2123 0
2070 }, 2124 },
2071 ); 2125 );
2072 2126
2073 $BUTTONBAR->show; 2127 $BUTTONBAR->show;
2074 $SETUP_DIALOG->show; 2128 $SETUP_DIALOG->show;
2129 $MESSAGE_WINDOW->show;
2075 } 2130 }
2076 2131
2077 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 2132 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2078} 2133}
2079 2134
2087my $animate_timer; 2142my $animate_timer;
2088 2143
2089my $fps = 9; 2144my $fps = 9;
2090 2145
2091sub force_refresh { 2146sub force_refresh {
2147 if ($ENV{CFPLUS_DEBUG} & 4) {
2092 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2148 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2093 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2149 debug sprintf "%3.2f", $fps;
2150 }
2094 2151
2095 $CFPlus::UI::ROOT->draw; 2152 $CFPlus::UI::ROOT->draw;
2096 2153 CFPlus::SDL_GL_SwapBuffers;
2097 $WANT_REFRESH = 0;
2098 $CAN_REFRESH = 0;
2099 $LAST_REFRESH = $NOW; 2154 $LAST_REFRESH = $NOW;
2100 2155 $WANT_REFRESH->stop;
2101 CFPlus::SDL_GL_SwapBuffers;
2102} 2156}
2103 2157
2158$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2159
2104my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { 2160my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub {
2105 $NOW = time; 2161 $NOW = time;
2106 2162
2107 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2163 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2108 for CFPlus::poll_events; 2164 for CFPlus::poll_events;
2109 2165
2110 if (%animate_object) { 2166 if (%animate_object) {
2111 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2167 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2112 ++$WANT_REFRESH; 2168 $WANT_REFRESH->start;
2113 }
2114
2115 if ($WANT_REFRESH) {
2116 force_refresh;
2117 } else {
2118 $CAN_REFRESH = 1;
2119 } 2169 }
2120}); 2170});
2121 2171
2122sub animation_start { 2172sub animation_start {
2123 my ($widget) = @_; 2173 my ($widget) = @_;
2129 delete $animate_object{$widget}; 2179 delete $animate_object{$widget};
2130} 2180}
2131 2181
2132%SDL_CB = ( 2182%SDL_CB = (
2133 CFPlus::SDL_QUIT => sub { 2183 CFPlus::SDL_QUIT => sub {
2134 exit; 2184 Event::unloop_all;
2135 }, 2185 },
2136 CFPlus::SDL_VIDEORESIZE => sub { 2186 CFPlus::SDL_VIDEORESIZE => sub {
2137 }, 2187 },
2138 CFPlus::SDL_VIDEOEXPOSE => sub { 2188 CFPlus::SDL_VIDEOEXPOSE => sub {
2139 CFPlus::UI::full_refresh; 2189 CFPlus::UI::full_refresh;
2178 CFPlus::DB::Server::run; 2228 CFPlus::DB::Server::run;
2179 2229
2180 CFPlus::UI::set_layout ($::CFG->{layout}); 2230 CFPlus::UI::set_layout ($::CFG->{layout});
2181 2231
2182 my %DEF_CFG = ( 2232 my %DEF_CFG = (
2183 sdl_mode => 0, 2233 sdl_mode => 0,
2184 fullscreen => 0, 2234 fullscreen => 0,
2185 fast => 0, 2235 fast => 0,
2236 force_opengl11 => undef,
2237 texture_compression => 1,
2186 map_scale => 1, 2238 map_scale => 1,
2187 fow_enable => 1, 2239 fow_enable => 1,
2188 fow_intensity => 0, 2240 fow_intensity => 0,
2189 map_smoothing => 1, 2241 map_smoothing => 1,
2190 gui_fontsize => 1, 2242 gui_fontsize => 1,
2191 log_fontsize => 0.7, 2243 log_fontsize => 0.7,
2192 gauge_fontsize => 1, 2244 gauge_fontsize => 1,
2193 gauge_size => 0.35, 2245 gauge_size => 0.35,
2194 stat_fontsize => 0.7, 2246 stat_fontsize => 0.7,
2195 mapsize => 100, 2247 mapsize => 100,
2196 audio_enable => 1, 2248 audio_enable => 1,
2197 effects_enable => 1, 2249 effects_enable => 1,
2198 effects_volume => 1, 2250 effects_volume => 1,
2199 bgm_enable => 1, 2251 bgm_enable => 1,
2200 bgm_volume => 0.5, 2252 bgm_volume => 0.5,
2201 output_sync => 1, 2253 output_sync => 1,
2202 output_count => 1, 2254 output_count => 1,
2203 output_rate => "", 2255 output_rate => "",
2204 pickup => 0, 2256 pickup => 0,
2205 inv_sort => "mtime", 2257 inv_sort => "mtime",
2206 default => "profile", # default profile 2258 default => "profile", # default profile
2207 show_tips => 1, 2259 show_tips => 1,
2208 logview_max_par => 1000, 2260 logview_max_par => 1000,
2209 ); 2261 );
2210 2262
2211 while (my ($k, $v) = each %DEF_CFG) { 2263 while (my ($k, $v) = each %DEF_CFG) {
2212 $CFG->{$k} = $v unless exists $CFG->{$k}; 2264 $CFG->{$k} = $v unless exists $CFG->{$k};
2213 } 2265 }
2270# } 2322# }
2271# my $t2 = Time::HiRes::time; 2323# my $t2 = Time::HiRes::time;
2272# warn $t2-$t1; 2324# warn $t2-$t1;
2273# } 2325# }
2274 2326
2275 $startup_done->();
2276
2277 video_init; 2327 video_init;
2278 audio_init; 2328 audio_init;
2279} 2329}
2280 2330
2281show_tip_of_the_day if $CFG->{show_tips}; 2331show_tip_of_the_day if $CFG->{show_tips};
2282 2332
2333Event->idle (cb => sub {
2334 $_[0]->w->cancel;
2335 $startup_done->();
2336});
2337
2283Event::loop; 2338Event::loop;
2339
2340#video_shutdown;
2341#audio_shutdown;
2284#CFPlus::SDL_Quit; 2342CFPlus::SDL_Quit;
2285#CFPlus::_exit 0;
2286
2287END {
2288 video_shutdown;
2289 audio_shutdown;
2290 CFPlus::SDL_Quit;
2291 CFPlus::DB::Server::stop; 2343CFPlus::DB::Server::stop;
2292}
2293 2344
2294=head1 NAME 2345=head1 NAME
2295 2346
2296cfplus - A Crossfire TRT and Crossfire game client 2347cfplus - A Crossfire TRT and Crossfire game client
2297 2348

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines