… | |
… | |
29 | use Fcntl; |
29 | use Fcntl; |
30 | use YAML::Syck (); |
30 | use YAML::Syck (); |
31 | use IO::AIO 2.32 (); |
31 | use IO::AIO 2.32 (); |
32 | use Time::HiRes; |
32 | use Time::HiRes; |
33 | use Compress::LZF; |
33 | use Compress::LZF; |
|
|
34 | use 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 |
38 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
39 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
… | |
… | |
1488 | my ($path) = @_; |
1489 | my ($path) = @_; |
1489 | |
1490 | |
1490 | my ($match, $specificity); |
1491 | my ($match, $specificity); |
1491 | |
1492 | |
1492 | for my $region (list) { |
1493 | for my $region (list) { |
1493 | if ($region->match && $path =~ $region->match) { |
1494 | if ($region->{match} && $path =~ $region->{match}) { |
1494 | ($match, $specificity) = ($region, $region->specificity) |
1495 | ($match, $specificity) = ($region, $region->specificity) |
1495 | if $region->specificity > $specificity; |
1496 | if $region->specificity > $specificity; |
1496 | } |
1497 | } |
1497 | } |
1498 | } |
1498 | |
1499 | |
… | |
… | |
2464 | =cut |
2465 | =cut |
2465 | |
2466 | |
2466 | sub cf::client::ext_event($$%) { |
2467 | sub cf::client::ext_event($$%) { |
2467 | my ($self, $type, %msg) = @_; |
2468 | my ($self, $type, %msg) = @_; |
2468 | |
2469 | |
|
|
2470 | return unless $self->extcmd; |
|
|
2471 | |
2469 | $msg{msgtype} = "event_$type"; |
2472 | $msg{msgtype} = "event_$type"; |
2470 | $self->send_packet ("ext " . $self->{json_coder}->encode (\%msg)); |
2473 | $self->send_packet ("ext " . $self->{json_coder}->encode (\%msg)); |
2471 | } |
2474 | } |
2472 | |
2475 | |
2473 | =item $success = $client->query ($flags, "text", \&cb) |
2476 | =item $success = $client->query ($flags, "text", \&cb) |
… | |
… | |
2719 | { |
2722 | { |
2720 | my $faces = $facedata->{faceinfo}; |
2723 | my $faces = $facedata->{faceinfo}; |
2721 | |
2724 | |
2722 | while (my ($face, $info) = each %$faces) { |
2725 | while (my ($face, $info) = each %$faces) { |
2723 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2726 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2724 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
2727 | cf::face::set_visibility $idx, $info->{visibility}; |
|
|
2728 | cf::face::set_magicmap $idx, $info->{magicmap}; |
2725 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
2729 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
2726 | cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; |
2730 | cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; |
2727 | Coro::cede; |
2731 | |
|
|
2732 | cf::cede_to_tick; |
2728 | } |
2733 | } |
2729 | |
2734 | |
2730 | while (my ($face, $info) = each %$faces) { |
2735 | while (my ($face, $info) = each %$faces) { |
2731 | next unless $info->{smooth}; |
2736 | next unless $info->{smooth}; |
2732 | my $idx = cf::face::find $face |
2737 | my $idx = cf::face::find $face |
2733 | or next; |
2738 | or next; |
2734 | if (my $smooth = cf::face::find $info->{smooth}) { |
2739 | if (my $smooth = cf::face::find $info->{smooth}) { |
|
|
2740 | cf::face::set_smooth $idx, $smooth; |
2735 | cf::face::set_smooth $idx, $smooth, $info->{smoothlevel}; |
2741 | cf::face::set_smoothlevel $idx, $info->{smoothlevel}; |
2736 | } else { |
2742 | } else { |
2737 | warn "smooth face '$info->{smooth}' not found for face '$face'"; |
2743 | warn "smooth face '$info->{smooth}' not found for face '$face'"; |
2738 | } |
2744 | } |
2739 | Coro::cede; |
2745 | |
|
|
2746 | cf::cede_to_tick; |
2740 | } |
2747 | } |
2741 | } |
2748 | } |
2742 | |
2749 | |
2743 | { |
2750 | { |
2744 | my $anims = $facedata->{animinfo}; |
2751 | my $anims = $facedata->{animinfo}; |
2745 | |
2752 | |
2746 | while (my ($anim, $info) = each %$anims) { |
2753 | while (my ($anim, $info) = each %$anims) { |
2747 | cf::anim::set $anim, $info->{frames}, $info->{facings}; |
2754 | cf::anim::set $anim, $info->{frames}, $info->{facings}; |
2748 | Coro::cede; |
2755 | cf::cede_to_tick; |
2749 | } |
2756 | } |
2750 | |
2757 | |
2751 | 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 | } |
2752 | } |
2782 | } |
2753 | |
2783 | |
2754 | 1 |
2784 | 1 |
2755 | } |
2785 | } |
2756 | |
2786 | |
2757 | sub reload_regions { |
2787 | sub reload_regions { |
2758 | load_resource_file "$MAPDIR/regions" |
2788 | load_resource_file "$MAPDIR/regions" |
2759 | 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 | } |
2760 | } |
2795 | } |
2761 | |
2796 | |
2762 | sub reload_facedata { |
2797 | sub reload_facedata { |
2763 | load_facedata "$DATADIR/facedata" |
2798 | load_facedata "$DATADIR/facedata" |
2764 | or die "unable to load facedata\n"; |
2799 | or die "unable to load facedata\n"; |