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.243 by root, Mon Apr 16 13:02:29 2007 UTC vs.
Revision 1.245 by root, Tue Apr 17 10:06:33 2007 UTC

9use Event; 9use Event;
10use Opcode; 10use Opcode;
11use Safe; 11use Safe;
12use Safe::Hole; 12use Safe::Hole;
13 13
14use Coro 3.52 (); 14use Coro 3.61 ();
15use Coro::State; 15use Coro::State;
16use Coro::Event; 16use Coro::Event;
17use Coro::Timer; 17use Coro::Timer;
18use Coro::Signal; 18use Coro::Signal;
19use Coro::Semaphore; 19use Coro::Semaphore;
54 54
55our $RELOAD; # number of reloads so far 55our $RELOAD; # number of reloads so far
56our @EVENT; 56our @EVENT;
57our $LIBDIR = datadir . "/ext"; 57our $LIBDIR = datadir . "/ext";
58 58
59our $TICK = MAX_TIME * 1e-6; 59our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
60our $TICK_WATCHER; 60our $TICK_WATCHER;
61our $AIO_POLL_WATCHER; 61our $AIO_POLL_WATCHER;
62our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 62our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
63our $NEXT_TICK; 63our $NEXT_TICK;
64our $NOW; 64our $NOW;
2384 } 2384 }
2385 2385
2386 1 2386 1
2387} 2387}
2388 2388
2389our $archetypes_loaded;
2390
2391sub load_archetypes { 2389sub load_archetypes {
2392 return 1 if $archetypes_loaded++; # current can only load them once
2393 load_archetype_file sprintf "%s/archetypes", cf::datadir; # remove when stable 2390 load_archetype_file sprintf "%s/archetypes", cf::datadir; # remove when stable
2394 load_archetype_file sprintf "%s/archetypes", cf::datadir 2391 load_archetype_file sprintf "%s/archetypes", cf::datadir
2395} 2392}
2396 2393
2397sub load_treasures { 2394sub load_treasures {
2398 load_treasure_file sprintf "%s/treasures", cf::datadir 2395 load_treasure_file sprintf "%s/treasures", cf::datadir
2399} 2396}
2400 2397
2401sub reload_resources { 2398sub reload_resources {
2399 warn "reloading resource files...\n";
2400
2402 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir 2401 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir
2403 or die "unable to load regions file\n"; 2402 or die "unable to load regions file\n";
2404 load_facedata 2403 load_facedata
2405 or die "unable to load facedata\n"; 2404 or die "unable to load facedata\n";
2406 load_archetypes 2405 load_archetypes
2407 or die "unable to load archetypes\n"; 2406 or die "unable to load archetypes\n";
2408 load_treasures 2407 load_treasures
2409 or die "unable to load treasurelists\n"; 2408 or die "unable to load treasurelists\n";
2409
2410 warn "finished reloading resource files\n";
2410} 2411}
2411 2412
2412sub init { 2413sub init {
2413 reload_resources; 2414 reload_resources;
2414} 2415}
2695 } 2696 }
2696 2697
2697 $NOW = Event::time; 2698 $NOW = Event::time;
2698 2699
2699 cf::server_tick; # one server iteration 2700 cf::server_tick; # one server iteration
2701
2700 $RUNTIME += $TICK; 2702 $RUNTIME += $TICK;
2701 $NEXT_TICK += $TICK; 2703 $NEXT_TICK += $TICK;
2702 2704
2703 if ($NOW >= $NEXT_RUNTIME_WRITE) { 2705 if ($NOW >= $NEXT_RUNTIME_WRITE) {
2704 $NEXT_RUNTIME_WRITE = $NOW + 10; 2706 $NEXT_RUNTIME_WRITE = $NOW + 10;
2706 write_runtime 2708 write_runtime
2707 or warn "ERROR: unable to write runtime file: $!"; 2709 or warn "ERROR: unable to write runtime file: $!";
2708 }; 2710 };
2709 } 2711 }
2710 2712
2713# my $AFTER = Event::time;
2714# warn $AFTER - $NOW;#d#
2715
2716 # if we are delayed by four ticks or more, skip them all
2717 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2718
2719 $TICK_WATCHER->at ($NEXT_TICK);
2720 $TICK_WATCHER->start;
2721
2711 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { 2722 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {
2712 $sig->send; 2723 $sig->send;
2713 } 2724 }
2714 while (my $sig = shift @WAIT_FOR_TICK) { 2725 while (my $sig = shift @WAIT_FOR_TICK) {
2715 $sig->send; 2726 $sig->send;
2716 } 2727 }
2717 2728
2718# my $AFTER = Event::time; 2729 _post_tick;
2719# warn $AFTER - $NOW;#d#
2720
2721 # if we are delayed by four ticks or more, skip them all
2722 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2723
2724 $TICK_WATCHER->at ($NEXT_TICK);
2725 $TICK_WATCHER->start;
2726 }, 2730 },
2727); 2731);
2728 2732
2729{ 2733{
2730 BDB::max_poll_time $TICK * 0.1; 2734 BDB::max_poll_time $TICK * 0.1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines