ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.595 by root, Fri Nov 9 16:27:55 2012 UTC vs.
Revision 1.598 by root, Sun Nov 11 02:38:10 2012 UTC

58use BDB (); 58use BDB ();
59use Data::Dumper; 59use Data::Dumper;
60use Fcntl; 60use Fcntl;
61use YAML::XS (); 61use YAML::XS ();
62use IO::AIO (); 62use IO::AIO ();
63use Time::HiRes;
64use Compress::LZF; 63use Compress::LZF;
65use Digest::MD5 (); 64use Digest::MD5 ();
66 65
67AnyEvent::detect; 66AnyEvent::detect;
68 67
901 900
902 return db_get cache => "$id/data"; 901 return db_get cache => "$id/data";
903 } 902 }
904 } 903 }
905 904
906 my $t1 = Time::HiRes::time; 905 my $t1 = EV::time;
907 my $data = $process->(\@data); 906 my $data = $process->(\@data);
908 my $t2 = Time::HiRes::time; 907 my $t2 = EV::time;
909 908
910 info "cache: '$id' processed in ", $t2 - $t1, "s\n"; 909 info "cache: '$id' processed in ", $t2 - $t1, "s\n";
911 910
912 db_put cache => "$id/data", $data; 911 db_put cache => "$id/data", $data;
913 db_put cache => "$id/md5" , $md5; 912 db_put cache => "$id/md5" , $md5;
3522# the server's init and main functions 3521# the server's init and main functions
3523 3522
3524our %FACEHASH; # hash => idx, #d# HACK for http server 3523our %FACEHASH; # hash => idx, #d# HACK for http server
3525 3524
3526# internal api, not fianlised 3525# internal api, not fianlised
3527sub add_face { 3526sub set_face {
3528 my ($name, $type, $data) = @_; 3527 my ($name, $type, $data) = @_;
3529 3528
3530 my $idx = cf::face::find $name; 3529 my $idx = cf::face::find $name;
3531 3530
3532 if ($idx) { 3531 if ($idx) {
3562 or cf::cleanup "$path: version mismatch, cannot proceed."; 3561 or cf::cleanup "$path: version mismatch, cannot proceed.";
3563 3562
3564 cf::cede_to_tick; 3563 cf::cede_to_tick;
3565 3564
3566 { 3565 {
3567 my $faces = $facedata->{faceinfo}; 3566 my $faces = delete $facedata->{faceinfo};
3568 3567
3569 for my $face (sort keys %$faces) { 3568 for my $face (sort keys %$faces) {
3570 my $info = $faces->{$face}; 3569 my $info = $faces->{$face};
3571 my $idx = (cf::face::find $face) || cf::face::alloc $face; 3570 my $idx = (cf::face::find $face) || cf::face::alloc $face;
3572 3571
3574 cf::face::set_magicmap $idx, $info->{magicmap}; 3573 cf::face::set_magicmap $idx, $info->{magicmap};
3575 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; 3574 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32};
3576 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; 3575 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64};
3577 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; 3576 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ;
3578 $FACEHASH{$info->{hash64}} = $idx;#d# 3577 $FACEHASH{$info->{hash64}} = $idx;#d#
3579 3578
3580 cf::cede_to_tick; 3579 cf::cede_to_tick;
3581 } 3580 }
3582 3581
3583 while (my ($face, $info) = each %$faces) { 3582 while (my ($face, $info) = each %$faces) {
3584 next unless $info->{smooth}; 3583 next unless $info->{smooth};
3596 cf::cede_to_tick; 3595 cf::cede_to_tick;
3597 } 3596 }
3598 } 3597 }
3599 3598
3600 { 3599 {
3601 my $anims = $facedata->{animinfo}; 3600 my $anims = delete $facedata->{animinfo};
3602 3601
3603 while (my ($anim, $info) = each %$anims) { 3602 while (my ($anim, $info) = each %$anims) {
3604 cf::anim::set $anim, $info->{frames}, $info->{facings}; 3603 cf::anim::set $anim, $info->{frames}, $info->{facings};
3605 cf::cede_to_tick; 3604 cf::cede_to_tick;
3606 } 3605 }
3607 3606
3608 cf::anim::invalidate_all; # d'oh 3607 cf::anim::invalidate_all; # d'oh
3609 } 3608 }
3610 3609
3611 { 3610 {
3612 my $res = $facedata->{resource}; 3611 my $res = delete $facedata->{resource};
3613 3612
3614 while (my ($name, $info) = each %$res) { 3613 while (my ($name, $info) = each %$res) {
3615 if (defined (my $type = $info->{type})) { 3614 if (defined (my $type = $info->{type})) {
3616 # TODO: different hash - must free and use new index, or cache ixface data queue 3615 # TODO: different hash - must free and use new index, or cache ixface data queue
3617 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3616 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3652} 3651}
3653 3652
3654sub reload_exp_table { 3653sub reload_exp_table {
3655 _reload_exp_table; 3654 _reload_exp_table;
3656 3655
3657 add_face "res/exp_table" => FT_RSRC, 3656 set_face "res/exp_table" => FT_RSRC,
3658 JSON::XS->new->utf8->canonical->encode ( 3657 JSON::XS->new->utf8->canonical->encode (
3659 [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level] 3658 [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]
3660 ); 3659 );
3661} 3660}
3662 3661
3685 3684
3686sub reload_archetypes { 3685sub reload_archetypes {
3687 load_resource_file "$DATADIR/archetypes" 3686 load_resource_file "$DATADIR/archetypes"
3688 or die "unable to load archetypes\n"; 3687 or die "unable to load archetypes\n";
3689 3688
3690 add_face "res/skill_info" => FT_RSRC, 3689 set_face "res/skill_info" => FT_RSRC,
3691 JSON::XS->new->utf8->canonical->encode ( 3690 JSON::XS->new->utf8->canonical->encode (
3692 [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1] 3691 [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1]
3693 ); 3692 );
3694 add_face "res/spell_paths" => FT_RSRC, 3693 set_face "res/spell_paths" => FT_RSRC,
3695 JSON::XS->new->utf8->canonical->encode ( 3694 JSON::XS->new->utf8->canonical->encode (
3696 [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1] 3695 [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1]
3697 ); 3696 );
3698} 3697}
3699 3698

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines