--- deliantra/server/lib/cf.pm 2007/04/16 11:09:32 1.241 +++ deliantra/server/lib/cf.pm 2007/04/17 18:40:32 1.248 @@ -11,7 +11,7 @@ use Safe; use Safe::Hole; -use Coro 3.52 (); +use Coro 3.61 (); use Coro::State; use Coro::Event; use Coro::Timer; @@ -56,7 +56,7 @@ our @EVENT; our $LIBDIR = datadir . "/ext"; -our $TICK = MAX_TIME * 1e-6; +our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) our $TICK_WATCHER; our $AIO_POLL_WATCHER; our $NEXT_RUNTIME_WRITE; # when should the runtime file be written @@ -2334,8 +2334,8 @@ ############################################################################# # the server's init and main functions -sub load_facedata { - my $path = sprintf "%s/facedata", cf::datadir; +sub load_facedata($) { + my ($path) = @_; warn "loading facedata from $path\n"; @@ -2386,28 +2386,37 @@ 1 } -our $archetypes_loaded; - -sub load_archetypes { - return 1 if $archetypes_loaded++; # current can only load them once - load_archetype_file sprintf "%s/archetypes", cf::datadir -} - -sub load_treasures { - load_treasure_file sprintf "%s/treasures", cf::datadir +sub reload_facedata { + load_facedata sprintf "%s/facedata", cf::datadir + or die "unable to load facedata\n"; } -sub reload_resources { +sub reload_regions { load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir or die "unable to load regions file\n"; - load_facedata - or die "unable to load facedata\n"; - load_archetypes +} + +sub reload_archetypes { + load_resource_file sprintf "%s/archetypes", cf::datadir or die "unable to load archetypes\n"; - load_treasures +} + +sub reload_treasures { + load_resource_file sprintf "%s/treasures", cf::datadir or die "unable to load treasurelists\n"; } +sub reload_resources { + warn "reloading resource files...\n"; + + reload_regions; + reload_facedata; + reload_archetypes; + reload_treasures; + + warn "finished reloading resource files\n"; +} + sub init { reload_resources; } @@ -2508,7 +2517,7 @@ if $make_core; } -sub reload() { +sub do_reload_perl() { # can/must only be called in main if ($Coro::current != $Coro::main) { warn "can only reload from main coroutine"; @@ -2617,9 +2626,6 @@ warn "reattaching attachments to players"; reattach $_ for values %PLAYER; - warn "loading reloadable resources"; - reload_resources; - warn "leaving sync_job"; 1 @@ -2634,24 +2640,27 @@ our $RELOAD_WATCHER; # used only during reload +sub reload_perl() { + # doing reload synchronously and two reloads happen back-to-back, + # coro crashes during coro_state_free->destroy here. + + $RELOAD_WATCHER ||= Event->timer ( + reentrant => 0, + after => 0, + data => WF_AUTOCANCEL, + cb => sub { + do_reload_perl; + undef $RELOAD_WATCHER; + }, + ); +} + register_command "reload" => sub { my ($who, $arg) = @_; if ($who->flag (FLAG_WIZ)) { $who->message ("reloading server."); - - # doing reload synchronously and two reloads happen back-to-back, - # coro crashes during coro_state_free->destroy here. - - $RELOAD_WATCHER ||= Event->timer ( - reentrant => 0, - after => 0, - data => WF_AUTOCANCEL, - cb => sub { - reload; - undef $RELOAD_WATCHER; - }, - ); + async { reload_perl }; } }; @@ -2696,6 +2705,7 @@ $NOW = Event::time; cf::server_tick; # one server iteration + $RUNTIME += $TICK; $NEXT_TICK += $TICK; @@ -2707,13 +2717,6 @@ }; } - if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { - $sig->send; - } - while (my $sig = shift @WAIT_FOR_TICK) { - $sig->send; - } - # my $AFTER = Event::time; # warn $AFTER - $NOW;#d# @@ -2722,6 +2725,15 @@ $TICK_WATCHER->at ($NEXT_TICK); $TICK_WATCHER->start; + + if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { + $sig->send; + } + while (my $sig = shift @WAIT_FOR_TICK) { + $sig->send; + } + + _post_tick; }, );