--- deliantra/Deliantra-Client/DC.pm 2007/04/06 21:53:56 1.141 +++ deliantra/Deliantra-Client/DC.pm 2007/12/26 20:46:39 1.168 @@ -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.97'; + $VERSION = '0.9962'; 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,15 +162,7 @@ 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 { @@ -185,7 +172,7 @@ open my $fh, ">:utf8", $file or return; - print $fh to_json $::CFG; + print $fh encode_json $::CFG; } sub http_proxy { @@ -210,7 +197,7 @@ sub lwp_useragent { require LWP::UserAgent; - CFPlus::set_proxy; + dc::set_proxy; my $ua = LWP::UserAgent->new ( agent => "cfplus $VERSION", @@ -232,19 +219,23 @@ sub fh_nonblocking($$) { my ($fh, $nb) = @_; - if ($^O =~ /Win32/) { - $nb = ! ! $nb; - ioctl $fh, 0x8004667e, $nb; # FIONBIO + if ($^O eq "MSWin32") { + $nb = (! ! $nb) + 0; + ioctl $fh, 0x8004667e, \$nb; # FIONBIO } else { fcntl $fh, &Fcntl::F_SETFL, $nb ? &Fcntl::O_NONBLOCK : 0; } } -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;