… | |
… | |
1775 | our $MAX_RESET = 3600; |
1775 | our $MAX_RESET = 3600; |
1776 | our $DEFAULT_RESET = 3000; |
1776 | our $DEFAULT_RESET = 3000; |
1777 | |
1777 | |
1778 | sub generate_random_map { |
1778 | sub generate_random_map { |
1779 | my ($self, $rmp) = @_; |
1779 | my ($self, $rmp) = @_; |
|
|
1780 | |
|
|
1781 | my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM |
|
|
1782 | |
1780 | # mit "rum" bekleckern, nicht |
1783 | # mit "rum" bekleckern, nicht |
1781 | $self->_create_random_map ( |
1784 | $self->_create_random_map ( |
1782 | $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, |
1785 | $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, |
1783 | $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, |
1786 | $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, |
1784 | $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, |
1787 | $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, |
… | |
… | |
1906 | |
1909 | |
1907 | # the temporary/swap location |
1910 | # the temporary/swap location |
1908 | sub save_path { |
1911 | sub save_path { |
1909 | my ($self) = @_; |
1912 | my ($self) = @_; |
1910 | |
1913 | |
1911 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; |
1914 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go; |
1912 | "$TMPDIR/$path.map" |
1915 | "$TMPDIR/$path.map" |
1913 | } |
1916 | } |
1914 | |
1917 | |
1915 | # the unique path, undef == no special unique path |
1918 | # the unique path, undef == no special unique path |
1916 | sub uniq_path { |
1919 | sub uniq_path { |
1917 | my ($self) = @_; |
1920 | my ($self) = @_; |
1918 | |
1921 | |
1919 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; |
1922 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go; |
1920 | "$UNIQUEDIR/$path" |
1923 | "$UNIQUEDIR/$path" |
1921 | } |
1924 | } |
1922 | |
1925 | |
1923 | # and all this just because we cannot iterate over |
1926 | # and all this just because we cannot iterate over |
1924 | # all maps in C++... |
1927 | # all maps in C++... |
… | |
… | |
2370 | |
2373 | |
2371 | sub unique_maps() { |
2374 | sub unique_maps() { |
2372 | [ |
2375 | [ |
2373 | map { |
2376 | map { |
2374 | utf8::decode $_; |
2377 | utf8::decode $_; |
2375 | /\.map$/ |
2378 | s/\.map$//; # TODO future compatibility hack |
|
|
2379 | /\.pst$/ || !/^$PATH_SEP/o # TODO unique maps apparebntly lack the .map suffix :/ |
|
|
2380 | ? () |
2376 | ? normalise $_ |
2381 | : normalise $_ |
2377 | : () |
|
|
2378 | } @{ aio_readdir $UNIQUEDIR or [] } |
2382 | } @{ aio_readdir $UNIQUEDIR or [] } |
2379 | ] |
2383 | ] |
2380 | } |
2384 | } |
2381 | |
2385 | |
2382 | =back |
2386 | =back |
… | |
… | |
2389 | |
2393 | |
2390 | =over 4 |
2394 | =over 4 |
2391 | |
2395 | |
2392 | =item $ob->inv_recursive |
2396 | =item $ob->inv_recursive |
2393 | |
2397 | |
2394 | Returns the inventory of the object _and_ their inventories, recursively. |
2398 | Returns the inventory of the object I<and> their inventories, recursively, |
|
|
2399 | but I<not> the object itself. |
2395 | |
2400 | |
2396 | =cut |
2401 | =cut |
2397 | |
2402 | |
2398 | sub inv_recursive_; |
2403 | sub inv_recursive_; |
2399 | sub inv_recursive_ { |
2404 | sub inv_recursive_ { |
… | |
… | |
2404 | inv_recursive_ inv $_[0] |
2409 | inv_recursive_ inv $_[0] |
2405 | } |
2410 | } |
2406 | |
2411 | |
2407 | =item $ref = $ob->ref |
2412 | =item $ref = $ob->ref |
2408 | |
2413 | |
2409 | creates and returns a persistent reference to an objetc that can be stored as a string. |
2414 | Creates and returns a persistent reference to an object that can be stored as a string. |
2410 | |
2415 | |
2411 | =item $ob = cf::object::deref ($refstring) |
2416 | =item $ob = cf::object::deref ($refstring) |
2412 | |
2417 | |
2413 | returns the objetc referenced by refstring. may return undef when it cnanot find the object, |
2418 | returns the objetc referenced by refstring. may return undef when it cnanot find the object, |
2414 | even if the object actually exists. May block. |
2419 | even if the object actually exists. May block. |
… | |
… | |
3404 | cf::cleanup "SIG$signal"; |
3409 | cf::cleanup "SIG$signal"; |
3405 | }; |
3410 | }; |
3406 | } |
3411 | } |
3407 | } |
3412 | } |
3408 | |
3413 | |
3409 | sub write_runtime { |
3414 | sub write_runtime_sync { |
3410 | my $runtime = "$LOCALDIR/runtime"; |
3415 | my $runtime = "$LOCALDIR/runtime"; |
3411 | |
3416 | |
3412 | # first touch the runtime file to show we are still running: |
3417 | # first touch the runtime file to show we are still running: |
3413 | # the fsync below can take a very very long time. |
3418 | # the fsync below can take a very very long time. |
3414 | |
3419 | |
… | |
… | |
3542 | warn "reloading..."; |
3547 | warn "reloading..."; |
3543 | |
3548 | |
3544 | warn "entering sync_job"; |
3549 | warn "entering sync_job"; |
3545 | |
3550 | |
3546 | cf::sync_job { |
3551 | cf::sync_job { |
3547 | cf::write_runtime; # external watchdog should not bark |
3552 | cf::write_runtime_sync; # external watchdog should not bark |
3548 | cf::emergency_save; |
3553 | cf::emergency_save; |
3549 | cf::write_runtime; # external watchdog should not bark |
3554 | cf::write_runtime_sync; # external watchdog should not bark |
3550 | |
3555 | |
3551 | warn "syncing database to disk"; |
3556 | warn "syncing database to disk"; |
3552 | BDB::db_env_txn_checkpoint $DB_ENV; |
3557 | BDB::db_env_txn_checkpoint $DB_ENV; |
3553 | |
3558 | |
3554 | # if anything goes wrong in here, we should simply crash as we already saved |
3559 | # if anything goes wrong in here, we should simply crash as we already saved |
… | |
… | |
3709 | |
3714 | |
3710 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3715 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3711 | $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; |
3716 | $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; |
3712 | Coro::async_pool { |
3717 | Coro::async_pool { |
3713 | $Coro::current->{desc} = "runtime saver"; |
3718 | $Coro::current->{desc} = "runtime saver"; |
3714 | write_runtime |
3719 | write_runtime_sync |
3715 | or warn "ERROR: unable to write runtime file: $!"; |
3720 | or warn "ERROR: unable to write runtime file: $!"; |
3716 | }; |
3721 | }; |
3717 | } |
3722 | } |
3718 | |
3723 | |
3719 | if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { |
3724 | if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { |