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.618 by root, Mon Aug 10 18:48:41 2015 UTC vs.
Revision 1.623 by root, Wed Aug 30 14:18:51 2017 UTC

57use JSON::XS 2.01 (); 57use JSON::XS 2.01 ();
58use BDB (); 58use BDB ();
59use Data::Dumper; 59use Data::Dumper;
60use Fcntl; 60use Fcntl;
61use YAML::XS (); 61use YAML::XS ();
62use CBOR::XS ();
62use IO::AIO (); 63use IO::AIO ();
63use Compress::LZF; 64use Compress::LZF;
64use Digest::MD5 (); 65use Digest::MD5 ();
65 66
66AnyEvent::detect; 67AnyEvent::detect;
225=item $cf::RUNTIME 226=item $cf::RUNTIME
226 227
227The time this server has run, starts at 0 and is increased by $cf::TICK on 228The time this server has run, starts at 0 and is increased by $cf::TICK on
228every server tick. 229every server tick.
229 230
230=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR 231=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR
231$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR 232$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR
232$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR 233$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR
233 234
234Various directories - "/etc", read-only install directory, perl-library 235Various directories - "/etc", read-only install directory, perl-library
235directory, pod-directory, read-only maps directory, "/var", "/var/tmp", 236directory, pod-directory, read-only maps directory, "/var", "/var/tmp",
464 465
465sub decode_yaml($) { 466sub decode_yaml($) {
466 fork_call { YAML::XS::Load $_[0] } @_ 467 fork_call { YAML::XS::Load $_[0] } @_
467} 468}
468 469
470=item $scalar = cf::decode_cbor $scalar
471
472Same as CBOR::XS::decode_cbor, but takes server ticks into account, so
473blocks. For small amounts of data, C<CBOR::XS::decode_cbor> is the better
474alternative.
475
476=cut
477
478sub decode_cbor($) {
479 # we assume 10mb/s minimum decoding speed (on a ~2ghz machine)
480 cf::get_slot +(length $_[0]) / 10_000_000, 0, "decode_cbor";
481 CBOR::XS::decode_cbor $_[0]
482}
483
469=item $scalar = cf::unlzf $scalar 484=item $scalar = cf::unlzf $scalar
470 485
471Same as Compress::LZF::compress, but takes server ticks into account, so 486Same as Compress::LZF::compress, but takes server ticks into account, so
472blocks. 487blocks.
473 488
510 } 525 }
511} 526}
512 527
513=item cf::lock_wait $string 528=item cf::lock_wait $string
514 529
515Wait until the given lock is available. See cf::lock_acquire. 530Wait until the given lock is available. See cf::lock_acquire.
516 531
517=item my $lock = cf::lock_acquire $string 532=item my $lock = cf::lock_acquire $string
518 533
519Wait until the given lock is available and then acquires it and returns 534Wait 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, 535a L<Guard> object. If the guard object gets destroyed (goes out of scope,
649BEGIN { *async = \&Coro::async_pool } 664BEGIN { *async = \&Coro::async_pool }
650 665
651=item cf::sync_job { BLOCK } 666=item cf::sync_job { BLOCK }
652 667
653The design of Deliantra requires that the main coroutine ($Coro::main) 668The design of Deliantra requires that the main coroutine ($Coro::main)
654is always able to handle events or runnable, as Deliantra is only 669is 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 670partly reentrant. Thus "blocking" it by e.g. waiting for I/O is not
656acceptable. 671acceptable.
657 672
658If it must be done, put the blocking parts into C<sync_job>. This will run 673If 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 674the given BLOCK in another coroutine while waiting for the result. The
2384 2399
2385 $MAP_PREFETCHER ||= cf::async { 2400 $MAP_PREFETCHER ||= cf::async {
2386 $Coro::current->{desc} = "map prefetcher"; 2401 $Coro::current->{desc} = "map prefetcher";
2387 2402
2388 while (%MAP_PREFETCH) { 2403 while (%MAP_PREFETCH) {
2389 while (my ($k, $v) = each %MAP_PREFETCH) { 2404 for my $k (keys %MAP_PREFETCH) {
2390 if (my $map = find $k) { 2405 if (my $map = find $k) {
2391 $map->load if $v; 2406 $map->load if $MAP_PREFETCH{$k};
2392 } 2407 }
2393 2408
2394 delete $MAP_PREFETCH{$k}; 2409 delete $MAP_PREFETCH{$k};
2395 } 2410 }
2396 } 2411 }
3155 }, 3170 },
3156 "c/body" => { 3171 "c/body" => {
3157 id => "infobox", 3172 id => "infobox",
3158 title => "Body Parts", 3173 title => "Body Parts",
3159 reply => undef, 3174 reply => undef,
3160 tooltip => "Shows which body parts you posess and are available", 3175 tooltip => "Shows which body parts you possess and are available",
3161 }, 3176 },
3162 "c/statistics" => { 3177 "c/statistics" => {
3163 id => "infobox", 3178 id => "infobox",
3164 title => "Statistics", 3179 title => "Statistics",
3165 reply => undef, 3180 reply => undef,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines