--- deliantra/Deliantra-Client/DC/Main.pm 2012/01/07 15:24:41 1.11 +++ deliantra/Deliantra-Client/DC/Main.pm 2012/04/05 04:38:43 1.20 @@ -35,6 +35,7 @@ use Compress::LZF; use JSON::XS; +use Urlader; use DC; @@ -46,7 +47,7 @@ $SIG{__DIE__} = sub { return if $^S; # quick reject - # return if there are any eval contexts in the csall stack + # return if there are any eval contexts in the call stack for my $i (0..999) { my ($sub, $is_require) = (caller $i)[3, 7] or last; @@ -59,6 +60,7 @@ } use DC::OpenGL (); +use DC::Audio (); use DC::Protocol; use DC::DB; use DC::UI; @@ -475,25 +477,9 @@ sub audio_init { if ($CFG->{audio_enable}) { - if (length $CFG->{audio_driver}) { - local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver}; - DC::SDL_Init DC::SDL_INIT_AUDIO - and die "SDL::Init failed!\n"; - } else { - DC::SDL_Init DC::SDL_INIT_AUDIO - and die "SDL::Init failed!\n"; - } - - $ENV{MIX_EFFECTSMAXSPEED} = 1; - $SDL_MIXER = !DC::Mix_OpenAudio - $CFG->{audio_hw_frequency}, - DC::MIX_DEFAULT_FORMAT, - $CFG->{audio_hw_channels}, - $CFG->{audio_hw_chunksize}; + DC::Audio::init $CFG->{audio_driver}; if ($SDL_MIXER) { - DC::Mix_AllocateChannels $CFG->{audio_mix_channels}; - audio_music_finished; } else { status "Unable to open sound device: there will be no sound"; @@ -599,9 +585,10 @@ if ($fh) { $error ||= Coro::AIO::aio_stat "$override.tmp"; $error ||= -s _ != $size; - $error ||= Coro::AIO::aio_readahead $fh, 0, $size; + Coro::AIO::aio_readahead $fh, 0, $size; my $f_md5 = new Digest::MD5; + binmode $fh; # ugh :( $f_md5->addfile ($fh); $f_md5 = $f_md5->hexdigest; $error ||= $md5 ne $f_md5; @@ -2030,7 +2017,7 @@ tooltip => "Use this to manually save configuration and UI layout when " . "autosave is disabled.", on_activate => sub { - DC::write_cfg; + DC::save_cfg; 0 } ); @@ -2968,145 +2955,97 @@ }; # due to mac os x + sdl combined braindamage, we need this contortion -sub DC::Main::main { - { - DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; +sub DC::Main::run { + DC::SDL_main_hack { + { + DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; - if (-e "$Deliantra::VARDIR/client.cf") { - DC::read_cfg "$Deliantra::VARDIR/client.cf"; - } else { - #TODO: compatibility cruft - DC::read_cfg "$Deliantra::OLDDIR/cfplusrc"; - print STDERR "INFO: used old configuration file\n"; - } - - DC::DB::Server::run; - - if ($CFG->{db_schema} < 1) { - warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; - DC::DB::nuke_db; - $CFG->{db_schema} = 1; - DC::write_cfg; - } - - DC::DB::open_db; - - DC::UI::set_layout ($::CFG->{layout}); - - my %DEF_CFG = ( - config_autosave => 1, - sdl_mode => undef, - fullscreen => 1, - fast => 0, - force_opengl11 => undef, - disable_alpha => 0, - smooth_movement => 1, - smooth_transitions => 1, - texture_compression => 1, - map_scale => 1, - fow_enable => 1, - fow_intensity => 0, - fow_texture => 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 => 0, - audio_hw_frequency => 0, - audio_hw_chunksize => 0, - audio_mix_channels => 8, - effects_enable => 1, - effects_volume => 1, - bgm_enable => 1, - bgm_volume => 0.5, - output_rate => "", - pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES, - inv_sort => "mtime", - default => "profile", # default profile - show_tips => 1, - logview_max_par => 1000, - shift_fire_stop => 0, - uitheme => "wood", - map_shift_x => -24, # arbitrary - map_shift_y => +24, # arbitrary - ); - - while (my ($k, $v) = each %DEF_CFG) { - $CFG->{$k} = $v unless exists $CFG->{$k}; - } - - my @args = @ARGV; - - # OS X passes some process serial number of other shit. they - # could have used an env var or any other sane mechanism. but - # would it be os x then? no... - shift @args if $args[0] =~ /^-psn_/; - - my $profile = 'default'; - - for (my $i = 0; $i < @args; $i++) { - if ($args[$i] =~ /^--?profile$/) { - $profile = $args[$i + 1]; - splice @args, $i, 2, (); - $i = 0; - } elsif ($args[$i] =~ /^--?h/) { - print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; - exit 0; - } - } - - $CFG->{profile}{$profile} ||= {}; - $PROFILE = $CFG->{profile}{$profile}; - $PROFILE->{host} ||= "gameserver.deliantra.net"; - - $PROFILE->{host} = $args[0] if @args > 0; - $PROFILE->{user} = $args[1] if @args > 1; - $PROFILE->{password} = $args[2] if @args > 2; - - # convert old bindings (only default profile matters) - if (my $bindings = delete $PROFILE->{bindings}) { - while (my ($mod, $syms) = each %$bindings) { - while (my ($sym, $cmds) = each %$syms) { - push @{ $PROFILE->{macro} }, { - accelkey => [$mod*1, $sym*1], - action => $cmds, - }; + DC::load_cfg; + DC::upgrade_cfg; + + DC::Audio::probe; + + DC::DB::Server::run; + + if ($CFG->{db_schema} < 1) { + warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; + DC::DB::nuke_db; + $CFG->{db_schema} = 1; + DC::save_cfg; + } + + DC::DB::open_db; + + DC::UI::set_layout ($::CFG->{layout}); + + my @args = @ARGV; + + # OS X passes some process serial number of other shit. they + # could have used an env var or any other sane mechanism. but + # would it be os x then? no... + shift @args if $args[0] =~ /^-psn_/; + + my $profile = 'default'; + + for (my $i = 0; $i < @args; $i++) { + if ($args[$i] =~ /^--?profile$/) { + $profile = $args[$i + 1]; + splice @args, $i, 2, (); + $i = 0; + } elsif ($args[$i] =~ /^--?h/) { + print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; + exit 0; } } - } - # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed - # these are ignored under windows, for some reason, and thus set in the loader - $ENV{FONTCONFIG_FILE} = "fonts.conf"; - $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; - $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions + $CFG->{profile}{$profile} ||= {}; + $PROFILE = $CFG->{profile}{$profile}; + $PROFILE->{host} ||= "gameserver.deliantra.net"; + + $PROFILE->{host} = $args[0] if @args > 0; + $PROFILE->{user} = $args[1] if @args > 1; + $PROFILE->{password} = $args[2] if @args > 2; + + # convert old bindings (only default profile matters) + if (my $bindings = delete $PROFILE->{bindings}) { + while (my ($mod, $syms) = each %$bindings) { + while (my ($sym, $cmds) = each %$syms) { + push @{ $PROFILE->{macro} }, { + accelkey => [$mod*1, $sym*1], + action => $cmds, + }; + } + } + } - { - my @fonts = map DC::find_rcfile "fonts/$_", qw( - DejaVuSans.ttf - DejaVuSansMono.ttf - DejaVuSans-Bold.ttf - DejaVuSansMono-Bold.ttf - DejaVuSans-Oblique.ttf - DejaVuSansMono-Oblique.ttf - DejaVuSans-BoldOblique.ttf - DejaVuSansMono-BoldOblique.ttf - mona.ttf - ); + # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed + # these are ignored under windows, for some reason, and thus set in the loader + $ENV{FONTCONFIG_FILE} = "fonts.conf"; + $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; + $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions + + { + my @fonts = map DC::find_rcfile "fonts/$_", qw( + DejaVuSans.ttf + DejaVuSansMono.ttf + DejaVuSans-Bold.ttf + DejaVuSansMono-Bold.ttf + DejaVuSans-Oblique.ttf + DejaVuSansMono-Oblique.ttf + DejaVuSans-BoldOblique.ttf + DejaVuSansMono-BoldOblique.ttf + mona.ttf + ); - DC::add_font $_ for @fonts; + DC::add_font $_ for @fonts; - $FONT_PROP = new_from_file DC::Font $fonts[0]; - $FONT_FIXED = new_from_file DC::Font $fonts[1]; + $FONT_PROP = new_from_file DC::Font $fonts[0]; + $FONT_FIXED = new_from_file DC::Font $fonts[1]; - $FONT_PROP->make_default; + $FONT_PROP->make_default; - DC::pango_init; - } + DC::pango_init; + } # compare mono (ft) vs. rgba (cairo) # ft - 1.8s, cairo 3s, even in alpha-only mode @@ -3121,33 +3060,34 @@ # warn $t2-$t1; # } + } + + DC::SDL_Init 0; DC::IMG_Init; video_init; DC::Mix_Init; audio_init; - } - show_tip_of_the_day if $CFG->{show_tips}; + show_tip_of_the_day if $CFG->{show_tips}; - my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { - undef $STARTUP_CANCEL; - (pop @::STARTUP_DONE)->() - while @::STARTUP_DONE; - }; + my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { + undef $STARTUP_CANCEL; + (pop @::STARTUP_DONE)->() + while @::STARTUP_DONE; + }; - debug_toggle 0; + debug_toggle 0; - delete $SIG{__DIE__}; - EV::loop; + delete $SIG{__DIE__}; + EV::loop; - DC::write_cfg if $CFG->{config_autosave}; + DC::save_cfg if $CFG->{config_autosave}; - #video_shutdown; - #audio_shutdown; + #video_shutdown; + #audio_shutdown; - DC::OpenGL::quit; - DC::SDL_Quit; - DC::DB::Server::stop; + DC::OpenGL::quit; + DC::SDL_Quit; + DC::DB::Server::stop; + }; } -*DC::Main::run = \&DC::SDL_braino; # see sub above - 1