… | |
… | |
341 | |
341 | |
342 | ############################################################################# |
342 | ############################################################################# |
343 | |
343 | |
344 | our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs |
344 | our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs |
345 | our $SAVE_TIMEOUT = 20; # save players every n seconds |
345 | our $SAVE_TIMEOUT = 20; # save players every n seconds |
346 | our $SAVE_INTERVAL = 0.5; # save at max. one player every $SAVE_INTERVAL |
|
|
347 | |
346 | |
348 | our $SCHEDULER = cf::async_ext { |
347 | our $SCHEDULER = cf::async_ext { |
349 | while () { |
348 | while () { |
350 | Coro::Timer::sleep $SCHEDULE_INTERVAL; |
349 | Coro::Timer::sleep $SCHEDULE_INTERVAL; |
351 | |
350 | |
… | |
… | |
359 | or next; |
358 | or next; |
360 | $pl->valid or next; |
359 | $pl->valid or next; |
361 | |
360 | |
362 | eval { |
361 | eval { |
363 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
362 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
|
|
363 | $cf::WAIT_FOR_TICK_ONE->wait; |
364 | $pl->save; |
364 | $pl->save; |
365 | |
365 | |
366 | unless ($pl->active) { |
366 | unless ($pl->active) { |
367 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
367 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
368 | my $ob = $pl->ob; |
368 | my $ob = $pl->ob; |
… | |
… | |
386 | $pl->destroy; |
386 | $pl->destroy; |
387 | } else { |
387 | } else { |
388 | warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# |
388 | warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# |
389 | } |
389 | } |
390 | } |
390 | } |
391 | Coro::Timer::sleep $SAVE_INTERVAL; |
|
|
392 | } |
391 | } |
393 | }; |
392 | }; |
394 | warn $@ if $@; |
393 | warn $@ if $@; |
395 | Coro::cede; |
394 | Coro::cede; |
396 | }; |
395 | }; |