ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-scheduler.ext
Revision: 1.11
Committed: Thu Jan 4 16:19:32 2007 UTC (17 years, 4 months ago) by root
Branch: MAIN
Changes since 1.10: +9 -0 lines
Log Message:
- word of recall activated the player indirectly
- implement maptile->xy_find and xy_load
- separate find and load, even on C level
- generate map_leave/enter and map_change events even for tiled map changes
  (experimental)
- implement mainloop freezeing by start/stop, not skipping ticks
- no map updates when player !active

File Contents

# User Rev Content
1 root 1.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 root 1.7 our $DEACTIVATE_TIMEOUT = 20; # number of seconds after which maps get deactivated to save cpu
7 root 1.10 our $SWAP_TIMEOUT = 35; # number of seconds after which maps inactive get swapped out
8 root 1.7 our $SCHEDULE_INTERVAL = 2; # time the map scheduler sleeps between runs
9 root 1.10 our $SAVE_TIMEOUT = 20; # save maps every n seconds
10     our $SAVE_INTERVAL = 0.1; # save at max. one map every $SAVE_INTERVAL
11 root 1.1
12     our $SCHEDULER = cf::coro {
13     while () {
14     Coro::Timer::sleep $SCHEDULE_INTERVAL;
15    
16 root 1.9 # 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 root 1.8 my @maps = keys %cf::MAP;
21     for (@maps) {
22     my $map = $cf::MAP{$_}
23     or next;
24     $map->valid or next;
25 root 1.9
26 root 1.1 eval {
27     # not yet, because maps might become visible to players nearby
28 root 1.3 # we need to remove the map from %cf::MAP and all tiled map links
29 root 1.1 # if ($last_access + $DEACTIVATE_TIMEOUT <= $cf::RUNTIME) {
30     # $map->deactivate;
31     # delete $map->{active};
32     # }
33     if ($map->should_reset) {
34     $map->reset;
35 root 1.3 } elsif ($map->in_memory == cf::MAP_IN_MEMORY) {
36 root 1.6 if ($map->last_access + $SWAP_TIMEOUT <= $cf::RUNTIME && !$map->players) {
37 root 1.3 $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 root 1.1 }
44     };
45     warn $@ if $@;
46     Coro::cede;
47 root 1.8 };
48 root 1.1 }
49     };
50 root 1.5
51 root 1.1 $SCHEDULER->prio (-2);
52    
53 root 1.11 # map load prefetch
54     cf::map->attach (
55     on_enter => sub {
56     my ($map, $pl) = @_;
57    
58     # floodfill surrounging maps, asynchronously
59     },
60     );
61