… | |
… | |
76 | our %MAP; # all maps |
76 | our %MAP; # all maps |
77 | our $LINK_MAP; # the special {link} map, which is always available |
77 | our $LINK_MAP; # the special {link} map, which is always available |
78 | our $RANDOM_MAPS = cf::localdir . "/random"; |
78 | our $RANDOM_MAPS = cf::localdir . "/random"; |
79 | our $BDB_ENV_DIR = cf::localdir . "/db"; |
79 | our $BDB_ENV_DIR = cf::localdir . "/db"; |
80 | |
80 | |
81 | our $WAIT_FOR_TICK; $WAIT_FOR_TICK ||= new Coro::Signal; |
|
|
82 | our $WAIT_FOR_TICK_ONE; $WAIT_FOR_TICK_ONE ||= new Coro::Signal; |
|
|
83 | |
|
|
84 | # 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 ∕ |
85 | our $PATH_SEP = "∕"; # U+2215, chosen purely for visual reasons |
82 | our $PATH_SEP = "∕"; # U+2215, chosen purely for visual reasons |
86 | |
83 | |
87 | binmode STDOUT; |
84 | binmode STDOUT; |
88 | binmode STDERR; |
85 | binmode STDERR; |
… | |
… | |
136 | =item %cf::CFG |
133 | =item %cf::CFG |
137 | |
134 | |
138 | Configuration for the server, loaded from C</etc/crossfire/config>, or |
135 | Configuration for the server, loaded from C</etc/crossfire/config>, or |
139 | from wherever your confdir points to. |
136 | from wherever your confdir points to. |
140 | |
137 | |
141 | =item $cf::WAIT_FOR_TICK, $cf::WAIT_FOR_TICK_ONE |
138 | =item cf::wait_for_tick, cf::wait_for_tick_begin |
142 | |
139 | |
143 | 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 |
144 | 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 |
145 | 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. |
146 | window of cpu time available, or simply to synchronise to the server tick. |
|
|
147 | |
143 | |
148 | =back |
144 | =back |
149 | |
145 | |
150 | =cut |
146 | =cut |
151 | |
147 | |
… | |
… | |
1483 | $self->in_memory (cf::MAP_LOADING); |
1479 | $self->in_memory (cf::MAP_LOADING); |
1484 | |
1480 | |
1485 | $self->alloc; |
1481 | $self->alloc; |
1486 | |
1482 | |
1487 | $self->pre_load; |
1483 | $self->pre_load; |
|
|
1484 | Coro::cede; |
1488 | |
1485 | |
1489 | $self->_load_objects ($self->{load_path}, 1) |
1486 | $self->_load_objects ($self->{load_path}, 1) |
1490 | or return; |
1487 | or return; |
1491 | |
1488 | |
1492 | $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) |
1489 | $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) |
… | |
… | |
1499 | $self->_load_objects ($uniq, 0); |
1496 | $self->_load_objects ($uniq, 0); |
1500 | } |
1497 | } |
1501 | } |
1498 | } |
1502 | |
1499 | |
1503 | Coro::cede; |
1500 | Coro::cede; |
1504 | |
|
|
1505 | # now do the right thing for maps |
1501 | # now do the right thing for maps |
1506 | $self->link_multipart_objects; |
1502 | $self->link_multipart_objects; |
|
|
1503 | Coro::cede; |
1507 | |
1504 | |
1508 | unless ($self->{deny_activate}) { |
1505 | unless ($self->{deny_activate}) { |
1509 | $self->decay_objects; |
1506 | $self->decay_objects; |
1510 | $self->fix_auto_apply; |
1507 | $self->fix_auto_apply; |
1511 | $self->update_buttons; |
1508 | $self->update_buttons; |
… | |
… | |
1513 | $self->set_darkness_map; |
1510 | $self->set_darkness_map; |
1514 | $self->difficulty ($self->estimate_difficulty) |
1511 | $self->difficulty ($self->estimate_difficulty) |
1515 | unless $self->difficulty; |
1512 | unless $self->difficulty; |
1516 | Coro::cede; |
1513 | Coro::cede; |
1517 | $self->activate; |
1514 | $self->activate; |
|
|
1515 | Coro::cede; |
1518 | } |
1516 | } |
1519 | |
1517 | |
1520 | $self->post_load; |
1518 | $self->post_load; |
|
|
1519 | Coro::cede; |
1521 | |
1520 | |
1522 | $self->in_memory (cf::MAP_IN_MEMORY); |
1521 | $self->in_memory (cf::MAP_IN_MEMORY); |
1523 | } |
1522 | } |
1524 | |
1523 | |
1525 | sub customise_for { |
1524 | sub customise_for { |
… | |
… | |
2643 | |
2642 | |
2644 | unshift @INC, $LIBDIR; |
2643 | unshift @INC, $LIBDIR; |
2645 | |
2644 | |
2646 | my $bug_warning = 0; |
2645 | my $bug_warning = 0; |
2647 | |
2646 | |
|
|
2647 | our @WAIT_FOR_TICK; |
|
|
2648 | our @WAIT_FOR_TICK_BEGIN; |
|
|
2649 | |
|
|
2650 | sub wait_for_tick { |
|
|
2651 | my $signal = new Coro::Signal; |
|
|
2652 | push @WAIT_FOR_TICK, $signal; |
|
|
2653 | $signal->wait; |
|
|
2654 | } |
|
|
2655 | |
|
|
2656 | sub wait_for_tick_begin { |
|
|
2657 | my $signal = new Coro::Signal; |
|
|
2658 | push @WAIT_FOR_TICK_BEGIN, $signal; |
|
|
2659 | $signal->wait; |
|
|
2660 | } |
|
|
2661 | |
2648 | $TICK_WATCHER = Event->timer ( |
2662 | $TICK_WATCHER = Event->timer ( |
2649 | reentrant => 0, |
2663 | reentrant => 0, |
2650 | parked => 1, |
2664 | parked => 1, |
2651 | prio => 0, |
2665 | prio => 0, |
2652 | at => $NEXT_TICK || $TICK, |
2666 | at => $NEXT_TICK || $TICK, |
… | |
… | |
2670 | write_runtime |
2684 | write_runtime |
2671 | or warn "ERROR: unable to write runtime file: $!"; |
2685 | or warn "ERROR: unable to write runtime file: $!"; |
2672 | }; |
2686 | }; |
2673 | } |
2687 | } |
2674 | |
2688 | |
2675 | $WAIT_FOR_TICK->broadcast; |
2689 | if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { |
2676 | $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; |
2690 | $sig->send; |
|
|
2691 | } |
|
|
2692 | while (my $sig = shift @WAIT_FOR_TICK) { |
|
|
2693 | $sig->send; |
|
|
2694 | } |
2677 | |
2695 | |
2678 | # my $AFTER = Event::time; |
2696 | # my $AFTER = Event::time; |
2679 | # warn $AFTER - $NOW;#d# |
2697 | # warn $AFTER - $NOW;#d# |
2680 | |
2698 | |
2681 | # if we are delayed by four ticks or more, skip them all |
2699 | # if we are delayed by four ticks or more, skip them all |