… | |
… | |
33 | use AnyEvent::Socket (); |
33 | use AnyEvent::Socket (); |
34 | use AnyEvent::DNS (); |
34 | use AnyEvent::DNS (); |
35 | |
35 | |
36 | use Compress::LZF; |
36 | use Compress::LZF; |
37 | use JSON::XS; |
37 | use JSON::XS; |
|
|
38 | use Urlader; |
38 | |
39 | |
39 | use DC; |
40 | use DC; |
40 | |
41 | |
41 | sub crash($;$) { |
42 | sub crash($;$) { |
42 | # nop at compiletime |
43 | # nop at compiletime |
… | |
… | |
44 | |
45 | |
45 | BEGIN { |
46 | BEGIN { |
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 | |
61 | use DC::OpenGL (); |
62 | use DC::OpenGL (); |
62 | use DC::Audio; |
63 | use DC::Audio (); |
63 | use DC::Protocol; |
64 | use DC::Protocol; |
64 | use DC::DB; |
65 | use DC::DB; |
65 | use DC::UI; |
66 | use DC::UI; |
66 | use DC::UI::Canvas; |
67 | use DC::UI::Canvas; |
67 | use DC::UI::Inventory; |
68 | use DC::UI::Inventory; |
… | |
… | |
688 | ::message { markup => "Server has no newer version." }; |
689 | ::message { markup => "Server has no newer version." }; |
689 | } |
690 | } |
690 | } else { |
691 | } else { |
691 | ::message { markup => "Server does not support software update." }; |
692 | ::message { markup => "Server does not support software update." }; |
692 | } |
693 | } |
693 | |
|
|
694 | # $self->register_face_handler ($exp_table, sub { |
|
|
695 | # my ($face) = @_; |
|
|
696 | |
|
|
697 | # $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
698 | # $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
699 | # }); |
|
|
700 | |
694 | |
701 | () |
695 | () |
702 | }); |
696 | }); |
703 | } |
697 | } |
704 | |
698 | |
… | |
… | |
2014 | $table->add_at (2, $row++, new DC::UI::Button |
2008 | $table->add_at (2, $row++, new DC::UI::Button |
2015 | text => "Save Now", |
2009 | text => "Save Now", |
2016 | tooltip => "Use this to manually save configuration and UI layout when " |
2010 | tooltip => "Use this to manually save configuration and UI layout when " |
2017 | . "autosave is disabled.", |
2011 | . "autosave is disabled.", |
2018 | on_activate => sub { |
2012 | on_activate => sub { |
2019 | DC::write_cfg; |
2013 | DC::save_cfg; |
2020 | 0 |
2014 | 0 |
2021 | } |
2015 | } |
2022 | ); |
2016 | ); |
2023 | } |
2017 | } |
2024 | |
2018 | |
… | |
… | |
2660 | DC::set_theme $CFG->{uitheme}; |
2654 | DC::set_theme $CFG->{uitheme}; |
2661 | |
2655 | |
2662 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2656 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2663 | $SDL_REINIT = 0; |
2657 | $SDL_REINIT = 0; |
2664 | |
2658 | |
2665 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2659 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2; |
2666 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2660 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2667 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2661 | @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)"; |
2662 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2669 | |
2663 | |
2670 | @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; |
… | |
… | |
2952 | EV::unloop; |
2946 | EV::unloop; |
2953 | #d# TODO calling exit here hangs the process in some futex |
2947 | #d# TODO calling exit here hangs the process in some futex |
2954 | }; |
2948 | }; |
2955 | |
2949 | |
2956 | # 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 |
2957 | sub DC::Main::main { |
2951 | sub DC::Main::run { |
2958 | { |
2952 | DC::SDL_main_hack { |
|
|
2953 | { |
2959 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
2954 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
2960 | |
2955 | |
2961 | if (-e "$Deliantra::VARDIR/client.cf") { |
2956 | DC::load_cfg; |
2962 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
2957 | 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 | |
2958 | |
|
|
2959 | DC::Audio::probe; |
|
|
2960 | |
2969 | DC::DB::Server::run; |
2961 | DC::DB::Server::run; |
2970 | |
2962 | |
2971 | if ($CFG->{db_schema} < 1) { |
2963 | if ($CFG->{db_schema} < 1) { |
2972 | 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"; |
2973 | DC::DB::nuke_db; |
2965 | DC::DB::nuke_db; |
2974 | $CFG->{db_schema} = 1; |
2966 | $CFG->{db_schema} = 1; |
2975 | DC::write_cfg; |
2967 | 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 | } |
2968 | } |
3002 | } |
|
|
3003 | |
2969 | |
3004 | $CFG->{profile}{$profile} ||= {}; |
2970 | DC::DB::open_db; |
3005 | $PROFILE = $CFG->{profile}{$profile}; |
|
|
3006 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
|
|
3007 | |
2971 | |
3008 | $PROFILE->{host} = $args[0] if @args > 0; |
2972 | DC::UI::set_layout ($::CFG->{layout}); |
3009 | $PROFILE->{user} = $args[1] if @args > 1; |
|
|
3010 | $PROFILE->{password} = $args[2] if @args > 2; |
|
|
3011 | |
2973 | |
3012 | # convert old bindings (only default profile matters) |
2974 | my @args = @ARGV; |
3013 | if (my $bindings = delete $PROFILE->{bindings}) { |
2975 | |
3014 | while (my ($mod, $syms) = each %$bindings) { |
2976 | # OS X passes some process serial number of other shit. they |
3015 | while (my ($sym, $cmds) = each %$syms) { |
2977 | # could have used an env var or any other sane mechanism. but |
3016 | push @{ $PROFILE->{macro} }, { |
2978 | # would it be os x then? no... |
3017 | accelkey => [$mod*1, $sym*1], |
2979 | shift @args if $args[0] =~ /^-psn_/; |
3018 | 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, (); |
3019 | }; |
2987 | $i = 0; |
|
|
2988 | } elsif ($args[$i] =~ /^--?h/) { |
|
|
2989 | print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; |
|
|
2990 | exit 0; |
3020 | } |
2991 | } |
3021 | } |
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 | } |
3022 | } |
3012 | } |
3023 | |
3013 | |
3024 | # 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 |
3025 | # 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 |
3026 | $ENV{FONTCONFIG_FILE} = "fonts.conf"; |
3016 | $ENV{FONTCONFIG_FILE} = "fonts.conf"; |
3027 | $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; |
3017 | $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; |
3028 | $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions |
3018 | $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions |
3029 | |
3019 | |
3030 | { |
3020 | { |
3031 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
3021 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
3032 | DejaVuSans.ttf |
3022 | DejaVuSans.ttf |
3033 | DejaVuSansMono.ttf |
3023 | DejaVuSansMono.ttf |
3034 | DejaVuSans-Bold.ttf |
3024 | DejaVuSans-Bold.ttf |
3035 | DejaVuSansMono-Bold.ttf |
3025 | DejaVuSansMono-Bold.ttf |
3036 | DejaVuSans-Oblique.ttf |
3026 | DejaVuSans-Oblique.ttf |
3037 | DejaVuSansMono-Oblique.ttf |
3027 | DejaVuSansMono-Oblique.ttf |
3038 | DejaVuSans-BoldOblique.ttf |
3028 | DejaVuSans-BoldOblique.ttf |
3039 | DejaVuSansMono-BoldOblique.ttf |
3029 | DejaVuSansMono-BoldOblique.ttf |
3040 | mona.ttf |
3030 | mona.ttf |
3041 | ); |
3031 | ); |
3042 | |
3032 | |
3043 | DC::add_font $_ for @fonts; |
3033 | DC::add_font $_ for @fonts; |
3044 | |
3034 | |
3045 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
3035 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
3046 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
3036 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
3047 | |
3037 | |
3048 | $FONT_PROP->make_default; |
3038 | $FONT_PROP->make_default; |
3049 | |
3039 | |
3050 | DC::pango_init; |
3040 | DC::pango_init; |
3051 | } |
3041 | } |
3052 | |
3042 | |
3053 | # compare mono (ft) vs. rgba (cairo) |
3043 | # compare mono (ft) vs. rgba (cairo) |
3054 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
3044 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
3055 | # for my $rgba (0..1) { |
3045 | # for my $rgba (0..1) { |
3056 | # my $t1 = Time::HiRes::time; |
3046 | # my $t1 = Time::HiRes::time; |
… | |
… | |
3061 | # } |
3051 | # } |
3062 | # my $t2 = Time::HiRes::time; |
3052 | # my $t2 = Time::HiRes::time; |
3063 | # warn $t2-$t1; |
3053 | # warn $t2-$t1; |
3064 | # } |
3054 | # } |
3065 | |
3055 | |
|
|
3056 | } |
|
|
3057 | |
|
|
3058 | DC::SDL_Init 0; |
3066 | DC::IMG_Init; video_init; |
3059 | DC::IMG_Init; video_init; |
3067 | DC::Mix_Init; audio_init; |
3060 | DC::Mix_Init; audio_init; |
3068 | } |
|
|
3069 | |
3061 | |
3070 | show_tip_of_the_day if $CFG->{show_tips}; |
3062 | show_tip_of_the_day if $CFG->{show_tips}; |
3071 | |
3063 | |
3072 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
3064 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
3073 | undef $STARTUP_CANCEL; |
3065 | undef $STARTUP_CANCEL; |
3074 | (pop @::STARTUP_DONE)->() |
3066 | (pop @::STARTUP_DONE)->() |
3075 | 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; |
3076 | }; |
3083 | }; |
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 | } |
3084 | } |
3092 | |
|
|
3093 | *DC::Main::run = \&DC::SDL_braino; # see sub above |
|
|
3094 | |
3085 | |
3095 | 1 |
3086 | 1 |