ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.560 by root, Fri Apr 22 02:03:12 2011 UTC vs.
Revision 1.575 by root, Sat Aug 13 20:20:30 2011 UTC

1# 1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG. 2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3# 3#
4# Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4# Copyright (©) 2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 5#
6# Deliantra is free software: you can redistribute it and/or modify it under 6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 8# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version. 9# option) any later version.
131our @EXTRA_MODULES = qw(pod match mapscript incloader); 131our @EXTRA_MODULES = qw(pod match mapscript incloader);
132 132
133our %CFG; 133our %CFG;
134 134
135our $UPTIME; $UPTIME ||= time; 135our $UPTIME; $UPTIME ||= time;
136our $RUNTIME; 136our $RUNTIME = 0;
137our $SERVER_TICK = 0;
137our $NOW; 138our $NOW;
138 139
139our (%PLAYER, %PLAYER_LOADING); # all users 140our (%PLAYER, %PLAYER_LOADING); # all users
140our (%MAP, %MAP_LOADING ); # all maps 141our (%MAP, %MAP_LOADING ); # all maps
141our $LINK_MAP; # the special {link} map, which is always available 142our $LINK_MAP; # the special {link} map, which is always available
150 151
151our @POST_INIT; 152our @POST_INIT;
152 153
153our $REATTACH_ON_RELOAD; # set to true to force object reattach on reload (slow) 154our $REATTACH_ON_RELOAD; # set to true to force object reattach on reload (slow)
154our $REALLY_UNLOOP; # never set to true, please :) 155our $REALLY_UNLOOP; # never set to true, please :)
156
157our $WAIT_FOR_TICK = new Coro::Signal;
158our @WAIT_FOR_TICK_BEGIN;
155 159
156binmode STDOUT; 160binmode STDOUT;
157binmode STDERR; 161binmode STDERR;
158 162
159# read virtual server time, if available 163# read virtual server time, if available
193 197
194=over 4 198=over 4
195 199
196=item $cf::UPTIME 200=item $cf::UPTIME
197 201
198The timestamp of the server start (so not actually an uptime). 202The timestamp of the server start (so not actually an "uptime").
203
204=item $cf::SERVER_TICK
205
206An unsigned integer that starts at zero when the server is started and is
207incremented on every tick.
208
209=item $cf::NOW
210
211The (real) time of the last (current) server tick - updated before and
212after tick processing, so this is useful only as a rough "what time is it
213now" estimate.
214
215=item $cf::TICK
216
217The interval between each server tick, in seconds.
199 218
200=item $cf::RUNTIME 219=item $cf::RUNTIME
201 220
202The time this server has run, starts at 0 and is increased by $cf::TICK on 221The time this server has run, starts at 0 and is increased by $cf::TICK on
203every server tick. 222every server tick.
209Various directories - "/etc", read-only install directory, perl-library 228Various directories - "/etc", read-only install directory, perl-library
210directory, pod-directory, read-only maps directory, "/var", "/var/tmp", 229directory, pod-directory, read-only maps directory, "/var", "/var/tmp",
211unique-items directory, player file directory, random maps directory and 230unique-items directory, player file directory, random maps directory and
212database environment. 231database environment.
213 232
214=item $cf::NOW
215
216The time of the last (current) server tick.
217
218=item $cf::TICK
219
220The interval between server ticks, in seconds.
221
222=item $cf::LOADAVG 233=item $cf::LOADAVG
223 234
224The current CPU load on the server (alpha-smoothed), as a value between 0 235The current CPU load on the server (alpha-smoothed), as a value between 0
225(none) and 1 (overloaded), indicating how much time is spent on processing 236(none) and 1 (overloaded), indicating how much time is spent on processing
226objects per tick. Healthy values are < 0.5. 237objects per tick. Healthy values are < 0.5.
237=item cf::wait_for_tick, cf::wait_for_tick_begin 248=item cf::wait_for_tick, cf::wait_for_tick_begin
238 249
239These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only 250These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only
240returns directly I<after> the tick processing (and consequently, can only wake one thread 251returns directly I<after> the tick processing (and consequently, can only wake one thread
241per tick), while cf::wait_for_tick wakes up all waiters after tick processing. 252per tick), while cf::wait_for_tick wakes up all waiters after tick processing.
253
254Note that cf::Wait_for_tick will immediately return when the server is not
255ticking, making it suitable for small pauses in threads that need to run
256when the server is paused. If that is not applicable (i.e. you I<really>
257want to wait, use C<$cf::WAIT_FOR_TICK>).
258
259=item $cf::WAIT_FOR_TICK
260
261Note that C<cf::wait_for_tick> is probably the correct thing to use. This
262variable contains a L<Coro::Signal> that is broadcats after every server
263tick. Calling C<< ->wait >> on it will suspend the caller until after the
264next server tick.
242 265
243=cut 266=cut
244 267
245sub wait_for_tick(); 268sub wait_for_tick();
246sub wait_for_tick_begin(); 269sub wait_for_tick_begin();
545 } 568 }
546 } 569 }
547 570
548 if (@SLOT_QUEUE) { 571 if (@SLOT_QUEUE) {
549 # we do not use wait_for_tick() as it returns immediately when tick is inactive 572 # we do not use wait_for_tick() as it returns immediately when tick is inactive
550 push @cf::WAIT_FOR_TICK, $signal; 573 $WAIT_FOR_TICK->wait;
551 $signal->wait;
552 } else { 574 } else {
553 $busy = 0; 575 $busy = 0;
554 Coro::schedule; 576 Coro::schedule;
555 } 577 }
556 } 578 }
1555 1577
1556 while (my ($k, $v) = each %todo) { 1578 while (my ($k, $v) = each %todo) {
1557 cf::cleanup "mandatory extension '$k' has unresolved dependencies, exiting." 1579 cf::cleanup "mandatory extension '$k' has unresolved dependencies, exiting."
1558 if exists $v->{meta}{mandatory}; 1580 if exists $v->{meta}{mandatory};
1559 } 1581 }
1582
1583 last;
1560 } 1584 }
1561 } 1585 }
1562 }; 1586 };
1563} 1587}
1564 1588
1992 2016
1993 Carp::cluck "unable to resolve path '$path' (base '$base')"; 2017 Carp::cluck "unable to resolve path '$path' (base '$base')";
1994 () 2018 ()
1995} 2019}
1996 2020
2021# may re-bless or do other evil things
1997sub init { 2022sub init {
1998 my ($self) = @_; 2023 my ($self) = @_;
1999 2024
2000 $self 2025 $self
2001} 2026}
2066 $self->{load_path} = $path; 2091 $self->{load_path} = $path;
2067 2092
2068 1 2093 1
2069} 2094}
2070 2095
2096# used to laod the header of an original map
2071sub load_header_orig { 2097sub load_header_orig {
2072 my ($self) = @_; 2098 my ($self) = @_;
2073 2099
2074 $self->load_header_from ($self->load_path) 2100 $self->load_header_from ($self->load_path)
2075} 2101}
2076 2102
2103# used to laod the header of an instantiated map
2077sub load_header_temp { 2104sub load_header_temp {
2078 my ($self) = @_; 2105 my ($self) = @_;
2079 2106
2080 $self->load_header_from ($self->save_path) 2107 $self->load_header_from ($self->save_path)
2081} 2108}
2082 2109
2110# called after loading the header from an instantiated map
2083sub prepare_temp { 2111sub prepare_temp {
2084 my ($self) = @_; 2112 my ($self) = @_;
2085 2113
2086 $self->last_access ((delete $self->{last_access}) 2114 $self->last_access ((delete $self->{last_access})
2087 || $cf::RUNTIME); #d# 2115 || $cf::RUNTIME); #d#
2088 # safety 2116 # safety
2089 $self->{instantiate_time} = $cf::RUNTIME 2117 $self->{instantiate_time} = $cf::RUNTIME
2090 if $self->{instantiate_time} > $cf::RUNTIME; 2118 if $self->{instantiate_time} > $cf::RUNTIME;
2091} 2119}
2092 2120
2121# called after loading the header from an original map
2093sub prepare_orig { 2122sub prepare_orig {
2094 my ($self) = @_; 2123 my ($self) = @_;
2095 2124
2096 $self->{load_original} = 1; 2125 $self->{load_original} = 1;
2097 $self->{instantiate_time} = $cf::RUNTIME; 2126 $self->{instantiate_time} = $cf::RUNTIME;
2123sub find { 2152sub find {
2124 my ($path, $origin) = @_; 2153 my ($path, $origin) = @_;
2125 2154
2126 cf::cede_to_tick; 2155 cf::cede_to_tick;
2127 2156
2128 $path = normalise $path, $origin && $origin->path; 2157 $path = normalise $path, $origin;
2129 2158
2130 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove 2159 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove
2131 my $guard2 = cf::lock_acquire "map_find:$path"; 2160 my $guard2 = cf::lock_acquire "map_find:$path";
2132 2161
2133 $cf::MAP{$path} || do { 2162 $cf::MAP{$path} || do {
2164 2193
2165 { 2194 {
2166 my $guard = cf::lock_acquire "map_data:$path"; 2195 my $guard = cf::lock_acquire "map_data:$path";
2167 2196
2168 return unless $self->valid; 2197 return unless $self->valid;
2169 return unless $self->in_memory == cf::MAP_SWAPPED; 2198 return unless $self->state == cf::MAP_SWAPPED;
2170
2171 $self->in_memory (cf::MAP_LOADING);
2172 2199
2173 $self->alloc; 2200 $self->alloc;
2174 2201
2175 $self->pre_load; 2202 $self->pre_load;
2176 cf::cede_to_tick; 2203 cf::cede_to_tick;
2177 2204
2205 if (exists $self->{load_path}) {
2178 my $f = new_from_file cf::object::thawer $self->{load_path}; 2206 my $f = new_from_file cf::object::thawer $self->{load_path};
2179 $f->skip_block; 2207 $f->skip_block;
2180 $self->_load_objects ($f) 2208 $self->_load_objects ($f)
2181 or return; 2209 or return;
2182 2210
2183 $self->post_load_original 2211 $self->post_load_original
2184 if delete $self->{load_original}; 2212 if delete $self->{load_original};
2185 2213
2186 if (my $uniq = $self->uniq_path) { 2214 if (my $uniq = $self->uniq_path) {
2187 utf8::encode $uniq; 2215 utf8::encode $uniq;
2188 unless (aio_stat $uniq) { 2216 unless (aio_stat $uniq) {
2189 if (my $f = new_from_file cf::object::thawer $uniq) { 2217 if (my $f = new_from_file cf::object::thawer $uniq) {
2190 $self->clear_unique_items; 2218 $self->clear_unique_items;
2191 $self->_load_objects ($f); 2219 $self->_load_objects ($f);
2192 $f->resolve_delayed_derefs; 2220 $f->resolve_delayed_derefs;
2221 }
2193 } 2222 }
2194 } 2223 }
2195 }
2196 2224
2197 $f->resolve_delayed_derefs; 2225 $f->resolve_delayed_derefs;
2226 } else {
2227 $self->post_load_original
2228 if delete $self->{load_original};
2229 }
2230
2231 $self->state (cf::MAP_INACTIVE);
2198 2232
2199 cf::cede_to_tick; 2233 cf::cede_to_tick;
2200 # now do the right thing for maps 2234 # now do the right thing for maps
2201 $self->link_multipart_objects; 2235 $self->link_multipart_objects;
2202 $self->difficulty ($self->estimate_difficulty) 2236 $self->difficulty ($self->estimate_difficulty)
2206 unless ($self->{deny_activate}) { 2240 unless ($self->{deny_activate}) {
2207 $self->decay_objects; 2241 $self->decay_objects;
2208 $self->fix_auto_apply; 2242 $self->fix_auto_apply;
2209 $self->update_buttons; 2243 $self->update_buttons;
2210 cf::cede_to_tick; 2244 cf::cede_to_tick;
2211 $self->activate; 2245 #$self->activate; # no longer activate maps automatically
2212 } 2246 }
2213 2247
2214 $self->{last_save} = $cf::RUNTIME; 2248 $self->{last_save} = $cf::RUNTIME;
2215 $self->last_access ($cf::RUNTIME); 2249 $self->last_access ($cf::RUNTIME);
2216
2217 $self->in_memory (cf::MAP_ACTIVE);
2218 } 2250 }
2219 2251
2220 $self->post_load; 2252 $self->post_load;
2221 2253
2222 1 2254 1
2235# if $self->per_party; 2267# if $self->per_party;
2236 2268
2237 $self 2269 $self
2238} 2270}
2239 2271
2240# find and load all maps in the 3x3 area around a map
2241sub load_neighbours {
2242 my ($map) = @_;
2243
2244 my @neigh; # diagonal neighbours
2245
2246 for (0 .. 3) {
2247 my $neigh = $map->tile_path ($_)
2248 or next;
2249 $neigh = find $neigh, $map
2250 or next;
2251 $neigh->load;
2252
2253 # now find the diagonal neighbours
2254 push @neigh,
2255 [$neigh->tile_path (($_ + 3) % 4), $neigh],
2256 [$neigh->tile_path (($_ + 1) % 4), $neigh];
2257 }
2258
2259 for (grep defined $_->[0], @neigh) {
2260 my ($path, $origin) = @$_;
2261 my $neigh = find $path, $origin
2262 or next;
2263 $neigh->load;
2264 }
2265}
2266
2267sub find_sync { 2272sub find_sync {
2268 my ($path, $origin) = @_; 2273 my ($path, $origin) = @_;
2269 2274
2275 # it's a bug to call this from the main context
2270 return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync" 2276 return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync"
2271 if $Coro::current == $Coro::main; 2277 if $Coro::current == $Coro::main;
2272 2278
2273 find $path, $origin 2279 find $path, $origin
2274} 2280}
2275 2281
2276sub do_load_sync { 2282sub do_load_sync {
2277 my ($map) = @_; 2283 my ($map) = @_;
2278 2284
2285 # it's a bug to call this from the main context
2279 return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync" 2286 return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync"
2280 if $Coro::current == $Coro::main; 2287 if $Coro::current == $Coro::main;
2281 2288
2282 $map->load; 2289 $map->load;
2283} 2290}
2286our $MAP_PREFETCHER = undef; 2293our $MAP_PREFETCHER = undef;
2287 2294
2288sub find_async { 2295sub find_async {
2289 my ($path, $origin, $load) = @_; 2296 my ($path, $origin, $load) = @_;
2290 2297
2291 $path = normalise $path, $origin && $origin->{path}; 2298 $path = normalise $path, $origin;
2292 2299
2293 if (my $map = $cf::MAP{$path}) { 2300 if (my $map = $cf::MAP{$path}) {
2294 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; 2301 return $map if !$load || $map->linkable;
2295 } 2302 }
2296 2303
2297 $MAP_PREFETCH{$path} |= $load; 2304 $MAP_PREFETCH{$path} |= $load;
2298 2305
2299 $MAP_PREFETCHER ||= cf::async { 2306 $MAP_PREFETCHER ||= cf::async {
2358sub swap_out { 2365sub swap_out {
2359 my ($self) = @_; 2366 my ($self) = @_;
2360 2367
2361 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2368 my $lock = cf::lock_acquire "map_data:$self->{path}";
2362 2369
2363 return if $self->in_memory != cf::MAP_ACTIVE; 2370 return if !$self->linkable;
2364 return if $self->{deny_save}; 2371 return if $self->{deny_save};
2365 return if $self->players; 2372 return if $self->players;
2366 2373
2367 # first deactivate the map and "unlink" it from the core 2374 # first deactivate the map and "unlink" it from the core
2368 $self->deactivate; 2375 $self->deactivate;
2369 $_->clear_links_to ($self) for values %cf::MAP; 2376 $_->clear_links_to ($self) for values %cf::MAP;
2370 $self->in_memory (cf::MAP_SWAPPED); 2377 $self->state (cf::MAP_SWAPPED);
2371 2378
2372 # then atomically save 2379 # then atomically save
2373 $self->_save; 2380 $self->_save;
2374 2381
2375 # then free the map 2382 # then free the map
2401 2408
2402 return if $self->players; 2409 return if $self->players;
2403 2410
2404 cf::trace "resetting map ", $self->path, "\n"; 2411 cf::trace "resetting map ", $self->path, "\n";
2405 2412
2406 $self->in_memory (cf::MAP_SWAPPED); 2413 $self->state (cf::MAP_SWAPPED);
2407 2414
2408 # need to save uniques path 2415 # need to save uniques path
2409 unless ($self->{deny_save}) { 2416 unless ($self->{deny_save}) {
2410 my $uniq = $self->uniq_path; utf8::encode $uniq; 2417 my $uniq = $self->uniq_path; utf8::encode $uniq;
2411 2418
2741 # use -1 or undef as default coordinates, not 0, 0 2748 # use -1 or undef as default coordinates, not 0, 0
2742 ($x, $y) = ($map->enter_x, $map->enter_y) 2749 ($x, $y) = ($map->enter_x, $map->enter_y)
2743 if $x <= 0 && $y <= 0; 2750 if $x <= 0 && $y <= 0;
2744 2751
2745 $map->load; 2752 $map->load;
2746 $map->load_neighbours;
2747 2753
2748 return unless $self->contr->active; 2754 return unless $self->contr->active;
2749 2755
2750 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2756 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2751 if ($self->enter_map ($map, $x, $y)) { 2757 if ($self->enter_map ($map, $x, $y)) {
2807 ($path, $x, $y) = (undef, undef, undef); 2813 ($path, $x, $y) = (undef, undef, undef);
2808 } 2814 }
2809 } 2815 }
2810 2816
2811 my $map = eval { 2817 my $map = eval {
2812 my $map = defined $path ? cf::map::find $path : undef; 2818 my $map = defined $path ? cf::map::find $path, $self->map : undef;
2813 2819
2814 if ($map) { 2820 if ($map) {
2815 $map = $map->customise_for ($self); 2821 $map = $map->customise_for ($self);
2816 $map = $check->($map, $x, $y, $self) if $check && $map; 2822 $map = $check->($map, $x, $y, $self) if $check && $map;
2817 } else { 2823 } else {
2907 $Coro::current->{desc} = "enter_exit"; 2913 $Coro::current->{desc} = "enter_exit";
2908 2914
2909 unless (eval { 2915 unless (eval {
2910 $self->deactivate_recursive; # just to be sure 2916 $self->deactivate_recursive; # just to be sure
2911 2917
2912 # random map handling
2913 {
2914 my $guard = cf::lock_acquire "exit_prepare:$exit";
2915
2916 prepare_random_map $exit
2917 if $exit->slaying eq "/!";
2918 }
2919
2920 my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; 2918 my $map = cf::map::normalise $exit->slaying, $exit->map;
2921 my $x = $exit->stats->hp; 2919 my $x = $exit->stats->hp;
2922 my $y = $exit->stats->sp; 2920 my $y = $exit->stats->sp;
2921
2922 # special map handling
2923 my $slaying = $exit->slaying;
2924
2925 # special map handling
2926 if ($slaying eq "/!") {
2927 my $guard = cf::lock_acquire "exit_prepare:$exit";
2928
2929 prepare_random_map $exit
2930 if $exit->slaying eq "/!"; # need to re-check after getting the lock
2931
2932 $map = $exit->slaying;
2933
2934 } elsif ($slaying eq '!up') {
2935 $map = $exit->map->tile_path (cf::TILE_UP);
2936 $x = $exit->x;
2937 $y = $exit->y;
2938
2939 } elsif ($slaying eq '!down') {
2940 $map = $exit->map->tile_path (cf::TILE_DOWN);
2941 $x = $exit->x;
2942 $y = $exit->y;
2943 }
2923 2944
2924 $self->goto ($map, $x, $y); 2945 $self->goto ($map, $x, $y);
2925 2946
2926 # if exit is damned, update players death & WoR home-position 2947 # if exit is damned, update players death & WoR home-position
2927 $self->contr->savebed ($map, $x, $y) 2948 $self->contr->savebed ($map, $x, $y)
3655 3676
3656sub main { 3677sub main {
3657 cf::init_globals; # initialise logging 3678 cf::init_globals; # initialise logging
3658 3679
3659 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3680 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3660 LOG llevInfo, "Copyright (C) 2005-2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3681 LOG llevInfo, "Copyright (C) 2005-2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3661 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3682 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3662 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3683 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3663 3684
3664 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3685 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3665 3686
3707 }; 3728 };
3708 3729
3709 cf::object::thawer::errors_are_fatal 0; 3730 cf::object::thawer::errors_are_fatal 0;
3710 info "parse errors in files are no longer fatal from this point on.\n"; 3731 info "parse errors in files are no longer fatal from this point on.\n";
3711 3732
3712 my $free_main; $free_main = EV::idle sub { 3733 AE::postpone {
3713 undef $free_main;
3714 undef &main; # free gobs of memory :) 3734 undef &main; # free gobs of memory :)
3715 }; 3735 };
3716 3736
3717 goto &main_loop; 3737 goto &main_loop;
3718} 3738}
3875 3895
3876 cf::write_runtime_sync; # external watchdog should not bark 3896 cf::write_runtime_sync; # external watchdog should not bark
3877 3897
3878 trace "emergency_perl_save: flushing outstanding aio requests"; 3898 trace "emergency_perl_save: flushing outstanding aio requests";
3879 while (IO::AIO::nreqs || BDB::nreqs) { 3899 while (IO::AIO::nreqs || BDB::nreqs) {
3880 Coro::EV::timer_once 0.01; # let the sync_job do it's thing 3900 Coro::AnyEvent::sleep 0.01; # let the sync_job do it's thing
3881 } 3901 }
3882 3902
3883 cf::write_runtime_sync; # external watchdog should not bark 3903 cf::write_runtime_sync; # external watchdog should not bark
3884 }; 3904 };
3885 3905
4066 4086
4067############################################################################# 4087#############################################################################
4068 4088
4069my $bug_warning = 0; 4089my $bug_warning = 0;
4070 4090
4071our @WAIT_FOR_TICK;
4072our @WAIT_FOR_TICK_BEGIN;
4073
4074sub wait_for_tick() { 4091sub wait_for_tick() {
4075 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4092 return Coro::AnyEvent::poll if tick_inhibit || $Coro::current == $Coro::main;
4076 4093
4077 my $signal = new Coro::Signal; 4094 $WAIT_FOR_TICK->wait;
4078 push @WAIT_FOR_TICK, $signal;
4079 $signal->wait;
4080} 4095}
4081 4096
4082sub wait_for_tick_begin() { 4097sub wait_for_tick_begin() {
4083 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4098 return Coro::AnyEvent::poll if tick_inhibit || $Coro::current == $Coro::main;
4084 4099
4085 my $signal = new Coro::Signal; 4100 my $signal = new Coro::Signal;
4086 push @WAIT_FOR_TICK_BEGIN, $signal; 4101 push @WAIT_FOR_TICK_BEGIN, $signal;
4087 $signal->wait; 4102 $signal->wait;
4088} 4103}
4092 Carp::cluck "major BUG: server tick called outside of main coro, skipping it" 4107 Carp::cluck "major BUG: server tick called outside of main coro, skipping it"
4093 unless ++$bug_warning > 10; 4108 unless ++$bug_warning > 10;
4094 return; 4109 return;
4095 } 4110 }
4096 4111
4097 cf::server_tick; # one server iteration 4112 cf::one_tick; # one server iteration
4098 4113
4099 #for(1..3e6){} AE::now_update; $NOW=AE::now; # generate load #d# 4114 #for(1..3e6){} AE::now_update; $NOW=AE::now; # generate load #d#
4100 4115
4101 if ($NOW >= $NEXT_RUNTIME_WRITE) { 4116 if ($NOW >= $NEXT_RUNTIME_WRITE) {
4102 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; 4117 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
4108 } 4123 }
4109 4124
4110 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { 4125 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {
4111 $sig->send; 4126 $sig->send;
4112 } 4127 }
4113 while (my $sig = shift @WAIT_FOR_TICK) { 4128 $WAIT_FOR_TICK->broadcast;
4114 $sig->send;
4115 }
4116 4129
4117 $LOAD = ($NOW - $TICK_START) / $TICK; 4130 $LOAD = ($NOW - $TICK_START) / $TICK;
4118 $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25; 4131 $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25;
4119 4132
4120 if (0) { 4133 if (0) {
4129{ 4142{
4130 # configure BDB 4143 # configure BDB
4131 4144
4132 BDB::min_parallel 16; 4145 BDB::min_parallel 16;
4133 BDB::max_poll_reqs $TICK * 0.1; 4146 BDB::max_poll_reqs $TICK * 0.1;
4134 $AnyEvent::BDB::WATCHER->priority (1); 4147 #$AnyEvent::BDB::WATCHER->priority (1);
4135 4148
4136 unless ($DB_ENV) { 4149 unless ($DB_ENV) {
4137 $DB_ENV = BDB::db_env_create; 4150 $DB_ENV = BDB::db_env_create;
4138 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT); 4151 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT);
4139 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; 4152 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines