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.419 by root, Sun Apr 13 01:34:09 2008 UTC vs.
Revision 1.426 by root, Thu Apr 24 04:40:31 2008 UTC

427 } 427 }
428 } 428 }
429}; 429};
430 430
431sub get_slot($;$$) { 431sub get_slot($;$$) {
432 return if tick_inhibit || $Coro::current == $Coro::main;
433
432 my ($time, $pri, $name) = @_; 434 my ($time, $pri, $name) = @_;
433 435
434 $time = $TICK * .6 if $time > $TICK * .6; 436 $time = $TICK * .6 if $time > $TICK * .6;
435 my $sig = new Coro::Signal; 437 my $sig = new Coro::Signal;
436 438
1473 1475
1474 return if $pl->{deny_save}; 1476 return if $pl->{deny_save};
1475 1477
1476 aio_mkdir playerdir $pl, 0770; 1478 aio_mkdir playerdir $pl, 0770;
1477 $pl->{last_save} = $cf::RUNTIME; 1479 $pl->{last_save} = $cf::RUNTIME;
1480
1481 cf::get_slot 0.01;
1478 1482
1479 $pl->save_pl ($path); 1483 $pl->save_pl ($path);
1480 cf::cede_to_tick; 1484 cf::cede_to_tick;
1481} 1485}
1482 1486
2113 } 2117 }
2114 2118
2115 $self->{last_save} = $cf::RUNTIME; 2119 $self->{last_save} = $cf::RUNTIME;
2116 $self->last_access ($cf::RUNTIME); 2120 $self->last_access ($cf::RUNTIME);
2117 2121
2118 $self->in_memory (cf::MAP_IN_MEMORY); 2122 $self->in_memory (cf::MAP_ACTIVE);
2119 } 2123 }
2120 2124
2121 $self->post_load; 2125 $self->post_load;
2122} 2126}
2123 2127
2181 my ($path, $origin, $load) = @_; 2185 my ($path, $origin, $load) = @_;
2182 2186
2183 $path = normalise $path, $origin && $origin->{path}; 2187 $path = normalise $path, $origin && $origin->{path};
2184 2188
2185 if (my $map = $cf::MAP{$path}) { 2189 if (my $map = $cf::MAP{$path}) {
2186 return $map if !$load || $map->in_memory == cf::MAP_IN_MEMORY; 2190 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE;
2187 } 2191 }
2188 2192
2189 $MAP_PREFETCH{$path} |= $load; 2193 $MAP_PREFETCH{$path} |= $load;
2190 2194
2191 $MAP_PREFETCHER ||= cf::async { 2195 $MAP_PREFETCHER ||= cf::async {
2228 cf::async { 2232 cf::async {
2229 $Coro::current->{desc} = "map player save"; 2233 $Coro::current->{desc} = "map player save";
2230 $_->contr->save for $self->players; 2234 $_->contr->save for $self->players;
2231 }; 2235 };
2232 2236
2237 cf::get_slot 0.02;
2238
2233 if ($uniq) { 2239 if ($uniq) {
2234 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS); 2240 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS);
2235 $self->_save_objects ($uniq, cf::IO_UNIQUES); 2241 $self->_save_objects ($uniq, cf::IO_UNIQUES);
2236 } else { 2242 } else {
2237 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); 2243 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES);
2245 $self->save; 2251 $self->save;
2246 2252
2247 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2253 my $lock = cf::lock_acquire "map_data:$self->{path}";
2248 2254
2249 return if $self->players; 2255 return if $self->players;
2250 return if $self->in_memory != cf::MAP_IN_MEMORY; 2256 return if $self->in_memory != cf::MAP_ACTIVE;
2251 return if $self->{deny_save}; 2257 return if $self->{deny_save};
2252 2258
2253 $self->in_memory (cf::MAP_SWAPPED); 2259 $self->in_memory (cf::MAP_SWAPPED);
2254 2260
2255 $self->deactivate; 2261 $self->deactivate;
2693 $rmp->{origin_y} = $exit->y; 2699 $rmp->{origin_y} = $exit->y;
2694 } 2700 }
2695 2701
2696 $rmp->{random_seed} ||= $exit->random_seed; 2702 $rmp->{random_seed} ||= $exit->random_seed;
2697 2703
2698 my $data = cf::encode_json $rmp; 2704 my $data = JSON::XS->new->utf8->pretty->canonical->encode ($rmp);
2699 my $md5 = Digest::MD5::md5_hex $data; 2705 my $md5 = Digest::MD5::md5_hex $data;
2700 my $meta = "$RANDOMDIR/$md5.meta"; 2706 my $meta = "$RANDOMDIR/$md5.meta";
2701 2707
2702 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) { 2708 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
2703 aio_write $fh, 0, (length $data), $data, 0; 2709 aio_write $fh, 0, (length $data), $data, 0;
2826 id => "infobox", 2832 id => "infobox",
2827 title => "Map Info", 2833 title => "Map Info",
2828 reply => undef, 2834 reply => undef,
2829 tooltip => "Information related to the maps", 2835 tooltip => "Information related to the maps",
2830 }, 2836 },
2837 "c/party" => {
2838 id => "party",
2839 title => "Party",
2840 reply => "gsay ",
2841 tooltip => "Messages and chat related to your party",
2842 },
2831); 2843);
2832 2844
2833sub cf::client::send_msg { 2845sub cf::client::send_msg {
2834 my ($self, $channel, $msg, $color, @extra) = @_; 2846 my ($self, $channel, $msg, $color, @extra) = @_;
2835 2847
3072 3084
3073The following functions and methods are available within a safe environment: 3085The following functions and methods are available within a safe environment:
3074 3086
3075 cf::object 3087 cf::object
3076 contr pay_amount pay_player map x y force_find force_add destroy 3088 contr pay_amount pay_player map x y force_find force_add destroy
3077 insert remove name archname title slaying race decrease_ob_nr 3089 insert remove name archname title slaying race decrease split
3078 3090
3079 cf::object::player 3091 cf::object::player
3080 player 3092 player
3081 3093
3082 cf::player 3094 cf::player
3088=cut 3100=cut
3089 3101
3090for ( 3102for (
3091 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y 3103 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y
3092 insert remove inv name archname title slaying race 3104 insert remove inv name archname title slaying race
3093 decrease_ob_nr destroy)], 3105 decrease split destroy)],
3094 ["cf::object::player" => qw(player)], 3106 ["cf::object::player" => qw(player)],
3095 ["cf::player" => qw(peaceful)], 3107 ["cf::player" => qw(peaceful)],
3096 ["cf::map" => qw(trigger)], 3108 ["cf::map" => qw(trigger)],
3097) { 3109) {
3098 no strict 'refs'; 3110 no strict 'refs';
3306 while (my ($k, $v) = each %$want) { 3318 while (my ($k, $v) = each %$want) {
3307 $ns->fx_want ($k, $v); 3319 $ns->fx_want ($k, $v);
3308 } 3320 }
3309}; 3321};
3310 3322
3323sub load_resource_file($) {
3324 my $guard = lock_acquire "load_resource_file";
3325
3326 my $status = load_resource_file_ $_[0];
3327 get_slot 0.1, 100;
3328 cf::arch::commit_load;
3329
3330 $status
3331}
3332
3311sub reload_regions { 3333sub reload_regions {
3312 # HACK to clear player env face cache, we need some signal framework 3334 # HACK to clear player env face cache, we need some signal framework
3313 # for this (global event?) 3335 # for this (global event?)
3314 %ext::player_env::MUSIC_FACE_CACHE = (); 3336 %ext::player_env::MUSIC_FACE_CACHE = ();
3315 3337
3328} 3350}
3329 3351
3330sub reload_archetypes { 3352sub reload_archetypes {
3331 load_resource_file "$DATADIR/archetypes" 3353 load_resource_file "$DATADIR/archetypes"
3332 or die "unable to load archetypes\n"; 3354 or die "unable to load archetypes\n";
3333 #d# NEED to laod twice to resolve forward references
3334 # this really needs to be done in an extra post-pass
3335 # (which needs to be synchronous, so solve it differently)
3336 load_resource_file "$DATADIR/archetypes"
3337 or die "unable to load archetypes\n";
3338} 3355}
3339 3356
3340sub reload_treasures { 3357sub reload_treasures {
3341 load_resource_file "$DATADIR/treasures" 3358 load_resource_file "$DATADIR/treasures"
3342 or die "unable to load treasurelists\n"; 3359 or die "unable to load treasurelists\n";
3343} 3360}
3344 3361
3345sub reload_resources { 3362sub reload_resources {
3346 warn "reloading resource files...\n"; 3363 warn "reloading resource files...\n";
3347 3364
3365 reload_facedata;
3366 reload_archetypes;
3348 reload_regions; 3367 reload_regions;
3349 reload_facedata;
3350 #reload_archetypes;#d#
3351 reload_archetypes;
3352 reload_treasures; 3368 reload_treasures;
3353 3369
3354 warn "finished reloading resource files\n"; 3370 warn "finished reloading resource files\n";
3355} 3371}
3356 3372
3357sub init { 3373sub init {
3374 my $guard = freeze_mainloop;
3375
3358 reload_resources; 3376 reload_resources;
3359} 3377}
3360 3378
3361sub reload_config { 3379sub reload_config {
3362 open my $fh, "<:utf8", "$CONFDIR/config" 3380 open my $fh, "<:utf8", "$CONFDIR/config"
3387 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3405 $Coro::current->{desc} = "IDLE BUG HANDLER";
3388 EV::loop EV::LOOP_ONESHOT; 3406 EV::loop EV::LOOP_ONESHOT;
3389 })->prio (Coro::PRIO_MAX); 3407 })->prio (Coro::PRIO_MAX);
3390 }; 3408 };
3391 3409
3410 {
3411 my $guard = freeze_mainloop;
3392 reload_config; 3412 reload_config;
3393 db_init; 3413 db_init;
3394 load_extensions; 3414 load_extensions;
3395 3415
3396 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3416 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3397 evthread_start IO::AIO::poll_fileno; 3417 evthread_start IO::AIO::poll_fileno;
3418 }
3419
3398 EV::loop; 3420 EV::loop;
3399} 3421}
3400 3422
3401############################################################################# 3423#############################################################################
3402# initialisation and cleanup 3424# initialisation and cleanup
3684 3706
3685our @WAIT_FOR_TICK; 3707our @WAIT_FOR_TICK;
3686our @WAIT_FOR_TICK_BEGIN; 3708our @WAIT_FOR_TICK_BEGIN;
3687 3709
3688sub wait_for_tick { 3710sub wait_for_tick {
3689 return if tick_inhibit;
3690 return if $Coro::current == $Coro::main; 3711 return if tick_inhibit || $Coro::current == $Coro::main;
3691 3712
3692 my $signal = new Coro::Signal; 3713 my $signal = new Coro::Signal;
3693 push @WAIT_FOR_TICK, $signal; 3714 push @WAIT_FOR_TICK, $signal;
3694 $signal->wait; 3715 $signal->wait;
3695} 3716}
3696 3717
3697sub wait_for_tick_begin { 3718sub wait_for_tick_begin {
3698 return if tick_inhibit;
3699 return if $Coro::current == $Coro::main; 3719 return if tick_inhibit || $Coro::current == $Coro::main;
3700 3720
3701 my $signal = new Coro::Signal; 3721 my $signal = new Coro::Signal;
3702 push @WAIT_FOR_TICK_BEGIN, $signal; 3722 push @WAIT_FOR_TICK_BEGIN, $signal;
3703 $signal->wait; 3723 $signal->wait;
3704} 3724}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines