ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/00_map_handling.ext
(Generate patch)

Comparing deliantra/server/ext/00_map_handling.ext (file contents):
Revision 1.3 by root, Sat Dec 30 15:07:59 2006 UTC vs.
Revision 1.4 by root, Sat Dec 30 16:56:16 2006 UTC

130 and return; 130 and return;
131 131
132 1 132 1
133} 133}
134 134
135(Coro::unblock_sub { 135(Coro::async {
136 unless (write_runtime) { 136 unless (write_runtime) {
137 warn "unable to write runtime file: $!"; 137 warn "unable to write runtime file: $!";
138 exit 1; 138 exit 1;
139 } 139 }
140})->(); 140})->prio (Coro::PRIO_MAX);
141 141
142our $SCHEDULER = cf::coro { 142our $SCHEDULER = cf::coro {
143 while () { 143 while () {
144 Coro::Timer::sleep $SCHEDULE_INTERVAL; 144 Coro::Timer::sleep $SCHEDULE_INTERVAL;
145 145
181 181
182 Carp::confess "nested sync_job" if $cf::FREEZE; 182 Carp::confess "nested sync_job" if $cf::FREEZE;
183 183
184 local $cf::FREEZE = 1; 184 local $cf::FREEZE = 1;
185 185
186 (async { 186 (Coro::async {
187 @res = eval { $job->() }; 187 @res = eval { $job->() };
188 warn $@ if $@; 188 warn $@ if $@;
189 $done = 1; 189 $done = 1;
190 })->prio (Coro::PRIO_MAX); 190 })->prio (Coro::PRIO_MAX);
191 191
371} 371}
372 372
373sub cf::object::player::enter_exit { 373sub cf::object::player::enter_exit {
374 my ($ob, $exit) = @_; 374 my ($ob, $exit) = @_;
375 375
376 # if at login, move to interim map immediately
377 unless ($exit) {
378 # used on login only
379 $ob->enter_map ($LINK_MAP, 0, 0);
380 }
381
382 #TODO: do this in the background, freeze the player if required
376 sync_job { 383 sync_job {
377 my ($map, $x, $y); 384 my ($map, $x, $y);
378 385
379 if ($exit) { 386 unless ($exit) {
387 # used on login only(?)
388 $map = cf::map::find_map_nb $ob->contr->maplevel;
389 ($x, $y) = ($ob->x, $ob->y);
390 } else {
380 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path; 391 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path;
381 392
382 $map = cf::map::find_map_nb $path->as_string; 393 $map = cf::map::find_map_nb $path->as_string;
383 $map = $map->customise_for ($ob) if $map; 394 $map = $map->customise_for ($ob) if $map;
384 ($x, $y) = ($exit->stats->hp, $exit->stats->sp); 395 ($x, $y) = ($exit->stats->hp, $exit->stats->sp);
385 } else { 396 }
386 # used on login only(?)
387 $map = cf::map::find_map_nb $ob->contr->maplevel;
388 ($x, $y) = ($ob->x, $ob->y);
389 397
390 unless ($map) { 398 unless ($map) {
391 $map = cf::map::find_map_nb $emergency_position->[0] 399 $map = cf::map::find_map_nb $emergency_position->[0]
392 or die "FATAL: cannot load emergency map\n"; 400 or die "FATAL: cannot load emergency map\n";
393 $x = $emergency_position->[1]; 401 $x = $emergency_position->[1];
394 $y = $emergency_position->[2]; 402 $y = $emergency_position->[2];
395 }
396 } 403 }
397 404
398 if ($map) { 405 if ($map) {
399 warn "entering ", $map->path, " at ($x, $y)\n";#d# 406 warn "entering ", $map->path, " at ($x, $y)\n";#d#
400 $map->do_load_nb; 407 $map->do_load_nb;
416} 423}
417 424
418sub cf::map::emergency_save { 425sub cf::map::emergency_save {
419 local $cf::FREEZE = 1; 426 local $cf::FREEZE = 1;
420 427
428 warn "enter emergency map save\n";
429
430 my $saver = async {
421 warn "begin emergency map save\n"; 431 warn "begin emergency map save\n";
422 $_->save for values %cf::MAP; 432 $_->save for values %cf::MAP;
433 };
434 $saver->prio (Coro::PRIO_MAX);
435 $saver->join;
436
423 warn "emergency map save drain\n"; 437 warn "emergency map save drain\n";
424
425 Event::one_event while IO::AIO::nreqs; 438 Event::one_event while IO::AIO::nreqs;
426 warn "end emergency map save\n"; 439 warn "end emergency map save\n";
427} 440}
428 441

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines