ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-scheduler.ext
(Generate patch)

Comparing deliantra/server/ext/map-scheduler.ext (file contents):
Revision 1.7 by root, Tue Jan 2 21:13:22 2007 UTC vs.
Revision 1.11 by root, Thu Jan 4 16:19:32 2007 UTC

2 2
3# this extension swaps out maps and resets them, in essence managing 3# this extension swaps out maps and resets them, in essence managing
4# the reset/swap policy of the server. 4# the reset/swap policy of the server.
5 5
6our $DEACTIVATE_TIMEOUT = 20; # number of seconds after which maps get deactivated to save cpu 6our $DEACTIVATE_TIMEOUT = 20; # number of seconds after which maps get deactivated to save cpu
7our $SWAP_TIMEOUT = 50; # number of seconds after which maps inactive get swapped out 7our $SWAP_TIMEOUT = 35; # number of seconds after which maps inactive get swapped out
8our $SCHEDULE_INTERVAL = 2; # time the map scheduler sleeps between runs 8our $SCHEDULE_INTERVAL = 2; # time the map scheduler sleeps between runs
9our $SAVE_TIMEOUT = 30; # save maps every n seconds 9our $SAVE_TIMEOUT = 20; # save maps every n seconds
10our $SAVE_INTERVAL = 0.3; # save at max. one map every $SAVE_INTERVAL 10our $SAVE_INTERVAL = 0.1; # save at max. one map every $SAVE_INTERVAL
11 11
12our $SCHEDULER = cf::coro { 12our $SCHEDULER = cf::coro {
13 while () { 13 while () {
14 Coro::Timer::sleep $SCHEDULE_INTERVAL; 14 Coro::Timer::sleep $SCHEDULE_INTERVAL;
15 15
16 for my $map (values %cf::MAP) { 16 # this weird form of iteration over values is used because
17 # the hash changes underneath us frequently, and for
18 # keeps a direct reference to the value without (in 5.8 perls)
19 # keeping a reference, so this is prone to crashes or worse.
20 my @maps = keys %cf::MAP;
21 for (@maps) {
22 my $map = $cf::MAP{$_}
23 or next;
24 $map->valid or next;
25
17 eval { 26 eval {
18 # not yet, because maps might become visible to players nearby 27 # not yet, because maps might become visible to players nearby
19 # we need to remove the map from %cf::MAP and all tiled map links 28 # we need to remove the map from %cf::MAP and all tiled map links
20# if ($last_access + $DEACTIVATE_TIMEOUT <= $cf::RUNTIME) { 29# if ($last_access + $DEACTIVATE_TIMEOUT <= $cf::RUNTIME) {
21# $map->deactivate; 30# $map->deactivate;
33 } 42 }
34 } 43 }
35 }; 44 };
36 warn $@ if $@; 45 warn $@ if $@;
37 Coro::cede; 46 Coro::cede;
38 } 47 };
39 } 48 }
40}; 49};
41 50
42$SCHEDULER->prio (-2); 51$SCHEDULER->prio (-2);
43 52
53# map load prefetch
54cf::map->attach (
55 on_enter => sub {
56 my ($map, $pl) = @_;
57
58 # floodfill surrounging maps, asynchronously
59 },
60);
61

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines