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.9 by root, Thu Jan 5 05:37:02 2012 UTC vs.
Revision 1.20 by root, Thu Apr 5 04:38:43 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;
196 AnyEvent::Util::fh_nonblocking $fh, 1; 198 AnyEvent::Util::fh_nonblocking $fh, 1;
197 199
198 $msg =~ s/\s+$//; 200 $msg =~ s/\s+$//;
199 201
200 # backtrace as second step, in case it crashes, too 202 # backtrace as second step, in case it crashes, too
201 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" 203 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated"
202 if $backtrace; 204 if $backtrace;
203}; 205};
204 206
205sub clienterror($;$) { 207sub clienterror($;$) {
206 my ($msg, $backtrace) = @_; 208 my ($msg, $backtrace) = @_;
208 warn $msg; 210 warn $msg;
209 211
210 return unless $CONN; 212 return unless $CONN;
211 213
212 $CONN->send_exti_msg (clientlog => $msg); 214 $CONN->send_exti_msg (clientlog => $msg);
213 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; 215 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace;
214} 216}
215 217
216############################################################################# 218#############################################################################
217 219
218sub status { 220sub status {
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;
591 binmode $fh; # ugh :(
605 $f_md5->addfile ($fh); 592 $f_md5->addfile ($fh);
606 $f_md5 = $f_md5->hexdigest; 593 $f_md5 = $f_md5->hexdigest;
607 $error ||= $md5 ne $f_md5; 594 $error ||= $md5 ne $f_md5;
608 } 595 }
609 } 596 }
964 mapw => $mapw, 951 mapw => $mapw,
965 maph => $maph, 952 maph => $maph,
966 953
967 c_version => { 954 c_version => {
968 client => "deliantra", 955 client => "deliantra",
969 clientver => $DC::VERSION, 956 clientver => "$DC::VERSION$Urlader::EXE_VER",
970 gl_vendor => DC::OpenGL::gl_vendor, 957 gl_vendor => DC::OpenGL::gl_vendor,
971 gl_version => DC::OpenGL::gl_version, 958 gl_version => DC::OpenGL::gl_version,
972 }, 959 },
973 960
974 map_widget => $MAPWIDGET, 961 map_widget => $MAPWIDGET,
2028 $table->add_at (2, $row++, new DC::UI::Button 2015 $table->add_at (2, $row++, new DC::UI::Button
2029 text => "Save Now", 2016 text => "Save Now",
2030 tooltip => "Use this to manually save configuration and UI layout when " 2017 tooltip => "Use this to manually save configuration and UI layout when "
2031 . "autosave is disabled.", 2018 . "autosave is disabled.",
2032 on_activate => sub { 2019 on_activate => sub {
2033 DC::write_cfg; 2020 DC::save_cfg;
2034 0 2021 0
2035 } 2022 }
2036 ); 2023 );
2037 } 2024 }
2038 2025
2697 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2684 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2698 2685
2699 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2686 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2700 $FULLSCREEN = $CFG->{fullscreen}; 2687 $FULLSCREEN = $CFG->{fullscreen};
2701 $FAST = $CFG->{fast}; 2688 $FAST = $CFG->{fast};
2689
2690 DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init
2702 2691
2703 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error 2692 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error
2704 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2693 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2705 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2694 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2706 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2695 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2964 EV::unloop; 2953 EV::unloop;
2965 #d# TODO calling exit here hangs the process in some futex 2954 #d# TODO calling exit here hangs the process in some futex
2966}; 2955};
2967 2956
2968# due to mac os x + sdl combined braindamage, we need this contortion 2957# due to mac os x + sdl combined braindamage, we need this contortion
2969sub DC::Main::main { 2958sub DC::Main::run {
2970 { 2959 DC::SDL_main_hack {
2960 {
2971 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2961 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2972 2962
2973 if (-e "$Deliantra::VARDIR/client.cf") { 2963 DC::load_cfg;
2974 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2964 DC::upgrade_cfg;
2975 } else {
2976 #TODO: compatibility cruft
2977 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2978 print STDERR "INFO: used old configuration file\n";
2979 }
2980 2965
2966 DC::Audio::probe;
2967
2981 DC::DB::Server::run; 2968 DC::DB::Server::run;
2982 2969
2983 if ($CFG->{db_schema} < 1) { 2970 if ($CFG->{db_schema} < 1) {
2984 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 2971 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2985 DC::DB::nuke_db; 2972 DC::DB::nuke_db;
2986 $CFG->{db_schema} = 1; 2973 $CFG->{db_schema} = 1;
2987 DC::write_cfg; 2974 DC::save_cfg;
2988 }
2989
2990 DC::DB::open_db;
2991
2992 DC::UI::set_layout ($::CFG->{layout});
2993
2994 my %DEF_CFG = (
2995 config_autosave => 1,
2996 sdl_mode => undef,
2997 fullscreen => 1,
2998 fast => 0,
2999 force_opengl11 => undef,
3000 disable_alpha => 0,
3001 smooth_movement => 1,
3002 smooth_transitions => 1,
3003 texture_compression => 1,
3004 map_scale => 1,
3005 fow_enable => 1,
3006 fow_intensity => 0,
3007 fow_texture => 0,
3008 map_smoothing => 1,
3009 gui_fontsize => 1,
3010 log_fontsize => 0.7,
3011 gauge_fontsize => 1,
3012 gauge_size => 0.35,
3013 stat_fontsize => 0.7,
3014 mapsize => 100,
3015 audio_enable => 1,
3016 audio_hw_channels => 0,
3017 audio_hw_frequency => 0,
3018 audio_hw_chunksize => 0,
3019 audio_mix_channels => 8,
3020 effects_enable => 1,
3021 effects_volume => 1,
3022 bgm_enable => 1,
3023 bgm_volume => 0.5,
3024 output_rate => "",
3025 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
3026 inv_sort => "mtime",
3027 default => "profile", # default profile
3028 show_tips => 1,
3029 logview_max_par => 1000,
3030 shift_fire_stop => 0,
3031 uitheme => "wood",
3032 map_shift_x => -24, # arbitrary
3033 map_shift_y => +24, # arbitrary
3034 );
3035
3036 while (my ($k, $v) = each %DEF_CFG) {
3037 $CFG->{$k} = $v unless exists $CFG->{$k};
3038 }
3039
3040 my @args = @ARGV;
3041
3042 # OS X passes some process serial number of other shit. they
3043 # could have used an env var or any other sane mechanism. but
3044 # would it be os x then? no...
3045 shift @args if $args[0] =~ /^-psn_/;
3046
3047 my $profile = 'default';
3048
3049 for (my $i = 0; $i < @args; $i++) {
3050 if ($args[$i] =~ /^--?profile$/) {
3051 $profile = $args[$i + 1];
3052 splice @args, $i, 2, ();
3053 $i = 0;
3054 } elsif ($args[$i] =~ /^--?h/) {
3055 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3056 exit 0;
3057 } 2975 }
3058 }
3059 2976
3060 $CFG->{profile}{$profile} ||= {}; 2977 DC::DB::open_db;
3061 $PROFILE = $CFG->{profile}{$profile};
3062 $PROFILE->{host} ||= "gameserver.deliantra.net";
3063 2978
3064 $PROFILE->{host} = $args[0] if @args > 0; 2979 DC::UI::set_layout ($::CFG->{layout});
3065 $PROFILE->{user} = $args[1] if @args > 1;
3066 $PROFILE->{password} = $args[2] if @args > 2;
3067 2980
3068 # convert old bindings (only default profile matters) 2981 my @args = @ARGV;
3069 if (my $bindings = delete $PROFILE->{bindings}) { 2982
3070 while (my ($mod, $syms) = each %$bindings) { 2983 # OS X passes some process serial number of other shit. they
3071 while (my ($sym, $cmds) = each %$syms) { 2984 # could have used an env var or any other sane mechanism. but
3072 push @{ $PROFILE->{macro} }, { 2985 # would it be os x then? no...
3073 accelkey => [$mod*1, $sym*1], 2986 shift @args if $args[0] =~ /^-psn_/;
3074 action => $cmds, 2987
2988 my $profile = 'default';
2989
2990 for (my $i = 0; $i < @args; $i++) {
2991 if ($args[$i] =~ /^--?profile$/) {
2992 $profile = $args[$i + 1];
2993 splice @args, $i, 2, ();
3075 }; 2994 $i = 0;
2995 } elsif ($args[$i] =~ /^--?h/) {
2996 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2997 exit 0;
3076 } 2998 }
3077 } 2999 }
3000
3001 $CFG->{profile}{$profile} ||= {};
3002 $PROFILE = $CFG->{profile}{$profile};
3003 $PROFILE->{host} ||= "gameserver.deliantra.net";
3004
3005 $PROFILE->{host} = $args[0] if @args > 0;
3006 $PROFILE->{user} = $args[1] if @args > 1;
3007 $PROFILE->{password} = $args[2] if @args > 2;
3008
3009 # convert old bindings (only default profile matters)
3010 if (my $bindings = delete $PROFILE->{bindings}) {
3011 while (my ($mod, $syms) = each %$bindings) {
3012 while (my ($sym, $cmds) = each %$syms) {
3013 push @{ $PROFILE->{macro} }, {
3014 accelkey => [$mod*1, $sym*1],
3015 action => $cmds,
3016 };
3017 }
3018 }
3078 } 3019 }
3079 3020
3080 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3021 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3081 # these are ignored under windows, for some reason, and thus set in the loader 3022 # these are ignored under windows, for some reason, and thus set in the loader
3082 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3023 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3083 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3024 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3084 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3025 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3085 3026
3086 { 3027 {
3087 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3028 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3088 DejaVuSans.ttf 3029 DejaVuSans.ttf
3089 DejaVuSansMono.ttf 3030 DejaVuSansMono.ttf
3090 DejaVuSans-Bold.ttf 3031 DejaVuSans-Bold.ttf
3091 DejaVuSansMono-Bold.ttf 3032 DejaVuSansMono-Bold.ttf
3092 DejaVuSans-Oblique.ttf 3033 DejaVuSans-Oblique.ttf
3093 DejaVuSansMono-Oblique.ttf 3034 DejaVuSansMono-Oblique.ttf
3094 DejaVuSans-BoldOblique.ttf 3035 DejaVuSans-BoldOblique.ttf
3095 DejaVuSansMono-BoldOblique.ttf 3036 DejaVuSansMono-BoldOblique.ttf
3096 mona.ttf 3037 mona.ttf
3097 ); 3038 );
3098 3039
3099 DC::add_font $_ for @fonts; 3040 DC::add_font $_ for @fonts;
3100 3041
3101 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3042 $FONT_PROP = new_from_file DC::Font $fonts[0];
3102 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3043 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3103 3044
3104 $FONT_PROP->make_default; 3045 $FONT_PROP->make_default;
3105 3046
3106 DC::pango_init; 3047 DC::pango_init;
3107 } 3048 }
3108 3049
3109# compare mono (ft) vs. rgba (cairo) 3050# compare mono (ft) vs. rgba (cairo)
3110# ft - 1.8s, cairo 3s, even in alpha-only mode 3051# ft - 1.8s, cairo 3s, even in alpha-only mode
3111# for my $rgba (0..1) { 3052# for my $rgba (0..1) {
3112# my $t1 = Time::HiRes::time; 3053# my $t1 = Time::HiRes::time;
3117# } 3058# }
3118# my $t2 = Time::HiRes::time; 3059# my $t2 = Time::HiRes::time;
3119# warn $t2-$t1; 3060# warn $t2-$t1;
3120# } 3061# }
3121 3062
3063 }
3064
3065 DC::SDL_Init 0;
3122 DC::IMG_Init; video_init; 3066 DC::IMG_Init; video_init;
3123 DC::Mix_Init; audio_init; 3067 DC::Mix_Init; audio_init;
3124 }
3125 3068
3126 show_tip_of_the_day if $CFG->{show_tips}; 3069 show_tip_of_the_day if $CFG->{show_tips};
3127 3070
3128 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3071 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3129 undef $STARTUP_CANCEL; 3072 undef $STARTUP_CANCEL;
3130 (pop @::STARTUP_DONE)->() 3073 (pop @::STARTUP_DONE)->()
3131 while @::STARTUP_DONE; 3074 while @::STARTUP_DONE;
3075 };
3076
3077 debug_toggle 0;
3078
3079 delete $SIG{__DIE__};
3080 EV::loop;
3081
3082 DC::save_cfg if $CFG->{config_autosave};
3083
3084 #video_shutdown;
3085 #audio_shutdown;
3086
3087 DC::OpenGL::quit;
3088 DC::SDL_Quit;
3089 DC::DB::Server::stop;
3132 }; 3090 };
3133
3134 debug_toggle 0;
3135
3136 delete $SIG{__DIE__};
3137 EV::loop;
3138
3139 DC::write_cfg if $CFG->{config_autosave};
3140
3141 #video_shutdown;
3142 #audio_shutdown;
3143
3144 DC::OpenGL::quit;
3145 DC::SDL_Quit;
3146 DC::DB::Server::stop;
3147} 3091}
3148
3149*DC::Main::run = \&DC::SDL_braino; # see sub above
3150 3092
31511 30931

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines