… | |
… | |
80 | our $NEXT_TICK; |
80 | our $NEXT_TICK; |
81 | our $NOW; |
81 | our $NOW; |
82 | our $USE_FSYNC = 1; # use fsync to write maps - default off |
82 | our $USE_FSYNC = 1; # use fsync to write maps - default off |
83 | |
83 | |
84 | our $BDB_POLL_WATCHER; |
84 | our $BDB_POLL_WATCHER; |
|
|
85 | our $BDB_DEADLOCK_WATCHER; |
85 | our $BDB_CHECKPOINT_WATCHER; |
86 | our $BDB_CHECKPOINT_WATCHER; |
86 | our $BDB_TRICKLE_WATCHER; |
87 | our $BDB_TRICKLE_WATCHER; |
87 | our $DB_ENV; |
88 | our $DB_ENV; |
88 | |
89 | |
89 | our %CFG; |
90 | our %CFG; |
… | |
… | |
1352 | aio_unlink +(playerdir $login) . "/$login.pl"; |
1353 | aio_unlink +(playerdir $login) . "/$login.pl"; |
1353 | |
1354 | |
1354 | my $f = new_from_file cf::object::thawer path $login |
1355 | my $f = new_from_file cf::object::thawer path $login |
1355 | or return; |
1356 | or return; |
1356 | |
1357 | |
1357 | $f->next; |
|
|
1358 | my $pl = cf::player::load_pl $f |
1358 | my $pl = cf::player::load_pl $f |
1359 | or return; |
1359 | or return; |
1360 | local $cf::PLAYER_LOADING{$login} = $pl; |
1360 | local $cf::PLAYER_LOADING{$login} = $pl; |
1361 | $f->resolve_delayed_derefs; |
1361 | $f->resolve_delayed_derefs; |
1362 | $cf::PLAYER{$login} = $pl |
1362 | $cf::PLAYER{$login} = $pl |
… | |
… | |
2458 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2458 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2459 | |
2459 | |
2460 | $self->enter_link; |
2460 | $self->enter_link; |
2461 | |
2461 | |
2462 | (async { |
2462 | (async { |
|
|
2463 | # *tag paths override both path and x|y |
|
|
2464 | if ($path =~ /^\*(.*)$/) { |
|
|
2465 | if (my @obs = grep $_->map, ext::map_tags::find $1) { |
|
|
2466 | my $ob = $obs[rand @obs]; |
|
|
2467 | |
|
|
2468 | # see if we actually can go there |
|
|
2469 | if (@obs = grep !$self->blocked ($_->map, $_->x, $_->y), $ob, $ob->tail) { |
|
|
2470 | $ob = $obs[rand @obs]; |
|
|
2471 | } else { |
|
|
2472 | $self->message ("Wow, it's pretty crowded in there.", cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
2473 | } |
|
|
2474 | # else put us there anyways for now #d# |
|
|
2475 | |
|
|
2476 | ($path, $x, $y) = ($ob->map, $ob->x, $ob->y); |
|
|
2477 | } else { |
|
|
2478 | ($path, $x, $y) = (undef, undef, undef); |
|
|
2479 | } |
|
|
2480 | } |
|
|
2481 | |
2463 | my $map = eval { |
2482 | my $map = eval { |
2464 | my $map = cf::map::find $path; |
2483 | my $map = defined $path ? cf::map::find $path : undef; |
2465 | |
2484 | |
2466 | if ($map) { |
2485 | if ($map) { |
2467 | $map = $map->customise_for ($self); |
2486 | $map = $map->customise_for ($self); |
2468 | $map = $check->($map) if $check && $map; |
2487 | $map = $check->($map) if $check && $map; |
2469 | } else { |
2488 | } else { |
2470 | $self->message ("The exit to '$path' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
2489 | $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); |
2471 | } |
2490 | } |
2472 | |
2491 | |
2473 | $map |
2492 | $map |
2474 | }; |
2493 | }; |
2475 | |
2494 | |
… | |
… | |
3445 | my $signal = new Coro::Signal; |
3464 | my $signal = new Coro::Signal; |
3446 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3465 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3447 | $signal->wait; |
3466 | $signal->wait; |
3448 | } |
3467 | } |
3449 | |
3468 | |
3450 | my $min = 1e6;#d# |
|
|
3451 | my $avg = 10; |
|
|
3452 | $TICK_WATCHER = Event->timer ( |
3469 | $TICK_WATCHER = Event->timer ( |
3453 | reentrant => 0, |
3470 | reentrant => 0, |
3454 | parked => 1, |
3471 | parked => 1, |
3455 | prio => 0, |
3472 | prio => 0, |
3456 | at => $NEXT_TICK || $TICK, |
3473 | at => $NEXT_TICK || $TICK, |
… | |
… | |
3464 | |
3481 | |
3465 | $NOW = $tick_start = Event::time; |
3482 | $NOW = $tick_start = Event::time; |
3466 | |
3483 | |
3467 | cf::server_tick; # one server iteration |
3484 | cf::server_tick; # one server iteration |
3468 | |
3485 | |
3469 | 0 && sync_job {#d# |
|
|
3470 | for(1..10) { |
|
|
3471 | my $t = Event::time; |
|
|
3472 | my $map = my $map = new_from_path cf::map "/tmp/x.map" |
|
|
3473 | or die; |
|
|
3474 | |
|
|
3475 | $map->width (50); |
|
|
3476 | $map->height (50); |
|
|
3477 | $map->alloc; |
|
|
3478 | $map->_load_objects ("/tmp/x.map", 1); #TODO: does not work |
|
|
3479 | my $t = Event::time - $t; |
|
|
3480 | |
|
|
3481 | #next unless $t < 0.0013;#d# |
|
|
3482 | if ($t < $min) { |
|
|
3483 | $min = $t; |
|
|
3484 | } |
|
|
3485 | $avg = $avg * 0.99 + $t * 0.01; |
|
|
3486 | } |
|
|
3487 | warn "XXXXXXXXXXXXXXXXXX min $min avg $avg\n";#d# |
|
|
3488 | exit 0; |
|
|
3489 | # 2007-05-22 02:33:04.569 min 0.00112509727478027 avg 0.0012259249572477 |
|
|
3490 | }; |
|
|
3491 | |
|
|
3492 | $RUNTIME += $TICK; |
3486 | $RUNTIME += $TICK; |
3493 | $NEXT_TICK += $TICK; |
3487 | $NEXT_TICK += $TICK; |
3494 | |
3488 | |
3495 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3489 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3496 | $NEXT_RUNTIME_WRITE = $NOW + 10; |
3490 | $NEXT_RUNTIME_WRITE = $NOW + 10; |
… | |
… | |
3498 | write_runtime |
3492 | write_runtime |
3499 | or warn "ERROR: unable to write runtime file: $!"; |
3493 | or warn "ERROR: unable to write runtime file: $!"; |
3500 | }; |
3494 | }; |
3501 | } |
3495 | } |
3502 | |
3496 | |
3503 | # my $AFTER = Event::time; |
|
|
3504 | # warn $AFTER - $NOW;#d# |
|
|
3505 | |
|
|
3506 | if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { |
3497 | if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { |
3507 | $sig->send; |
3498 | $sig->send; |
3508 | } |
3499 | } |
3509 | while (my $sig = shift @WAIT_FOR_TICK) { |
3500 | while (my $sig = shift @WAIT_FOR_TICK) { |
3510 | $sig->send; |
3501 | $sig->send; |
… | |
… | |
3520 | |
3511 | |
3521 | $LOAD = ($NOW - $tick_start) / $TICK; |
3512 | $LOAD = ($NOW - $tick_start) / $TICK; |
3522 | $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25; |
3513 | $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25; |
3523 | |
3514 | |
3524 | _post_tick; |
3515 | _post_tick; |
3525 | |
|
|
3526 | |
|
|
3527 | }, |
3516 | }, |
3528 | ); |
3517 | ); |
3529 | |
3518 | |
3530 | { |
3519 | { |
3531 | BDB::min_parallel 8; |
3520 | BDB::min_parallel 8; |
… | |
… | |
3554 | ) |
3543 | ) |
3555 | }; |
3544 | }; |
3556 | |
3545 | |
3557 | unless ($DB_ENV) { |
3546 | unless ($DB_ENV) { |
3558 | $DB_ENV = BDB::db_env_create; |
3547 | $DB_ENV = BDB::db_env_create; |
|
|
3548 | $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC |
|
|
3549 | | BDB::LOG_AUTOREMOVE, 1); |
|
|
3550 | $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); |
|
|
3551 | $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); |
3559 | |
3552 | |
3560 | cf::sync_job { |
3553 | cf::sync_job { |
3561 | eval { |
3554 | eval { |
3562 | BDB::db_env_open |
3555 | BDB::db_env_open |
3563 | $DB_ENV, |
3556 | $DB_ENV, |
… | |
… | |
3565 | BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN |
3558 | BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN |
3566 | | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, |
3559 | | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, |
3567 | 0666; |
3560 | 0666; |
3568 | |
3561 | |
3569 | cf::cleanup "db_env_open($BDBDIR): $!" if $!; |
3562 | cf::cleanup "db_env_open($BDBDIR): $!" if $!; |
3570 | |
|
|
3571 | $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC |
|
|
3572 | | BDB::LOG_AUTOREMOVE, 1); |
|
|
3573 | $DB_ENV->set_lk_detect; |
|
|
3574 | }; |
3563 | }; |
3575 | |
3564 | |
3576 | cf::cleanup "db_env_open(db): $@" if $@; |
3565 | cf::cleanup "db_env_open(db): $@" if $@; |
3577 | }; |
3566 | }; |
3578 | } |
3567 | } |
3579 | |
3568 | |
|
|
3569 | $BDB_DEADLOCK_WATCHER = Event->timer ( |
|
|
3570 | after => 3, |
|
|
3571 | interval => 1, |
|
|
3572 | hard => 1, |
|
|
3573 | prio => 0, |
|
|
3574 | data => WF_AUTOCANCEL, |
|
|
3575 | cb => sub { |
|
|
3576 | BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { }; |
|
|
3577 | }, |
|
|
3578 | ); |
3580 | $BDB_CHECKPOINT_WATCHER = Event->timer ( |
3579 | $BDB_CHECKPOINT_WATCHER = Event->timer ( |
3581 | after => 11, |
3580 | after => 11, |
3582 | interval => 60, |
3581 | interval => 60, |
3583 | hard => 1, |
3582 | hard => 1, |
3584 | prio => 0, |
3583 | prio => 0, |