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.239 by root, Mon Apr 16 06:23:42 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
2389sub load_archetypes {
2390 load_archetype_file sprintf "%s/archetypes", cf::datadir; # remove when stable
2391 load_archetype_file sprintf "%s/archetypes", cf::datadir
2392}
2393
2394sub load_treasures {
2395 load_treasure_file sprintf "%s/treasures", cf::datadir
2396}
2397
2389sub reload_resources { 2398sub reload_resources {
2399 warn "reloading resource files...\n";
2400
2390 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir 2401 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir
2391 or die "unable to load regions file\n";#d# 2402 or die "unable to load regions file\n";
2392 load_facedata 2403 load_facedata
2393 or die "unable to load facedata\n";#d# 2404 or die "unable to load facedata\n";
2405 load_archetypes
2406 or die "unable to load archetypes\n";
2407 load_treasures
2408 or die "unable to load treasurelists\n";
2409
2410 warn "finished reloading resource files\n";
2394} 2411}
2395 2412
2396sub init { 2413sub init {
2397 reload_resources; 2414 reload_resources;
2398} 2415}
2646 2663
2647our @WAIT_FOR_TICK; 2664our @WAIT_FOR_TICK;
2648our @WAIT_FOR_TICK_BEGIN; 2665our @WAIT_FOR_TICK_BEGIN;
2649 2666
2650sub wait_for_tick { 2667sub wait_for_tick {
2668 return unless $TICK_WATCHER->is_active;
2669 return if $Coro::current == $Coro::main;
2670
2651 my $signal = new Coro::Signal; 2671 my $signal = new Coro::Signal;
2652 push @WAIT_FOR_TICK, $signal; 2672 push @WAIT_FOR_TICK, $signal;
2653 $signal->wait; 2673 $signal->wait;
2654} 2674}
2655 2675
2656sub wait_for_tick_begin { 2676sub wait_for_tick_begin {
2677 return unless $TICK_WATCHER->is_active;
2678 return if $Coro::current == $Coro::main;
2679
2657 my $signal = new Coro::Signal; 2680 my $signal = new Coro::Signal;
2658 push @WAIT_FOR_TICK_BEGIN, $signal; 2681 push @WAIT_FOR_TICK_BEGIN, $signal;
2659 $signal->wait; 2682 $signal->wait;
2660} 2683}
2661 2684
2673 } 2696 }
2674 2697
2675 $NOW = Event::time; 2698 $NOW = Event::time;
2676 2699
2677 cf::server_tick; # one server iteration 2700 cf::server_tick; # one server iteration
2701
2678 $RUNTIME += $TICK; 2702 $RUNTIME += $TICK;
2679 $NEXT_TICK += $TICK; 2703 $NEXT_TICK += $TICK;
2680 2704
2681 if ($NOW >= $NEXT_RUNTIME_WRITE) { 2705 if ($NOW >= $NEXT_RUNTIME_WRITE) {
2682 $NEXT_RUNTIME_WRITE = $NOW + 10; 2706 $NEXT_RUNTIME_WRITE = $NOW + 10;
2684 write_runtime 2708 write_runtime
2685 or warn "ERROR: unable to write runtime file: $!"; 2709 or warn "ERROR: unable to write runtime file: $!";
2686 }; 2710 };
2687 } 2711 }
2688 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
2689 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { 2722 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {
2690 $sig->send; 2723 $sig->send;
2691 } 2724 }
2692 while (my $sig = shift @WAIT_FOR_TICK) { 2725 while (my $sig = shift @WAIT_FOR_TICK) {
2693 $sig->send; 2726 $sig->send;
2694 } 2727 }
2695 2728
2696# my $AFTER = Event::time; 2729 _post_tick;
2697# warn $AFTER - $NOW;#d#
2698
2699 # if we are delayed by four ticks or more, skip them all
2700 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2701
2702 $TICK_WATCHER->at ($NEXT_TICK);
2703 $TICK_WATCHER->start;
2704 }, 2730 },
2705); 2731);
2706 2732
2707{ 2733{
2708 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