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.15 by root, Wed Jan 18 00:51:23 2012 UTC vs.
Revision 1.21 by root, Thu Jun 7 15:40:03 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 ();
62use DC::Audio; 63use DC::Audio ();
63use DC::Protocol; 64use DC::Protocol;
64use DC::DB; 65use DC::DB;
65use DC::UI; 66use DC::UI;
66use DC::UI::Canvas; 67use DC::UI::Canvas;
67use DC::UI::Inventory; 68use DC::UI::Inventory;
2014 $table->add_at (2, $row++, new DC::UI::Button 2015 $table->add_at (2, $row++, new DC::UI::Button
2015 text => "Save Now", 2016 text => "Save Now",
2016 tooltip => "Use this to manually save configuration and UI layout when " 2017 tooltip => "Use this to manually save configuration and UI layout when "
2017 . "autosave is disabled.", 2018 . "autosave is disabled.",
2018 on_activate => sub { 2019 on_activate => sub {
2019 DC::write_cfg; 2020 DC::save_cfg;
2020 0 2021 0
2021 } 2022 }
2022 ); 2023 );
2023 } 2024 }
2024 2025
2660 DC::set_theme $CFG->{uitheme}; 2661 DC::set_theme $CFG->{uitheme};
2661 2662
2662 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2663 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2663 $SDL_REINIT = 0; 2664 $SDL_REINIT = 0;
2664 2665
2665 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2666 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2666 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2667 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2667 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2668 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2668 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 2669 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2669 2670
2670 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; 2671 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2952 EV::unloop; 2953 EV::unloop;
2953 #d# TODO calling exit here hangs the process in some futex 2954 #d# TODO calling exit here hangs the process in some futex
2954}; 2955};
2955 2956
2956# 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
2957sub DC::Main::main { 2958sub DC::Main::run {
2958 { 2959 DC::SDL_main_hack {
2960 {
2959 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2961 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2960 2962
2961 if (-e "$Deliantra::VARDIR/client.cf") { 2963 DC::load_cfg;
2962 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2964 DC::upgrade_cfg;
2963 } else {
2964 #TODO: compatibility cruft
2965 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2966 print STDERR "INFO: used old configuration file\n";
2967 }
2968 2965
2966 DC::Audio::probe;
2967
2969 DC::DB::Server::run; 2968 DC::DB::Server::run;
2970 2969
2971 if ($CFG->{db_schema} < 1) { 2970 if ($CFG->{db_schema} < 1) {
2972 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";
2973 DC::DB::nuke_db; 2972 DC::DB::nuke_db;
2974 $CFG->{db_schema} = 1; 2973 $CFG->{db_schema} = 1;
2975 DC::write_cfg; 2974 DC::save_cfg;
2976 }
2977
2978 DC::upgrade_cfg;
2979
2980 DC::DB::open_db;
2981
2982 DC::UI::set_layout ($::CFG->{layout});
2983
2984 my @args = @ARGV;
2985
2986 # OS X passes some process serial number of other shit. they
2987 # could have used an env var or any other sane mechanism. but
2988 # would it be os x then? no...
2989 shift @args if $args[0] =~ /^-psn_/;
2990
2991 my $profile = 'default';
2992
2993 for (my $i = 0; $i < @args; $i++) {
2994 if ($args[$i] =~ /^--?profile$/) {
2995 $profile = $args[$i + 1];
2996 splice @args, $i, 2, ();
2997 $i = 0;
2998 } elsif ($args[$i] =~ /^--?h/) {
2999 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3000 exit 0;
3001 } 2975 }
3002 }
3003 2976
3004 $CFG->{profile}{$profile} ||= {}; 2977 DC::DB::open_db;
3005 $PROFILE = $CFG->{profile}{$profile};
3006 $PROFILE->{host} ||= "gameserver.deliantra.net";
3007 2978
3008 $PROFILE->{host} = $args[0] if @args > 0; 2979 DC::UI::set_layout ($::CFG->{layout});
3009 $PROFILE->{user} = $args[1] if @args > 1;
3010 $PROFILE->{password} = $args[2] if @args > 2;
3011 2980
3012 # convert old bindings (only default profile matters) 2981 my @args = @ARGV;
3013 if (my $bindings = delete $PROFILE->{bindings}) { 2982
3014 while (my ($mod, $syms) = each %$bindings) { 2983 # OS X passes some process serial number of other shit. they
3015 while (my ($sym, $cmds) = each %$syms) { 2984 # could have used an env var or any other sane mechanism. but
3016 push @{ $PROFILE->{macro} }, { 2985 # would it be os x then? no...
3017 accelkey => [$mod*1, $sym*1], 2986 shift @args if $args[0] =~ /^-psn_/;
3018 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, ();
3019 }; 2994 $i = 0;
2995 } elsif ($args[$i] =~ /^--?h/) {
2996 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2997 exit 0;
3020 } 2998 }
3021 } 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 }
3022 } 3019 }
3023 3020
3024 # 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
3025 # 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
3026 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3023 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3027 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3024 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3028 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3025 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3029 3026
3030 { 3027 {
3031 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3028 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3032 DejaVuSans.ttf 3029 DejaVuSans.ttf
3033 DejaVuSansMono.ttf 3030 DejaVuSansMono.ttf
3034 DejaVuSans-Bold.ttf 3031 DejaVuSans-Bold.ttf
3035 DejaVuSansMono-Bold.ttf 3032 DejaVuSansMono-Bold.ttf
3036 DejaVuSans-Oblique.ttf 3033 DejaVuSans-Oblique.ttf
3037 DejaVuSansMono-Oblique.ttf 3034 DejaVuSansMono-Oblique.ttf
3038 DejaVuSans-BoldOblique.ttf 3035 DejaVuSans-BoldOblique.ttf
3039 DejaVuSansMono-BoldOblique.ttf 3036 DejaVuSansMono-BoldOblique.ttf
3040 mona.ttf 3037 mona.ttf
3041 ); 3038 );
3042 3039
3043 DC::add_font $_ for @fonts; 3040 DC::add_font $_ for @fonts;
3044 3041
3045 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3042 $FONT_PROP = new_from_file DC::Font $fonts[0];
3046 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3043 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3047 3044
3048 $FONT_PROP->make_default; 3045 $FONT_PROP->make_default;
3049 3046
3050 DC::pango_init; 3047 DC::pango_init;
3051 } 3048 }
3052 3049
3053# compare mono (ft) vs. rgba (cairo) 3050# compare mono (ft) vs. rgba (cairo)
3054# ft - 1.8s, cairo 3s, even in alpha-only mode 3051# ft - 1.8s, cairo 3s, even in alpha-only mode
3055# for my $rgba (0..1) { 3052# for my $rgba (0..1) {
3056# my $t1 = Time::HiRes::time; 3053# my $t1 = Time::HiRes::time;
3061# } 3058# }
3062# my $t2 = Time::HiRes::time; 3059# my $t2 = Time::HiRes::time;
3063# warn $t2-$t1; 3060# warn $t2-$t1;
3064# } 3061# }
3065 3062
3063 }
3064
3065 DC::SDL_Init 0;
3066 DC::IMG_Init; video_init; 3066 DC::IMG_Init; video_init;
3067 DC::Mix_Init; audio_init; 3067 DC::Mix_Init; audio_init;
3068 }
3069 3068
3070 show_tip_of_the_day if $CFG->{show_tips}; 3069 show_tip_of_the_day if $CFG->{show_tips};
3071 3070
3072 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3071 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3073 undef $STARTUP_CANCEL; 3072 undef $STARTUP_CANCEL;
3074 (pop @::STARTUP_DONE)->() 3073 (pop @::STARTUP_DONE)->()
3075 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;
3076 }; 3090 };
3077
3078 debug_toggle 0;
3079
3080 delete $SIG{__DIE__};
3081 EV::loop;
3082
3083 DC::write_cfg if $CFG->{config_autosave};
3084
3085 #video_shutdown;
3086 #audio_shutdown;
3087
3088 DC::OpenGL::quit;
3089 DC::SDL_Quit;
3090 DC::DB::Server::stop;
3091} 3091}
3092
3093*DC::Main::run = \&DC::SDL_braino; # see sub above
3094 3092
30951 30931

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines