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.440 by root, Mon Aug 11 23:23:41 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
242for my $pkg (qw( 243for my $pkg (qw(
243 cf::global cf::attachable 244 cf::global cf::attachable
244 cf::object cf::object::player 245 cf::object cf::object::player
245 cf::client cf::player 246 cf::client cf::player
246 cf::arch cf::living 247 cf::arch cf::living
248 cf::map cf::mapspace
247 cf::map cf::party cf::region 249 cf::party cf::region
248)) { 250)) {
249 no strict 'refs'; 251 no strict 'refs';
250 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 252 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
251} 253}
252 254
2085 my $f = new_from_file cf::object::thawer $self->{load_path}; 2087 my $f = new_from_file cf::object::thawer $self->{load_path};
2086 $f->skip_block; 2088 $f->skip_block;
2087 $self->_load_objects ($f) 2089 $self->_load_objects ($f)
2088 or return; 2090 or return;
2089 2091
2090 $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) 2092 $self->post_load_original
2091 if delete $self->{load_original}; 2093 if delete $self->{load_original};
2092 2094
2093 if (my $uniq = $self->uniq_path) { 2095 if (my $uniq = $self->uniq_path) {
2094 utf8::encode $uniq; 2096 utf8::encode $uniq;
2095 unless (aio_stat $uniq) { 2097 unless (aio_stat $uniq) {
2612Moves the player to the given map-path and coordinates by first freezing 2614Moves the player to the given map-path and coordinates by first freezing
2613her, loading and preparing them map, calling the provided $check callback 2615her, loading and preparing them map, calling the provided $check callback
2614that has to return the map if sucecssful, and then unfreezes the player on 2616that 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 2617the new (success) or old (failed) map position. In either case, $done will
2616be called at the end of this process. 2618be called at the end of this process.
2619
2620Note that $check will be called with a potentially non-loaded map, so if
2621it needs a loaded map it has to call C<< ->load >>.
2617 2622
2618=cut 2623=cut
2619 2624
2620our $GOTOGEN; 2625our $GOTOGEN;
2621 2626
3124=cut 3129=cut
3125 3130
3126for ( 3131for (
3127 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y 3132 ["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 3133 insert remove inv nrof name archname title slaying race
3129 decrease split destroy)], 3134 decrease split destroy change_exp)],
3130 ["cf::object::player" => qw(player)], 3135 ["cf::object::player" => qw(player)],
3131 ["cf::player" => qw(peaceful)], 3136 ["cf::player" => qw(peaceful)],
3132 ["cf::map" => qw(trigger)], 3137 ["cf::map" => qw(trigger)],
3133) { 3138) {
3134 no strict 'refs'; 3139 no strict 'refs';
3394 warn "finished reloading resource files\n"; 3399 warn "finished reloading resource files\n";
3395} 3400}
3396 3401
3397sub init { 3402sub init {
3398 my $guard = freeze_mainloop; 3403 my $guard = freeze_mainloop;
3404
3405 evthread_start IO::AIO::poll_fileno;
3399 3406
3400 reload_resources; 3407 reload_resources;
3401} 3408}
3402 3409
3403sub reload_config { 3410sub reload_config {
3436 reload_config; 3443 reload_config;
3437 db_init; 3444 db_init;
3438 load_extensions; 3445 load_extensions;
3439 3446
3440 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3447 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3441 evthread_start IO::AIO::poll_fileno;
3442 } 3448 }
3443 3449
3444 EV::loop; 3450 EV::loop;
3445} 3451}
3446 3452
3787{ 3793{
3788 # configure BDB 3794 # configure BDB
3789 3795
3790 BDB::min_parallel 8; 3796 BDB::min_parallel 8;
3791 BDB::max_poll_reqs $TICK * 0.1; 3797 BDB::max_poll_reqs $TICK * 0.1;
3792 $Coro::BDB::WATCHER->priority (1); 3798 $AnyEvent::BDB::WATCHER->priority (1);
3793 3799
3794 unless ($DB_ENV) { 3800 unless ($DB_ENV) {
3795 $DB_ENV = BDB::db_env_create; 3801 $DB_ENV = BDB::db_env_create;
3796 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC 3802 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT);
3797 | BDB::LOG_AUTOREMOVE, 1); 3803 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7;
3804 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7;
3798 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); 3805 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT);
3799 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); 3806 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT);
3800 3807
3801 cf::sync_job { 3808 cf::sync_job {
3802 eval { 3809 eval {
3828{ 3835{
3829 # configure IO::AIO 3836 # configure IO::AIO
3830 3837
3831 IO::AIO::min_parallel 8; 3838 IO::AIO::min_parallel 8;
3832 IO::AIO::max_poll_time $TICK * 0.1; 3839 IO::AIO::max_poll_time $TICK * 0.1;
3833 $Coro::AIO::WATCHER->priority (1); 3840 undef $AnyEvent::AIO::WATCHER;
3834} 3841}
3835 3842
3836my $_log_backtrace; 3843my $_log_backtrace;
3837 3844
3838sub _log_backtrace { 3845sub _log_backtrace {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines