… | |
… | |
427 | } |
427 | } |
428 | } |
428 | } |
429 | }; |
429 | }; |
430 | |
430 | |
431 | sub get_slot($;$$) { |
431 | sub get_slot($;$$) { |
|
|
432 | return if tick_inhibit; |
|
|
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 |
1911 | sub save_path { |
1915 | sub 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 |
1919 | sub uniq_path { |
1923 | sub 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 | |
2374 | sub unique_maps() { |
2380 | sub 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 | |
2397 | Returns the inventory of the object _and_ their inventories, recursively. |
2404 | Returns the inventory of the object I<and> their inventories, recursively, |
|
|
2405 | but I<not> the object itself. |
2398 | |
2406 | |
2399 | =cut |
2407 | =cut |
2400 | |
2408 | |
2401 | sub inv_recursive_; |
2409 | sub inv_recursive_; |
2402 | sub inv_recursive_ { |
2410 | sub 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 | |
2412 | creates and returns a persistent reference to an objetc that can be stored as a string. |
2420 | Creates 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 | |
2416 | returns the objetc referenced by refstring. may return undef when it cnanot find the object, |
2424 | returns the objetc referenced by refstring. may return undef when it cnanot find the object, |
2417 | even if the object actually exists. May block. |
2425 | even 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; |