… | |
… | |
9 | use Event; |
9 | use Event; |
10 | use Opcode; |
10 | use Opcode; |
11 | use Safe; |
11 | use Safe; |
12 | use Safe::Hole; |
12 | use Safe::Hole; |
13 | |
13 | |
14 | use Coro 3.52 (); |
14 | use Coro 3.61 (); |
15 | use Coro::State; |
15 | use Coro::State; |
16 | use Coro::Event; |
16 | use Coro::Event; |
17 | use Coro::Timer; |
17 | use Coro::Timer; |
18 | use Coro::Signal; |
18 | use Coro::Signal; |
19 | use Coro::Semaphore; |
19 | use Coro::Semaphore; |
20 | use Coro::AIO; |
20 | use Coro::AIO; |
|
|
21 | use Coro::Storable; |
21 | |
22 | |
22 | use BDB (); |
23 | use BDB (); |
23 | use Data::Dumper; |
24 | use Data::Dumper; |
24 | use Digest::MD5; |
25 | use Digest::MD5; |
25 | use Fcntl; |
26 | use Fcntl; |
… | |
… | |
28 | use Time::HiRes; |
29 | use Time::HiRes; |
29 | use Compress::LZF; |
30 | use Compress::LZF; |
30 | |
31 | |
31 | # configure various modules to our taste |
32 | # configure various modules to our taste |
32 | # |
33 | # |
|
|
34 | $Storable::canonical = 1; # reduce rsync transfers |
33 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
35 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
34 | Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later |
36 | Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later |
35 | |
37 | |
36 | $Event::Eval = 1; # no idea why this is required, but it is |
38 | $Event::Eval = 1; # no idea why this is required, but it is |
37 | |
39 | |
… | |
… | |
52 | |
54 | |
53 | our $RELOAD; # number of reloads so far |
55 | our $RELOAD; # number of reloads so far |
54 | our @EVENT; |
56 | our @EVENT; |
55 | our $LIBDIR = datadir . "/ext"; |
57 | our $LIBDIR = datadir . "/ext"; |
56 | |
58 | |
57 | our $TICK = MAX_TIME * 1e-6; |
59 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
58 | our $TICK_WATCHER; |
60 | our $TICK_WATCHER; |
59 | our $AIO_POLL_WATCHER; |
61 | our $AIO_POLL_WATCHER; |
60 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
62 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
61 | our $NEXT_TICK; |
63 | our $NEXT_TICK; |
62 | our $NOW; |
64 | our $NOW; |
… | |
… | |
74 | our %MAP; # all maps |
76 | our %MAP; # all maps |
75 | our $LINK_MAP; # the special {link} map, which is always available |
77 | our $LINK_MAP; # the special {link} map, which is always available |
76 | our $RANDOM_MAPS = cf::localdir . "/random"; |
78 | our $RANDOM_MAPS = cf::localdir . "/random"; |
77 | our $BDB_ENV_DIR = cf::localdir . "/db"; |
79 | our $BDB_ENV_DIR = cf::localdir . "/db"; |
78 | |
80 | |
79 | our $WAIT_FOR_TICK; $WAIT_FOR_TICK ||= new Coro::Signal; |
|
|
80 | our $WAIT_FOR_TICK_ONE; $WAIT_FOR_TICK_ONE ||= new Coro::Signal; |
|
|
81 | |
|
|
82 | # used to convert map paths into valid unix filenames by replacing / by ∕ |
81 | # used to convert map paths into valid unix filenames by replacing / by ∕ |
83 | our $PATH_SEP = "∕"; # U+2215, chosen purely for visual reasons |
82 | our $PATH_SEP = "∕"; # U+2215, chosen purely for visual reasons |
84 | |
83 | |
85 | binmode STDOUT; |
84 | binmode STDOUT; |
86 | binmode STDERR; |
85 | binmode STDERR; |
… | |
… | |
134 | =item %cf::CFG |
133 | =item %cf::CFG |
135 | |
134 | |
136 | Configuration for the server, loaded from C</etc/crossfire/config>, or |
135 | Configuration for the server, loaded from C</etc/crossfire/config>, or |
137 | from wherever your confdir points to. |
136 | from wherever your confdir points to. |
138 | |
137 | |
139 | =item $cf::WAIT_FOR_TICK, $cf::WAIT_FOR_TICK_ONE |
138 | =item cf::wait_for_tick, cf::wait_for_tick_begin |
140 | |
139 | |
141 | These are Coro::Signal objects that are C<< ->broadcast >> (WAIT_FOR_TICK) |
140 | These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only |
142 | or C<< ->send >> (WAIT_FOR_TICK_ONE) on after normal server tick |
141 | returns directly I<after> the tick processing (and consequently, can only wake one process |
143 | processing has been done. Call C<< ->wait >> on them to maximise the |
142 | per tick), while cf::wait_for_tick wakes up all waiters after tick processing. |
144 | window of cpu time available, or simply to synchronise to the server tick. |
|
|
145 | |
143 | |
146 | =back |
144 | =back |
147 | |
145 | |
148 | =cut |
146 | =cut |
149 | |
147 | |
… | |
… | |
1157 | my ($self, $type, %msg) = @_; |
1155 | my ($self, $type, %msg) = @_; |
1158 | |
1156 | |
1159 | $self->ns->ext_event ($type, %msg); |
1157 | $self->ns->ext_event ($type, %msg); |
1160 | } |
1158 | } |
1161 | |
1159 | |
1162 | package cf; |
1160 | =head3 cf::region |
|
|
1161 | |
|
|
1162 | =over 4 |
|
|
1163 | |
|
|
1164 | =cut |
|
|
1165 | |
|
|
1166 | package cf::region; |
|
|
1167 | |
|
|
1168 | =item cf::region::find_by_path $path |
|
|
1169 | |
|
|
1170 | Tries to decuce the probable region for a map knowing only its path. |
|
|
1171 | |
|
|
1172 | =cut |
|
|
1173 | |
|
|
1174 | sub find_by_path($) { |
|
|
1175 | my ($path) = @_; |
|
|
1176 | |
|
|
1177 | my ($match, $specificity); |
|
|
1178 | |
|
|
1179 | for my $region (list) { |
|
|
1180 | if ($region->match && $path =~ $region->match) { |
|
|
1181 | ($match, $specificity) = ($region, $region->specificity) |
|
|
1182 | if $region->specificity > $specificity; |
|
|
1183 | } |
|
|
1184 | } |
|
|
1185 | |
|
|
1186 | $match |
|
|
1187 | } |
1163 | |
1188 | |
1164 | =back |
1189 | =back |
1165 | |
|
|
1166 | |
1190 | |
1167 | =head3 cf::map |
1191 | =head3 cf::map |
1168 | |
1192 | |
1169 | =over 4 |
1193 | =over 4 |
1170 | |
1194 | |
… | |
… | |
1401 | $self->load_header_orig |
1425 | $self->load_header_orig |
1402 | or return; |
1426 | or return; |
1403 | $self->prepare_orig; |
1427 | $self->prepare_orig; |
1404 | } |
1428 | } |
1405 | |
1429 | |
|
|
1430 | $self->default_region (cf::region::find_by_path $self->{path}) |
|
|
1431 | unless $self->default_region; |
|
|
1432 | |
1406 | 1 |
1433 | 1 |
1407 | } |
1434 | } |
1408 | |
1435 | |
1409 | sub find; |
1436 | sub find; |
1410 | sub find { |
1437 | sub find { |
… | |
… | |
1452 | $self->in_memory (cf::MAP_LOADING); |
1479 | $self->in_memory (cf::MAP_LOADING); |
1453 | |
1480 | |
1454 | $self->alloc; |
1481 | $self->alloc; |
1455 | |
1482 | |
1456 | $self->pre_load; |
1483 | $self->pre_load; |
|
|
1484 | Coro::cede; |
1457 | |
1485 | |
1458 | $self->_load_objects ($self->{load_path}, 1) |
1486 | $self->_load_objects ($self->{load_path}, 1) |
1459 | or return; |
1487 | or return; |
1460 | |
1488 | |
1461 | $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) |
1489 | $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) |
… | |
… | |
1468 | $self->_load_objects ($uniq, 0); |
1496 | $self->_load_objects ($uniq, 0); |
1469 | } |
1497 | } |
1470 | } |
1498 | } |
1471 | |
1499 | |
1472 | Coro::cede; |
1500 | Coro::cede; |
1473 | |
|
|
1474 | # now do the right thing for maps |
1501 | # now do the right thing for maps |
1475 | $self->link_multipart_objects; |
1502 | $self->link_multipart_objects; |
|
|
1503 | Coro::cede; |
1476 | |
1504 | |
1477 | unless ($self->{deny_activate}) { |
1505 | unless ($self->{deny_activate}) { |
1478 | $self->decay_objects; |
1506 | $self->decay_objects; |
1479 | $self->fix_auto_apply; |
1507 | $self->fix_auto_apply; |
1480 | $self->update_buttons; |
1508 | $self->update_buttons; |
… | |
… | |
1482 | $self->set_darkness_map; |
1510 | $self->set_darkness_map; |
1483 | $self->difficulty ($self->estimate_difficulty) |
1511 | $self->difficulty ($self->estimate_difficulty) |
1484 | unless $self->difficulty; |
1512 | unless $self->difficulty; |
1485 | Coro::cede; |
1513 | Coro::cede; |
1486 | $self->activate; |
1514 | $self->activate; |
|
|
1515 | Coro::cede; |
1487 | } |
1516 | } |
1488 | |
1517 | |
1489 | $self->post_load; |
1518 | $self->post_load; |
|
|
1519 | Coro::cede; |
1490 | |
1520 | |
1491 | $self->in_memory (cf::MAP_IN_MEMORY); |
1521 | $self->in_memory (cf::MAP_IN_MEMORY); |
1492 | } |
1522 | } |
1493 | |
1523 | |
1494 | sub customise_for { |
1524 | sub customise_for { |
… | |
… | |
2299 | sub db_put($$$) { |
2329 | sub db_put($$$) { |
2300 | BDB::dbreq_pri 4; |
2330 | BDB::dbreq_pri 4; |
2301 | BDB::db_put $DB, undef, "$_[0]/$_[1]", Compress::LZF::sfreeze_cr $_[2], 0, sub { }; |
2331 | BDB::db_put $DB, undef, "$_[0]/$_[1]", Compress::LZF::sfreeze_cr $_[2], 0, sub { }; |
2302 | } |
2332 | } |
2303 | |
2333 | |
|
|
2334 | =item cf::cache $id => ... |
|
|
2335 | |
|
|
2336 | Generic caching function that returns the value of the resource $id, |
|
|
2337 | caching and regenerating as required. |
|
|
2338 | |
|
|
2339 | This function can block. |
|
|
2340 | |
|
|
2341 | source => filename returning the data (must be a scalar) |
|
|
2342 | expensive => true == try to cache harder |
|
|
2343 | filter => sub that processes the data into a scalar |
|
|
2344 | |
|
|
2345 | =cut |
|
|
2346 | |
|
|
2347 | sub cache { |
|
|
2348 | my ($id, %arg) = @_; |
|
|
2349 | |
|
|
2350 | aio_stat $arg{source} |
|
|
2351 | and Carp::croak "$arg{source}: $!"; |
|
|
2352 | |
|
|
2353 | my $meta = join ":", (stat _)[7,9]; |
|
|
2354 | my $md5; |
|
|
2355 | |
|
|
2356 | if ($arg{expensive}) { |
|
|
2357 | 0 <= aio_load $arg{source}, my $buf |
|
|
2358 | or Carp::croak "$arg{source}: $!"; |
|
|
2359 | |
|
|
2360 | $md5 = Digest::MD5::md5_hex $buf; |
|
|
2361 | } |
|
|
2362 | |
|
|
2363 | my $dbmeta = db_get "$id/meta"; |
|
|
2364 | if ($dbmeta ne $meta) { |
|
|
2365 | # changed, we need to process |
|
|
2366 | } else { |
|
|
2367 | # just fetch |
|
|
2368 | } |
|
|
2369 | |
|
|
2370 | |
|
|
2371 | } |
|
|
2372 | |
2304 | ############################################################################# |
2373 | ############################################################################# |
2305 | # the server's init and main functions |
2374 | # the server's init and main functions |
2306 | |
2375 | |
2307 | sub load_facedata { |
2376 | sub load_facedata($) { |
2308 | my $path = sprintf "%s/facedata", cf::datadir; |
2377 | my ($path) = @_; |
2309 | |
2378 | |
2310 | warn "loading facedata from $path\n"; |
2379 | warn "loading facedata from $path\n"; |
2311 | |
2380 | |
2312 | my $faces; |
2381 | my $facedata; |
2313 | 0 < aio_load $path, $faces |
2382 | 0 < aio_load $path, $facedata |
2314 | or die "$path: $!"; |
2383 | or die "$path: $!"; |
2315 | |
2384 | |
2316 | Coro::cede; |
|
|
2317 | $faces = Storable::thaw $faces; |
2385 | $facedata = Coro::Storable::thaw $facedata; |
2318 | Coro::cede; |
|
|
2319 | |
2386 | |
2320 | my $meta = delete $faces->{""}; |
|
|
2321 | $meta->{version} == 1 |
2387 | $facedata->{version} == 2 |
2322 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
2388 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
2323 | |
2389 | |
|
|
2390 | { |
|
|
2391 | my $faces = $facedata->{faceinfo}; |
|
|
2392 | |
2324 | while (my ($face, $info) = each %$faces) { |
2393 | while (my ($face, $info) = each %$faces) { |
2325 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2394 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2326 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
2395 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
2327 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
2396 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
2328 | cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; |
2397 | cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; |
2329 | Coro::cede; |
2398 | Coro::cede; |
2330 | } |
2399 | } |
2331 | |
2400 | |
2332 | while (my ($face, $info) = each %$faces) { |
2401 | while (my ($face, $info) = each %$faces) { |
2333 | next unless $info->{smooth}; |
2402 | next unless $info->{smooth}; |
2334 | my $idx = cf::face::find $face |
2403 | my $idx = cf::face::find $face |
2335 | or next; |
2404 | or next; |
2336 | if (my $smooth = cf::face::find $info->{smooth}) { |
2405 | if (my $smooth = cf::face::find $info->{smooth}) { |
2337 | cf::face::set_smooth $idx, $smooth, $info->{smoothlevel}; |
2406 | cf::face::set_smooth $idx, $smooth, $info->{smoothlevel}; |
2338 | } else { |
2407 | } else { |
2339 | warn "smooth face '$info->{smooth}' not found for face '$face'"; |
2408 | warn "smooth face '$info->{smooth}' not found for face '$face'"; |
2340 | } |
2409 | } |
2341 | Coro::cede; |
2410 | Coro::cede; |
|
|
2411 | } |
|
|
2412 | } |
|
|
2413 | |
|
|
2414 | { |
|
|
2415 | my $anims = $facedata->{animinfo}; |
|
|
2416 | |
|
|
2417 | while (my ($anim, $info) = each %$anims) { |
|
|
2418 | cf::anim::set $anim, $info->{frames}, $info->{facings}; |
|
|
2419 | Coro::cede; |
|
|
2420 | } |
|
|
2421 | |
|
|
2422 | cf::anim::invalidate_all; # d'oh |
2342 | } |
2423 | } |
2343 | |
2424 | |
2344 | 1 |
2425 | 1 |
2345 | } |
2426 | } |
2346 | |
2427 | |
|
|
2428 | sub reload_facedata { |
|
|
2429 | load_facedata sprintf "%s/facedata", cf::datadir |
|
|
2430 | or die "unable to load facedata\n"; |
|
|
2431 | } |
|
|
2432 | |
|
|
2433 | sub reload_regions { |
|
|
2434 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
|
|
2435 | or die "unable to load regions file\n"; |
|
|
2436 | } |
|
|
2437 | |
|
|
2438 | sub reload_archetypes { |
|
|
2439 | load_resource_file sprintf "%s/archetypes", cf::datadir |
|
|
2440 | or die "unable to load archetypes\n"; |
|
|
2441 | } |
|
|
2442 | |
|
|
2443 | sub reload_treasures { |
|
|
2444 | load_resource_file sprintf "%s/treasures", cf::datadir |
|
|
2445 | or die "unable to load treasurelists\n"; |
|
|
2446 | } |
|
|
2447 | |
2347 | sub reload_resources { |
2448 | sub reload_resources { |
2348 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2449 | warn "reloading resource files...\n"; |
2349 | or die "unable to load regions file\n";#d# |
2450 | |
|
|
2451 | reload_regions; |
2350 | load_facedata |
2452 | reload_facedata; |
2351 | or die "unable to load facedata\n";#d# |
2453 | reload_archetypes; |
|
|
2454 | reload_treasures; |
|
|
2455 | |
|
|
2456 | warn "finished reloading resource files\n"; |
2352 | } |
2457 | } |
2353 | |
2458 | |
2354 | sub init { |
2459 | sub init { |
2355 | reload_resources; |
2460 | reload_resources; |
2356 | } |
2461 | } |
… | |
… | |
2449 | |
2554 | |
2450 | warn Carp::longmess "post_cleanup backtrace" |
2555 | warn Carp::longmess "post_cleanup backtrace" |
2451 | if $make_core; |
2556 | if $make_core; |
2452 | } |
2557 | } |
2453 | |
2558 | |
2454 | sub reload() { |
2559 | sub do_reload_perl() { |
2455 | # can/must only be called in main |
2560 | # can/must only be called in main |
2456 | if ($Coro::current != $Coro::main) { |
2561 | if ($Coro::current != $Coro::main) { |
2457 | warn "can only reload from main coroutine"; |
2562 | warn "can only reload from main coroutine"; |
2458 | return; |
2563 | return; |
2459 | } |
2564 | } |
… | |
… | |
2558 | warn "reattaching attachments to maps"; |
2663 | warn "reattaching attachments to maps"; |
2559 | reattach $_ for values %MAP; |
2664 | reattach $_ for values %MAP; |
2560 | warn "reattaching attachments to players"; |
2665 | warn "reattaching attachments to players"; |
2561 | reattach $_ for values %PLAYER; |
2666 | reattach $_ for values %PLAYER; |
2562 | |
2667 | |
2563 | warn "loading reloadable resources"; |
|
|
2564 | reload_resources; |
|
|
2565 | |
|
|
2566 | warn "leaving sync_job"; |
2668 | warn "leaving sync_job"; |
2567 | |
2669 | |
2568 | 1 |
2670 | 1 |
2569 | } or do { |
2671 | } or do { |
2570 | warn $@; |
2672 | warn $@; |
… | |
… | |
2575 | warn "reloaded"; |
2677 | warn "reloaded"; |
2576 | }; |
2678 | }; |
2577 | |
2679 | |
2578 | our $RELOAD_WATCHER; # used only during reload |
2680 | our $RELOAD_WATCHER; # used only during reload |
2579 | |
2681 | |
|
|
2682 | sub reload_perl() { |
|
|
2683 | # doing reload synchronously and two reloads happen back-to-back, |
|
|
2684 | # coro crashes during coro_state_free->destroy here. |
|
|
2685 | |
|
|
2686 | $RELOAD_WATCHER ||= Event->timer ( |
|
|
2687 | reentrant => 0, |
|
|
2688 | after => 0, |
|
|
2689 | data => WF_AUTOCANCEL, |
|
|
2690 | cb => sub { |
|
|
2691 | do_reload_perl; |
|
|
2692 | undef $RELOAD_WATCHER; |
|
|
2693 | }, |
|
|
2694 | ); |
|
|
2695 | } |
|
|
2696 | |
2580 | register_command "reload" => sub { |
2697 | register_command "reload" => sub { |
2581 | my ($who, $arg) = @_; |
2698 | my ($who, $arg) = @_; |
2582 | |
2699 | |
2583 | if ($who->flag (FLAG_WIZ)) { |
2700 | if ($who->flag (FLAG_WIZ)) { |
2584 | $who->message ("reloading server."); |
2701 | $who->message ("reloading server."); |
2585 | |
2702 | async { reload_perl }; |
2586 | # doing reload synchronously and two reloads happen back-to-back, |
|
|
2587 | # coro crashes during coro_state_free->destroy here. |
|
|
2588 | |
|
|
2589 | $RELOAD_WATCHER ||= Event->timer ( |
|
|
2590 | reentrant => 0, |
|
|
2591 | after => 0, |
|
|
2592 | data => WF_AUTOCANCEL, |
|
|
2593 | cb => sub { |
|
|
2594 | reload; |
|
|
2595 | undef $RELOAD_WATCHER; |
|
|
2596 | }, |
|
|
2597 | ); |
|
|
2598 | } |
2703 | } |
2599 | }; |
2704 | }; |
2600 | |
2705 | |
2601 | unshift @INC, $LIBDIR; |
2706 | unshift @INC, $LIBDIR; |
2602 | |
2707 | |
2603 | my $bug_warning = 0; |
2708 | my $bug_warning = 0; |
|
|
2709 | |
|
|
2710 | our @WAIT_FOR_TICK; |
|
|
2711 | our @WAIT_FOR_TICK_BEGIN; |
|
|
2712 | |
|
|
2713 | sub wait_for_tick { |
|
|
2714 | return unless $TICK_WATCHER->is_active; |
|
|
2715 | return if $Coro::current == $Coro::main; |
|
|
2716 | |
|
|
2717 | my $signal = new Coro::Signal; |
|
|
2718 | push @WAIT_FOR_TICK, $signal; |
|
|
2719 | $signal->wait; |
|
|
2720 | } |
|
|
2721 | |
|
|
2722 | sub wait_for_tick_begin { |
|
|
2723 | return unless $TICK_WATCHER->is_active; |
|
|
2724 | return if $Coro::current == $Coro::main; |
|
|
2725 | |
|
|
2726 | my $signal = new Coro::Signal; |
|
|
2727 | push @WAIT_FOR_TICK_BEGIN, $signal; |
|
|
2728 | $signal->wait; |
|
|
2729 | } |
2604 | |
2730 | |
2605 | $TICK_WATCHER = Event->timer ( |
2731 | $TICK_WATCHER = Event->timer ( |
2606 | reentrant => 0, |
2732 | reentrant => 0, |
2607 | parked => 1, |
2733 | parked => 1, |
2608 | prio => 0, |
2734 | prio => 0, |
… | |
… | |
2616 | } |
2742 | } |
2617 | |
2743 | |
2618 | $NOW = Event::time; |
2744 | $NOW = Event::time; |
2619 | |
2745 | |
2620 | cf::server_tick; # one server iteration |
2746 | cf::server_tick; # one server iteration |
|
|
2747 | |
2621 | $RUNTIME += $TICK; |
2748 | $RUNTIME += $TICK; |
2622 | $NEXT_TICK += $TICK; |
2749 | $NEXT_TICK += $TICK; |
2623 | |
2750 | |
2624 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
2751 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
2625 | $NEXT_RUNTIME_WRITE = $NOW + 10; |
2752 | $NEXT_RUNTIME_WRITE = $NOW + 10; |
… | |
… | |
2627 | write_runtime |
2754 | write_runtime |
2628 | or warn "ERROR: unable to write runtime file: $!"; |
2755 | or warn "ERROR: unable to write runtime file: $!"; |
2629 | }; |
2756 | }; |
2630 | } |
2757 | } |
2631 | |
2758 | |
2632 | $WAIT_FOR_TICK->broadcast; |
|
|
2633 | $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; |
|
|
2634 | |
|
|
2635 | # my $AFTER = Event::time; |
2759 | # my $AFTER = Event::time; |
2636 | # warn $AFTER - $NOW;#d# |
2760 | # warn $AFTER - $NOW;#d# |
2637 | |
2761 | |
2638 | # if we are delayed by four ticks or more, skip them all |
2762 | # if we are delayed by four ticks or more, skip them all |
2639 | $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4; |
2763 | $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4; |
2640 | |
2764 | |
2641 | $TICK_WATCHER->at ($NEXT_TICK); |
2765 | $TICK_WATCHER->at ($NEXT_TICK); |
2642 | $TICK_WATCHER->start; |
2766 | $TICK_WATCHER->start; |
|
|
2767 | |
|
|
2768 | if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { |
|
|
2769 | $sig->send; |
|
|
2770 | } |
|
|
2771 | while (my $sig = shift @WAIT_FOR_TICK) { |
|
|
2772 | $sig->send; |
|
|
2773 | } |
|
|
2774 | |
|
|
2775 | _post_tick; |
2643 | }, |
2776 | }, |
2644 | ); |
2777 | ); |
2645 | |
2778 | |
2646 | { |
2779 | { |
2647 | BDB::max_poll_time $TICK * 0.1; |
2780 | BDB::max_poll_time $TICK * 0.1; |
… | |
… | |
2706 | prio => 6, |
2839 | prio => 6, |
2707 | cb => \&IO::AIO::poll_cb, |
2840 | cb => \&IO::AIO::poll_cb, |
2708 | ); |
2841 | ); |
2709 | } |
2842 | } |
2710 | |
2843 | |
|
|
2844 | # load additional modules |
|
|
2845 | use cf::pod; |
|
|
2846 | |
2711 | END { cf::emergency_save } |
2847 | END { cf::emergency_save } |
2712 | |
2848 | |
2713 | 1 |
2849 | 1 |
2714 | |
2850 | |