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.599 by root, Sun Nov 11 04:29:11 2012 UTC vs.
Revision 1.624 by root, Sat Nov 17 23:40:02 2018 UTC

1# 1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG. 2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3# 3#
4# Copyright (©) 2018 Marc Alexander Lehmann / the Deliantra team
4# Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5# Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 6#
6# Deliantra is free software: you can redistribute it and/or modify it under 7# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 8# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 9# Free Software Foundation, either version 3 of the License, or (at your
57use JSON::XS 2.01 (); 58use JSON::XS 2.01 ();
58use BDB (); 59use BDB ();
59use Data::Dumper; 60use Data::Dumper;
60use Fcntl; 61use Fcntl;
61use YAML::XS (); 62use YAML::XS ();
63use CBOR::XS ();
62use IO::AIO (); 64use IO::AIO ();
63use Compress::LZF; 65use Compress::LZF;
64use Digest::MD5 (); 66use Digest::MD5 ();
65 67
66AnyEvent::detect; 68AnyEvent::detect;
225=item $cf::RUNTIME 227=item $cf::RUNTIME
226 228
227The time this server has run, starts at 0 and is increased by $cf::TICK on 229The time this server has run, starts at 0 and is increased by $cf::TICK on
228every server tick. 230every server tick.
229 231
230=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR 232=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR
231$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR 233$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR
232$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR 234$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR
233 235
234Various directories - "/etc", read-only install directory, perl-library 236Various directories - "/etc", read-only install directory, perl-library
235directory, pod-directory, read-only maps directory, "/var", "/var/tmp", 237directory, pod-directory, read-only maps directory, "/var", "/var/tmp",
464 466
465sub decode_yaml($) { 467sub decode_yaml($) {
466 fork_call { YAML::XS::Load $_[0] } @_ 468 fork_call { YAML::XS::Load $_[0] } @_
467} 469}
468 470
471=item $scalar = cf::decode_cbor $scalar
472
473Same as CBOR::XS::decode_cbor, but takes server ticks into account, so
474blocks. For small amounts of data, C<CBOR::XS::decode_cbor> is the better
475alternative.
476
477=cut
478
479sub decode_cbor($) {
480 # we assume 10mb/s minimum decoding speed (on a ~2ghz machine)
481 cf::get_slot +(length $_[0]) / 10_000_000, 0, "decode_cbor";
482 CBOR::XS::decode_cbor $_[0]
483}
484
469=item $scalar = cf::unlzf $scalar 485=item $scalar = cf::unlzf $scalar
470 486
471Same as Compress::LZF::compress, but takes server ticks into account, so 487Same as Compress::LZF::compress, but takes server ticks into account, so
472blocks. 488blocks.
473 489
510 } 526 }
511} 527}
512 528
513=item cf::lock_wait $string 529=item cf::lock_wait $string
514 530
515Wait until the given lock is available. See cf::lock_acquire. 531Wait until the given lock is available. See cf::lock_acquire.
516 532
517=item my $lock = cf::lock_acquire $string 533=item my $lock = cf::lock_acquire $string
518 534
519Wait until the given lock is available and then acquires it and returns 535Wait until the given lock is available and then acquires it and returns
520a L<Guard> object. If the guard object gets destroyed (goes out of scope, 536a L<Guard> object. If the guard object gets destroyed (goes out of scope,
573Allocate $time seconds of blocking CPU time at priority C<$priority> 589Allocate $time seconds of blocking CPU time at priority C<$priority>
574(default: 0): This call blocks and returns only when you have at least 590(default: 0): This call blocks and returns only when you have at least
575C<$time> seconds of cpu time till the next tick. The slot is only valid 591C<$time> seconds of cpu time till the next tick. The slot is only valid
576till the next cede. 592till the next cede.
577 593
578Background jobs should use a priority les than zero, interactive jobs 594Background jobs should use a priority less than zero, interactive jobs
579should use 100 or more. 595should use 100 or more.
580 596
581The optional C<$name> can be used to identify the job to run. It might be 597The optional C<$name> can be used to identify the job to run. It might be
582used for statistical purposes and should identify the same time-class. 598used for statistical purposes and should identify the same time-class.
583 599
596 my $signal = new Coro::Signal; 612 my $signal = new Coro::Signal;
597 my $busy; 613 my $busy;
598 614
599 while () { 615 while () {
600 next_job: 616 next_job:
617
618 Coro::cede;
601 619
602 my $avail = cf::till_tick; 620 my $avail = cf::till_tick;
603 621
604 for (0 .. $#SLOT_QUEUE) { 622 for (0 .. $#SLOT_QUEUE) {
605 if ($SLOT_QUEUE[$_][0] <= $avail) { 623 if ($SLOT_QUEUE[$_][0] <= $avail) {
606 $busy = 0; 624 $busy = 0;
607 my $job = splice @SLOT_QUEUE, $_, 1, (); 625 my $job = splice @SLOT_QUEUE, $_, 1, ();
608 $job->[2]->send; 626 $job->[2]->send;
609 Coro::cede;
610 goto next_job; 627 goto next_job;
611 } else { 628 } else {
612 $SLOT_QUEUE[$_][0] *= $SLOT_DECAY; 629 $SLOT_QUEUE[$_][0] *= $SLOT_DECAY;
613 } 630 }
614 } 631 }
615 632
616 if (@SLOT_QUEUE) { 633 if (@SLOT_QUEUE) {
617 # we do not use wait_for_tick() as it returns immediately when tick is inactive 634 wait_for_tick;
618 $WAIT_FOR_TICK->wait;
619 } else { 635 } else {
620 $busy = 0; 636 $busy = 0;
621 Coro::schedule; 637 Coro::schedule;
622 } 638 }
623 } 639 }
649BEGIN { *async = \&Coro::async_pool } 665BEGIN { *async = \&Coro::async_pool }
650 666
651=item cf::sync_job { BLOCK } 667=item cf::sync_job { BLOCK }
652 668
653The design of Deliantra requires that the main coroutine ($Coro::main) 669The design of Deliantra requires that the main coroutine ($Coro::main)
654is always able to handle events or runnable, as Deliantra is only 670is always able to handle events or is runnable, as Deliantra is only
655partly reentrant. Thus "blocking" it by e.g. waiting for I/O is not 671partly reentrant. Thus "blocking" it by e.g. waiting for I/O is not
656acceptable. 672acceptable.
657 673
658If it must be done, put the blocking parts into C<sync_job>. This will run 674If it must be done, put the blocking parts into C<sync_job>. This will run
659the given BLOCK in another coroutine while waiting for the result. The 675the given BLOCK in another coroutine while waiting for the result. The
687 703
688 while ($busy) { 704 while ($busy) {
689 if (Coro::nready) { 705 if (Coro::nready) {
690 Coro::cede_notself; 706 Coro::cede_notself;
691 } else { 707 } else {
692 EV::loop EV::LOOP_ONESHOT; 708 EV::run EV::RUN_ONCE;
693 } 709 }
694 } 710 }
695 711
696 my $time = AE::time - $time; 712 my $time = AE::time - $time;
697 713
738 reset_signals; 754 reset_signals;
739} 755}
740 756
741sub fork_call(&@) { 757sub fork_call(&@) {
742 my ($cb, @args) = @_; 758 my ($cb, @args) = @_;
743
744 # we seemingly have to make a local copy of the whole thing,
745 # otherwise perl prematurely frees the stuff :/
746 # TODO: investigate and fix (likely this will be rather laborious)
747 759
748 my @res = Coro::Util::fork_eval { 760 my @res = Coro::Util::fork_eval {
749 cf::post_fork; 761 cf::post_fork;
750 &$cb 762 &$cb
751 } @args; 763 } @args;
2388 2400
2389 $MAP_PREFETCHER ||= cf::async { 2401 $MAP_PREFETCHER ||= cf::async {
2390 $Coro::current->{desc} = "map prefetcher"; 2402 $Coro::current->{desc} = "map prefetcher";
2391 2403
2392 while (%MAP_PREFETCH) { 2404 while (%MAP_PREFETCH) {
2393 while (my ($k, $v) = each %MAP_PREFETCH) { 2405 for my $k (keys %MAP_PREFETCH) {
2394 if (my $map = find $k) { 2406 if (my $map = find $k) {
2395 $map->load if $v; 2407 $map->load if $MAP_PREFETCH{$k};
2396 } 2408 }
2397 2409
2398 delete $MAP_PREFETCH{$k}; 2410 delete $MAP_PREFETCH{$k};
2399 } 2411 }
2400 } 2412 }
2654 2666
2655Creates and returns a persistent reference to an object that can be stored as a string. 2667Creates and returns a persistent reference to an object that can be stored as a string.
2656 2668
2657=item $ob = cf::object::deref ($refstring) 2669=item $ob = cf::object::deref ($refstring)
2658 2670
2659returns the objetc referenced by refstring. may return undef when it cnanot find the object, 2671returns the objetc referenced by refstring. may return undef when it cannot find the object,
2660even if the object actually exists. May block. 2672even if the object actually exists. May block.
2661 2673
2662=cut 2674=cut
2663 2675
2664sub deref { 2676sub deref {
2746=item $player_object->may ("access") 2758=item $player_object->may ("access")
2747 2759
2748Returns wether the given player is authorized to access resource "access" 2760Returns wether the given player is authorized to access resource "access"
2749(e.g. "command_wizcast"). 2761(e.g. "command_wizcast").
2750 2762
2763This is implemented by checking a config setting of C<may_access> where
2764C<access> is replaced by the access string. The following alternatives are
2765possible (and are tested in order):
2766
2767=over 4
2768
2769=item * Player is DM
2770
2771The request will succeed.
2772
2773=item * may_access is an array reference
2774
2775If either the player nickname or UUID is in the array, the request will
2776succeed, otherwise it will fail.
2777
2778=item * may_access is a true value
2779
2780The request will succeed.
2781
2782=item * may_access is missing or false
2783
2784The request will fail.
2785
2786=back
2787
2751=cut 2788=cut
2752 2789
2753sub cf::object::player::may { 2790sub cf::object::player::may {
2754 my ($self, $access) = @_; 2791 my ($self, $access) = @_;
2755 2792
2756 $self->flag (cf::FLAG_WIZ) || 2793 $self->flag (cf::FLAG_WIZ) ||
2757 (ref $cf::CFG{"may_$access"} 2794 (ref $cf::CFG{"may_$access"}
2758 ? scalar grep $self->name eq $_, @{$cf::CFG{"may_$access"}} 2795 ? scalar grep $self->name eq $_ || $self->uuid eq $_, @{$cf::CFG{"may_$access"}}
2759 : $cf::CFG{"may_$access"}) 2796 : $cf::CFG{"may_$access"})
2760} 2797}
2761 2798
2762=item $player_object->enter_link 2799=item $player_object->enter_link
2763 2800
2766The player should be reasonably safe there for short amounts of time (e.g. 2803The player should be reasonably safe there for short amounts of time (e.g.
2767for loading a map). You I<MUST> call C<leave_link> as soon as possible, 2804for loading a map). You I<MUST> call C<leave_link> as soon as possible,
2768though, as the player cannot control the character while it is on the link 2805though, as the player cannot control the character while it is on the link
2769map. 2806map.
2770 2807
2771Will never block. 2808This method will never block, which is the whole reaosn for it's
2809existance: you can I<always> put a player onto the link map, which is the
2810only place to put objects that is guaranteed to exist.
2811
2812A typical usage pattern is to call C<enter_link> synchronously from the
2813server, then start a new thread, do your blocking stuff there and then
2814call C<leave_link> from that thread.
2772 2815
2773=item $player_object->leave_link ($map, $x, $y) 2816=item $player_object->leave_link ($map, $x, $y)
2774 2817
2775Moves the player out of the special C<{link}> map onto the specified 2818Moves the player out of the special C<{link}> map onto the specified
2776map. If the map is not valid (or omitted), the player will be moved back 2819map. If the map is not valid (or omitted), the player will be moved back
3046 3089
3047=head3 cf::client 3090=head3 cf::client
3048 3091
3049=over 4 3092=over 4
3050 3093
3051=item $client->send_drawinfo ($text, $flags)
3052
3053Sends a drawinfo packet to the client. Circumvents output buffering so
3054should not be used under normal circumstances.
3055
3056=cut
3057
3058sub cf::client::send_drawinfo {
3059 my ($self, $text, $flags) = @_;
3060
3061 utf8::encode $text;
3062 $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text);
3063}
3064
3065=item $client->send_big_packet ($pkt) 3094=item $client->send_big_packet ($pkt)
3066 3095
3067Like C<send_packet>, but tries to compress large packets, and fragments 3096Like C<send_packet>, but tries to compress large packets, and fragments
3068them as required. 3097them as required.
3069 3098
3087 $self->send_packet ($pkt); 3116 $self->send_packet ($pkt);
3088} 3117}
3089 3118
3090=item $client->send_msg ($channel, $msg, $color, [extra...]) 3119=item $client->send_msg ($channel, $msg, $color, [extra...])
3091 3120
3092Send a drawinfo or msg packet to the client, formatting the msg for the 3121Send a msg packet to the client, formatting the msg for the client if
3093client if neccessary. C<$type> should be a string identifying the type of 3122necessary. C<$type> should be a string identifying the type of the
3094the message, with C<log> being the default. If C<$color> is negative, suppress 3123message, with C<log> being the default. If C<$color> is negative, suppress
3095the message unless the client supports the msg packet. 3124the message unless the client supports the msg packet.
3096 3125
3097=cut 3126=cut
3098 3127
3099# non-persistent channels (usually the info channel) 3128# non-persistent channels (usually the info channel)
3142 }, 3171 },
3143 "c/body" => { 3172 "c/body" => {
3144 id => "infobox", 3173 id => "infobox",
3145 title => "Body Parts", 3174 title => "Body Parts",
3146 reply => undef, 3175 reply => undef,
3147 tooltip => "Shows which body parts you posess and are available", 3176 tooltip => "Shows which body parts you possess and are available",
3148 }, 3177 },
3149 "c/statistics" => { 3178 "c/statistics" => {
3150 id => "infobox", 3179 id => "infobox",
3151 title => "Statistics", 3180 title => "Statistics",
3152 reply => undef, 3181 reply => undef,
3204 id => "death", 3233 id => "death",
3205 title => "Death", 3234 title => "Death",
3206 reply => undef, 3235 reply => undef,
3207 tooltip => "Reason for and more info about your most recent death", 3236 tooltip => "Reason for and more info about your most recent death",
3208 }, 3237 },
3238 "c/fatal" => {
3239 id => "fatal",
3240 title => "Fatal Error",
3241 reply => undef,
3242 tooltip => "Reason for the server disconnect",
3243 },
3209 "c/say" => $SAY_CHANNEL, 3244 "c/say" => $SAY_CHANNEL,
3210 "c/chat" => $CHAT_CHANNEL, 3245 "c/chat" => $CHAT_CHANNEL,
3211); 3246);
3212 3247
3213sub cf::client::send_msg { 3248sub cf::client::send_msg {
3286 3321
3287 $self->send_packet ($self->{query_queue}[0][0]) 3322 $self->send_packet ($self->{query_queue}[0][0])
3288 if @{ $self->{query_queue} } == 1; 3323 if @{ $self->{query_queue} } == 1;
3289 3324
3290 1 3325 1
3326}
3327
3328=item $client->update_command_faces
3329
3330=cut
3331
3332our %COMMAND_FACE;
3333
3334sub cf::client::update_command_faces {
3335 my ($self) = @_;
3336
3337 my @faces = grep $_,
3338 $COMMAND_FACE{preferred},
3339 $COMMAND_FACE{standard},
3340 $COMMAND_FACE{skill},
3341 $self->pl->ob->flag (cf::FLAG_WIZ) ? $COMMAND_FACE{dm} : (),
3342 $COMMAND_FACE{emote},
3343 ;
3344
3345 $self->send_face ($_)
3346 for @faces;
3347 $self->flush_fx;
3348
3349 $self->ext_msg (command_list => @faces);
3350}
3351
3352=item cf::client::set_command_face $type, $commands
3353
3354=cut
3355
3356sub cf::client::set_command_face {
3357 my ($type, $list) = @_;
3358
3359 my $idx = &cf::face::set ( #d# ugly forward reference
3360 "command_list/$type" => cf::FT_RSRC,
3361 JSON::XS->new->utf8->encode ([ sort @$list ])
3362 );
3363
3364 $COMMAND_FACE{$type} = $idx;
3291} 3365}
3292 3366
3293cf::client->attach ( 3367cf::client->attach (
3294 on_connect => sub { 3368 on_connect => sub {
3295 my ($ns) = @_; 3369 my ($ns) = @_;
3519=cut 3593=cut
3520 3594
3521############################################################################# 3595#############################################################################
3522# the server's init and main functions 3596# the server's init and main functions
3523 3597
3524our %FACEHASH; # hash => idx, #d# HACK for http server 3598{
3525our @FACEDATA; # dynamically-created facedata 3599 package cf::face;
3526 3600
3601 our %HASH; # hash => idx
3602 our @DATA; # dynamically-created facedata, only faceste 0 used
3603 our @FOFS; # file offset, if > 0
3604 our @SIZE; # size of face, in octets
3605 our @META; # meta hash of face, if any
3606 our $DATAFH; # facedata filehandle
3607
3527# internal api, not fianlised 3608 # internal api, not finalised
3528sub set_face { 3609 sub set {
3529 my ($name, $type, $data) = @_; 3610 my ($name, $type, $data) = @_;
3530 3611
3531 my $idx = cf::face::find $name; 3612 my $idx = cf::face::find $name;
3532 3613
3533 if ($idx) { 3614 if ($idx) {
3534 delete $FACEHASH{cf::face::get_chksum $idx}; 3615 delete $HASH{cf::face::get_csum $idx};
3535 } else { 3616 } else {
3536 $idx = cf::face::alloc $name; 3617 $idx = cf::face::alloc $name;
3537 } 3618 }
3538 3619
3539 my $hash = cf::face::mangle_chksum Digest::MD5::md5 $data; 3620 my $hash = cf::face::mangle_csum Digest::MD5::md5 $data;
3540 3621
3541 cf::face::set_type $idx, $type; 3622 cf::face::set_type $idx, $type;
3542 cf::face::set_data $idx, 0, (length $data), 0, $hash; 3623 cf::face::set_csum $idx, 0, $hash;
3543 cf::face::set_meta $idx, $type & 1 ? undef : undef;
3544 3624
3545 # we need to destroy the SV itself, not just overwrite, 3625 # we need to destroy the SV itself, not just modify it, as a running ix
3546 # as a running ix might hold a reference to it. 3626 # might hold a reference to it: "delete" achieves that.
3547 # delete achieves that. 3627 delete $FOFS[0][$idx];
3628 delete $DATA[0][$idx];
3629 $DATA[0][$idx] = $data;
3630 $SIZE[0][$idx] = length $data;
3548 delete $FACEDATA[$idx]; 3631 delete $META[$idx];
3549 $FACEDATA[$idx] = $data;
3550 $FACEHASH{$hash} = $idx;#d# 3632 $HASH{$hash} = $idx;#d#
3551 3633
3552 $idx 3634 $idx
3553} 3635 }
3554 3636
3555our $FACEDATA; # facedata filehandle
3556
3557sub _face_get_data($$$$) { 3637 sub _get_data($$$) {
3558 my ($idx, $size, $fofs, $cb) = @_; 3638 my ($idx, $set, $cb) = @_;
3559 3639
3560 if (defined $FACEDATA[$idx]) { 3640 if (defined $DATA[$set][$idx]) {
3561 $cb->($FACEDATA[$idx]); 3641 $cb->($DATA[$set][$idx]);
3562 } elsif ($fofs) { 3642 } elsif (my $fofs = $FOFS[$set][$idx]) {
3643 my $size = $SIZE[$set][$idx];
3563 my $buf; 3644 my $buf;
3564 IO::AIO::aio_read $FACEDATA, $fofs, $size, $buf, 0, sub { 3645 IO::AIO::aio_read $DATAFH, $fofs, $size, $buf, 0, sub {
3565 if ($_[0] == $size) { 3646 if ($_[0] == $size) {
3566 #cf::debug "read face $idx, $size from $fofs as ", length $buf;#d# 3647 #cf::debug "read face $idx, $size from $fofs as ", length $buf;#d#
3567 $cb->($buf); 3648 $cb->($buf);
3568 } else { 3649 } else {
3569 cf::error "INTERNAL ERROR: unable to read facedata for face $idx ($size, $fofs), ignoring request."; 3650 cf::error "INTERNAL ERROR: unable to read facedata for face $idx#$set ($size, $fofs), ignoring request.";
3651 }
3570 } 3652 };
3653 } else {
3654 cf::error "requested facedata for unknown face $idx#$set, ignoring.";
3655 }
3656 }
3657
3658 # rather ineffient
3659 sub cf::face::get_data($;$) {
3660 my ($idx, $set) = @_;
3661
3662 _get_data $idx, $set, Coro::rouse_cb;
3663 Coro::rouse_wait
3664 }
3665
3666 sub cf::face::ix {
3667 my ($ns, $set, $idx, $pri) = @_;
3668
3669 _get_data $idx, $set, sub {
3670 $ns->ix_send ($idx, $pri, $_[0]);
3571 }; 3671 };
3572 } else {
3573 cf::error "requested facedata for unknown face $idx ($size, $fofs), ignoring.";
3574 }
3575}
3576
3577# rather ineffient
3578sub cf::face::get_data($;$) {
3579 my ($idx, $faceset) = @_;
3580
3581 my $size = cf::face::get_size $idx, $faceset;
3582 my $fofs = cf::face::get_fofs $idx, $faceset;
3583
3584 _face_get_data $idx, $size, $fofs, Coro::rouse_cb;
3585 Coro::rouse_wait
3586}
3587
3588sub cf::face::ix {
3589 my ($ns, $idx, $pri, $size, $fofs) = @_;
3590
3591 _face_get_data $idx, $size, $fofs, sub {
3592 $ns->ix_send ($idx, $pri, $_[0]);
3593 }; 3672 }
3594} 3673}
3595 3674
3596sub load_facedata($) { 3675sub load_facedata($) {
3597 my ($path) = @_; 3676 my ($path) = @_;
3598 3677
3604 3683
3605 $facedata->{version} == 2 3684 $facedata->{version} == 2
3606 or cf::cleanup "$path/faceinfo: version mismatch, cannot proceed."; 3685 or cf::cleanup "$path/faceinfo: version mismatch, cannot proceed.";
3607 3686
3608 my $fh = aio_open "$DATADIR/facedata", IO::AIO::O_RDONLY, 0 3687 my $fh = aio_open "$DATADIR/facedata", IO::AIO::O_RDONLY, 0
3609 or cf::cleanup "$path/facedata: $!, cnanot proceed."; 3688 or cf::cleanup "$path/facedata: $!, cannot proceed.";
3610 3689
3611 get_slot 1, -100, "load_facedata"; # make sure we get a very big slot 3690 get_slot 1, -100, "load_facedata"; # make sure we get a very big slot
3612 3691
3613 # BEGIN ATOMIC 3692 # BEGIN ATOMIC
3614 # from here on, everything must be atomic - no thread switch allowed 3693 # from here on, everything must be atomic - no thread switch allowed
3621 my $info = $faces->{$face}; 3700 my $info = $faces->{$face};
3622 my $idx = (cf::face::find $face) || cf::face::alloc $face; 3701 my $idx = (cf::face::find $face) || cf::face::alloc $face;
3623 3702
3624 cf::face::set_visibility $idx, $info->{visibility}; 3703 cf::face::set_visibility $idx, $info->{visibility};
3625 cf::face::set_magicmap $idx, $info->{magicmap}; 3704 cf::face::set_magicmap $idx, $info->{magicmap};
3626 cf::face::set_data $idx, 0, $info->{size32}, $info->{fofs32}, $info->{hash32}; 3705 cf::face::set_csum $idx, 0, $info->{hash64}; $cf::face::SIZE[0][$idx] = $info->{size64}; $cf::face::FOFS[0][$idx] = $info->{fofs64};
3627 cf::face::set_data $idx, 1, $info->{size64}, $info->{fofs64}, $info->{hash64}; 3706 cf::face::set_csum $idx, 1, $info->{hash32}; $cf::face::SIZE[1][$idx] = $info->{size32}; $cf::face::FOFS[1][$idx] = $info->{fofs32};
3628 #cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; 3707 cf::face::set_csum $idx, 2, $info->{glyph}; $cf::face::DATA[2][$idx] = $info->{glyph};
3629 $FACEHASH{$info->{hash64}} = $idx;#d# 3708 $cf::face::HASH{$info->{hash64}} = $idx;
3709 delete $cf::face::META[$idx];
3630 } 3710 }
3631 3711
3632 while (my ($face, $info) = each %$faces) { 3712 while (my ($face, $info) = each %$faces) {
3633 next unless $info->{smooth}; 3713 next unless $info->{smooth};
3634 3714
3661 if (defined (my $type = $info->{type})) { 3741 if (defined (my $type = $info->{type})) {
3662 # TODO: different hash - must free and use new index, or cache ixface data queue 3742 # TODO: different hash - must free and use new index, or cache ixface data queue
3663 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3743 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3664 3744
3665 cf::face::set_type $idx, $type; 3745 cf::face::set_type $idx, $type;
3666 cf::face::set_data $idx, 0, $info->{size}, $info->{fofs}, $info->{hash}; 3746 cf::face::set_csum $idx, 0, $info->{hash};
3747 $cf::face::SIZE[0][$idx] = $info->{size};
3748 $cf::face::FOFS[0][$idx] = $info->{fofs};
3667 cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already 3749 $cf::face::META[$idx] = $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already
3668 $FACEHASH{$info->{hash}} = $idx;#d# 3750 $cf::face::HASH{$info->{hash}} = $idx;
3669 } else { 3751 } else {
3670# $RESOURCE{$name} = $info; # unused 3752# $RESOURCE{$name} = $info; # unused
3671 } 3753 }
3672 } 3754 }
3673 } 3755 }
3674 3756
3675 ($fh, $FACEDATA) = ($FACEDATA, $fh); 3757 ($fh, $cf::face::DATAFH) = ($cf::face::DATAFH, $fh);
3676 3758
3677 # HACK to clear player env face cache, we need some signal framework 3759 # HACK to clear player env face cache, we need some signal framework
3678 # for this (global event?) 3760 # for this (global event?)
3679 %ext::player_env::MUSIC_FACE_CACHE = (); 3761 %ext::player_env::MUSIC_FACE_CACHE = ();
3680 3762
3708} 3790}
3709 3791
3710sub reload_exp_table { 3792sub reload_exp_table {
3711 _reload_exp_table; 3793 _reload_exp_table;
3712 3794
3795 cf::face::set
3713 set_face "res/exp_table" => FT_RSRC, 3796 "res/exp_table" => FT_RSRC,
3714 JSON::XS->new->utf8->canonical->encode ( 3797 JSON::XS->new->utf8->canonical->encode (
3715 [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level] 3798 [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]
3716 ); 3799 );
3717} 3800}
3718 3801
3719sub reload_materials { 3802sub reload_materials {
3720 _reload_materials; 3803 _reload_materials;
3721} 3804}
3741 3824
3742sub reload_archetypes { 3825sub reload_archetypes {
3743 load_resource_file "$DATADIR/archetypes" 3826 load_resource_file "$DATADIR/archetypes"
3744 or die "unable to load archetypes\n"; 3827 or die "unable to load archetypes\n";
3745 3828
3829 cf::face::set
3746 set_face "res/skill_info" => FT_RSRC, 3830 "res/skill_info" => FT_RSRC,
3747 JSON::XS->new->utf8->canonical->encode ( 3831 JSON::XS->new->utf8->canonical->encode (
3748 [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1] 3832 [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1]
3749 ); 3833 );
3834
3835 cf::face::set
3750 set_face "res/spell_paths" => FT_RSRC, 3836 "res/spell_paths" => FT_RSRC,
3751 JSON::XS->new->utf8->canonical->encode ( 3837 JSON::XS->new->utf8->canonical->encode (
3752 [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1] 3838 [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1]
3753 ); 3839 );
3840
3841 # command completion
3842 my @commands;
3843
3844 for (0..cf::arch::skillvec_size - 1) {
3845 my $skill = cf::arch::skillvec $_;
3846 my $name = $skill->name;
3847 my $flags = cf::skill_flags $skill->subtype;
3848
3849 push @commands, "ready_skill $name" if $flags & (SF_COMBAT | SF_RANGED | SF_GRACE);
3850 push @commands, "use_skill $name" if $flags & (SF_USE | SF_AUTARK | SF_GRACE);
3851 }
3852
3853 cf::client::set_command_face skill => \@commands;
3754} 3854}
3755 3855
3756sub reload_treasures { 3856sub reload_treasures {
3757 load_resource_file "$DATADIR/treasures" 3857 load_resource_file "$DATADIR/treasures"
3758 or die "unable to load treasurelists\n"; 3858 or die "unable to load treasurelists\n";
3831 seek $fh, 0, 0; 3931 seek $fh, 0, 0;
3832 print $fh $$; 3932 print $fh $$;
3833} 3933}
3834 3934
3835sub main_loop { 3935sub main_loop {
3836 trace "EV::loop starting\n"; 3936 trace "EV::run starting\n";
3837 if (1) { 3937 if (1) {
3838 EV::loop; 3938 EV::run;
3839 } 3939 }
3840 trace "EV::loop returned\n"; 3940 trace "EV::run returned\n";
3841 goto &main_loop unless $REALLY_UNLOOP; 3941 goto &main_loop unless $REALLY_UNLOOP;
3842} 3942}
3843 3943
3844sub main { 3944sub main {
3845 cf::init_globals; # initialise logging 3945 cf::init_globals; # initialise logging
3846 3946
3847 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3947 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3948 LOG llevInfo, "Copyright (C) 2017-2018 Marc Alexander Lehmann / the Deliantra team.";
3848 LOG llevInfo, "Copyright (C) 2005-2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3949 LOG llevInfo, "Copyright (C) 2005-2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3849 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3950 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3850 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3951 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3851 3952
3852 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3953 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3853 3954
3854 # we must not ever block the main coroutine 3955 # we must not ever block the main coroutine
3855 $Coro::idle = sub { 3956 $Coro::idle = sub {
3856 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3957 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3857 (async { 3958 (async {
3858 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3959 $Coro::current->{desc} = "IDLE BUG HANDLER";
3859 EV::loop EV::LOOP_ONESHOT; 3960 EV::run EV::RUN_ONCE;
3860 })->prio (Coro::PRIO_MAX); 3961 })->prio (Coro::PRIO_MAX);
3861 }; 3962 };
3862 3963
3863 evthread_start IO::AIO::poll_fileno; 3964 evthread_start IO::AIO::poll_fileno;
3864 3965

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines