--- deliantra/Deliantra-Client/bin/cfplus 2007/08/13 16:46:08 1.213 +++ deliantra/Deliantra-Client/bin/cfplus 2007/10/08 16:10:14 1.228 @@ -1,9 +1,7 @@ #!/opt/bin/perl -my $startup_done = sub { }; -our $PANGO = "1.5.0"; - # do splash-screen thingy on win32 +my $startup_done = sub { }; BEGIN { if (%PAR::LibCache && $^O eq "MSWin32") { while (my ($filename, $zip) = each %PAR::LibCache) { @@ -32,38 +30,41 @@ if (%PAR::LibCache) { @INC = grep ref, @INC; # weed out all paths except pars loader refs - my $tmp = $ENV{PAR_TEMP}; + my $root = $ENV{PAR_TEMP}; while (my ($filename, $zip) = each %PAR::LibCache) { for ($zip->memberNames) { next unless /^root\/(.*)/; - $zip->extractMember ($_, "$tmp/$1") - unless -e "$tmp/$1"; + $zip->extractMember ($_, "$root/$1") + unless -e "$root/$1"; } } if ($^O eq "MSWin32") { - # relocatable + # pango is relocatable on win32 } else { + open my $fh, "<:perlio", "$root/pangoversion" + or die "pangoversion: $!"; + my $PANGO = <$fh>; # unix, need to patch pango rc file - open my $fh, "<:perlio", "$tmp/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules" - or die "$tmp/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!"; + open my $fh, "<:perlio", "$root/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules" + or die "$root/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!"; local $/; my $rc = <$fh>; - $rc =~ s/^\//$tmp\//gm; # replace abs paths by relative ones + $rc =~ s/^\//$root\//gm; # replace abs paths by relative ones - mkdir "$tmp/pango-modules"; - open my $fh, ">:perlio", "$tmp/pango-modules/pango.modules" - or die "$tmp/pango-modules/pango.modules: $!"; + mkdir "$root/pango-modules"; + open my $fh, ">:perlio", "$root/pango-modules/pango.modules" + or die "$root/pango-modules/pango.modules: $!"; print $fh $rc; - $ENV{PANGO_RC_FILE} = "$tmp/pango.rc"; + $ENV{PANGO_RC_FILE} = "$root/pango.rc"; open my $fh, ">:perlio", $ENV{PANGO_RC_FILE} or die "$ENV{PANGO_RC_FILE}: $!"; - print $fh "[Pango]\nModuleFiles = $tmp/pango-modules\n"; + print $fh "[Pango]\nModuleFiles = $root/pango-modules\n"; } - unshift @INC, $tmp; + unshift @INC, $root; } } @@ -88,7 +89,9 @@ use CFPlus::UI::Canvas; use CFPlus::UI::Inventory; use CFPlus::UI::SpellList; +use CFPlus::UI::Dockable; use CFPlus::UI::MessageWindow; +use CFPlus::UI::ChatView; use CFPlus::Pod; use CFPlus::MapWidget; use CFPlus::Macro; @@ -128,6 +131,7 @@ our $MAP; our $MAPMAP; our $MAPWIDGET; +our $COMPLETER; our $BUTTONBAR; our $METASERVER; our $LOGIN_BUTTON; @@ -148,6 +152,7 @@ our $MUSIC_PLAYING_WIDGET; our $LICENSE_WIDGET; +our $PICKUP_PAGE; our $INVENTORY_PAGE; our $STATS_PAGE; our $SKILL_PAGE; @@ -169,9 +174,7 @@ our $INV; our $INVR; -our $INV_RIGHT_HB; - -our $PICKUP_CFG; +our $INVR_HB; ############################################################################# @@ -184,8 +187,7 @@ } sub message { - my ($para) = @_; - $MESSAGE_WINDOW->message ($para); + $MESSAGE_WINDOW->message (@_); } ############################################################################# @@ -232,11 +234,14 @@ } } else { # sound_meta not set means data is in flight either way - my $meta = $CONN->{sound_meta}{$face} + my $meta = $CONN->{face}[$face] + or return; + + $meta->{data} or return; # if its a jingle, play it as ambient music - if ($meta->{meta}{jingle}) { + if ($meta->{data}{jingle}) { if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue &audio_music_push ($face); @@ -247,7 +252,7 @@ my $rwops = new CFPlus::RW $_[0]; my $chunk = new CFPlus::MixChunk $rwops or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; - $chunk->volume (($meta->{meta}{volume} || 1) * 128); + $chunk->volume (($meta->{data}{volume} || 1) * 128); $AUDIO_CHUNK{$face} = $chunk; audio_sound_push ($face); @@ -275,17 +280,17 @@ $MUSIC_PLAYING_META = $meta; $MUSIC_PLAYING_WIDGET->set_markup ( - "Name: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" - . "Author: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" - . "Source: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" - . "License: " . (CFPlus::asxml $meta->{meta}{license}) + "Name: " . (CFPlus::asxml $meta->{data}{name}) . "\n" + . "Author: " . (CFPlus::asxml $meta->{data}{author}) . "\n" + . "Source: " . (CFPlus::asxml $meta->{data}{source}) . "\n" + . "License: " . (CFPlus::asxml $meta->{data}{license}) ); } sub audio_music_update_volume { return unless $MUSIC_PLAYING_META; - my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; - my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; + my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1; + my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume}; CFPlus::MixMusic::volume $base * $volume * 128; } @@ -314,7 +319,7 @@ if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { my $pos = $MUSIC_PLAYING_META->{stop_pos}; - $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); + $MUSIC_PLAYER->fade_in_pos (0, 700, $pos); $MUSIC_START = time - $pos; } else { $MUSIC_PLAYER->play (0); @@ -338,16 +343,19 @@ return unless $CFG->{bgm_enable}; my @have = - grep $_, - map $CONN->{music_meta}{$_}, + grep $_ && $_->{data}, + map $CONN->{face}[$_], @$MUSIC_WANT; + # randomize music a bit so that the order is not always the same + $_->{stop_time} ||= rand for @have; + @MUSIC_HAVE = @have if @have; # default MUSIC_HAVE == MUSIC_DEFAULT @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; - $fade_out = 1000; + $fade_out = 700; } # if the currently playing song is acceptable, let it continue @@ -366,7 +374,7 @@ # if the most recently-played piece played very recently, # resume it, else choose the oldest piece for rotation. audio_music_set_meta - $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME + $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME ? $MUSIC_HAVE[-1] : $MUSIC_HAVE[0]; @@ -382,6 +390,10 @@ } sub audio_music_finished { + if ($MUSIC_PLAYING_META) { + $MUSIC_PLAYING_META->{stop_time} = time; + } + # we compress multiple jingles of the same type shift @MUSIC_JINGLE while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; @@ -398,19 +410,25 @@ sub audio_init { if ($CFG->{audio_enable}) { $ENV{MIX_EFFECTSMAXSPEED} = 1; - $SDL_MIXER = !CFPlus::Mix_OpenAudio; + $SDL_MIXER = !CFPlus::Mix_OpenAudio + $CFG->{audio_hw_frequency}, + CFPlus::MIX_DEFAULT_FORMAT, + $CFG->{audio_hw_channels}, + $CFG->{audio_hw_chunksize}; - unless ($SDL_MIXER) { + if ($SDL_MIXER) { + CFPlus::Mix_AllocateChannels $CFG->{audio_mix_channels}; + + audio_music_finished; + } else { status "Unable to open sound device: there will be no sound"; - return; } - - CFPlus::Mix_AllocateChannels 16; - - audio_music_finished; } else { undef $SDL_MIXER; } + + sub audio_tab_update; + audio_tab_update; } sub audio_shutdown { @@ -773,14 +791,24 @@ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); $table->add_at (1, $row++, new CFPlus::UI::CheckBox - state => $CFG->{opengl11}, + state => $CFG->{force_opengl11}, tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " . "higher memory usage and slower performance. It will, however, help tremendously on " . "cards that claim to support a feature but fall back to software rendering. " . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " . "but cards and drivers from other vendors (ATI) are often just as bad. If you " . "experience extremely low framerates and your card should do better, try this option.", - on_changed => sub { my ($self, $value) = @_; $CFG->{opengl11} = $value; 0 } + on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } + ); + + $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); + $table->add_at (1, $row++, new CFPlus::UI::CheckBox + state => $CFG->{texture_compression}, + tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " + . "will save a lot of memory and increase performance. The compression algorithm " + . "can differ form card to card, so your mileage may vary. This setting is ignored in " + . "forced OpenGL 1.1 mode.", + on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } ); $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); @@ -870,6 +898,27 @@ $vbox } +our $AUDIO_HW_CHUNKSIZE; +our $AUDIO_INFO; + +sub audio_tab_update { + my ($freq, $format, $chans) = CFPlus::Mix_QuerySpec; + + $AUDIO_HW_CHUNKSIZE->set_options ([ + map { + my $ms = sprintf "%dms", 1000 * $_ / $CFG->{audio_hw_frequency}; + [$_, $ms, "$ms ($_ samples)"], + } 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 + ]); + + my $text = !$freq + ? "audio is off" + : "Frequency (Hz): $freq\n" + . "Channels: $chans"; + + $AUDIO_INFO->set_text ($text); +} + sub audio_setup { my $vbox = new CFPlus::UI::VBox; @@ -881,12 +930,8 @@ $table->add_at (1, $row++, new CFPlus::UI::CheckBox state => $CFG->{audio_enable}, tooltip => "Master Audio Enable. If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.", - on_changed => sub { $CFG->{audio_enable} = $_[1]; 0 } + on_changed => sub { $CFG->{audio_enable} = $_[1]; 1 } ); -# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); -# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { -# $CFG->{effects_volume} = $_[1]; -# }); $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects"); $table->add_at (1, $row, new CFPlus::UI::CheckBox @@ -895,14 +940,14 @@ on_changed => sub { $CFG->{effects_enable} = $_[1]; $CONN->update_fx_want if $CONN; - 0 + 1 } ); $table->add_at (2, $row++, new CFPlus::UI::Slider expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.", - on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } + on_changed => sub { $CFG->{effects_volume} = $_[1]; 1 } ); $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); @@ -912,7 +957,8 @@ on_changed => sub { $CFG->{bgm_enable} = $_[1]; $CONN->update_fx_want if $CONN; - 0 + audio_music_push; + 1 } ); $table->add_at (2, $row++, new CFPlus::UI::Slider @@ -921,6 +967,72 @@ on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } ); + $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Frequency"); + $table->add_at (1, $row++, new CFPlus::UI::Selector + c_colspan => 2, expand => 1, + value => $CFG->{audio_hw_frequency}, + options => [ + [11025, "11 kHz" , "11kHz (low quality)"], + [22050, "22 kHz" , "22kHz (reduced quality)"], + [44100, "44.1 kHz", "44.1kHz (cd quality)"], + [48000, "48 kHz" , "48kHz (studio quality)"], + ], + tooltip => "The sampling frequency to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.", + on_changed => sub { + $CFG->{audio_hw_frequency} = $_[1]; + audio_tab_update; + 1 + } + ); + + $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Channels"); + $table->add_at (1, $row++, new CFPlus::UI::Selector + c_colspan => 2, expand => 1, + value => $CFG->{audio_hw_channels}, + options => [ + [1, "Mono" , "Mono (single channel, low quality)"], + [2, "Stereo" , "Stereo (dual channe, standard quality)"], + [4, "4 Ch Surround", "4 Channel Surround Sound (3d sound, high quality)"], + [6, "6 Ch Surround", "6 Channel Surround Sound (3d sound + center + lfe)"], + ], + tooltip => "The number of independent sound channels to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.", + on_changed => sub { + $CFG->{audio_hw_channels} = $_[1]; + audio_tab_update; + 1 + } + ); + + $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Latency"); + $table->add_at (1, $row++, $AUDIO_HW_CHUNKSIZE = new CFPlus::UI::Selector + c_colspan => 2, expand => 1, + value => $CFG->{audio_hw_chunksize}, + tooltip => "The guarenteed latency. Lower is better, but also more cpu-intensive and might cause stuttering. If music playback " + . "is stuttering, increase this value. Values of 50-100ms are optimal.", + on_changed => sub { + $CFG->{audio_hw_chunksize} = $_[1] + if $_[1]; + audio_tab_update; + 1 + } + ); + + # should really be a slider + $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Mixer Voices"); + $table->add_at (1, $row++, new CFPlus::UI::ValSlider + c_colspan => 2, expand => 1, + tooltip => "The number of simultaneous sound effects possible. Higher is better, but also more cpu-intensive and might cause stuttering.", + range => [$::CFG->{audio_mix_channels}, 4, 32, 0, 1], + template => ">= 99", + on_changed => sub { + my ($slider, $value) = @_; + + $CFG->{audio_mix_channels} = $value + if $value; + 1; + } + ); + $table->add_at (1, $row++, new CFPlus::UI::Button c_colspan => 2, expand => 1, align => 0, text => "Apply", tooltip => "Apply the audio settings", @@ -931,6 +1043,14 @@ } ); + $vbox->add (new CFPlus::UI::FancyFrame + expand => 1, + label => "Audio Info", + child => ($AUDIO_INFO = new CFPlus::UI::Label ellipsise => 0), + ); + + audio_tab_update; + $vbox } @@ -974,12 +1094,15 @@ $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); - $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); - $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); + $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); + $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress); + $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress); + $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); $GAUGES = { - exp => $exp, win => $win, range => $rng, - food => $fg, mana => $mg, hp => $hg, grace => $gg + exp => $exp, prg => $prg, sklprg => $sklprg, + win => $win, range => $rng, + hp => $hg, mana => $mg, grace => $gg, food => $fg, }; &set_gauge_window_fontsize; @@ -1190,7 +1313,9 @@ sub skill_window { my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); - $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); + + $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]); + $sw } @@ -1612,7 +1737,7 @@ $hb->add (my $vb2 = new CFPlus::UI::VBox); - $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); + $vb2->add ($INVR_HB = new CFPlus::UI::HBox); $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); $sw2->add ($INVR = new CFPlus::UI::Inventory); @@ -1645,7 +1770,7 @@ sub add_license { my ($meta) = @_; - $meta = $meta->{meta} + $meta = $meta->{data} or return; $meta->{license} || $meta->{author} || $meta->{source} @@ -1709,7 +1834,7 @@ "Toggles the inventory window, where you can manage your loot (or treasures :). " . "You can also hit the Tab-key to show/hide the Inventory." ); - $ntb->add_tab (Pickup => autopickup_setup, + $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup, "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); $ntb->add_tab (Media => media_window, @@ -1960,6 +2085,7 @@ $LAST_REFRESH = time - 0.01; CFPlus::OpenGL::init; + CFPlus::Macro::init; $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; @@ -1970,7 +2096,19 @@ if ($DEBUG_STATUS) { CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; } else { - # create the widgets + # create/configure the widgets + + $CFPlus::UI::ROOT->connect (key_down => sub { + my (undef, $ev) = @_; + + if (my @macros = CFPlus::Macro::find $ev) { + CFPlus::Macro::execute $_ for @macros; + + return 1; + } + + 0 + }); $DEBUG_STATUS = new CFPlus::UI::Label padding => 0, @@ -2011,6 +2149,11 @@ $MAPWIDGET->show; $MAPWIDGET->grab_focus; + $COMPLETER = new CFPlus::MapWidget::Command:: + command => { }, + tooltip => "#completer_help", + ; + $SETUP_DIALOG = new CFPlus::UI::Toplevel title => "Setup", name => "setup_dialog", @@ -2089,6 +2232,7 @@ $BUTTONBAR->show; $SETUP_DIALOG->show; + $MESSAGE_WINDOW->show; } $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); @@ -2143,7 +2287,7 @@ %SDL_CB = ( CFPlus::SDL_QUIT => sub { - exit; + Event::unloop_all; }, CFPlus::SDL_VIDEORESIZE => sub { }, @@ -2192,33 +2336,38 @@ CFPlus::UI::set_layout ($::CFG->{layout}); my %DEF_CFG = ( - sdl_mode => 0, - fullscreen => 0, - fast => 0, - opengl11 => 0, - map_scale => 1, - fow_enable => 1, - fow_intensity => 0, - map_smoothing => 1, - gui_fontsize => 1, - log_fontsize => 0.7, - gauge_fontsize => 1, - gauge_size => 0.35, - stat_fontsize => 0.7, - mapsize => 100, - audio_enable => 1, - effects_enable => 1, - effects_volume => 1, - bgm_enable => 1, - bgm_volume => 0.5, - output_sync => 1, - output_count => 1, - output_rate => "", - pickup => 0, - inv_sort => "mtime", - default => "profile", # default profile - show_tips => 1, - logview_max_par => 1000, + sdl_mode => 0, + fullscreen => 0, + fast => 0, + force_opengl11 => undef, + texture_compression => 1, + map_scale => 1, + fow_enable => 1, + fow_intensity => 0, + map_smoothing => 1, + gui_fontsize => 1, + log_fontsize => 0.7, + gauge_fontsize => 1, + gauge_size => 0.35, + stat_fontsize => 0.7, + mapsize => 100, + audio_enable => 1, + audio_hw_channels => 2, + audio_hw_frequency => 22050, + audio_hw_chunksize => 2048, + audio_mix_channels => 8, + effects_enable => 1, + effects_volume => 1, + bgm_enable => 1, + bgm_volume => 0.5, + output_sync => 1, + output_count => 1, + output_rate => "", + pickup => 0, + inv_sort => "mtime", + default => "profile", # default profile + show_tips => 1, + logview_max_par => 1000, ); while (my ($k, $v) = each %DEF_CFG) { @@ -2285,14 +2434,17 @@ # warn $t2-$t1; # } - $startup_done->(); - video_init; audio_init; } show_tip_of_the_day if $CFG->{show_tips}; +Event->idle (cb => sub { + $_[0]->w->cancel; + $startup_done->(); +}); + Event::loop; #video_shutdown;