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.72 by root, Sun Oct 1 11:41:37 2006 UTC vs.
Revision 1.77 by root, Sun Nov 5 11:13:01 2006 UTC

5use Storable; 5use Storable;
6use Opcode; 6use Opcode;
7use Safe; 7use Safe;
8use Safe::Hole; 8use Safe::Hole;
9 9
10use IO::AIO ();
10use YAML::Syck (); 11use YAML::Syck ();
11use Time::HiRes; 12use Time::HiRes;
12use Event; 13use 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
26our $TICK = MAX_TIME * 1e-6; 27our $TICK = MAX_TIME * 1e-6;
27our $TICK_WATCHER; 28our $TICK_WATCHER;
28our $NEXT_TICK; 29our $NEXT_TICK;
29 30
30our %CFG; 31our %CFG;
32
33our $uptime;
34
35$uptime ||= time;
31 36
32############################################################################# 37#############################################################################
33 38
34=head2 GLOBAL VARIABLES 39=head2 GLOBAL VARIABLES
35 40
770sub cf::player::exists($) { 775sub 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
777Sends a message to the player, as if the npc C<$npc> replied. C<$npc> 782Sends a message to the player, as if the npc C<$npc> replied. C<$npc>
778can be C<undef>. Does the right thing when the player is currently in a 783can be C<undef>. Does the right thing when the player is currently in a
779dialogue with the given NPC character. 784dialogue with the given NPC character.
780 785
1029} 1034}
1030 1035
1031############################################################################# 1036#############################################################################
1032# the server's main() 1037# the server's main()
1033 1038
1034sub load_cfg { 1039sub cfg_load {
1035 open my $fh, "<:utf8", cf::confdir . "/config" 1040 open my $fh, "<:utf8", cf::confdir . "/config"
1036 or return; 1041 or return;
1037 1042
1038 local $/; 1043 local $/;
1039 *CFG = YAML::Syck::Load <$fh>; 1044 *CFG = YAML::Syck::Load <$fh>;
1040
1041 use Data::Dumper; warn Dumper \%CFG;
1042} 1045}
1043 1046
1044sub main { 1047sub main {
1045 load_cfg; 1048 cfg_load;
1046 db_load; 1049 db_load;
1047 load_extensions; 1050 load_extensions;
1048 Event::loop; 1051 Event::loop;
1049} 1052}
1050 1053
1102 1105
1103 # reload cf.pm 1106 # reload cf.pm
1104 $msg->("reloading cf.pm"); 1107 $msg->("reloading cf.pm");
1105 require cf; 1108 require cf;
1106 1109
1107 # load database again 1110 # load config and database again
1111 cf::cfg_load;
1108 cf::db_load; 1112 cf::db_load;
1109 1113
1110 # load extensions 1114 # load extensions
1111 $msg->("load extensions"); 1115 $msg->("load extensions");
1112 cf::load_extensions; 1116 cf::load_extensions;
1141register "<global>", __PACKAGE__; 1145register "<global>", __PACKAGE__;
1142 1146
1143unshift @INC, $LIBDIR; 1147unshift @INC, $LIBDIR;
1144 1148
1145$TICK_WATCHER = Event->timer ( 1149$TICK_WATCHER = Event->timer (
1146 prio => 1, 1150 prio => 1,
1151 async => 1,
1147 at => $NEXT_TICK || 1, 1152 at => $NEXT_TICK || 1,
1148 cb => sub { 1153 cb => sub {
1149 cf::server_tick; # one server iteration 1154 cf::server_tick; # one server iteration
1150 1155
1151 my $NOW = Event::time; 1156 my $NOW = Event::time;
1152 $NEXT_TICK += $TICK; 1157 $NEXT_TICK += $TICK;
1153 1158
1157 $TICK_WATCHER->at ($NEXT_TICK); 1162 $TICK_WATCHER->at ($NEXT_TICK);
1158 $TICK_WATCHER->start; 1163 $TICK_WATCHER->start;
1159 }, 1164 },
1160); 1165);
1161 1166
1167IO::AIO::max_poll_time $TICK * 0.2;
1168
1169Event->io (fd => IO::AIO::poll_fileno,
1170 poll => 'r',
1171 prio => 5,
1172 cb => \&IO::AIO::poll_cb);
1173
11621 11741
1163 1175

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines