ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Main.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Main.pm (file contents):
Revision 1.11 by root, Sat Jan 7 15:24:41 2012 UTC vs.
Revision 1.18 by root, Wed Jan 18 15:31:51 2012 UTC

57 DC::fatal Carp::longmess "$_[0]"; 57 DC::fatal Carp::longmess "$_[0]";
58 } 58 }
59} 59}
60 60
61use DC::OpenGL (); 61use DC::OpenGL ();
62use DC::Audio ();
62use DC::Protocol; 63use DC::Protocol;
63use DC::DB; 64use DC::DB;
64use DC::UI; 65use DC::UI;
65use DC::UI::Canvas; 66use DC::UI::Canvas;
66use DC::UI::Inventory; 67use DC::UI::Inventory;
473 audio_music_push; 474 audio_music_push;
474} 475}
475 476
476sub audio_init { 477sub audio_init {
477 if ($CFG->{audio_enable}) { 478 if ($CFG->{audio_enable}) {
478 if (length $CFG->{audio_driver}) { 479 DC::Audio::init $CFG->{audio_driver};
479 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
480 DC::SDL_Init DC::SDL_INIT_AUDIO
481 and die "SDL::Init failed!\n";
482 } else {
483 DC::SDL_Init DC::SDL_INIT_AUDIO
484 and die "SDL::Init failed!\n";
485 }
486
487 $ENV{MIX_EFFECTSMAXSPEED} = 1;
488 $SDL_MIXER = !DC::Mix_OpenAudio
489 $CFG->{audio_hw_frequency},
490 DC::MIX_DEFAULT_FORMAT,
491 $CFG->{audio_hw_channels},
492 $CFG->{audio_hw_chunksize};
493 480
494 if ($SDL_MIXER) { 481 if ($SDL_MIXER) {
495 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
496
497 audio_music_finished; 482 audio_music_finished;
498 } else { 483 } else {
499 status "Unable to open sound device: there will be no sound"; 484 status "Unable to open sound device: there will be no sound";
500 } 485 }
501 } else { 486 } else {
597 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0; 582 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0;
598 583
599 if ($fh) { 584 if ($fh) {
600 $error ||= Coro::AIO::aio_stat "$override.tmp"; 585 $error ||= Coro::AIO::aio_stat "$override.tmp";
601 $error ||= -s _ != $size; 586 $error ||= -s _ != $size;
602 $error ||= Coro::AIO::aio_readahead $fh, 0, $size; 587 Coro::AIO::aio_readahead $fh, 0, $size;
603 588
604 my $f_md5 = new Digest::MD5; 589 my $f_md5 = new Digest::MD5;
590 binmode $fh; # ugh :(
605 $f_md5->addfile ($fh); 591 $f_md5->addfile ($fh);
606 $f_md5 = $f_md5->hexdigest; 592 $f_md5 = $f_md5->hexdigest;
607 $error ||= $md5 ne $f_md5; 593 $error ||= $md5 ne $f_md5;
608 } 594 }
609 } 595 }
2028 $table->add_at (2, $row++, new DC::UI::Button 2014 $table->add_at (2, $row++, new DC::UI::Button
2029 text => "Save Now", 2015 text => "Save Now",
2030 tooltip => "Use this to manually save configuration and UI layout when " 2016 tooltip => "Use this to manually save configuration and UI layout when "
2031 . "autosave is disabled.", 2017 . "autosave is disabled.",
2032 on_activate => sub { 2018 on_activate => sub {
2033 DC::write_cfg; 2019 DC::save_cfg;
2034 0 2020 0
2035 } 2021 }
2036 ); 2022 );
2037 } 2023 }
2038 2024
2966 EV::unloop; 2952 EV::unloop;
2967 #d# TODO calling exit here hangs the process in some futex 2953 #d# TODO calling exit here hangs the process in some futex
2968}; 2954};
2969 2955
2970# due to mac os x + sdl combined braindamage, we need this contortion 2956# due to mac os x + sdl combined braindamage, we need this contortion
2971sub DC::Main::main { 2957sub DC::Main::run {
2972 { 2958 DC::SDL_main_hack {
2959 {
2973 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2960 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2974 2961
2975 if (-e "$Deliantra::VARDIR/client.cf") { 2962 DC::load_cfg;
2976 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2963 DC::upgrade_cfg;
2977 } else {
2978 #TODO: compatibility cruft
2979 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2980 print STDERR "INFO: used old configuration file\n";
2981 }
2982 2964
2965 DC::Audio::probe;
2966
2983 DC::DB::Server::run; 2967 DC::DB::Server::run;
2984 2968
2985 if ($CFG->{db_schema} < 1) { 2969 if ($CFG->{db_schema} < 1) {
2986 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 2970 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2987 DC::DB::nuke_db; 2971 DC::DB::nuke_db;
2988 $CFG->{db_schema} = 1; 2972 $CFG->{db_schema} = 1;
2989 DC::write_cfg; 2973 DC::save_cfg;
2990 }
2991
2992 DC::DB::open_db;
2993
2994 DC::UI::set_layout ($::CFG->{layout});
2995
2996 my %DEF_CFG = (
2997 config_autosave => 1,
2998 sdl_mode => undef,
2999 fullscreen => 1,
3000 fast => 0,
3001 force_opengl11 => undef,
3002 disable_alpha => 0,
3003 smooth_movement => 1,
3004 smooth_transitions => 1,
3005 texture_compression => 1,
3006 map_scale => 1,
3007 fow_enable => 1,
3008 fow_intensity => 0,
3009 fow_texture => 0,
3010 map_smoothing => 1,
3011 gui_fontsize => 1,
3012 log_fontsize => 0.7,
3013 gauge_fontsize => 1,
3014 gauge_size => 0.35,
3015 stat_fontsize => 0.7,
3016 mapsize => 100,
3017 audio_enable => 1,
3018 audio_hw_channels => 0,
3019 audio_hw_frequency => 0,
3020 audio_hw_chunksize => 0,
3021 audio_mix_channels => 8,
3022 effects_enable => 1,
3023 effects_volume => 1,
3024 bgm_enable => 1,
3025 bgm_volume => 0.5,
3026 output_rate => "",
3027 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
3028 inv_sort => "mtime",
3029 default => "profile", # default profile
3030 show_tips => 1,
3031 logview_max_par => 1000,
3032 shift_fire_stop => 0,
3033 uitheme => "wood",
3034 map_shift_x => -24, # arbitrary
3035 map_shift_y => +24, # arbitrary
3036 );
3037
3038 while (my ($k, $v) = each %DEF_CFG) {
3039 $CFG->{$k} = $v unless exists $CFG->{$k};
3040 }
3041
3042 my @args = @ARGV;
3043
3044 # OS X passes some process serial number of other shit. they
3045 # could have used an env var or any other sane mechanism. but
3046 # would it be os x then? no...
3047 shift @args if $args[0] =~ /^-psn_/;
3048
3049 my $profile = 'default';
3050
3051 for (my $i = 0; $i < @args; $i++) {
3052 if ($args[$i] =~ /^--?profile$/) {
3053 $profile = $args[$i + 1];
3054 splice @args, $i, 2, ();
3055 $i = 0;
3056 } elsif ($args[$i] =~ /^--?h/) {
3057 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3058 exit 0;
3059 } 2974 }
3060 }
3061 2975
3062 $CFG->{profile}{$profile} ||= {}; 2976 DC::DB::open_db;
3063 $PROFILE = $CFG->{profile}{$profile};
3064 $PROFILE->{host} ||= "gameserver.deliantra.net";
3065 2977
3066 $PROFILE->{host} = $args[0] if @args > 0; 2978 DC::UI::set_layout ($::CFG->{layout});
3067 $PROFILE->{user} = $args[1] if @args > 1;
3068 $PROFILE->{password} = $args[2] if @args > 2;
3069 2979
3070 # convert old bindings (only default profile matters) 2980 my @args = @ARGV;
3071 if (my $bindings = delete $PROFILE->{bindings}) { 2981
3072 while (my ($mod, $syms) = each %$bindings) { 2982 # OS X passes some process serial number of other shit. they
3073 while (my ($sym, $cmds) = each %$syms) { 2983 # could have used an env var or any other sane mechanism. but
3074 push @{ $PROFILE->{macro} }, { 2984 # would it be os x then? no...
3075 accelkey => [$mod*1, $sym*1], 2985 shift @args if $args[0] =~ /^-psn_/;
3076 action => $cmds, 2986
2987 my $profile = 'default';
2988
2989 for (my $i = 0; $i < @args; $i++) {
2990 if ($args[$i] =~ /^--?profile$/) {
2991 $profile = $args[$i + 1];
2992 splice @args, $i, 2, ();
3077 }; 2993 $i = 0;
2994 } elsif ($args[$i] =~ /^--?h/) {
2995 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2996 exit 0;
3078 } 2997 }
3079 } 2998 }
2999
3000 $CFG->{profile}{$profile} ||= {};
3001 $PROFILE = $CFG->{profile}{$profile};
3002 $PROFILE->{host} ||= "gameserver.deliantra.net";
3003
3004 $PROFILE->{host} = $args[0] if @args > 0;
3005 $PROFILE->{user} = $args[1] if @args > 1;
3006 $PROFILE->{password} = $args[2] if @args > 2;
3007
3008 # convert old bindings (only default profile matters)
3009 if (my $bindings = delete $PROFILE->{bindings}) {
3010 while (my ($mod, $syms) = each %$bindings) {
3011 while (my ($sym, $cmds) = each %$syms) {
3012 push @{ $PROFILE->{macro} }, {
3013 accelkey => [$mod*1, $sym*1],
3014 action => $cmds,
3015 };
3016 }
3017 }
3080 } 3018 }
3081 3019
3082 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3020 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3083 # these are ignored under windows, for some reason, and thus set in the loader 3021 # these are ignored under windows, for some reason, and thus set in the loader
3084 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3022 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3085 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3023 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3086 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3024 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3087 3025
3088 { 3026 {
3089 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3027 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3090 DejaVuSans.ttf 3028 DejaVuSans.ttf
3091 DejaVuSansMono.ttf 3029 DejaVuSansMono.ttf
3092 DejaVuSans-Bold.ttf 3030 DejaVuSans-Bold.ttf
3093 DejaVuSansMono-Bold.ttf 3031 DejaVuSansMono-Bold.ttf
3094 DejaVuSans-Oblique.ttf 3032 DejaVuSans-Oblique.ttf
3095 DejaVuSansMono-Oblique.ttf 3033 DejaVuSansMono-Oblique.ttf
3096 DejaVuSans-BoldOblique.ttf 3034 DejaVuSans-BoldOblique.ttf
3097 DejaVuSansMono-BoldOblique.ttf 3035 DejaVuSansMono-BoldOblique.ttf
3098 mona.ttf 3036 mona.ttf
3099 ); 3037 );
3100 3038
3101 DC::add_font $_ for @fonts; 3039 DC::add_font $_ for @fonts;
3102 3040
3103 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3041 $FONT_PROP = new_from_file DC::Font $fonts[0];
3104 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3042 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3105 3043
3106 $FONT_PROP->make_default; 3044 $FONT_PROP->make_default;
3107 3045
3108 DC::pango_init; 3046 DC::pango_init;
3109 } 3047 }
3110 3048
3111# compare mono (ft) vs. rgba (cairo) 3049# compare mono (ft) vs. rgba (cairo)
3112# ft - 1.8s, cairo 3s, even in alpha-only mode 3050# ft - 1.8s, cairo 3s, even in alpha-only mode
3113# for my $rgba (0..1) { 3051# for my $rgba (0..1) {
3114# my $t1 = Time::HiRes::time; 3052# my $t1 = Time::HiRes::time;
3119# } 3057# }
3120# my $t2 = Time::HiRes::time; 3058# my $t2 = Time::HiRes::time;
3121# warn $t2-$t1; 3059# warn $t2-$t1;
3122# } 3060# }
3123 3061
3062 }
3063
3064 DC::SDL_Init 0;
3124 DC::IMG_Init; video_init; 3065 DC::IMG_Init; video_init;
3125 DC::Mix_Init; audio_init; 3066 DC::Mix_Init; audio_init;
3126 }
3127 3067
3128 show_tip_of_the_day if $CFG->{show_tips}; 3068 show_tip_of_the_day if $CFG->{show_tips};
3129 3069
3130 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3070 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3131 undef $STARTUP_CANCEL; 3071 undef $STARTUP_CANCEL;
3132 (pop @::STARTUP_DONE)->() 3072 (pop @::STARTUP_DONE)->()
3133 while @::STARTUP_DONE; 3073 while @::STARTUP_DONE;
3074 };
3075
3076 debug_toggle 0;
3077
3078 delete $SIG{__DIE__};
3079 EV::loop;
3080
3081 DC::save_cfg if $CFG->{config_autosave};
3082
3083 #video_shutdown;
3084 #audio_shutdown;
3085
3086 DC::OpenGL::quit;
3087 DC::SDL_Quit;
3088 DC::DB::Server::stop;
3134 }; 3089 };
3135
3136 debug_toggle 0;
3137
3138 delete $SIG{__DIE__};
3139 EV::loop;
3140
3141 DC::write_cfg if $CFG->{config_autosave};
3142
3143 #video_shutdown;
3144 #audio_shutdown;
3145
3146 DC::OpenGL::quit;
3147 DC::SDL_Quit;
3148 DC::DB::Server::stop;
3149} 3090}
3150
3151*DC::Main::run = \&DC::SDL_braino; # see sub above
3152 3091
31531 30921

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines