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.418 by root, Fri Apr 11 21:09:53 2008 UTC vs.
Revision 1.423 by root, Sun Apr 20 00:44:13 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
1909 1913
1910# the temporary/swap location 1914# the temporary/swap location
1911sub save_path { 1915sub save_path {
1912 my ($self) = @_; 1916 my ($self) = @_;
1913 1917
1914 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; 1918 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go;
1915 "$TMPDIR/$path.map" 1919 "$TMPDIR/$path.map"
1916} 1920}
1917 1921
1918# the unique path, undef == no special unique path 1922# the unique path, undef == no special unique path
1919sub uniq_path { 1923sub uniq_path {
1920 my ($self) = @_; 1924 my ($self) = @_;
1921 1925
1922 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; 1926 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go;
1923 "$UNIQUEDIR/$path" 1927 "$UNIQUEDIR/$path"
1924} 1928}
1925 1929
1926# and all this just because we cannot iterate over 1930# and all this just because we cannot iterate over
1927# all maps in C++... 1931# all maps in C++...
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;
2373 2379
2374sub unique_maps() { 2380sub unique_maps() {
2375 [ 2381 [
2376 map { 2382 map {
2377 utf8::decode $_; 2383 utf8::decode $_;
2378 /\.map$/ 2384 s/\.map$//; # TODO future compatibility hack
2385 /\.pst$/ || !/^$PATH_SEP/o # TODO unique maps apparebntly lack the .map suffix :/
2386 ? ()
2379 ? normalise $_ 2387 : normalise $_
2380 : ()
2381 } @{ aio_readdir $UNIQUEDIR or [] } 2388 } @{ aio_readdir $UNIQUEDIR or [] }
2382 ] 2389 ]
2383} 2390}
2384 2391
2385=back 2392=back
2392 2399
2393=over 4 2400=over 4
2394 2401
2395=item $ob->inv_recursive 2402=item $ob->inv_recursive
2396 2403
2397Returns the inventory of the object _and_ their inventories, recursively. 2404Returns the inventory of the object I<and> their inventories, recursively,
2405but I<not> the object itself.
2398 2406
2399=cut 2407=cut
2400 2408
2401sub inv_recursive_; 2409sub inv_recursive_;
2402sub inv_recursive_ { 2410sub inv_recursive_ {
2407 inv_recursive_ inv $_[0] 2415 inv_recursive_ inv $_[0]
2408} 2416}
2409 2417
2410=item $ref = $ob->ref 2418=item $ref = $ob->ref
2411 2419
2412creates and returns a persistent reference to an objetc that can be stored as a string. 2420Creates and returns a persistent reference to an object that can be stored as a string.
2413 2421
2414=item $ob = cf::object::deref ($refstring) 2422=item $ob = cf::object::deref ($refstring)
2415 2423
2416returns the objetc referenced by refstring. may return undef when it cnanot find the object, 2424returns the objetc referenced by refstring. may return undef when it cnanot find the object,
2417even if the object actually exists. May block. 2425even if the object actually exists. May block.
2691 $rmp->{origin_y} = $exit->y; 2699 $rmp->{origin_y} = $exit->y;
2692 } 2700 }
2693 2701
2694 $rmp->{random_seed} ||= $exit->random_seed; 2702 $rmp->{random_seed} ||= $exit->random_seed;
2695 2703
2696 my $data = cf::encode_json $rmp; 2704 my $data = JSON::XS->new->utf8->pretty->canonical->encode ($rmp);
2697 my $md5 = Digest::MD5::md5_hex $data; 2705 my $md5 = Digest::MD5::md5_hex $data;
2698 my $meta = "$RANDOMDIR/$md5.meta"; 2706 my $meta = "$RANDOMDIR/$md5.meta";
2699 2707
2700 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) { 2708 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
2701 aio_write $fh, 0, (length $data), $data, 0; 2709 aio_write $fh, 0, (length $data), $data, 0;
3304 while (my ($k, $v) = each %$want) { 3312 while (my ($k, $v) = each %$want) {
3305 $ns->fx_want ($k, $v); 3313 $ns->fx_want ($k, $v);
3306 } 3314 }
3307}; 3315};
3308 3316
3317sub load_resource_file($) {
3318 my $status = load_resource_file_ $_[0];
3319 get_slot 0.1, 100;
3320 cf::arch::commit_load;
3321 $status
3322}
3323
3309sub reload_regions { 3324sub reload_regions {
3310 # HACK to clear player env face cache, we need some signal framework 3325 # HACK to clear player env face cache, we need some signal framework
3311 # for this (global event?) 3326 # for this (global event?)
3312 %ext::player_env::MUSIC_FACE_CACHE = (); 3327 %ext::player_env::MUSIC_FACE_CACHE = ();
3313 3328
3326} 3341}
3327 3342
3328sub reload_archetypes { 3343sub reload_archetypes {
3329 load_resource_file "$DATADIR/archetypes" 3344 load_resource_file "$DATADIR/archetypes"
3330 or die "unable to load archetypes\n"; 3345 or die "unable to load archetypes\n";
3331 #d# NEED to laod twice to resolve forward references
3332 # this really needs to be done in an extra post-pass
3333 # (which needs to be synchronous, so solve it differently)
3334 load_resource_file "$DATADIR/archetypes"
3335 or die "unable to load archetypes\n";
3336} 3346}
3337 3347
3338sub reload_treasures { 3348sub reload_treasures {
3339 load_resource_file "$DATADIR/treasures" 3349 load_resource_file "$DATADIR/treasures"
3340 or die "unable to load treasurelists\n"; 3350 or die "unable to load treasurelists\n";
3341} 3351}
3342 3352
3343sub reload_resources { 3353sub reload_resources {
3344 warn "reloading resource files...\n"; 3354 warn "reloading resource files...\n";
3345 3355
3356 reload_facedata;
3357 reload_archetypes;
3346 reload_regions; 3358 reload_regions;
3347 reload_facedata;
3348 #reload_archetypes;#d#
3349 reload_archetypes;
3350 reload_treasures; 3359 reload_treasures;
3351 3360
3352 warn "finished reloading resource files\n"; 3361 warn "finished reloading resource files\n";
3353} 3362}
3354 3363
3355sub init { 3364sub init {
3365 my $guard = freeze_mainloop;
3366
3356 reload_resources; 3367 reload_resources;
3357} 3368}
3358 3369
3359sub reload_config { 3370sub reload_config {
3360 open my $fh, "<:utf8", "$CONFDIR/config" 3371 open my $fh, "<:utf8", "$CONFDIR/config"
3385 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3396 $Coro::current->{desc} = "IDLE BUG HANDLER";
3386 EV::loop EV::LOOP_ONESHOT; 3397 EV::loop EV::LOOP_ONESHOT;
3387 })->prio (Coro::PRIO_MAX); 3398 })->prio (Coro::PRIO_MAX);
3388 }; 3399 };
3389 3400
3401 {
3402 my $guard = freeze_mainloop;
3390 reload_config; 3403 reload_config;
3391 db_init; 3404 db_init;
3392 load_extensions; 3405 load_extensions;
3393 3406
3394 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3407 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3395 evthread_start IO::AIO::poll_fileno; 3408 evthread_start IO::AIO::poll_fileno;
3409 }
3410
3396 EV::loop; 3411 EV::loop;
3397} 3412}
3398 3413
3399############################################################################# 3414#############################################################################
3400# initialisation and cleanup 3415# initialisation and cleanup
3682 3697
3683our @WAIT_FOR_TICK; 3698our @WAIT_FOR_TICK;
3684our @WAIT_FOR_TICK_BEGIN; 3699our @WAIT_FOR_TICK_BEGIN;
3685 3700
3686sub wait_for_tick { 3701sub wait_for_tick {
3687 return if tick_inhibit;
3688 return if $Coro::current == $Coro::main; 3702 return if tick_inhibit || $Coro::current == $Coro::main;
3689 3703
3690 my $signal = new Coro::Signal; 3704 my $signal = new Coro::Signal;
3691 push @WAIT_FOR_TICK, $signal; 3705 push @WAIT_FOR_TICK, $signal;
3692 $signal->wait; 3706 $signal->wait;
3693} 3707}
3694 3708
3695sub wait_for_tick_begin { 3709sub wait_for_tick_begin {
3696 return if tick_inhibit;
3697 return if $Coro::current == $Coro::main; 3710 return if tick_inhibit || $Coro::current == $Coro::main;
3698 3711
3699 my $signal = new Coro::Signal; 3712 my $signal = new Coro::Signal;
3700 push @WAIT_FOR_TICK_BEGIN, $signal; 3713 push @WAIT_FOR_TICK_BEGIN, $signal;
3701 $signal->wait; 3714 $signal->wait;
3702} 3715}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines