1 | # |
1 | # |
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | # |
3 | # |
4 | # Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | # Copyright (©) 2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | # |
5 | # |
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
7 | # the terms of the Affero GNU General Public License as published by the |
7 | # the terms of the Affero GNU General Public License as published by the |
8 | # Free Software Foundation, either version 3 of the License, or (at your |
8 | # Free Software Foundation, either version 3 of the License, or (at your |
9 | # option) any later version. |
9 | # option) any later version. |
… | |
… | |
93 | our @EVENT; |
93 | our @EVENT; |
94 | our @REFLECT; # set by XS |
94 | our @REFLECT; # set by XS |
95 | our %REFLECT; # set by us |
95 | our %REFLECT; # set by us |
96 | |
96 | |
97 | our $CONFDIR = confdir; |
97 | our $CONFDIR = confdir; |
|
|
98 | |
98 | our $DATADIR = datadir; |
99 | our $DATADIR = datadir; |
99 | our $LIBDIR = "$DATADIR/ext"; |
100 | our $LIBDIR = "$DATADIR/ext"; |
100 | our $PODDIR = "$DATADIR/pod"; |
101 | our $PODDIR = "$DATADIR/pod"; |
101 | our $MAPDIR = "$DATADIR/" . mapdir; |
102 | our $MAPDIR = "$DATADIR/" . mapdir; |
|
|
103 | |
102 | our $LOCALDIR = localdir; |
104 | our $LOCALDIR = localdir; |
103 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
105 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
104 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
106 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
105 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
107 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
106 | our $RANDOMDIR = "$LOCALDIR/random"; |
108 | our $RANDOMDIR = "$LOCALDIR/random"; |
… | |
… | |
312 | } |
314 | } |
313 | |
315 | |
314 | $EV::DIED = sub { |
316 | $EV::DIED = sub { |
315 | Carp::cluck "error in event callback: @_"; |
317 | Carp::cluck "error in event callback: @_"; |
316 | }; |
318 | }; |
|
|
319 | |
|
|
320 | ############################################################################# |
|
|
321 | |
|
|
322 | sub fork_call(&@); |
|
|
323 | sub get_slot($;$$); |
317 | |
324 | |
318 | ############################################################################# |
325 | ############################################################################# |
319 | |
326 | |
320 | =head2 UTILITY FUNCTIONS |
327 | =head2 UTILITY FUNCTIONS |
321 | |
328 | |
… | |
… | |
342 | $d =~ s/([\x00-\x07\x09\x0b\x0c\x0e-\x1f])/sprintf "\\x%02x", ord($1)/ge; |
349 | $d =~ s/([\x00-\x07\x09\x0b\x0c\x0e-\x1f])/sprintf "\\x%02x", ord($1)/ge; |
343 | $d |
350 | $d |
344 | } || "[unable to dump $_[0]: '$@']"; |
351 | } || "[unable to dump $_[0]: '$@']"; |
345 | } |
352 | } |
346 | |
353 | |
|
|
354 | =item $scalar = load_file $path |
|
|
355 | |
|
|
356 | Loads the given file from path and returns its contents. Croaks on error |
|
|
357 | and can block. |
|
|
358 | |
|
|
359 | =cut |
|
|
360 | |
|
|
361 | sub load_file($) { |
|
|
362 | 0 <= aio_load $_[0], my $data |
|
|
363 | or Carp::croak "$_[0]: $!"; |
|
|
364 | |
|
|
365 | $data |
|
|
366 | } |
|
|
367 | |
347 | =item $ref = cf::decode_json $json |
368 | =item $ref = cf::decode_json $json |
348 | |
369 | |
349 | Converts a JSON string into the corresponding perl data structure. |
370 | Converts a JSON string into the corresponding perl data structure. |
350 | |
371 | |
351 | =item $json = cf::encode_json $ref |
372 | =item $json = cf::encode_json $ref |
… | |
… | |
357 | our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max |
378 | our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max |
358 | |
379 | |
359 | sub encode_json($) { $json_coder->encode ($_[0]) } |
380 | sub encode_json($) { $json_coder->encode ($_[0]) } |
360 | sub decode_json($) { $json_coder->decode ($_[0]) } |
381 | sub decode_json($) { $json_coder->decode ($_[0]) } |
361 | |
382 | |
|
|
383 | =item $ref = cf::decode_storable $scalar |
|
|
384 | |
|
|
385 | Same as Coro::Storable::thaw, so blocks. |
|
|
386 | |
|
|
387 | =cut |
|
|
388 | |
|
|
389 | BEGIN { *decode_storable = \&Coro::Storable::thaw } |
|
|
390 | |
362 | =item $ref = cf::yaml_load $scalar |
391 | =item $ref = cf::decode_yaml $scalar |
363 | |
392 | |
364 | Same as YAML::XS::Load, but doesn't leak, because it forks (and thus blocks). |
393 | Same as YAML::XS::Load, but doesn't leak, because it forks (and thus blocks). |
365 | |
394 | |
366 | =cut |
395 | =cut |
367 | |
396 | |
368 | sub fork_call(&@); |
397 | sub decode_yaml($) { |
369 | |
|
|
370 | sub yaml_load($) { |
|
|
371 | fork_call { YAML::XS::Load $_[0] } @_ |
398 | fork_call { YAML::XS::Load $_[0] } @_ |
|
|
399 | } |
|
|
400 | |
|
|
401 | =item $scalar = cf::unlzf $scalar |
|
|
402 | |
|
|
403 | Same as Compress::LZF::compress, but takes server ticks into account, so |
|
|
404 | blocks. |
|
|
405 | |
|
|
406 | =cut |
|
|
407 | |
|
|
408 | sub unlzf($) { |
|
|
409 | # we assume 100mb/s minimum decompression speed (noncompressible data on a ~2ghz machine) |
|
|
410 | cf::get_slot +(length $_[0]) / 100_000_000, 0, "unlzf"; |
|
|
411 | Compress::LZF::decompress $_[0] |
372 | } |
412 | } |
373 | |
413 | |
374 | =item cf::post_init { BLOCK } |
414 | =item cf::post_init { BLOCK } |
375 | |
415 | |
376 | Execute the given codeblock, I<after> all extensions have been (re-)loaded, |
416 | Execute the given codeblock, I<after> all extensions have been (re-)loaded, |
… | |
… | |
460 | EV::periodic $start, $interval, 0, $cb |
500 | EV::periodic $start, $interval, 0, $cb |
461 | } |
501 | } |
462 | |
502 | |
463 | =item cf::get_slot $time[, $priority[, $name]] |
503 | =item cf::get_slot $time[, $priority[, $name]] |
464 | |
504 | |
465 | Allocate $time seconds of blocking CPU time at priority C<$priority>: |
505 | Allocate $time seconds of blocking CPU time at priority C<$priority> |
466 | This call blocks and returns only when you have at least C<$time> seconds |
506 | (default: 0): This call blocks and returns only when you have at least |
467 | of cpu time till the next tick. The slot is only valid till the next cede. |
507 | C<$time> seconds of cpu time till the next tick. The slot is only valid |
|
|
508 | till the next cede. |
|
|
509 | |
|
|
510 | Background jobs should use a priority les than zero, interactive jobs |
|
|
511 | should use 100 or more. |
468 | |
512 | |
469 | The optional C<$name> can be used to identify the job to run. It might be |
513 | The optional C<$name> can be used to identify the job to run. It might be |
470 | used for statistical purposes and should identify the same time-class. |
514 | used for statistical purposes and should identify the same time-class. |
471 | |
515 | |
472 | Useful for short background jobs. |
516 | Useful for short background jobs. |
… | |
… | |
767 | |
811 | |
768 | my @data; |
812 | my @data; |
769 | my $md5; |
813 | my $md5; |
770 | |
814 | |
771 | for (0 .. $#$src) { |
815 | for (0 .. $#$src) { |
772 | 0 <= aio_load $src->[$_], $data[$_] |
816 | $data[$_] = load_file $src->[$_]; |
773 | or Carp::croak "$src->[$_]: $!"; |
|
|
774 | } |
817 | } |
775 | |
818 | |
776 | # if processing is expensive, check |
819 | # if processing is expensive, check |
777 | # checksum first |
820 | # checksum first |
778 | if (1) { |
821 | if (1) { |
… | |
… | |
1512 | |
1555 | |
1513 | while (my ($k, $v) = each %todo) { |
1556 | while (my ($k, $v) = each %todo) { |
1514 | cf::cleanup "mandatory extension '$k' has unresolved dependencies, exiting." |
1557 | cf::cleanup "mandatory extension '$k' has unresolved dependencies, exiting." |
1515 | if exists $v->{meta}{mandatory}; |
1558 | if exists $v->{meta}{mandatory}; |
1516 | } |
1559 | } |
|
|
1560 | |
|
|
1561 | last; |
1517 | } |
1562 | } |
1518 | } |
1563 | } |
1519 | }; |
1564 | }; |
1520 | } |
1565 | } |
1521 | |
1566 | |
… | |
… | |
1949 | |
1994 | |
1950 | Carp::cluck "unable to resolve path '$path' (base '$base')"; |
1995 | Carp::cluck "unable to resolve path '$path' (base '$base')"; |
1951 | () |
1996 | () |
1952 | } |
1997 | } |
1953 | |
1998 | |
|
|
1999 | # may re-bless or do other evil things |
1954 | sub init { |
2000 | sub init { |
1955 | my ($self) = @_; |
2001 | my ($self) = @_; |
1956 | |
2002 | |
1957 | $self |
2003 | $self |
1958 | } |
2004 | } |
… | |
… | |
2023 | $self->{load_path} = $path; |
2069 | $self->{load_path} = $path; |
2024 | |
2070 | |
2025 | 1 |
2071 | 1 |
2026 | } |
2072 | } |
2027 | |
2073 | |
|
|
2074 | # used to laod the header of an original map |
2028 | sub load_header_orig { |
2075 | sub load_header_orig { |
2029 | my ($self) = @_; |
2076 | my ($self) = @_; |
2030 | |
2077 | |
2031 | $self->load_header_from ($self->load_path) |
2078 | $self->load_header_from ($self->load_path) |
2032 | } |
2079 | } |
2033 | |
2080 | |
|
|
2081 | # used to laod the header of an instantiated map |
2034 | sub load_header_temp { |
2082 | sub load_header_temp { |
2035 | my ($self) = @_; |
2083 | my ($self) = @_; |
2036 | |
2084 | |
2037 | $self->load_header_from ($self->save_path) |
2085 | $self->load_header_from ($self->save_path) |
2038 | } |
2086 | } |
2039 | |
2087 | |
|
|
2088 | # called after loading the header from an instantiated map |
2040 | sub prepare_temp { |
2089 | sub prepare_temp { |
2041 | my ($self) = @_; |
2090 | my ($self) = @_; |
2042 | |
2091 | |
2043 | $self->last_access ((delete $self->{last_access}) |
2092 | $self->last_access ((delete $self->{last_access}) |
2044 | || $cf::RUNTIME); #d# |
2093 | || $cf::RUNTIME); #d# |
2045 | # safety |
2094 | # safety |
2046 | $self->{instantiate_time} = $cf::RUNTIME |
2095 | $self->{instantiate_time} = $cf::RUNTIME |
2047 | if $self->{instantiate_time} > $cf::RUNTIME; |
2096 | if $self->{instantiate_time} > $cf::RUNTIME; |
2048 | } |
2097 | } |
2049 | |
2098 | |
|
|
2099 | # called after loading the header from an original map |
2050 | sub prepare_orig { |
2100 | sub prepare_orig { |
2051 | my ($self) = @_; |
2101 | my ($self) = @_; |
2052 | |
2102 | |
2053 | $self->{load_original} = 1; |
2103 | $self->{load_original} = 1; |
2054 | $self->{instantiate_time} = $cf::RUNTIME; |
2104 | $self->{instantiate_time} = $cf::RUNTIME; |
… | |
… | |
2080 | sub find { |
2130 | sub find { |
2081 | my ($path, $origin) = @_; |
2131 | my ($path, $origin) = @_; |
2082 | |
2132 | |
2083 | cf::cede_to_tick; |
2133 | cf::cede_to_tick; |
2084 | |
2134 | |
2085 | $path = normalise $path, $origin && $origin->path; |
2135 | $path = normalise $path, $origin; |
2086 | |
2136 | |
2087 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2137 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2088 | my $guard2 = cf::lock_acquire "map_find:$path"; |
2138 | my $guard2 = cf::lock_acquire "map_find:$path"; |
2089 | |
2139 | |
2090 | $cf::MAP{$path} || do { |
2140 | $cf::MAP{$path} || do { |
… | |
… | |
2121 | |
2171 | |
2122 | { |
2172 | { |
2123 | my $guard = cf::lock_acquire "map_data:$path"; |
2173 | my $guard = cf::lock_acquire "map_data:$path"; |
2124 | |
2174 | |
2125 | return unless $self->valid; |
2175 | return unless $self->valid; |
2126 | return unless $self->in_memory == cf::MAP_SWAPPED; |
2176 | return unless $self->state == cf::MAP_SWAPPED; |
2127 | |
|
|
2128 | $self->in_memory (cf::MAP_LOADING); |
|
|
2129 | |
2177 | |
2130 | $self->alloc; |
2178 | $self->alloc; |
2131 | |
2179 | |
2132 | $self->pre_load; |
2180 | $self->pre_load; |
2133 | cf::cede_to_tick; |
2181 | cf::cede_to_tick; |
2134 | |
2182 | |
|
|
2183 | if (exists $self->{load_path}) { |
2135 | my $f = new_from_file cf::object::thawer $self->{load_path}; |
2184 | my $f = new_from_file cf::object::thawer $self->{load_path}; |
2136 | $f->skip_block; |
2185 | $f->skip_block; |
2137 | $self->_load_objects ($f) |
2186 | $self->_load_objects ($f) |
2138 | or return; |
2187 | or return; |
2139 | |
2188 | |
2140 | $self->post_load_original |
2189 | $self->post_load_original |
2141 | if delete $self->{load_original}; |
2190 | if delete $self->{load_original}; |
2142 | |
2191 | |
2143 | if (my $uniq = $self->uniq_path) { |
2192 | if (my $uniq = $self->uniq_path) { |
2144 | utf8::encode $uniq; |
2193 | utf8::encode $uniq; |
2145 | unless (aio_stat $uniq) { |
2194 | unless (aio_stat $uniq) { |
2146 | if (my $f = new_from_file cf::object::thawer $uniq) { |
2195 | if (my $f = new_from_file cf::object::thawer $uniq) { |
2147 | $self->clear_unique_items; |
2196 | $self->clear_unique_items; |
2148 | $self->_load_objects ($f); |
2197 | $self->_load_objects ($f); |
2149 | $f->resolve_delayed_derefs; |
2198 | $f->resolve_delayed_derefs; |
|
|
2199 | } |
2150 | } |
2200 | } |
2151 | } |
2201 | } |
2152 | } |
|
|
2153 | |
2202 | |
2154 | $f->resolve_delayed_derefs; |
2203 | $f->resolve_delayed_derefs; |
|
|
2204 | } else { |
|
|
2205 | $self->post_load_original |
|
|
2206 | if delete $self->{load_original}; |
|
|
2207 | } |
|
|
2208 | |
|
|
2209 | $self->state (cf::MAP_INACTIVE); |
2155 | |
2210 | |
2156 | cf::cede_to_tick; |
2211 | cf::cede_to_tick; |
2157 | # now do the right thing for maps |
2212 | # now do the right thing for maps |
2158 | $self->link_multipart_objects; |
2213 | $self->link_multipart_objects; |
2159 | $self->difficulty ($self->estimate_difficulty) |
2214 | $self->difficulty ($self->estimate_difficulty) |
… | |
… | |
2163 | unless ($self->{deny_activate}) { |
2218 | unless ($self->{deny_activate}) { |
2164 | $self->decay_objects; |
2219 | $self->decay_objects; |
2165 | $self->fix_auto_apply; |
2220 | $self->fix_auto_apply; |
2166 | $self->update_buttons; |
2221 | $self->update_buttons; |
2167 | cf::cede_to_tick; |
2222 | cf::cede_to_tick; |
2168 | $self->activate; |
2223 | #$self->activate; # no longer activate maps automatically |
2169 | } |
2224 | } |
2170 | |
2225 | |
2171 | $self->{last_save} = $cf::RUNTIME; |
2226 | $self->{last_save} = $cf::RUNTIME; |
2172 | $self->last_access ($cf::RUNTIME); |
2227 | $self->last_access ($cf::RUNTIME); |
2173 | |
|
|
2174 | $self->in_memory (cf::MAP_ACTIVE); |
|
|
2175 | } |
2228 | } |
2176 | |
2229 | |
2177 | $self->post_load; |
2230 | $self->post_load; |
2178 | |
2231 | |
2179 | 1 |
2232 | 1 |
… | |
… | |
2222 | } |
2275 | } |
2223 | |
2276 | |
2224 | sub find_sync { |
2277 | sub find_sync { |
2225 | my ($path, $origin) = @_; |
2278 | my ($path, $origin) = @_; |
2226 | |
2279 | |
|
|
2280 | # it's a bug to call this from the main context |
2227 | return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync" |
2281 | return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync" |
2228 | if $Coro::current == $Coro::main; |
2282 | if $Coro::current == $Coro::main; |
2229 | |
2283 | |
2230 | find $path, $origin |
2284 | find $path, $origin |
2231 | } |
2285 | } |
2232 | |
2286 | |
2233 | sub do_load_sync { |
2287 | sub do_load_sync { |
2234 | my ($map) = @_; |
2288 | my ($map) = @_; |
2235 | |
2289 | |
|
|
2290 | # it's a bug to call this from the main context |
2236 | return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync" |
2291 | return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync" |
2237 | if $Coro::current == $Coro::main; |
2292 | if $Coro::current == $Coro::main; |
2238 | |
2293 | |
2239 | $map->load; |
2294 | $map->load; |
2240 | } |
2295 | } |
… | |
… | |
2243 | our $MAP_PREFETCHER = undef; |
2298 | our $MAP_PREFETCHER = undef; |
2244 | |
2299 | |
2245 | sub find_async { |
2300 | sub find_async { |
2246 | my ($path, $origin, $load) = @_; |
2301 | my ($path, $origin, $load) = @_; |
2247 | |
2302 | |
2248 | $path = normalise $path, $origin && $origin->{path}; |
2303 | $path = normalise $path, $origin; |
2249 | |
2304 | |
2250 | if (my $map = $cf::MAP{$path}) { |
2305 | if (my $map = $cf::MAP{$path}) { |
2251 | return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; |
2306 | return $map if !$load || $map->linkable; |
2252 | } |
2307 | } |
2253 | |
2308 | |
2254 | $MAP_PREFETCH{$path} |= $load; |
2309 | $MAP_PREFETCH{$path} |= $load; |
2255 | |
2310 | |
2256 | $MAP_PREFETCHER ||= cf::async { |
2311 | $MAP_PREFETCHER ||= cf::async { |
… | |
… | |
2315 | sub swap_out { |
2370 | sub swap_out { |
2316 | my ($self) = @_; |
2371 | my ($self) = @_; |
2317 | |
2372 | |
2318 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2373 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2319 | |
2374 | |
2320 | return if $self->in_memory != cf::MAP_ACTIVE; |
2375 | return if !$self->linkable; |
2321 | return if $self->{deny_save}; |
2376 | return if $self->{deny_save}; |
2322 | return if $self->players; |
2377 | return if $self->players; |
2323 | |
2378 | |
2324 | # first deactivate the map and "unlink" it from the core |
2379 | # first deactivate the map and "unlink" it from the core |
2325 | $self->deactivate; |
2380 | $self->deactivate; |
2326 | $_->clear_links_to ($self) for values %cf::MAP; |
2381 | $_->clear_links_to ($self) for values %cf::MAP; |
2327 | $self->in_memory (cf::MAP_SWAPPED); |
2382 | $self->state (cf::MAP_SWAPPED); |
2328 | |
2383 | |
2329 | # then atomically save |
2384 | # then atomically save |
2330 | $self->_save; |
2385 | $self->_save; |
2331 | |
2386 | |
2332 | # then free the map |
2387 | # then free the map |
… | |
… | |
2358 | |
2413 | |
2359 | return if $self->players; |
2414 | return if $self->players; |
2360 | |
2415 | |
2361 | cf::trace "resetting map ", $self->path, "\n"; |
2416 | cf::trace "resetting map ", $self->path, "\n"; |
2362 | |
2417 | |
2363 | $self->in_memory (cf::MAP_SWAPPED); |
2418 | $self->state (cf::MAP_SWAPPED); |
2364 | |
2419 | |
2365 | # need to save uniques path |
2420 | # need to save uniques path |
2366 | unless ($self->{deny_save}) { |
2421 | unless ($self->{deny_save}) { |
2367 | my $uniq = $self->uniq_path; utf8::encode $uniq; |
2422 | my $uniq = $self->uniq_path; utf8::encode $uniq; |
2368 | |
2423 | |
… | |
… | |
2764 | ($path, $x, $y) = (undef, undef, undef); |
2819 | ($path, $x, $y) = (undef, undef, undef); |
2765 | } |
2820 | } |
2766 | } |
2821 | } |
2767 | |
2822 | |
2768 | my $map = eval { |
2823 | my $map = eval { |
2769 | my $map = defined $path ? cf::map::find $path : undef; |
2824 | my $map = defined $path ? cf::map::find $path, $self->map : undef; |
2770 | |
2825 | |
2771 | if ($map) { |
2826 | if ($map) { |
2772 | $map = $map->customise_for ($self); |
2827 | $map = $map->customise_for ($self); |
2773 | $map = $check->($map, $x, $y, $self) if $check && $map; |
2828 | $map = $check->($map, $x, $y, $self) if $check && $map; |
2774 | } else { |
2829 | } else { |
… | |
… | |
2864 | $Coro::current->{desc} = "enter_exit"; |
2919 | $Coro::current->{desc} = "enter_exit"; |
2865 | |
2920 | |
2866 | unless (eval { |
2921 | unless (eval { |
2867 | $self->deactivate_recursive; # just to be sure |
2922 | $self->deactivate_recursive; # just to be sure |
2868 | |
2923 | |
2869 | # random map handling |
|
|
2870 | { |
|
|
2871 | my $guard = cf::lock_acquire "exit_prepare:$exit"; |
|
|
2872 | |
|
|
2873 | prepare_random_map $exit |
|
|
2874 | if $exit->slaying eq "/!"; |
|
|
2875 | } |
|
|
2876 | |
|
|
2877 | my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; |
2924 | my $map = cf::map::normalise $exit->slaying, $exit->map; |
2878 | my $x = $exit->stats->hp; |
2925 | my $x = $exit->stats->hp; |
2879 | my $y = $exit->stats->sp; |
2926 | my $y = $exit->stats->sp; |
|
|
2927 | |
|
|
2928 | # special map handling |
|
|
2929 | my $slaying = $exit->slaying; |
|
|
2930 | |
|
|
2931 | # special map handling |
|
|
2932 | if ($slaying eq "/!") { |
|
|
2933 | my $guard = cf::lock_acquire "exit_prepare:$exit"; |
|
|
2934 | |
|
|
2935 | prepare_random_map $exit |
|
|
2936 | if $exit->slaying eq "/!"; # need to re-check after getting the lock |
|
|
2937 | |
|
|
2938 | $map = $exit->slaying; |
|
|
2939 | |
|
|
2940 | } elsif ($slaying eq '!up') { |
|
|
2941 | $map = $exit->map->tile_path (cf::TILE_UP); |
|
|
2942 | $x = $exit->x; |
|
|
2943 | $y = $exit->y; |
|
|
2944 | |
|
|
2945 | } elsif ($slaying eq '!down') { |
|
|
2946 | $map = $exit->map->tile_path (cf::TILE_DOWN); |
|
|
2947 | $x = $exit->x; |
|
|
2948 | $y = $exit->y; |
|
|
2949 | } |
2880 | |
2950 | |
2881 | $self->goto ($map, $x, $y); |
2951 | $self->goto ($map, $x, $y); |
2882 | |
2952 | |
2883 | # if exit is damned, update players death & WoR home-position |
2953 | # if exit is damned, update players death & WoR home-position |
2884 | $self->contr->savebed ($map, $x, $y) |
2954 | $self->contr->savebed ($map, $x, $y) |
… | |
… | |
3399 | |
3469 | |
3400 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
3470 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
3401 | |
3471 | |
3402 | trace "loading facedata from $path\n"; |
3472 | trace "loading facedata from $path\n"; |
3403 | |
3473 | |
3404 | 0 < aio_load $path, my $facedata |
3474 | my $facedata = decode_storable load_file $path; |
3405 | or die "$path: $!"; |
|
|
3406 | |
|
|
3407 | $facedata = Coro::Storable::thaw $facedata; |
|
|
3408 | |
3475 | |
3409 | $facedata->{version} == 2 |
3476 | $facedata->{version} == 2 |
3410 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3477 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3411 | |
3478 | |
3412 | # patch in the exptable |
3479 | # patch in the exptable |
… | |
… | |
3531 | } |
3598 | } |
3532 | |
3599 | |
3533 | sub reload_sound { |
3600 | sub reload_sound { |
3534 | trace "loading sound config from $DATADIR/sound\n"; |
3601 | trace "loading sound config from $DATADIR/sound\n"; |
3535 | |
3602 | |
3536 | 0 < Coro::AIO::aio_load "$DATADIR/sound", my $data |
|
|
3537 | or die "$DATADIR/sound $!"; |
|
|
3538 | |
|
|
3539 | my $soundconf = JSON::XS->new->utf8->relaxed->decode ($data); |
3603 | my $soundconf = JSON::XS->new->utf8->relaxed->decode (load_file "$DATADIR/sound"); |
3540 | |
3604 | |
3541 | for (0 .. SOUND_CAST_SPELL_0 - 1) { |
3605 | for (0 .. SOUND_CAST_SPELL_0 - 1) { |
3542 | my $sound = $soundconf->{compat}[$_] |
3606 | my $sound = $soundconf->{compat}[$_] |
3543 | or next; |
3607 | or next; |
3544 | |
3608 | |
… | |
… | |
3568 | } |
3632 | } |
3569 | |
3633 | |
3570 | sub reload_config { |
3634 | sub reload_config { |
3571 | trace "reloading config file...\n"; |
3635 | trace "reloading config file...\n"; |
3572 | |
3636 | |
3573 | 0 < aio_load "$CONFDIR/config", my $config |
3637 | my $config = load_file "$CONFDIR/config"; |
3574 | or die "$CONFDIR/config: $!"; |
|
|
3575 | |
|
|
3576 | utf8::decode $config; |
3638 | utf8::decode $config; |
3577 | *CFG = yaml_load $config; |
3639 | *CFG = decode_yaml $config; |
3578 | |
3640 | |
3579 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3641 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3580 | |
3642 | |
3581 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3643 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3582 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3644 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
… | |
… | |
3620 | |
3682 | |
3621 | sub main { |
3683 | sub main { |
3622 | cf::init_globals; # initialise logging |
3684 | cf::init_globals; # initialise logging |
3623 | |
3685 | |
3624 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3686 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3625 | LOG llevInfo, "Copyright (C) 2005-2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3687 | LOG llevInfo, "Copyright (C) 2005-2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3626 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3688 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3627 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3689 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3628 | |
3690 | |
3629 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3691 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3630 | |
3692 | |