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.300 by root, Tue Jul 10 06:44:29 2007 UTC vs.
Revision 1.305 by root, Thu Jul 12 08:40:14 2007 UTC

29use Fcntl; 29use Fcntl;
30use YAML::Syck (); 30use YAML::Syck ();
31use IO::AIO 2.32 (); 31use IO::AIO 2.32 ();
32use Time::HiRes; 32use Time::HiRes;
33use Compress::LZF; 33use Compress::LZF;
34use Digest::MD5 ();
34 35
35# configure various modules to our taste 36# configure various modules to our taste
36# 37#
37$Storable::canonical = 1; # reduce rsync transfers 38$Storable::canonical = 1; # reduce rsync transfers
38Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator 39Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator
1435 s/\s+\n/\n/g; # ws line-ends 1436 s/\s+\n/\n/g; # ws line-ends
1436 s/\n\n+/\n/g; # double lines 1437 s/\n\n+/\n/g; # double lines
1437 s/^\n+//; # beginning lines 1438 s/^\n+//; # beginning lines
1438 s/\n+$//; # ending lines 1439 s/\n+$//; # ending lines
1439 1440
1440 warn $_;#d#
1441 $_ 1441 $_
1442} 1442}
1443 1443
1444sub hintmode { 1444sub hintmode {
1445 $_[0]{hintmode} = $_[1] if @_ > 1; 1445 $_[0]{hintmode} = $_[1] if @_ > 1;
1489 my ($path) = @_; 1489 my ($path) = @_;
1490 1490
1491 my ($match, $specificity); 1491 my ($match, $specificity);
1492 1492
1493 for my $region (list) { 1493 for my $region (list) {
1494 if ($region->match && $path =~ $region->match) { 1494 if ($region->{match} && $path =~ $region->{match}) {
1495 ($match, $specificity) = ($region, $region->specificity) 1495 ($match, $specificity) = ($region, $region->specificity)
1496 if $region->specificity > $specificity; 1496 if $region->specificity > $specificity;
1497 } 1497 }
1498 } 1498 }
1499 1499
2465=cut 2465=cut
2466 2466
2467sub cf::client::ext_event($$%) { 2467sub cf::client::ext_event($$%) {
2468 my ($self, $type, %msg) = @_; 2468 my ($self, $type, %msg) = @_;
2469 2469
2470 return unless $self->extcmd;
2471
2470 $msg{msgtype} = "event_$type"; 2472 $msg{msgtype} = "event_$type";
2471 $self->send_packet ("ext " . $self->{json_coder}->encode (\%msg)); 2473 $self->send_packet ("ext " . $self->{json_coder}->encode (\%msg));
2472} 2474}
2473 2475
2474=item $success = $client->query ($flags, "text", \&cb) 2476=item $success = $client->query ($flags, "text", \&cb)
2720 { 2722 {
2721 my $faces = $facedata->{faceinfo}; 2723 my $faces = $facedata->{faceinfo};
2722 2724
2723 while (my ($face, $info) = each %$faces) { 2725 while (my ($face, $info) = each %$faces) {
2724 my $idx = (cf::face::find $face) || cf::face::alloc $face; 2726 my $idx = (cf::face::find $face) || cf::face::alloc $face;
2725 cf::face::set $idx, $info->{visibility}, $info->{magicmap}; 2727 cf::face::set_visibility $idx, $info->{visibility};
2728 cf::face::set_magicmap $idx, $info->{magicmap};
2726 cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; 2729 cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32};
2727 cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; 2730 cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64};
2728 Coro::cede; 2731
2732 cf::cede_to_tick;
2729 } 2733 }
2730 2734
2731 while (my ($face, $info) = each %$faces) { 2735 while (my ($face, $info) = each %$faces) {
2732 next unless $info->{smooth}; 2736 next unless $info->{smooth};
2733 my $idx = cf::face::find $face 2737 my $idx = cf::face::find $face
2734 or next; 2738 or next;
2735 if (my $smooth = cf::face::find $info->{smooth}) { 2739 if (my $smooth = cf::face::find $info->{smooth}) {
2740 cf::face::set_smooth $idx, $smooth;
2736 cf::face::set_smooth $idx, $smooth, $info->{smoothlevel}; 2741 cf::face::set_smoothlevel $idx, $info->{smoothlevel};
2737 } else { 2742 } else {
2738 warn "smooth face '$info->{smooth}' not found for face '$face'"; 2743 warn "smooth face '$info->{smooth}' not found for face '$face'";
2739 } 2744 }
2740 Coro::cede; 2745
2746 cf::cede_to_tick;
2741 } 2747 }
2742 } 2748 }
2743 2749
2744 { 2750 {
2745 my $anims = $facedata->{animinfo}; 2751 my $anims = $facedata->{animinfo};
2746 2752
2747 while (my ($anim, $info) = each %$anims) { 2753 while (my ($anim, $info) = each %$anims) {
2748 cf::anim::set $anim, $info->{frames}, $info->{facings}; 2754 cf::anim::set $anim, $info->{frames}, $info->{facings};
2749 Coro::cede; 2755 cf::cede_to_tick;
2750 } 2756 }
2751 2757
2752 cf::anim::invalidate_all; # d'oh 2758 cf::anim::invalidate_all; # d'oh
2759 }
2760
2761 {
2762 # TODO: for gcfclient pleasure, we should give resources
2763 # that gcfclient doesn't grok a >10000 face index.
2764 my $res = $facedata->{resource};
2765 my $enc = JSON::XS->new->utf8->canonical;
2766
2767 while (my ($name, $info) = each %$res) {
2768 my $meta = $enc->encode ({
2769 name => $name,
2770 type => $info->{type},
2771 copyright => $info->{copyright}, #TODO#
2772 });
2773 my $data = pack "(w/a*)*", $meta, $info->{data};
2774 my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata
2775
2776 my $idx = (cf::face::find $name) || cf::face::alloc $name;
2777 cf::face::set_type $idx, 1;
2778 cf::face::set_data $idx, 0, $data, $chk;
2779
2780 cf::cede_to_tick;
2781 }
2753 } 2782 }
2754 2783
2755 1 2784 1
2756} 2785}
2757 2786
2758sub reload_regions { 2787sub reload_regions {
2759 load_resource_file "$MAPDIR/regions" 2788 load_resource_file "$MAPDIR/regions"
2760 or die "unable to load regions file\n"; 2789 or die "unable to load regions file\n";
2790
2791 for (cf::region::list) {
2792 $_->{match} = qr/$_->{match}/
2793 if exists $_->{match};
2794 }
2761} 2795}
2762 2796
2763sub reload_facedata { 2797sub reload_facedata {
2764 load_facedata "$DATADIR/facedata" 2798 load_facedata "$DATADIR/facedata"
2765 or die "unable to load facedata\n"; 2799 or die "unable to load facedata\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines