… | |
… | |
108 | our $PIDFILE = "$LOCALDIR/pid"; |
108 | our $PIDFILE = "$LOCALDIR/pid"; |
109 | our $RUNTIMEFILE = "$LOCALDIR/runtime"; |
109 | our $RUNTIMEFILE = "$LOCALDIR/runtime"; |
110 | |
110 | |
111 | our %RESOURCE; |
111 | our %RESOURCE; |
112 | |
112 | |
|
|
113 | our $OUTPUT_RATE_MIN = 4000; |
|
|
114 | our $OUTPUT_RATE_MAX = 100000; |
|
|
115 | |
113 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
116 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
114 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
117 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
115 | our $NEXT_TICK; |
118 | our $NEXT_TICK; |
116 | our $USE_FSYNC = 1; # use fsync to write maps - default on |
119 | our $USE_FSYNC = 1; # use fsync to write maps - default on |
117 | |
120 | |
… | |
… | |
396 | } |
399 | } |
397 | |
400 | |
398 | =item cf::periodic $interval, $cb |
401 | =item cf::periodic $interval, $cb |
399 | |
402 | |
400 | Like EV::periodic, but randomly selects a starting point so that the actions |
403 | Like EV::periodic, but randomly selects a starting point so that the actions |
401 | get spread over timer. |
404 | get spread over time. |
402 | |
405 | |
403 | =cut |
406 | =cut |
404 | |
407 | |
405 | sub periodic($$) { |
408 | sub periodic($$) { |
406 | my ($interval, $cb) = @_; |
409 | my ($interval, $cb) = @_; |
… | |
… | |
584 | reset_signals; |
587 | reset_signals; |
585 | &$cb |
588 | &$cb |
586 | }, @args; |
589 | }, @args; |
587 | |
590 | |
588 | wantarray ? @res : $res[-1] |
591 | wantarray ? @res : $res[-1] |
|
|
592 | } |
|
|
593 | |
|
|
594 | sub objinfo { |
|
|
595 | ( |
|
|
596 | "counter value" => cf::object::object_count, |
|
|
597 | "objects created" => cf::object::create_count, |
|
|
598 | "objects destroyed" => cf::object::destroy_count, |
|
|
599 | "freelist size" => cf::object::free_count, |
|
|
600 | "allocated objects" => cf::object::objects_size, |
|
|
601 | "active objects" => cf::object::actives_size, |
|
|
602 | ) |
589 | } |
603 | } |
590 | |
604 | |
591 | =item $coin = coin_from_name $name |
605 | =item $coin = coin_from_name $name |
592 | |
606 | |
593 | =cut |
607 | =cut |
… | |
… | |
2198 | $MAP_PREFETCHER->prio (6); |
2212 | $MAP_PREFETCHER->prio (6); |
2199 | |
2213 | |
2200 | () |
2214 | () |
2201 | } |
2215 | } |
2202 | |
2216 | |
|
|
2217 | # common code, used by both ->save and ->swapout |
2203 | sub save { |
2218 | sub _save { |
2204 | my ($self) = @_; |
2219 | my ($self) = @_; |
2205 | |
|
|
2206 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
|
|
2207 | |
2220 | |
2208 | $self->{last_save} = $cf::RUNTIME; |
2221 | $self->{last_save} = $cf::RUNTIME; |
2209 | |
2222 | |
2210 | return unless $self->dirty; |
2223 | return unless $self->dirty; |
2211 | |
2224 | |
… | |
… | |
2231 | } else { |
2244 | } else { |
2232 | $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); |
2245 | $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); |
2233 | } |
2246 | } |
2234 | } |
2247 | } |
2235 | |
2248 | |
|
|
2249 | sub save { |
|
|
2250 | my ($self) = @_; |
|
|
2251 | |
|
|
2252 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
|
|
2253 | |
|
|
2254 | $self->_save; |
|
|
2255 | } |
|
|
2256 | |
2236 | sub swap_out { |
2257 | sub swap_out { |
2237 | my ($self) = @_; |
2258 | my ($self) = @_; |
2238 | |
2259 | |
2239 | # save first because save cedes |
|
|
2240 | $self->save; |
|
|
2241 | |
|
|
2242 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2260 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2243 | |
2261 | |
2244 | return if $self->players; |
|
|
2245 | return if $self->in_memory != cf::MAP_ACTIVE; |
2262 | return if $self->in_memory != cf::MAP_ACTIVE; |
2246 | return if $self->{deny_save}; |
2263 | return if $self->{deny_save}; |
|
|
2264 | return if $self->players; |
2247 | |
2265 | |
2248 | $self->in_memory (cf::MAP_SWAPPED); |
2266 | # first deactivate the map and "unlink" it from the core |
2249 | |
|
|
2250 | $self->deactivate; |
2267 | $self->deactivate; |
2251 | $_->clear_links_to ($self) for values %cf::MAP; |
2268 | $_->clear_links_to ($self) for values %cf::MAP; |
|
|
2269 | $self->in_memory (cf::MAP_SWAPPED); |
|
|
2270 | |
|
|
2271 | # then atomically save |
|
|
2272 | $self->_save; |
|
|
2273 | |
|
|
2274 | # then free the map |
2252 | $self->clear; |
2275 | $self->clear; |
2253 | } |
2276 | } |
2254 | |
2277 | |
2255 | sub reset_at { |
2278 | sub reset_at { |
2256 | my ($self) = @_; |
2279 | my ($self) = @_; |
… | |
… | |
3529 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3552 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3530 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3553 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3531 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3554 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3532 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3555 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3533 | |
3556 | |
3534 | cf::init_experience; |
|
|
3535 | cf::init_anim; |
|
|
3536 | cf::init_attackmess; |
|
|
3537 | cf::init_dynamic; |
|
|
3538 | |
|
|
3539 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3557 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3540 | |
3558 | |
3541 | # we must not ever block the main coroutine |
3559 | # we must not ever block the main coroutine |
3542 | local $Coro::idle = sub { |
3560 | local $Coro::idle = sub { |
3543 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3561 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
… | |
… | |
3548 | }; |
3566 | }; |
3549 | |
3567 | |
3550 | evthread_start IO::AIO::poll_fileno; |
3568 | evthread_start IO::AIO::poll_fileno; |
3551 | |
3569 | |
3552 | cf::sync_job { |
3570 | cf::sync_job { |
|
|
3571 | cf::init_experience; |
|
|
3572 | cf::init_anim; |
|
|
3573 | cf::init_attackmess; |
|
|
3574 | cf::init_dynamic; |
|
|
3575 | |
3553 | cf::load_settings; |
3576 | cf::load_settings; |
3554 | cf::load_materials; |
3577 | cf::load_materials; |
3555 | |
3578 | |
3556 | reload_resources; |
3579 | reload_resources; |
3557 | reload_config; |
3580 | reload_config; |
… | |
… | |
3573 | use POSIX (); |
3596 | use POSIX (); |
3574 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3597 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3575 | |
3598 | |
3576 | (pop @POST_INIT)->(0) while @POST_INIT; |
3599 | (pop @POST_INIT)->(0) while @POST_INIT; |
3577 | }; |
3600 | }; |
|
|
3601 | |
|
|
3602 | cf::object::thawer::errors_are_fatal 0; |
|
|
3603 | warn "parse errors in files are no longer fatal from this point on.\n"; |
3578 | |
3604 | |
3579 | main_loop; |
3605 | main_loop; |
3580 | } |
3606 | } |
3581 | |
3607 | |
3582 | ############################################################################# |
3608 | ############################################################################# |