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.432 by root, Mon May 5 22:38:47 2008 UTC vs.
Revision 1.439 by root, Mon Jul 14 16:42:49 2008 UTC

25use strict; 25use strict;
26 26
27use Symbol; 27use Symbol;
28use List::Util; 28use List::Util;
29use Socket; 29use Socket;
30use EV 3.2; 30use EV;
31use Opcode; 31use Opcode;
32use Safe; 32use Safe;
33use Safe::Hole; 33use Safe::Hole;
34use Storable (); 34use Storable ();
35 35
36use Coro 4.50 (); 36use Coro ();
37use Coro::State; 37use Coro::State;
38use Coro::Handle; 38use Coro::Handle;
39use Coro::EV; 39use Coro::AnyEvent;
40use Coro::Timer; 40use Coro::Timer;
41use Coro::Signal; 41use Coro::Signal;
42use Coro::Semaphore; 42use Coro::Semaphore;
43use Coro::AnyEvent;
43use Coro::AIO; 44use Coro::AIO;
44use Coro::BDB; 45use Coro::BDB 1.6;
45use Coro::Storable; 46use Coro::Storable;
46use Coro::Util (); 47use Coro::Util ();
47 48
48use JSON::XS 2.01 (); 49use JSON::XS 2.01 ();
49use BDB (); 50use BDB ();
50use Data::Dumper; 51use Data::Dumper;
51use Digest::MD5; 52use Digest::MD5;
52use Fcntl; 53use Fcntl;
53use YAML (); 54use YAML ();
54use IO::AIO 2.51 (); 55use IO::AIO ();
55use Time::HiRes; 56use Time::HiRes;
56use Compress::LZF; 57use Compress::LZF;
57use Digest::MD5 (); 58use Digest::MD5 ();
59
60AnyEvent::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
62Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator 65Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator
90our $RANDOMDIR = "$LOCALDIR/random"; 93our $RANDOMDIR = "$LOCALDIR/random";
91our $BDBDIR = "$LOCALDIR/db"; 94our $BDBDIR = "$LOCALDIR/db";
92our %RESOURCE; 95our %RESOURCE;
93 96
94our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 97our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
95our $AIO_POLL_WATCHER;
96our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 98our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
97our $NEXT_TICK; 99our $NEXT_TICK;
98our $USE_FSYNC = 1; # use fsync to write maps - default off 100our $USE_FSYNC = 1; # use fsync to write maps - default off
99 101
100our $BDB_POLL_WATCHER;
101our $BDB_DEADLOCK_WATCHER; 102our $BDB_DEADLOCK_WATCHER;
102our $BDB_CHECKPOINT_WATCHER; 103our $BDB_CHECKPOINT_WATCHER;
103our $BDB_TRICKLE_WATCHER; 104our $BDB_TRICKLE_WATCHER;
104our $DB_ENV; 105our $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) {
2612Moves the player to the given map-path and coordinates by first freezing 2613Moves the player to the given map-path and coordinates by first freezing
2613her, loading and preparing them map, calling the provided $check callback 2614her, loading and preparing them map, calling the provided $check callback
2614that has to return the map if sucecssful, and then unfreezes the player on 2615that has to return the map if sucecssful, and then unfreezes the player on
2615the new (success) or old (failed) map position. In either case, $done will 2616the new (success) or old (failed) map position. In either case, $done will
2616be called at the end of this process. 2617be called at the end of this process.
2618
2619Note that $check will be called with a potentially non-loaded map, so if
2620it needs a loaded map it has to call C<< ->load >>.
2617 2621
2618=cut 2622=cut
2619 2623
2620our $GOTOGEN; 2624our $GOTOGEN;
2621 2625
3124=cut 3128=cut
3125 3129
3126for ( 3130for (
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
3397sub init { 3401sub 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
3403sub reload_config { 3409sub 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
3836my $_log_backtrace; 3842my $_log_backtrace;
3837 3843
3838sub _log_backtrace { 3844sub _log_backtrace {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines