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.617 by root, Mon Aug 10 18:46:04 2015 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,
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
2384 2400
2385 $MAP_PREFETCHER ||= cf::async { 2401 $MAP_PREFETCHER ||= cf::async {
2386 $Coro::current->{desc} = "map prefetcher"; 2402 $Coro::current->{desc} = "map prefetcher";
2387 2403
2388 while (%MAP_PREFETCH) { 2404 while (%MAP_PREFETCH) {
2389 while (my ($k, $v) = each %MAP_PREFETCH) { 2405 for my $k (keys %MAP_PREFETCH) {
2390 if (my $map = find $k) { 2406 if (my $map = find $k) {
2391 $map->load if $v; 2407 $map->load if $MAP_PREFETCH{$k};
2392 } 2408 }
2393 2409
2394 delete $MAP_PREFETCH{$k}; 2410 delete $MAP_PREFETCH{$k};
2395 } 2411 }
2396 } 2412 }
3155 }, 3171 },
3156 "c/body" => { 3172 "c/body" => {
3157 id => "infobox", 3173 id => "infobox",
3158 title => "Body Parts", 3174 title => "Body Parts",
3159 reply => undef, 3175 reply => undef,
3160 tooltip => "Shows which body parts you posess and are available", 3176 tooltip => "Shows which body parts you possess and are available",
3161 }, 3177 },
3162 "c/statistics" => { 3178 "c/statistics" => {
3163 id => "infobox", 3179 id => "infobox",
3164 title => "Statistics", 3180 title => "Statistics",
3165 reply => undef, 3181 reply => undef,
3927 3943
3928sub main { 3944sub main {
3929 cf::init_globals; # initialise logging 3945 cf::init_globals; # initialise logging
3930 3946
3931 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.";
3932 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.";
3933 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3950 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3934 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3951 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3935 3952
3936 $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
3937 3954
3938 # we must not ever block the main coroutine 3955 # we must not ever block the main coroutine
3939 $Coro::idle = sub { 3956 $Coro::idle = sub {
3940 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#
3941 (async { 3958 (async {
3942 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3959 $Coro::current->{desc} = "IDLE BUG HANDLER";
3943 EV::run EV::RUN_ONESHOT; 3960 EV::run EV::RUN_ONCE;
3944 })->prio (Coro::PRIO_MAX); 3961 })->prio (Coro::PRIO_MAX);
3945 }; 3962 };
3946 3963
3947 evthread_start IO::AIO::poll_fileno; 3964 evthread_start IO::AIO::poll_fileno;
3948 3965

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines