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.514 by root, Mon Apr 12 17:13:36 2010 UTC vs.
Revision 1.522 by root, Sat Apr 17 02:22:14 2010 UTC

165 165
166our $EMERGENCY_POSITION; 166our $EMERGENCY_POSITION;
167 167
168sub cf::map::normalise; 168sub cf::map::normalise;
169 169
170sub in_main() {
171 $Coro::current == $Coro::main
172}
173
170############################################################################# 174#############################################################################
171 175
172%REFLECT = (); 176%REFLECT = ();
173for (@REFLECT) { 177for (@REFLECT) {
174 my $reflect = JSON::XS::decode_json $_; 178 my $reflect = JSON::XS::decode_json $_;
261$Coro::State::DIEHOOK = sub { 265$Coro::State::DIEHOOK = sub {
262 return unless $^S eq 0; # "eq", not "==" 266 return unless $^S eq 0; # "eq", not "=="
263 267
264 warn Carp::longmess $_[0]; 268 warn Carp::longmess $_[0];
265 269
266 if ($Coro::current == $Coro::main) {#d# 270 if (in_main) {#d#
267 warn "DIEHOOK called in main context, Coro bug?\n";#d# 271 warn "DIEHOOK called in main context, Coro bug?\n";#d#
268 return;#d# 272 return;#d#
269 }#d# 273 }#d#
270 274
271 # kill coroutine otherwise 275 # kill coroutine otherwise
1436 if (length $@) { 1440 if (length $@) {
1437 warn "$v->{path}: $@\n"; 1441 warn "$v->{path}: $@\n";
1438 1442
1439 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1443 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1440 if exists $v->{meta}{mandatory}; 1444 if exists $v->{meta}{mandatory};
1445
1446 warn "$v->{base}: optional extension cannot be loaded, skipping.\n";
1447 delete $todo{$k};
1441 } else { 1448 } else {
1442 $done{$k} = delete $todo{$k}; 1449 $done{$k} = delete $todo{$k};
1443 push @EXTS, $v->{pkg}; 1450 push @EXTS, $v->{pkg};
1444 $progress = 1; 1451 $progress = 1;
1445 1452
2212 $MAP_PREFETCHER->prio (6); 2219 $MAP_PREFETCHER->prio (6);
2213 2220
2214 () 2221 ()
2215} 2222}
2216 2223
2224# common code, used by both ->save and ->swapout
2217sub save { 2225sub _save {
2218 my ($self) = @_; 2226 my ($self) = @_;
2219
2220 my $lock = cf::lock_acquire "map_data:$self->{path}";
2221 2227
2222 $self->{last_save} = $cf::RUNTIME; 2228 $self->{last_save} = $cf::RUNTIME;
2223 2229
2224 return unless $self->dirty; 2230 return unless $self->dirty;
2225 2231
2245 } else { 2251 } else {
2246 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); 2252 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES);
2247 } 2253 }
2248} 2254}
2249 2255
2256sub save {
2257 my ($self) = @_;
2258
2259 my $lock = cf::lock_acquire "map_data:$self->{path}";
2260
2261 $self->_save;
2262}
2263
2250sub swap_out { 2264sub swap_out {
2251 my ($self) = @_; 2265 my ($self) = @_;
2252 2266
2253 # save first because save cedes
2254 $self->save;
2255
2256 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2267 my $lock = cf::lock_acquire "map_data:$self->{path}";
2257 2268
2258 return if $self->players;
2259 return if $self->in_memory != cf::MAP_ACTIVE; 2269 return if $self->in_memory != cf::MAP_ACTIVE;
2260 return if $self->{deny_save}; 2270 return if $self->{deny_save};
2271 return if $self->players;
2261 2272
2262 $self->in_memory (cf::MAP_SWAPPED); 2273 # first deactivate the map and "unlink" it from the core
2263
2264 $self->deactivate; 2274 $self->deactivate;
2265 $_->clear_links_to ($self) for values %cf::MAP; 2275 $_->clear_links_to ($self) for values %cf::MAP;
2276 $self->in_memory (cf::MAP_SWAPPED);
2277
2278 # then atomically save
2279 $self->_save;
2280
2281 # then free the map
2266 $self->clear; 2282 $self->clear;
2267} 2283}
2268 2284
2269sub reset_at { 2285sub reset_at {
2270 my ($self) = @_; 2286 my ($self) = @_;
2599 return if UNIVERSAL::isa $self->map, "ext::map_link"; 2615 return if UNIVERSAL::isa $self->map, "ext::map_link";
2600 2616
2601 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] 2617 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y]
2602 if $self->map && $self->map->{path} ne "{link}"; 2618 if $self->map && $self->map->{path} ne "{link}";
2603 2619
2604 $self->enter_map ($LINK_MAP || link_map, 10, 10); 2620 $self->enter_map ($LINK_MAP || link_map, 3, 3);
2605} 2621}
2606 2622
2607sub cf::object::player::leave_link { 2623sub cf::object::player::leave_link {
2608 my ($self, $map, $x, $y) = @_; 2624 my ($self, $map, $x, $y) = @_;
2609 2625
3543 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3559 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3544 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3560 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3545 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3561 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3546 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3562 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3547 3563
3548 cf::init_experience;
3549 cf::init_anim;
3550 cf::init_attackmess;
3551 cf::init_dynamic;
3552
3553 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3564 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3554 3565
3555 # we must not ever block the main coroutine 3566 # we must not ever block the main coroutine
3556 local $Coro::idle = sub { 3567 local $Coro::idle = sub {
3557 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3568 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3562 }; 3573 };
3563 3574
3564 evthread_start IO::AIO::poll_fileno; 3575 evthread_start IO::AIO::poll_fileno;
3565 3576
3566 cf::sync_job { 3577 cf::sync_job {
3578 cf::init_experience;
3579 cf::init_anim;
3580 cf::init_attackmess;
3581 cf::init_dynamic;
3582
3567 cf::load_settings; 3583 cf::load_settings;
3568 cf::load_materials; 3584 cf::load_materials;
3569 3585
3570 reload_resources; 3586 reload_resources;
3571 reload_config; 3587 reload_config;
3587 use POSIX (); 3603 use POSIX ();
3588 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3604 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3589 3605
3590 (pop @POST_INIT)->(0) while @POST_INIT; 3606 (pop @POST_INIT)->(0) while @POST_INIT;
3591 }; 3607 };
3608
3609 cf::object::thawer::errors_are_fatal 0;
3610 warn "parse errors in files are no longer fatal from this point on.\n";
3592 3611
3593 main_loop; 3612 main_loop;
3594} 3613}
3595 3614
3596############################################################################# 3615#############################################################################
3773 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; 3792 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH};
3774 for my $name (keys %$leaf_symtab) { 3793 for my $name (keys %$leaf_symtab) {
3775 _gv_clear *{"$pkg$name"}; 3794 _gv_clear *{"$pkg$name"};
3776# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; 3795# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"};
3777 } 3796 }
3778 warn "cleared package $pkg\n";#d#
3779} 3797}
3780 3798
3781sub do_reload_perl() { 3799sub do_reload_perl() {
3782 # can/must only be called in main 3800 # can/must only be called in main
3783 if ($Coro::current != $Coro::main) { 3801 if (in_main) {
3784 warn "can only reload from main coroutine"; 3802 warn "can only reload from main coroutine";
3785 return; 3803 return;
3786 } 3804 }
3787 3805
3788 return if $RELOAD++; 3806 return if $RELOAD++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines