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.513 by root, Mon Apr 12 05:22:38 2010 UTC vs.
Revision 1.520 by root, Fri Apr 16 02:37:50 2010 UTC

399} 399}
400 400
401=item cf::periodic $interval, $cb 401=item cf::periodic $interval, $cb
402 402
403Like EV::periodic, but randomly selects a starting point so that the actions 403Like EV::periodic, but randomly selects a starting point so that the actions
404get spread over timer. 404get spread over time.
405 405
406=cut 406=cut
407 407
408sub periodic($$) { 408sub periodic($$) {
409 my ($interval, $cb) = @_; 409 my ($interval, $cb) = @_;
587 reset_signals; 587 reset_signals;
588 &$cb 588 &$cb
589 }, @args; 589 }, @args;
590 590
591 wantarray ? @res : $res[-1] 591 wantarray ? @res : $res[-1]
592}
593
594sub objinfo {
595 (
596 "counter value" => cf::object::object_count,
597 "objects created" => cf::object::create_count,
598 "objects destroyed" => cf::object::destroy_count,
599 "freelist size" => cf::object::free_count,
600 "allocated objects" => cf::object::objects_size,
601 "active objects" => cf::object::actives_size,
602 )
592} 603}
593 604
594=item $coin = coin_from_name $name 605=item $coin = coin_from_name $name
595 606
596=cut 607=cut
2201 $MAP_PREFETCHER->prio (6); 2212 $MAP_PREFETCHER->prio (6);
2202 2213
2203 () 2214 ()
2204} 2215}
2205 2216
2217# common code, used by both ->save and ->swapout
2206sub save { 2218sub _save {
2207 my ($self) = @_; 2219 my ($self) = @_;
2208
2209 my $lock = cf::lock_acquire "map_data:$self->{path}";
2210 2220
2211 $self->{last_save} = $cf::RUNTIME; 2221 $self->{last_save} = $cf::RUNTIME;
2212 2222
2213 return unless $self->dirty; 2223 return unless $self->dirty;
2214 2224
2234 } else { 2244 } else {
2235 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); 2245 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES);
2236 } 2246 }
2237} 2247}
2238 2248
2249sub save {
2250 my ($self) = @_;
2251
2252 my $lock = cf::lock_acquire "map_data:$self->{path}";
2253
2254 $self->_save;
2255}
2256
2239sub swap_out { 2257sub swap_out {
2240 my ($self) = @_; 2258 my ($self) = @_;
2241 2259
2242 # save first because save cedes
2243 $self->save;
2244
2245 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2260 my $lock = cf::lock_acquire "map_data:$self->{path}";
2246 2261
2247 return if $self->players;
2248 return if $self->in_memory != cf::MAP_ACTIVE; 2262 return if $self->in_memory != cf::MAP_ACTIVE;
2249 return if $self->{deny_save}; 2263 return if $self->{deny_save};
2264 return if $self->players;
2250 2265
2251 $self->in_memory (cf::MAP_SWAPPED); 2266 # first deactivate the map and "unlink" it from the core
2252
2253 $self->deactivate; 2267 $self->deactivate;
2254 $_->clear_links_to ($self) for values %cf::MAP; 2268 $_->clear_links_to ($self) for values %cf::MAP;
2269 $self->in_memory (cf::MAP_SWAPPED);
2270
2271 # then atomically save
2272 $self->_save;
2273
2274 # then free the map
2255 $self->clear; 2275 $self->clear;
2256} 2276}
2257 2277
2258sub reset_at { 2278sub reset_at {
2259 my ($self) = @_; 2279 my ($self) = @_;
2588 return if UNIVERSAL::isa $self->map, "ext::map_link"; 2608 return if UNIVERSAL::isa $self->map, "ext::map_link";
2589 2609
2590 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] 2610 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y]
2591 if $self->map && $self->map->{path} ne "{link}"; 2611 if $self->map && $self->map->{path} ne "{link}";
2592 2612
2593 $self->enter_map ($LINK_MAP || link_map, 10, 10); 2613 $self->enter_map ($LINK_MAP || link_map, 3, 3);
2594} 2614}
2595 2615
2596sub cf::object::player::leave_link { 2616sub cf::object::player::leave_link {
2597 my ($self, $map, $x, $y) = @_; 2617 my ($self, $map, $x, $y) = @_;
2598 2618
3532 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3552 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3533 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3553 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3534 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3554 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3535 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3555 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3536 3556
3537 cf::init_experience;
3538 cf::init_anim;
3539 cf::init_attackmess;
3540 cf::init_dynamic;
3541
3542 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3557 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3543 3558
3544 # we must not ever block the main coroutine 3559 # we must not ever block the main coroutine
3545 local $Coro::idle = sub { 3560 local $Coro::idle = sub {
3546 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3561 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3551 }; 3566 };
3552 3567
3553 evthread_start IO::AIO::poll_fileno; 3568 evthread_start IO::AIO::poll_fileno;
3554 3569
3555 cf::sync_job { 3570 cf::sync_job {
3571 cf::init_experience;
3572 cf::init_anim;
3573 cf::init_attackmess;
3574 cf::init_dynamic;
3575
3556 cf::load_settings; 3576 cf::load_settings;
3557 cf::load_materials; 3577 cf::load_materials;
3558 3578
3559 reload_resources; 3579 reload_resources;
3560 reload_config; 3580 reload_config;
3576 use POSIX (); 3596 use POSIX ();
3577 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3597 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3578 3598
3579 (pop @POST_INIT)->(0) while @POST_INIT; 3599 (pop @POST_INIT)->(0) while @POST_INIT;
3580 }; 3600 };
3601
3602 cf::object::thawer::errors_are_fatal 0;
3603 warn "parse errors in files are no longer fatal from this point on.\n";
3581 3604
3582 main_loop; 3605 main_loop;
3583} 3606}
3584 3607
3585############################################################################# 3608#############################################################################
3762 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; 3785 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH};
3763 for my $name (keys %$leaf_symtab) { 3786 for my $name (keys %$leaf_symtab) {
3764 _gv_clear *{"$pkg$name"}; 3787 _gv_clear *{"$pkg$name"};
3765# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; 3788# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"};
3766 } 3789 }
3767 warn "cleared package $pkg\n";#d#
3768} 3790}
3769 3791
3770sub do_reload_perl() { 3792sub do_reload_perl() {
3771 # can/must only be called in main 3793 # can/must only be called in main
3772 if ($Coro::current != $Coro::main) { 3794 if ($Coro::current != $Coro::main) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines