… | |
… | |
5 | use Storable; |
5 | use Storable; |
6 | use Opcode; |
6 | use Opcode; |
7 | use Safe; |
7 | use Safe; |
8 | use Safe::Hole; |
8 | use Safe::Hole; |
9 | |
9 | |
|
|
10 | use IO::AIO (); |
10 | use YAML::Syck (); |
11 | use YAML::Syck (); |
11 | use Time::HiRes; |
12 | use Time::HiRes; |
12 | use Event; |
13 | use Event; |
13 | $Event::Eval = 1; # no idea why this is required, but it is |
14 | $Event::Eval = 1; # no idea why this is required, but it is |
14 | |
15 | |
… | |
… | |
26 | our $TICK = MAX_TIME * 1e-6; |
27 | our $TICK = MAX_TIME * 1e-6; |
27 | our $TICK_WATCHER; |
28 | our $TICK_WATCHER; |
28 | our $NEXT_TICK; |
29 | our $NEXT_TICK; |
29 | |
30 | |
30 | our %CFG; |
31 | our %CFG; |
|
|
32 | |
|
|
33 | our $uptime; |
|
|
34 | |
|
|
35 | $uptime ||= time; |
31 | |
36 | |
32 | ############################################################################# |
37 | ############################################################################# |
33 | |
38 | |
34 | =head2 GLOBAL VARIABLES |
39 | =head2 GLOBAL VARIABLES |
35 | |
40 | |
… | |
… | |
770 | sub cf::player::exists($) { |
775 | sub cf::player::exists($) { |
771 | cf::player::find $_[0] |
776 | cf::player::find $_[0] |
772 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
777 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
773 | } |
778 | } |
774 | |
779 | |
775 | =item $player->reply ($npc, $msg[, $flags]) |
780 | =item $object->reply ($npc, $msg[, $flags]) |
776 | |
781 | |
777 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
782 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
778 | can be C<undef>. Does the right thing when the player is currently in a |
783 | can be C<undef>. Does the right thing when the player is currently in a |
779 | dialogue with the given NPC character. |
784 | dialogue with the given NPC character. |
780 | |
785 | |
… | |
… | |
1140 | register "<global>", __PACKAGE__; |
1145 | register "<global>", __PACKAGE__; |
1141 | |
1146 | |
1142 | unshift @INC, $LIBDIR; |
1147 | unshift @INC, $LIBDIR; |
1143 | |
1148 | |
1144 | $TICK_WATCHER = Event->timer ( |
1149 | $TICK_WATCHER = Event->timer ( |
1145 | prio => 1, |
1150 | prio => 1, |
|
|
1151 | async => 1, |
1146 | at => $NEXT_TICK || 1, |
1152 | at => $NEXT_TICK || 1, |
1147 | cb => sub { |
1153 | cb => sub { |
1148 | cf::server_tick; # one server iteration |
1154 | cf::server_tick; # one server iteration |
1149 | |
1155 | |
1150 | my $NOW = Event::time; |
1156 | my $NOW = Event::time; |
1151 | $NEXT_TICK += $TICK; |
1157 | $NEXT_TICK += $TICK; |
1152 | |
1158 | |
… | |
… | |
1156 | $TICK_WATCHER->at ($NEXT_TICK); |
1162 | $TICK_WATCHER->at ($NEXT_TICK); |
1157 | $TICK_WATCHER->start; |
1163 | $TICK_WATCHER->start; |
1158 | }, |
1164 | }, |
1159 | ); |
1165 | ); |
1160 | |
1166 | |
|
|
1167 | IO::AIO::max_poll_time $TICK * 0.2; |
|
|
1168 | |
|
|
1169 | Event->io (fd => IO::AIO::poll_fileno, |
|
|
1170 | poll => 'r', |
|
|
1171 | prio => 5, |
|
|
1172 | cb => \&IO::AIO::poll_cb); |
|
|
1173 | |
1161 | 1 |
1174 | 1 |
1162 | |
1175 | |