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.12 by root, Sat Jan 7 19:29:58 2012 UTC vs.
Revision 1.22 by root, Sun Nov 4 02:13:53 2012 UTC

33use AnyEvent::Socket (); 33use AnyEvent::Socket ();
34use AnyEvent::DNS (); 34use AnyEvent::DNS ();
35 35
36use Compress::LZF; 36use Compress::LZF;
37use JSON::XS; 37use JSON::XS;
38use Urlader;
38 39
39use DC; 40use DC;
40 41
41sub crash($;$) { 42sub crash($;$) {
42 # nop at compiletime 43 # nop at compiletime
44 45
45BEGIN { 46BEGIN {
46 $SIG{__DIE__} = sub { 47 $SIG{__DIE__} = sub {
47 return if $^S; # quick reject 48 return if $^S; # quick reject
48 49
49 # return if there are any eval contexts in the csall stack 50 # return if there are any eval contexts in the call stack
50 for my $i (0..999) { 51 for my $i (0..999) {
51 my ($sub, $is_require) = (caller $i)[3, 7] 52 my ($sub, $is_require) = (caller $i)[3, 7]
52 or last; 53 or last;
53 return if $sub eq "(eval)" && !$is_require; 54 return if $sub eq "(eval)" && !$is_require;
54 } 55 }
57 DC::fatal Carp::longmess "$_[0]"; 58 DC::fatal Carp::longmess "$_[0]";
58 } 59 }
59} 60}
60 61
61use DC::OpenGL (); 62use DC::OpenGL ();
63use DC::Audio ();
62use DC::Protocol; 64use DC::Protocol;
63use DC::DB; 65use DC::DB;
64use DC::UI; 66use DC::UI;
65use DC::UI::Canvas; 67use DC::UI::Canvas;
66use DC::UI::Inventory; 68use DC::UI::Inventory;
473 audio_music_push; 475 audio_music_push;
474} 476}
475 477
476sub audio_init { 478sub audio_init {
477 if ($CFG->{audio_enable}) { 479 if ($CFG->{audio_enable}) {
478 if (length $CFG->{audio_driver}) { 480 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 481
494 if ($SDL_MIXER) { 482 if ($SDL_MIXER) {
495 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
496
497 audio_music_finished; 483 audio_music_finished;
498 } else { 484 } else {
499 status "Unable to open sound device: there will be no sound"; 485 status "Unable to open sound device: there will be no sound";
500 } 486 }
501 } else { 487 } else {
597 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0; 583 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0;
598 584
599 if ($fh) { 585 if ($fh) {
600 $error ||= Coro::AIO::aio_stat "$override.tmp"; 586 $error ||= Coro::AIO::aio_stat "$override.tmp";
601 $error ||= -s _ != $size; 587 $error ||= -s _ != $size;
602 $error ||= Coro::AIO::aio_readahead $fh, 0, $size; 588 Coro::AIO::aio_readahead $fh, 0, $size;
603 589
604 my $f_md5 = new Digest::MD5; 590 my $f_md5 = new Digest::MD5;
605 binmode $f_md5; # ugh :( 591 binmode $fh; # ugh :(
606 $f_md5->addfile ($fh); 592 $f_md5->addfile ($fh);
607 $f_md5 = $f_md5->hexdigest; 593 $f_md5 = $f_md5->hexdigest;
608 $error ||= $md5 ne $f_md5; 594 $error ||= $md5 ne $f_md5;
609 } 595 }
610 } 596 }
703 ::message { markup => "Server has no newer version." }; 689 ::message { markup => "Server has no newer version." };
704 } 690 }
705 } else { 691 } else {
706 ::message { markup => "Server does not support software update." }; 692 ::message { markup => "Server does not support software update." };
707 } 693 }
708
709# $self->register_face_handler ($exp_table, sub {
710# my ($face) = @_;
711
712# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
713# $_->() for values %{ $self->{on_exp_update} || {} };
714# });
715 694
716 () 695 ()
717 }); 696 });
718} 697}
719 698
2029 $table->add_at (2, $row++, new DC::UI::Button 2008 $table->add_at (2, $row++, new DC::UI::Button
2030 text => "Save Now", 2009 text => "Save Now",
2031 tooltip => "Use this to manually save configuration and UI layout when " 2010 tooltip => "Use this to manually save configuration and UI layout when "
2032 . "autosave is disabled.", 2011 . "autosave is disabled.",
2033 on_activate => sub { 2012 on_activate => sub {
2034 DC::write_cfg; 2013 DC::save_cfg;
2035 0 2014 0
2036 } 2015 }
2037 ); 2016 );
2038 } 2017 }
2039 2018
2675 DC::set_theme $CFG->{uitheme}; 2654 DC::set_theme $CFG->{uitheme};
2676 2655
2677 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2656 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2678 $SDL_REINIT = 0; 2657 $SDL_REINIT = 0;
2679 2658
2680 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2659 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2681 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2660 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2682 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2661 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2683 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 2662 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2684 2663
2685 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; 2664 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2967 EV::unloop; 2946 EV::unloop;
2968 #d# TODO calling exit here hangs the process in some futex 2947 #d# TODO calling exit here hangs the process in some futex
2969}; 2948};
2970 2949
2971# due to mac os x + sdl combined braindamage, we need this contortion 2950# due to mac os x + sdl combined braindamage, we need this contortion
2972sub DC::Main::main { 2951sub DC::Main::run {
2973 { 2952 DC::SDL_main_hack {
2953 {
2974 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2954 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2975 2955
2976 if (-e "$Deliantra::VARDIR/client.cf") { 2956 DC::load_cfg;
2977 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2957 DC::upgrade_cfg;
2978 } else {
2979 #TODO: compatibility cruft
2980 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2981 print STDERR "INFO: used old configuration file\n";
2982 }
2983 2958
2959 DC::Audio::probe;
2960
2984 DC::DB::Server::run; 2961 DC::DB::Server::run;
2985 2962
2986 if ($CFG->{db_schema} < 1) { 2963 if ($CFG->{db_schema} < 1) {
2987 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 2964 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2988 DC::DB::nuke_db; 2965 DC::DB::nuke_db;
2989 $CFG->{db_schema} = 1; 2966 $CFG->{db_schema} = 1;
2990 DC::write_cfg; 2967 DC::save_cfg;
2991 }
2992
2993 DC::DB::open_db;
2994
2995 DC::UI::set_layout ($::CFG->{layout});
2996
2997 my %DEF_CFG = (
2998 config_autosave => 1,
2999 sdl_mode => undef,
3000 fullscreen => 1,
3001 fast => 0,
3002 force_opengl11 => undef,
3003 disable_alpha => 0,
3004 smooth_movement => 1,
3005 smooth_transitions => 1,
3006 texture_compression => 1,
3007 map_scale => 1,
3008 fow_enable => 1,
3009 fow_intensity => 0,
3010 fow_texture => 0,
3011 map_smoothing => 1,
3012 gui_fontsize => 1,
3013 log_fontsize => 0.7,
3014 gauge_fontsize => 1,
3015 gauge_size => 0.35,
3016 stat_fontsize => 0.7,
3017 mapsize => 100,
3018 audio_enable => 1,
3019 audio_hw_channels => 0,
3020 audio_hw_frequency => 0,
3021 audio_hw_chunksize => 0,
3022 audio_mix_channels => 8,
3023 effects_enable => 1,
3024 effects_volume => 1,
3025 bgm_enable => 1,
3026 bgm_volume => 0.5,
3027 output_rate => "",
3028 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
3029 inv_sort => "mtime",
3030 default => "profile", # default profile
3031 show_tips => 1,
3032 logview_max_par => 1000,
3033 shift_fire_stop => 0,
3034 uitheme => "wood",
3035 map_shift_x => -24, # arbitrary
3036 map_shift_y => +24, # arbitrary
3037 );
3038
3039 while (my ($k, $v) = each %DEF_CFG) {
3040 $CFG->{$k} = $v unless exists $CFG->{$k};
3041 }
3042
3043 my @args = @ARGV;
3044
3045 # OS X passes some process serial number of other shit. they
3046 # could have used an env var or any other sane mechanism. but
3047 # would it be os x then? no...
3048 shift @args if $args[0] =~ /^-psn_/;
3049
3050 my $profile = 'default';
3051
3052 for (my $i = 0; $i < @args; $i++) {
3053 if ($args[$i] =~ /^--?profile$/) {
3054 $profile = $args[$i + 1];
3055 splice @args, $i, 2, ();
3056 $i = 0;
3057 } elsif ($args[$i] =~ /^--?h/) {
3058 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3059 exit 0;
3060 } 2968 }
3061 }
3062 2969
3063 $CFG->{profile}{$profile} ||= {}; 2970 DC::DB::open_db;
3064 $PROFILE = $CFG->{profile}{$profile};
3065 $PROFILE->{host} ||= "gameserver.deliantra.net";
3066 2971
3067 $PROFILE->{host} = $args[0] if @args > 0; 2972 DC::UI::set_layout ($::CFG->{layout});
3068 $PROFILE->{user} = $args[1] if @args > 1;
3069 $PROFILE->{password} = $args[2] if @args > 2;
3070 2973
3071 # convert old bindings (only default profile matters) 2974 my @args = @ARGV;
3072 if (my $bindings = delete $PROFILE->{bindings}) { 2975
3073 while (my ($mod, $syms) = each %$bindings) { 2976 # OS X passes some process serial number of other shit. they
3074 while (my ($sym, $cmds) = each %$syms) { 2977 # could have used an env var or any other sane mechanism. but
3075 push @{ $PROFILE->{macro} }, { 2978 # would it be os x then? no...
3076 accelkey => [$mod*1, $sym*1], 2979 shift @args if $args[0] =~ /^-psn_/;
3077 action => $cmds, 2980
2981 my $profile = 'default';
2982
2983 for (my $i = 0; $i < @args; $i++) {
2984 if ($args[$i] =~ /^--?profile$/) {
2985 $profile = $args[$i + 1];
2986 splice @args, $i, 2, ();
3078 }; 2987 $i = 0;
2988 } elsif ($args[$i] =~ /^--?h/) {
2989 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2990 exit 0;
3079 } 2991 }
3080 } 2992 }
2993
2994 $CFG->{profile}{$profile} ||= {};
2995 $PROFILE = $CFG->{profile}{$profile};
2996 $PROFILE->{host} ||= "gameserver.deliantra.net";
2997
2998 $PROFILE->{host} = $args[0] if @args > 0;
2999 $PROFILE->{user} = $args[1] if @args > 1;
3000 $PROFILE->{password} = $args[2] if @args > 2;
3001
3002 # convert old bindings (only default profile matters)
3003 if (my $bindings = delete $PROFILE->{bindings}) {
3004 while (my ($mod, $syms) = each %$bindings) {
3005 while (my ($sym, $cmds) = each %$syms) {
3006 push @{ $PROFILE->{macro} }, {
3007 accelkey => [$mod*1, $sym*1],
3008 action => $cmds,
3009 };
3010 }
3011 }
3081 } 3012 }
3082 3013
3083 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3014 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3084 # these are ignored under windows, for some reason, and thus set in the loader 3015 # these are ignored under windows, for some reason, and thus set in the loader
3085 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3016 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3086 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3017 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3087 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3018 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3088 3019
3089 { 3020 {
3090 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3021 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3091 DejaVuSans.ttf 3022 DejaVuSans.ttf
3092 DejaVuSansMono.ttf 3023 DejaVuSansMono.ttf
3093 DejaVuSans-Bold.ttf 3024 DejaVuSans-Bold.ttf
3094 DejaVuSansMono-Bold.ttf 3025 DejaVuSansMono-Bold.ttf
3095 DejaVuSans-Oblique.ttf 3026 DejaVuSans-Oblique.ttf
3096 DejaVuSansMono-Oblique.ttf 3027 DejaVuSansMono-Oblique.ttf
3097 DejaVuSans-BoldOblique.ttf 3028 DejaVuSans-BoldOblique.ttf
3098 DejaVuSansMono-BoldOblique.ttf 3029 DejaVuSansMono-BoldOblique.ttf
3099 mona.ttf 3030 mona.ttf
3100 ); 3031 );
3101 3032
3102 DC::add_font $_ for @fonts; 3033 DC::add_font $_ for @fonts;
3103 3034
3104 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3035 $FONT_PROP = new_from_file DC::Font $fonts[0];
3105 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3036 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3106 3037
3107 $FONT_PROP->make_default; 3038 $FONT_PROP->make_default;
3108 3039
3109 DC::pango_init; 3040 DC::pango_init;
3110 } 3041 }
3111 3042
3112# compare mono (ft) vs. rgba (cairo) 3043# compare mono (ft) vs. rgba (cairo)
3113# ft - 1.8s, cairo 3s, even in alpha-only mode 3044# ft - 1.8s, cairo 3s, even in alpha-only mode
3114# for my $rgba (0..1) { 3045# for my $rgba (0..1) {
3115# my $t1 = Time::HiRes::time; 3046# my $t1 = Time::HiRes::time;
3120# } 3051# }
3121# my $t2 = Time::HiRes::time; 3052# my $t2 = Time::HiRes::time;
3122# warn $t2-$t1; 3053# warn $t2-$t1;
3123# } 3054# }
3124 3055
3056 }
3057
3058 DC::SDL_Init 0;
3125 DC::IMG_Init; video_init; 3059 DC::IMG_Init; video_init;
3126 DC::Mix_Init; audio_init; 3060 DC::Mix_Init; audio_init;
3127 }
3128 3061
3129 show_tip_of_the_day if $CFG->{show_tips}; 3062 show_tip_of_the_day if $CFG->{show_tips};
3130 3063
3131 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3064 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3132 undef $STARTUP_CANCEL; 3065 undef $STARTUP_CANCEL;
3133 (pop @::STARTUP_DONE)->() 3066 (pop @::STARTUP_DONE)->()
3134 while @::STARTUP_DONE; 3067 while @::STARTUP_DONE;
3068 };
3069
3070 debug_toggle 0;
3071
3072 delete $SIG{__DIE__};
3073 EV::loop;
3074
3075 DC::save_cfg if $CFG->{config_autosave};
3076
3077 #video_shutdown;
3078 #audio_shutdown;
3079
3080 DC::OpenGL::quit;
3081 DC::SDL_Quit;
3082 DC::DB::Server::stop;
3135 }; 3083 };
3136
3137 debug_toggle 0;
3138
3139 delete $SIG{__DIE__};
3140 EV::loop;
3141
3142 DC::write_cfg if $CFG->{config_autosave};
3143
3144 #video_shutdown;
3145 #audio_shutdown;
3146
3147 DC::OpenGL::quit;
3148 DC::SDL_Quit;
3149 DC::DB::Server::stop;
3150} 3084}
3151
3152*DC::Main::run = \&DC::SDL_braino; # see sub above
3153 3085
31541 30861

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines