--- deliantra/Deliantra-Client/DC.pm 2007/05/09 11:46:49 1.144 +++ deliantra/Deliantra-Client/DC.pm 2008/05/05 20:22:03 1.179 @@ -1,10 +1,10 @@ =head1 NAME -CFPlus - undocumented utility garbage for our crossfire client +DC - undocumented utility garbage for our deliantra client =head1 SYNOPSIS - use CFPlus; + use DC; =head1 DESCRIPTION @@ -12,15 +12,15 @@ =cut -package CFPlus; +package DC; use Carp (); BEGIN { - $VERSION = '0.98'; + $VERSION = '0.9971'; use XSLoader; - XSLoader::load "CFPlus", $VERSION; + XSLoader::load "Deliantra::Client", $VERSION; } use utf8; @@ -30,12 +30,7 @@ use File::Path (); use Storable (); # finally use Fcntl (); - -BEGIN { - use Crossfire::Protocol::Base (); - *to_json = \&Crossfire::Protocol::Base::to_json; - *from_json = \&Crossfire::Protocol::Base::from_json; -} +use JSON::XS qw(encode_json decode_json); =item guard { BLOCK } @@ -44,10 +39,10 @@ =cut sub guard(&) { - bless \(my $cb = $_[0]), "CFPlus::Guard" + bless \(my $cb = $_[0]), "DC::Guard" } -sub CFPlus::Guard::DESTROY { +sub DC::Guard::DESTROY { ${$_[0]}->() } @@ -81,7 +76,7 @@ sub background(&;&) { my ($bg, $cb) = @_; - my ($fh_r, $fh_w) = CFPlus::socketpipe; + my ($fh_r, $fh_w) = DC::socketpipe; my $pid = fork; @@ -101,13 +96,13 @@ my $msg = $@; $msg =~ s/\n+/\n/; warn "FATAL: $msg"; - CFPlus::_exit 1; + DC::_exit 1; } # win32 is fucked up, of course. exit will clean stuff up, # which destroys our database etc. _exit will exit ALL # forked processes, because of the dreaded fork emulation. - CFPlus::_exit 0; + DC::_exit 0; } close $fh_w; @@ -129,7 +124,7 @@ $cb->(JSON::XS->new->allow_nonref->decode ($1)); } else { ::message ({ - markup => "background($pid): " . CFPlus::asxml $line, + markup => "background($pid): " . DC::asxml $line, }); } } @@ -145,13 +140,13 @@ print $msg, "\n"; } -package CFPlus; +package DC; sub find_rcfile($) { my $path; for (grep !ref, @INC) { - $path = "$_/CFPlus/resources/$_[0]"; + $path = "$_/Deliantra/Client/private/resources/$_[0]"; return $path if -r $path; } @@ -167,25 +162,17 @@ local $/; my $CFG = <$fh>; - if ($CFG =~ /^---/) { ## TODO compatibility cruft, remove - require YAML; - utf8::decode $CFG; - $::CFG = YAML::Load ($CFG); - } elsif ($CFG =~ /^\{/) { - $::CFG = from_json $CFG; - } else { - $::CFG = eval $CFG; ## todo comaptibility cruft - } + $::CFG = decode_json $CFG; } sub write_cfg { - my ($file) = @_; + my $file = "$Deliantra::VARDIR/client.cf"; $::CFG->{VERSION} = $::VERSION; open my $fh, ">:utf8", $file or return; - print $fh to_json $::CFG; + print $fh encode_json $::CFG; } sub http_proxy { @@ -210,10 +197,10 @@ sub lwp_useragent { require LWP::UserAgent; - CFPlus::set_proxy; + DC::set_proxy; my $ua = LWP::UserAgent->new ( - agent => "cfplus $VERSION", + agent => "deliantra $VERSION", keep_alive => 1, env_proxy => 1, timeout => 30, @@ -241,10 +228,14 @@ } -package CFPlus::Layout; +package DC::Layout; + +$DC::OpenGL::INIT_HOOK{"DC::Layout"} = sub { + glyph_cache_restore; +}; -$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub { - reset_glyph_cache; +$DC::OpenGL::SHUTDOWN_HOOK{"DC::Layout"} = sub { + glyph_cache_backup; }; 1;