--- deliantra/server/lib/cf.pm 2006/10/01 10:55:37 1.70 +++ deliantra/server/lib/cf.pm 2006/11/05 11:13:01 1.77 @@ -7,10 +7,15 @@ use Safe; use Safe::Hole; +use IO::AIO (); +use YAML::Syck (); use Time::HiRes; use Event; $Event::Eval = 1; # no idea why this is required, but it is +# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode? +$YAML::Syck::ImplicitUnicode = 1; + use strict; _init_vars; @@ -25,6 +30,10 @@ our %CFG; +our $uptime; + +$uptime ||= time; + ############################################################################# =head2 GLOBAL VARIABLES @@ -111,6 +120,8 @@ =back +=cut + ############################################################################# =head2 EVENTS AND OBJECT ATTACHMENTS @@ -423,6 +434,8 @@ =back +=cut + ############################################################################# =head2 METHODS VALID FOR ALL CORE OBJECTS @@ -764,7 +777,7 @@ or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; } -=item $player->reply ($npc, $msg[, $flags]) +=item $object->reply ($npc, $msg[, $flags]) Sends a message to the player, as if the npc C<$npc> replied. C<$npc> can be C. Does the right thing when the player is currently in a @@ -914,6 +927,8 @@ =back +=cut + ############################################################################# =head2 EXTENSION DATABASE SUPPORT @@ -1021,7 +1036,16 @@ ############################################################################# # the server's main() +sub cfg_load { + open my $fh, "<:utf8", cf::confdir . "/config" + or return; + + local $/; + *CFG = YAML::Syck::Load <$fh>; +} + sub main { + cfg_load; db_load; load_extensions; Event::loop; @@ -1083,7 +1107,8 @@ $msg->("reloading cf.pm"); require cf; - # load database again + # load config and database again + cf::cfg_load; cf::db_load; # load extensions @@ -1122,9 +1147,10 @@ unshift @INC, $LIBDIR; $TICK_WATCHER = Event->timer ( - prio => 1, - at => $NEXT_TICK || 1, - cb => sub { + prio => 1, + async => 1, + at => $NEXT_TICK || 1, + cb => sub { cf::server_tick; # one server iteration my $NOW = Event::time; @@ -1138,5 +1164,12 @@ }, ); +IO::AIO::max_poll_time $TICK * 0.2; + +Event->io (fd => IO::AIO::poll_fileno, + poll => 'r', + prio => 5, + cb => \&IO::AIO::poll_cb); + 1