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.244 by root, Mon Apr 16 13:28:00 2007 UTC vs.
Revision 1.247 by root, Tue Apr 17 18:24:30 2007 UTC

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;
2332} 2332}
2333 2333
2334############################################################################# 2334#############################################################################
2335# the server's init and main functions 2335# the server's init and main functions
2336 2336
2337sub load_facedata { 2337sub load_facedata($) {
2338 my $path = sprintf "%s/facedata", cf::datadir; 2338 my ($path) = @_;
2339 2339
2340 warn "loading facedata from $path\n"; 2340 warn "loading facedata from $path\n";
2341 2341
2342 my $facedata; 2342 my $facedata;
2343 0 < aio_load $path, $facedata 2343 0 < aio_load $path, $facedata
2384 } 2384 }
2385 2385
2386 1 2386 1
2387} 2387}
2388 2388
2389sub load_archetypes { 2389sub reload_facedata {
2390 load_archetype_file sprintf "%s/archetypes", cf::datadir; # remove when stable
2391 load_archetype_file sprintf "%s/archetypes", cf::datadir 2390 load_facedata sprintf "%s/facedata", cf::datadir
2391 or die "unable to load facedata\n";
2392} 2392}
2393 2393
2394sub load_treasures {
2395 load_treasure_file sprintf "%s/treasures", cf::datadir
2396}
2397
2398sub reload_resources { 2394sub reload_regions {
2399 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir 2395 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir
2400 or die "unable to load regions file\n"; 2396 or die "unable to load regions file\n";
2401 load_facedata 2397}
2402 or die "unable to load facedata\n"; 2398
2403 load_archetypes 2399sub reload_archetypes {
2400 load_archetype_file sprintf "%s/archetypes", cf::datadir
2404 or die "unable to load archetypes\n"; 2401 or die "unable to load archetypes\n";
2405 load_treasures 2402}
2403
2404sub reload_treasures {
2405 load_resource_file sprintf "%s/treasures", cf::datadir
2406 or die "unable to load treasurelists\n"; 2406 or die "unable to load treasurelists\n";
2407}
2408
2409sub reload_resources {
2410 warn "reloading resource files...\n";
2411
2412 reload_regions;
2413 reload_facedata;
2414 reload_archetypes;
2415 reload_treasures;
2416
2417 warn "finished reloading resource files\n";
2407} 2418}
2408 2419
2409sub init { 2420sub init {
2410 reload_resources; 2421 reload_resources;
2411} 2422}
2504 2515
2505 warn Carp::longmess "post_cleanup backtrace" 2516 warn Carp::longmess "post_cleanup backtrace"
2506 if $make_core; 2517 if $make_core;
2507} 2518}
2508 2519
2509sub reload() { 2520sub do_reload_perl() {
2510 # can/must only be called in main 2521 # can/must only be called in main
2511 if ($Coro::current != $Coro::main) { 2522 if ($Coro::current != $Coro::main) {
2512 warn "can only reload from main coroutine"; 2523 warn "can only reload from main coroutine";
2513 return; 2524 return;
2514 } 2525 }
2613 warn "reattaching attachments to maps"; 2624 warn "reattaching attachments to maps";
2614 reattach $_ for values %MAP; 2625 reattach $_ for values %MAP;
2615 warn "reattaching attachments to players"; 2626 warn "reattaching attachments to players";
2616 reattach $_ for values %PLAYER; 2627 reattach $_ for values %PLAYER;
2617 2628
2618 warn "loading reloadable resources";
2619 reload_resources;
2620
2621 warn "leaving sync_job"; 2629 warn "leaving sync_job";
2622 2630
2623 1 2631 1
2624 } or do { 2632 } or do {
2625 warn $@; 2633 warn $@;
2630 warn "reloaded"; 2638 warn "reloaded";
2631}; 2639};
2632 2640
2633our $RELOAD_WATCHER; # used only during reload 2641our $RELOAD_WATCHER; # used only during reload
2634 2642
2643sub reload_perl() {
2644 # doing reload synchronously and two reloads happen back-to-back,
2645 # coro crashes during coro_state_free->destroy here.
2646
2647 $RELOAD_WATCHER ||= Event->timer (
2648 reentrant => 0,
2649 after => 0,
2650 data => WF_AUTOCANCEL,
2651 cb => sub {
2652 do_reload_perl;
2653 undef $RELOAD_WATCHER;
2654 },
2655 );
2656}
2657
2635register_command "reload" => sub { 2658register_command "reload" => sub {
2636 my ($who, $arg) = @_; 2659 my ($who, $arg) = @_;
2637 2660
2638 if ($who->flag (FLAG_WIZ)) { 2661 if ($who->flag (FLAG_WIZ)) {
2639 $who->message ("reloading server."); 2662 $who->message ("reloading server.");
2640 2663 async { reload_perl };
2641 # doing reload synchronously and two reloads happen back-to-back,
2642 # coro crashes during coro_state_free->destroy here.
2643
2644 $RELOAD_WATCHER ||= Event->timer (
2645 reentrant => 0,
2646 after => 0,
2647 data => WF_AUTOCANCEL,
2648 cb => sub {
2649 reload;
2650 undef $RELOAD_WATCHER;
2651 },
2652 );
2653 } 2664 }
2654}; 2665};
2655 2666
2656unshift @INC, $LIBDIR; 2667unshift @INC, $LIBDIR;
2657 2668
2692 } 2703 }
2693 2704
2694 $NOW = Event::time; 2705 $NOW = Event::time;
2695 2706
2696 cf::server_tick; # one server iteration 2707 cf::server_tick; # one server iteration
2708
2697 $RUNTIME += $TICK; 2709 $RUNTIME += $TICK;
2698 $NEXT_TICK += $TICK; 2710 $NEXT_TICK += $TICK;
2699 2711
2700 if ($NOW >= $NEXT_RUNTIME_WRITE) { 2712 if ($NOW >= $NEXT_RUNTIME_WRITE) {
2701 $NEXT_RUNTIME_WRITE = $NOW + 10; 2713 $NEXT_RUNTIME_WRITE = $NOW + 10;
2703 write_runtime 2715 write_runtime
2704 or warn "ERROR: unable to write runtime file: $!"; 2716 or warn "ERROR: unable to write runtime file: $!";
2705 }; 2717 };
2706 } 2718 }
2707 2719
2720# my $AFTER = Event::time;
2721# warn $AFTER - $NOW;#d#
2722
2723 # if we are delayed by four ticks or more, skip them all
2724 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2725
2726 $TICK_WATCHER->at ($NEXT_TICK);
2727 $TICK_WATCHER->start;
2728
2708 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { 2729 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {
2709 $sig->send; 2730 $sig->send;
2710 } 2731 }
2711 while (my $sig = shift @WAIT_FOR_TICK) { 2732 while (my $sig = shift @WAIT_FOR_TICK) {
2712 $sig->send; 2733 $sig->send;
2713 } 2734 }
2714 2735
2715# my $AFTER = Event::time; 2736 _post_tick;
2716# warn $AFTER - $NOW;#d#
2717
2718 # if we are delayed by four ticks or more, skip them all
2719 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2720
2721 $TICK_WATCHER->at ($NEXT_TICK);
2722 $TICK_WATCHER->start;
2723 }, 2737 },
2724); 2738);
2725 2739
2726{ 2740{
2727 BDB::max_poll_time $TICK * 0.1; 2741 BDB::max_poll_time $TICK * 0.1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines