… | |
… | |
25 | use strict; |
25 | use strict; |
26 | |
26 | |
27 | use Symbol; |
27 | use Symbol; |
28 | use List::Util; |
28 | use List::Util; |
29 | use Socket; |
29 | use Socket; |
30 | use EV 3.2; |
30 | use EV; |
31 | use Opcode; |
31 | use Opcode; |
32 | use Safe; |
32 | use Safe; |
33 | use Safe::Hole; |
33 | use Safe::Hole; |
34 | use Storable (); |
34 | use Storable (); |
35 | |
35 | |
36 | use Coro 4.50 (); |
36 | use Coro (); |
37 | use Coro::State; |
37 | use Coro::State; |
38 | use Coro::Handle; |
38 | use Coro::Handle; |
39 | use Coro::EV; |
39 | use Coro::AnyEvent; |
40 | use Coro::Timer; |
40 | use Coro::Timer; |
41 | use Coro::Signal; |
41 | use Coro::Signal; |
42 | use Coro::Semaphore; |
42 | use Coro::Semaphore; |
|
|
43 | use Coro::AnyEvent; |
43 | use Coro::AIO; |
44 | use Coro::AIO; |
44 | use Coro::BDB; |
45 | use Coro::BDB 1.6; |
45 | use Coro::Storable; |
46 | use Coro::Storable; |
46 | use Coro::Util (); |
47 | use Coro::Util (); |
47 | |
48 | |
48 | use JSON::XS 2.01 (); |
49 | use JSON::XS 2.01 (); |
49 | use BDB (); |
50 | use BDB (); |
50 | use Data::Dumper; |
51 | use Data::Dumper; |
51 | use Digest::MD5; |
52 | use Digest::MD5; |
52 | use Fcntl; |
53 | use Fcntl; |
53 | use YAML (); |
54 | use YAML (); |
54 | use IO::AIO 2.51 (); |
55 | use IO::AIO (); |
55 | use Time::HiRes; |
56 | use Time::HiRes; |
56 | use Compress::LZF; |
57 | use Compress::LZF; |
57 | use Digest::MD5 (); |
58 | use Digest::MD5 (); |
|
|
59 | |
|
|
60 | AnyEvent::detect; |
58 | |
61 | |
59 | # configure various modules to our taste |
62 | # configure various modules to our taste |
60 | # |
63 | # |
61 | $Storable::canonical = 1; # reduce rsync transfers |
64 | $Storable::canonical = 1; # reduce rsync transfers |
62 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
65 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
… | |
… | |
90 | our $RANDOMDIR = "$LOCALDIR/random"; |
93 | our $RANDOMDIR = "$LOCALDIR/random"; |
91 | our $BDBDIR = "$LOCALDIR/db"; |
94 | our $BDBDIR = "$LOCALDIR/db"; |
92 | our %RESOURCE; |
95 | our %RESOURCE; |
93 | |
96 | |
94 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
97 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
95 | our $AIO_POLL_WATCHER; |
|
|
96 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
98 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
97 | our $NEXT_TICK; |
99 | our $NEXT_TICK; |
98 | our $USE_FSYNC = 1; # use fsync to write maps - default off |
100 | our $USE_FSYNC = 1; # use fsync to write maps - default off |
99 | |
101 | |
100 | our $BDB_POLL_WATCHER; |
|
|
101 | our $BDB_DEADLOCK_WATCHER; |
102 | our $BDB_DEADLOCK_WATCHER; |
102 | our $BDB_CHECKPOINT_WATCHER; |
103 | our $BDB_CHECKPOINT_WATCHER; |
103 | our $BDB_TRICKLE_WATCHER; |
104 | our $BDB_TRICKLE_WATCHER; |
104 | our $DB_ENV; |
105 | our $DB_ENV; |
105 | |
106 | |
… | |
… | |
2085 | my $f = new_from_file cf::object::thawer $self->{load_path}; |
2086 | my $f = new_from_file cf::object::thawer $self->{load_path}; |
2086 | $f->skip_block; |
2087 | $f->skip_block; |
2087 | $self->_load_objects ($f) |
2088 | $self->_load_objects ($f) |
2088 | or return; |
2089 | or return; |
2089 | |
2090 | |
2090 | $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) |
2091 | $self->post_load_original |
2091 | if delete $self->{load_original}; |
2092 | if delete $self->{load_original}; |
2092 | |
2093 | |
2093 | if (my $uniq = $self->uniq_path) { |
2094 | if (my $uniq = $self->uniq_path) { |
2094 | utf8::encode $uniq; |
2095 | utf8::encode $uniq; |
2095 | unless (aio_stat $uniq) { |
2096 | unless (aio_stat $uniq) { |
… | |
… | |
2612 | Moves the player to the given map-path and coordinates by first freezing |
2613 | Moves the player to the given map-path and coordinates by first freezing |
2613 | her, loading and preparing them map, calling the provided $check callback |
2614 | her, loading and preparing them map, calling the provided $check callback |
2614 | that has to return the map if sucecssful, and then unfreezes the player on |
2615 | that has to return the map if sucecssful, and then unfreezes the player on |
2615 | the new (success) or old (failed) map position. In either case, $done will |
2616 | the new (success) or old (failed) map position. In either case, $done will |
2616 | be called at the end of this process. |
2617 | be called at the end of this process. |
|
|
2618 | |
|
|
2619 | Note that $check will be called with a potentially non-loaded map, so if |
|
|
2620 | it needs a loaded map it has to call C<< ->load >>. |
2617 | |
2621 | |
2618 | =cut |
2622 | =cut |
2619 | |
2623 | |
2620 | our $GOTOGEN; |
2624 | our $GOTOGEN; |
2621 | |
2625 | |
… | |
… | |
3124 | =cut |
3128 | =cut |
3125 | |
3129 | |
3126 | for ( |
3130 | for ( |
3127 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3131 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3128 | insert remove inv nrof name archname title slaying race |
3132 | insert remove inv nrof name archname title slaying race |
3129 | decrease split destroy)], |
3133 | decrease split destroy change_exp)], |
3130 | ["cf::object::player" => qw(player)], |
3134 | ["cf::object::player" => qw(player)], |
3131 | ["cf::player" => qw(peaceful)], |
3135 | ["cf::player" => qw(peaceful)], |
3132 | ["cf::map" => qw(trigger)], |
3136 | ["cf::map" => qw(trigger)], |
3133 | ) { |
3137 | ) { |
3134 | no strict 'refs'; |
3138 | no strict 'refs'; |
… | |
… | |
3394 | warn "finished reloading resource files\n"; |
3398 | warn "finished reloading resource files\n"; |
3395 | } |
3399 | } |
3396 | |
3400 | |
3397 | sub init { |
3401 | sub init { |
3398 | my $guard = freeze_mainloop; |
3402 | my $guard = freeze_mainloop; |
|
|
3403 | |
|
|
3404 | evthread_start IO::AIO::poll_fileno; |
3399 | |
3405 | |
3400 | reload_resources; |
3406 | reload_resources; |
3401 | } |
3407 | } |
3402 | |
3408 | |
3403 | sub reload_config { |
3409 | sub reload_config { |
… | |
… | |
3436 | reload_config; |
3442 | reload_config; |
3437 | db_init; |
3443 | db_init; |
3438 | load_extensions; |
3444 | load_extensions; |
3439 | |
3445 | |
3440 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3446 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3441 | evthread_start IO::AIO::poll_fileno; |
|
|
3442 | } |
3447 | } |
3443 | |
3448 | |
3444 | EV::loop; |
3449 | EV::loop; |
3445 | } |
3450 | } |
3446 | |
3451 | |
… | |
… | |
3787 | { |
3792 | { |
3788 | # configure BDB |
3793 | # configure BDB |
3789 | |
3794 | |
3790 | BDB::min_parallel 8; |
3795 | BDB::min_parallel 8; |
3791 | BDB::max_poll_reqs $TICK * 0.1; |
3796 | BDB::max_poll_reqs $TICK * 0.1; |
3792 | $Coro::BDB::WATCHER->priority (1); |
3797 | $AnyEvent::BDB::WATCHER->priority (1); |
3793 | |
3798 | |
3794 | unless ($DB_ENV) { |
3799 | unless ($DB_ENV) { |
3795 | $DB_ENV = BDB::db_env_create; |
3800 | $DB_ENV = BDB::db_env_create; |
3796 | $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC |
3801 | $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT); |
3797 | | BDB::LOG_AUTOREMOVE, 1); |
3802 | $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; |
|
|
3803 | $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; |
3798 | $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); |
3804 | $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); |
3799 | $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); |
3805 | $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); |
3800 | |
3806 | |
3801 | cf::sync_job { |
3807 | cf::sync_job { |
3802 | eval { |
3808 | eval { |
… | |
… | |
3828 | { |
3834 | { |
3829 | # configure IO::AIO |
3835 | # configure IO::AIO |
3830 | |
3836 | |
3831 | IO::AIO::min_parallel 8; |
3837 | IO::AIO::min_parallel 8; |
3832 | IO::AIO::max_poll_time $TICK * 0.1; |
3838 | IO::AIO::max_poll_time $TICK * 0.1; |
3833 | $Coro::AIO::WATCHER->priority (1); |
3839 | undef $AnyEvent::AIO::WATCHER; |
3834 | } |
3840 | } |
3835 | |
3841 | |
3836 | my $_log_backtrace; |
3842 | my $_log_backtrace; |
3837 | |
3843 | |
3838 | sub _log_backtrace { |
3844 | sub _log_backtrace { |