ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-scheduler.ext
Revision: 1.10
Committed: Thu Jan 4 01:35:55 2007 UTC (17 years, 4 months ago) by root
Branch: MAIN
Changes since 1.9: +3 -3 lines
Log Message:
tuning, and hopefully apply last access time more correctly

File Contents

# Content
1 #! perl
2
3 # this extension swaps out maps and resets them, in essence managing
4 # the reset/swap policy of the server.
5
6 our $DEACTIVATE_TIMEOUT = 20; # number of seconds after which maps get deactivated to save cpu
7 our $SWAP_TIMEOUT = 35; # number of seconds after which maps inactive get swapped out
8 our $SCHEDULE_INTERVAL = 2; # time the map scheduler sleeps between runs
9 our $SAVE_TIMEOUT = 20; # save maps every n seconds
10 our $SAVE_INTERVAL = 0.1; # save at max. one map every $SAVE_INTERVAL
11
12 our $SCHEDULER = cf::coro {
13 while () {
14 Coro::Timer::sleep $SCHEDULE_INTERVAL;
15
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
26 eval {
27 # not yet, because maps might become visible to players nearby
28 # we need to remove the map from %cf::MAP and all tiled map links
29 # if ($last_access + $DEACTIVATE_TIMEOUT <= $cf::RUNTIME) {
30 # $map->deactivate;
31 # delete $map->{active};
32 # }
33 if ($map->should_reset) {
34 $map->reset;
35 } elsif ($map->in_memory == cf::MAP_IN_MEMORY) {
36 if ($map->last_access + $SWAP_TIMEOUT <= $cf::RUNTIME && !$map->players) {
37 $map->swap_out;
38 Coro::Timer::sleep $SAVE_INTERVAL;
39 } elsif ($map->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
40 $map->save;
41 Coro::Timer::sleep $SAVE_INTERVAL;
42 }
43 }
44 };
45 warn $@ if $@;
46 Coro::cede;
47 };
48 }
49 };
50
51 $SCHEDULER->prio (-2);
52