… | |
… | |
348 | |
348 | |
349 | our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs |
349 | our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs |
350 | our $SAVE_TIMEOUT = 20; # save players every n seconds |
350 | our $SAVE_TIMEOUT = 20; # save players every n seconds |
351 | |
351 | |
352 | our $SCHEDULER = cf::async_ext { |
352 | our $SCHEDULER = cf::async_ext { |
|
|
353 | my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); |
353 | while () { |
354 | while () { |
354 | Coro::Timer::sleep $SCHEDULE_INTERVAL; |
355 | $schedule_interval->next; |
355 | |
356 | |
356 | # this weird form of iteration over values is used because |
357 | # this weird form of iteration over values is used because |
357 | # the hash changes underneath us frequently, and for |
358 | # the hash changes underneath us frequently, and for |
358 | # keeps a direct reference to the value without (in 5.8 perls) |
359 | # keeps a direct reference to the value without (in 5.8 perls) |
359 | # keeping a reference, so this is prone to crashes or worse. |
360 | # keeping a reference, so this is prone to crashes or worse. |
… | |
… | |
378 | my $pl_ref = $pl->refcnt_cnt; |
379 | my $pl_ref = $pl->refcnt_cnt; |
379 | my $ob_ref = $ob->refcnt_cnt; |
380 | my $ob_ref = $ob->refcnt_cnt; |
380 | |
381 | |
381 | ## pl_ref == one from object + one from cf::PLAYER |
382 | ## pl_ref == one from object + one from cf::PLAYER |
382 | ## ob_ref == one from simply being an object |
383 | ## ob_ref == one from simply being an object |
|
|
384 | #TODO: the above should be correct, understand the 1/0, respectively |
383 | if ($pl_ref == 2 && $ob_ref == 1) { |
385 | if ($pl_ref == 1 && $ob_ref == 0) { |
384 | warn "player-scheduler destroy ", $ob->name;#d# |
386 | warn "player-scheduler destroy ", $ob->name;#d# |
385 | |
387 | |
386 | # remove from sight and get fresh "copies" |
388 | # remove from sight and get fresh "copies" |
387 | $pl = delete $cf::PLAYER{$ob->name}; |
389 | $pl = delete $cf::PLAYER{$ob->name}; |
388 | $ob = $pl->ob; |
390 | $ob = $pl->ob; |