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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | # Copyright (©) 2006,2007,2008,2009,2010 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. |
… | |
… | |
53 | use Coro::Util (); |
53 | use Coro::Util (); |
54 | |
54 | |
55 | use JSON::XS 2.01 (); |
55 | use JSON::XS 2.01 (); |
56 | use BDB (); |
56 | use BDB (); |
57 | use Data::Dumper; |
57 | use Data::Dumper; |
58 | use Digest::MD5; |
|
|
59 | use Fcntl; |
58 | use Fcntl; |
60 | use YAML::XS (); |
59 | use YAML::XS (); |
61 | use IO::AIO (); |
60 | use IO::AIO (); |
62 | use Time::HiRes; |
61 | use Time::HiRes; |
63 | use Compress::LZF; |
62 | use Compress::LZF; |
… | |
… | |
424 | |
423 | |
425 | =cut |
424 | =cut |
426 | |
425 | |
427 | our @SLOT_QUEUE; |
426 | our @SLOT_QUEUE; |
428 | our $SLOT_QUEUE; |
427 | our $SLOT_QUEUE; |
|
|
428 | our $SLOT_DECAY = 0.9; |
429 | |
429 | |
430 | $SLOT_QUEUE->cancel if $SLOT_QUEUE; |
430 | $SLOT_QUEUE->cancel if $SLOT_QUEUE; |
431 | $SLOT_QUEUE = Coro::async { |
431 | $SLOT_QUEUE = Coro::async { |
432 | $Coro::current->desc ("timeslot manager"); |
432 | $Coro::current->desc ("timeslot manager"); |
433 | |
433 | |
434 | my $signal = new Coro::Signal; |
434 | my $signal = new Coro::Signal; |
|
|
435 | my $busy; |
435 | |
436 | |
436 | while () { |
437 | while () { |
437 | next_job: |
438 | next_job: |
|
|
439 | |
438 | my $avail = cf::till_tick; |
440 | my $avail = cf::till_tick; |
439 | if ($avail > 0.01) { |
441 | |
440 | for (0 .. $#SLOT_QUEUE) { |
442 | for (0 .. $#SLOT_QUEUE) { |
441 | if ($SLOT_QUEUE[$_][0] < $avail) { |
443 | if ($SLOT_QUEUE[$_][0] <= $avail) { |
|
|
444 | $busy = 0; |
442 | my $job = splice @SLOT_QUEUE, $_, 1, (); |
445 | my $job = splice @SLOT_QUEUE, $_, 1, (); |
443 | $job->[2]->send; |
446 | $job->[2]->send; |
444 | Coro::cede; |
447 | Coro::cede; |
445 | goto next_job; |
448 | goto next_job; |
446 | } |
449 | } else { |
|
|
450 | $SLOT_QUEUE[$_][0] *= $SLOT_DECAY; |
447 | } |
451 | } |
448 | } |
452 | } |
449 | |
453 | |
450 | if (@SLOT_QUEUE) { |
454 | if (@SLOT_QUEUE) { |
451 | # we do not use wait_for_tick() as it returns immediately when tick is inactive |
455 | # we do not use wait_for_tick() as it returns immediately when tick is inactive |
452 | push @cf::WAIT_FOR_TICK, $signal; |
456 | push @cf::WAIT_FOR_TICK, $signal; |
453 | $signal->wait; |
457 | $signal->wait; |
454 | } else { |
458 | } else { |
|
|
459 | $busy = 0; |
455 | Coro::schedule; |
460 | Coro::schedule; |
456 | } |
461 | } |
457 | } |
462 | } |
458 | }; |
463 | }; |
459 | |
464 | |
460 | sub get_slot($;$$) { |
465 | sub get_slot($;$$) { |
461 | return if tick_inhibit || $Coro::current == $Coro::main; |
466 | return if tick_inhibit || $Coro::current == $Coro::main; |
462 | |
467 | |
463 | my ($time, $pri, $name) = @_; |
468 | my ($time, $pri, $name) = @_; |
464 | |
469 | |
465 | $time = $TICK * .6 if $time > $TICK * .6; |
470 | $time = clamp $time, 0.01, $TICK * .6; |
|
|
471 | |
466 | my $sig = new Coro::Signal; |
472 | my $sig = new Coro::Signal; |
467 | |
473 | |
468 | push @SLOT_QUEUE, [$time, $pri, $sig, $name]; |
474 | push @SLOT_QUEUE, [$time, $pri, $sig, $name]; |
469 | @SLOT_QUEUE = sort { $b->[1] <=> $a->[1] } @SLOT_QUEUE; |
475 | @SLOT_QUEUE = sort { $b->[1] <=> $a->[1] } @SLOT_QUEUE; |
470 | $SLOT_QUEUE->ready; |
476 | $SLOT_QUEUE->ready; |
… | |
… | |
1304 | } |
1310 | } |
1305 | |
1311 | |
1306 | use File::Glob (); |
1312 | use File::Glob (); |
1307 | |
1313 | |
1308 | cf::player->attach ( |
1314 | cf::player->attach ( |
1309 | on_command => sub { |
1315 | on_unknown_command => sub { |
1310 | my ($pl, $name, $params) = @_; |
1316 | my ($pl, $name, $params) = @_; |
1311 | |
1317 | |
1312 | my $cb = $COMMAND{$name} |
1318 | my $cb = $COMMAND{$name} |
1313 | or return; |
1319 | or return; |
1314 | |
1320 | |
… | |
… | |
1393 | . "\n};\n1"; |
1399 | . "\n};\n1"; |
1394 | |
1400 | |
1395 | $todo{$base} = \%ext; |
1401 | $todo{$base} = \%ext; |
1396 | } |
1402 | } |
1397 | |
1403 | |
|
|
1404 | my $pass = 0; |
1398 | my %done; |
1405 | my %done; |
1399 | while (%todo) { |
1406 | while (%todo) { |
1400 | my $progress; |
1407 | my $progress; |
1401 | |
1408 | |
|
|
1409 | ++$pass; |
|
|
1410 | |
|
|
1411 | ext: |
1402 | while (my ($k, $v) = each %todo) { |
1412 | while (my ($k, $v) = each %todo) { |
1403 | for (split /,\s*/, $v->{meta}{depends}) { |
1413 | for (split /,\s*/, $v->{meta}{depends}) { |
1404 | goto skip |
1414 | next ext |
1405 | unless exists $done{$_}; |
1415 | unless exists $done{$_}; |
1406 | } |
1416 | } |
1407 | |
1417 | |
1408 | warn "... loading '$k' into '$v->{pkg}'\n"; |
1418 | warn "... pass $pass, loading '$k' into '$v->{pkg}'\n"; |
1409 | |
1419 | |
1410 | unless (eval $v->{source}) { |
1420 | my $active = eval $v->{source}; |
|
|
1421 | |
|
|
1422 | if (length $@) { |
1411 | my $msg = $@ ? "$v->{path}: $@\n" |
1423 | warn "$v->{path}: $@\n"; |
1412 | : "$v->{base}: extension inactive.\n"; |
|
|
1413 | |
1424 | |
1414 | if (exists $v->{meta}{mandatory}) { |
|
|
1415 | warn $msg; |
|
|
1416 | cf::cleanup "mandatory extension failed to load, exiting."; |
1425 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1417 | } |
1426 | if exists $v->{meta}{mandatory}; |
1418 | |
1427 | } else { |
1419 | warn $msg; |
1428 | $done{$k} = delete $todo{$k}; |
|
|
1429 | push @EXTS, $v->{pkg}; |
|
|
1430 | $progress = 1; |
|
|
1431 | |
|
|
1432 | warn "$v->{base}: extension inactive.\n" |
|
|
1433 | unless $active; |
1420 | } |
1434 | } |
1421 | |
|
|
1422 | $done{$k} = delete $todo{$k}; |
|
|
1423 | push @EXTS, $v->{pkg}; |
|
|
1424 | $progress = 1; |
|
|
1425 | } |
1435 | } |
1426 | |
1436 | |
1427 | skip: |
1437 | unless ($progress) { |
1428 | die "cannot load " . (join ", ", keys %todo) . ": unable to resolve dependencies\n" |
1438 | warn "cannot load " . (join ", ", keys %todo) . ": unable to resolve dependencies\n"; |
1429 | unless $progress; |
1439 | |
|
|
1440 | while (my ($k, $v) = each %todo) { |
|
|
1441 | cf::cleanup "mandatory extension '$k' has unresolved dependencies, exiting." |
|
|
1442 | if exists $v->{meta}{mandatory}; |
|
|
1443 | } |
|
|
1444 | } |
1430 | } |
1445 | } |
1431 | }; |
1446 | }; |
1432 | } |
1447 | } |
1433 | |
1448 | |
1434 | ############################################################################# |
1449 | ############################################################################# |
… | |
… | |
1754 | my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM |
1769 | my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM |
1755 | |
1770 | |
1756 | # mit "rum" bekleckern, nicht |
1771 | # mit "rum" bekleckern, nicht |
1757 | $self->_create_random_map ( |
1772 | $self->_create_random_map ( |
1758 | $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, |
1773 | $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, |
1759 | $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, |
1774 | $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle}, |
1760 | $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, |
1775 | $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, |
1761 | $rmp->{exit_on_final_map}, |
1776 | $rmp->{exit_on_final_map}, |
1762 | $rmp->{xsize}, $rmp->{ysize}, |
1777 | $rmp->{xsize}, $rmp->{ysize}, |
1763 | $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3}, |
1778 | $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3}, |
1764 | $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase}, |
1779 | $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase}, |
… | |
… | |
2010 | |
2025 | |
2011 | $cf::MAP{$path} = $map |
2026 | $cf::MAP{$path} = $map |
2012 | } |
2027 | } |
2013 | } |
2028 | } |
2014 | |
2029 | |
2015 | sub pre_load { } |
2030 | sub pre_load { } |
2016 | sub post_load { } |
2031 | #sub post_load { } # XS |
2017 | |
2032 | |
2018 | sub load { |
2033 | sub load { |
2019 | my ($self) = @_; |
2034 | my ($self) = @_; |
2020 | |
2035 | |
2021 | local $self->{deny_reset} = 1; # loading can take a long time |
2036 | local $self->{deny_reset} = 1; # loading can take a long time |
… | |
… | |
2078 | } |
2093 | } |
2079 | |
2094 | |
2080 | $self->post_load; |
2095 | $self->post_load; |
2081 | } |
2096 | } |
2082 | |
2097 | |
|
|
2098 | # customize the map for a given player, i.e. |
|
|
2099 | # return the _real_ map. used by e.g. per-player |
|
|
2100 | # maps to change the path to ~playername/mappath |
2083 | sub customise_for { |
2101 | sub customise_for { |
2084 | my ($self, $ob) = @_; |
2102 | my ($self, $ob) = @_; |
2085 | |
2103 | |
2086 | return find "~" . $ob->name . "/" . $self->{path} |
2104 | return find "~" . $ob->name . "/" . $self->{path} |
2087 | if $self->per_player; |
2105 | if $self->per_player; |
… | |
… | |
3116 | |
3134 | |
3117 | $coro |
3135 | $coro |
3118 | } |
3136 | } |
3119 | |
3137 | |
3120 | cf::client->attach ( |
3138 | cf::client->attach ( |
3121 | on_destroy => sub { |
3139 | on_client_destroy => sub { |
3122 | my ($ns) = @_; |
3140 | my ($ns) = @_; |
3123 | |
3141 | |
3124 | $_->cancel for values %{ (delete $ns->{_coro}) || {} }; |
3142 | $_->cancel for values %{ (delete $ns->{_coro}) || {} }; |
3125 | }, |
3143 | }, |
3126 | ); |
3144 | ); |
… | |
… | |
3142 | our $safe_hole = new Safe::Hole; |
3160 | our $safe_hole = new Safe::Hole; |
3143 | |
3161 | |
3144 | $SIG{FPE} = 'IGNORE'; |
3162 | $SIG{FPE} = 'IGNORE'; |
3145 | |
3163 | |
3146 | $safe->permit_only (Opcode::opset qw( |
3164 | $safe->permit_only (Opcode::opset qw( |
3147 | :base_core :base_mem :base_orig :base_math |
3165 | :base_core :base_mem :base_orig :base_math :base_loop |
3148 | grepstart grepwhile mapstart mapwhile |
3166 | grepstart grepwhile mapstart mapwhile |
3149 | sort time |
3167 | sort time |
3150 | )); |
3168 | )); |
3151 | |
3169 | |
3152 | # here we export the classes and methods available to script code |
3170 | # here we export the classes and methods available to script code |
… | |
… | |
3204 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3222 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3205 | $qcode =~ s/\n/\\n/g; |
3223 | $qcode =~ s/\n/\\n/g; |
3206 | |
3224 | |
3207 | %vars = (_dummy => 0) unless %vars; |
3225 | %vars = (_dummy => 0) unless %vars; |
3208 | |
3226 | |
|
|
3227 | my @res; |
3209 | local $_; |
3228 | local $_; |
3210 | local @safe::cf::_safe_eval_args = values %vars; |
|
|
3211 | |
3229 | |
3212 | my $eval = |
3230 | my $eval = |
3213 | "do {\n" |
3231 | "do {\n" |
3214 | . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n" |
3232 | . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n" |
3215 | . "#line 0 \"{$qcode}\"\n" |
3233 | . "#line 0 \"{$qcode}\"\n" |
3216 | . $code |
3234 | . $code |
3217 | . "\n}" |
3235 | . "\n}" |
3218 | ; |
3236 | ; |
3219 | |
3237 | |
|
|
3238 | if ($CFG{safe_eval}) { |
3220 | sub_generation_inc; |
3239 | sub_generation_inc; |
|
|
3240 | local @safe::cf::_safe_eval_args = values %vars; |
3221 | my @res = wantarray ? $safe->reval ($eval) : scalar $safe->reval ($eval); |
3241 | @res = wantarray ? $safe->reval ($eval) : scalar $safe->reval ($eval); |
3222 | sub_generation_inc; |
3242 | sub_generation_inc; |
|
|
3243 | } else { |
|
|
3244 | local @cf::_safe_eval_args = values %vars; |
|
|
3245 | @res = wantarray ? eval eval : scalar eval $eval; |
|
|
3246 | } |
3223 | |
3247 | |
3224 | if ($@) { |
3248 | if ($@) { |
3225 | warn "$@"; |
3249 | warn "$@"; |
3226 | warn "while executing safe code '$code'\n"; |
3250 | warn "while executing safe code '$code'\n"; |
3227 | warn "with arguments " . (join " ", %vars) . "\n"; |
3251 | warn "with arguments " . (join " ", %vars) . "\n"; |
… | |
… | |
3246 | =cut |
3270 | =cut |
3247 | |
3271 | |
3248 | sub register_script_function { |
3272 | sub register_script_function { |
3249 | my ($fun, $cb) = @_; |
3273 | my ($fun, $cb) = @_; |
3250 | |
3274 | |
3251 | no strict 'refs'; |
3275 | $fun = "safe::$fun" if $CFG{safe_eval}; |
3252 | *{"safe::$fun"} = $safe_hole->wrap ($cb); |
3276 | *$fun = $safe_hole->wrap ($cb); |
3253 | } |
3277 | } |
3254 | |
3278 | |
3255 | =back |
3279 | =back |
3256 | |
3280 | |
3257 | =cut |
3281 | =cut |
… | |
… | |
3278 | |
3302 | |
3279 | $facedata->{version} == 2 |
3303 | $facedata->{version} == 2 |
3280 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3304 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3281 | |
3305 | |
3282 | # patch in the exptable |
3306 | # patch in the exptable |
|
|
3307 | my $exp_table = $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]); |
3283 | $facedata->{resource}{"res/exp_table"} = { |
3308 | $facedata->{resource}{"res/exp_table"} = { |
3284 | type => FT_RSRC, |
3309 | type => FT_RSRC, |
3285 | data => $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]), |
3310 | data => $exp_table, |
|
|
3311 | hash => (Digest::MD5::md5 $exp_table), |
3286 | }; |
3312 | }; |
3287 | cf::cede_to_tick; |
3313 | cf::cede_to_tick; |
3288 | |
3314 | |
3289 | { |
3315 | { |
3290 | my $faces = $facedata->{faceinfo}; |
3316 | my $faces = $facedata->{faceinfo}; |
… | |
… | |
3292 | while (my ($face, $info) = each %$faces) { |
3318 | while (my ($face, $info) = each %$faces) { |
3293 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3319 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3294 | |
3320 | |
3295 | cf::face::set_visibility $idx, $info->{visibility}; |
3321 | cf::face::set_visibility $idx, $info->{visibility}; |
3296 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3322 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3297 | cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32}; |
3323 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3298 | cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64}; |
3324 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3299 | |
3325 | |
3300 | cf::cede_to_tick; |
3326 | cf::cede_to_tick; |
3301 | } |
3327 | } |
3302 | |
3328 | |
3303 | while (my ($face, $info) = each %$faces) { |
3329 | while (my ($face, $info) = each %$faces) { |
… | |
… | |
3327 | |
3353 | |
3328 | cf::anim::invalidate_all; # d'oh |
3354 | cf::anim::invalidate_all; # d'oh |
3329 | } |
3355 | } |
3330 | |
3356 | |
3331 | { |
3357 | { |
3332 | # TODO: for gcfclient pleasure, we should give resources |
|
|
3333 | # that gcfclient doesn't grok a >10000 face index. |
|
|
3334 | my $res = $facedata->{resource}; |
3358 | my $res = $facedata->{resource}; |
3335 | |
3359 | |
3336 | while (my ($name, $info) = each %$res) { |
3360 | while (my ($name, $info) = each %$res) { |
3337 | if (defined $info->{type}) { |
3361 | if (defined $info->{type}) { |
3338 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3362 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3339 | my $data; |
|
|
3340 | |
3363 | |
3341 | if ($info->{type} & 1) { |
3364 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3342 | # prepend meta info |
|
|
3343 | |
|
|
3344 | my $meta = $enc->encode ({ |
|
|
3345 | name => $name, |
|
|
3346 | %{ $info->{meta} || {} }, |
|
|
3347 | }); |
|
|
3348 | |
|
|
3349 | $data = pack "(w/a*)*", $meta, $info->{data}; |
|
|
3350 | } else { |
|
|
3351 | $data = $info->{data}; |
|
|
3352 | } |
|
|
3353 | |
|
|
3354 | cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data; |
|
|
3355 | cf::face::set_type $idx, $info->{type}; |
3365 | cf::face::set_type $idx, $info->{type}; |
3356 | } else { |
3366 | } else { |
3357 | $RESOURCE{$name} = $info; |
3367 | $RESOURCE{$name} = $info; |
3358 | } |
3368 | } |
3359 | |
3369 | |
… | |
… | |
3566 | }; |
3576 | }; |
3567 | } |
3577 | } |
3568 | } |
3578 | } |
3569 | |
3579 | |
3570 | sub write_runtime_sync { |
3580 | sub write_runtime_sync { |
|
|
3581 | my $t0 = EV::time; |
|
|
3582 | |
3571 | # first touch the runtime file to show we are still running: |
3583 | # first touch the runtime file to show we are still running: |
3572 | # the fsync below can take a very very long time. |
3584 | # the fsync below can take a very very long time. |
3573 | |
3585 | |
3574 | IO::AIO::aio_utime $RUNTIMEFILE, undef, undef; |
3586 | IO::AIO::aio_utime $RUNTIMEFILE, undef, undef; |
3575 | |
3587 | |
3576 | my $guard = cf::lock_acquire "write_runtime"; |
3588 | my $guard = cf::lock_acquire "write_runtime"; |
3577 | |
3589 | |
3578 | my $fh = aio_open "$RUNTIMEFILE~", O_WRONLY | O_CREAT, 0644 |
3590 | my $fh = aio_open "$RUNTIMEFILE~", O_WRONLY | O_CREAT | O_TRUNC, 0644 |
3579 | or return; |
3591 | or return; |
3580 | |
3592 | |
3581 | my $value = $cf::RUNTIME + 90 + 10; |
3593 | my $value = $cf::RUNTIME + 90 + 10; |
3582 | # 10 is the runtime save interval, for a monotonic clock |
3594 | # 10 is the runtime save interval, for a monotonic clock |
3583 | # 60 allows for the watchdog to kill the server. |
3595 | # 60 allows for the watchdog to kill the server. |
… | |
… | |
3596 | or return; |
3608 | or return; |
3597 | |
3609 | |
3598 | aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE |
3610 | aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE |
3599 | and return; |
3611 | and return; |
3600 | |
3612 | |
3601 | warn "runtime file written.\n"; |
3613 | warn sprintf "runtime file written (%gs).\n", EV::time - $t0; |
3602 | |
3614 | |
3603 | 1 |
3615 | 1 |
3604 | } |
3616 | } |
3605 | |
3617 | |
3606 | our $uuid_lock; |
3618 | our $uuid_lock; |
… | |
… | |
3897 | |
3909 | |
3898 | our @WAIT_FOR_TICK; |
3910 | our @WAIT_FOR_TICK; |
3899 | our @WAIT_FOR_TICK_BEGIN; |
3911 | our @WAIT_FOR_TICK_BEGIN; |
3900 | |
3912 | |
3901 | sub wait_for_tick { |
3913 | sub wait_for_tick { |
3902 | return if tick_inhibit || $Coro::current == $Coro::main; |
3914 | return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; |
3903 | |
3915 | |
3904 | my $signal = new Coro::Signal; |
3916 | my $signal = new Coro::Signal; |
3905 | push @WAIT_FOR_TICK, $signal; |
3917 | push @WAIT_FOR_TICK, $signal; |
3906 | $signal->wait; |
3918 | $signal->wait; |
3907 | } |
3919 | } |
3908 | |
3920 | |
3909 | sub wait_for_tick_begin { |
3921 | sub wait_for_tick_begin { |
3910 | return if tick_inhibit || $Coro::current == $Coro::main; |
3922 | return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; |
3911 | |
3923 | |
3912 | my $signal = new Coro::Signal; |
3924 | my $signal = new Coro::Signal; |
3913 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3925 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3914 | $signal->wait; |
3926 | $signal->wait; |
3915 | } |
3927 | } |
… | |
… | |
3920 | unless ++$bug_warning > 10; |
3932 | unless ++$bug_warning > 10; |
3921 | return; |
3933 | return; |
3922 | } |
3934 | } |
3923 | |
3935 | |
3924 | cf::server_tick; # one server iteration |
3936 | cf::server_tick; # one server iteration |
|
|
3937 | |
|
|
3938 | #for(1..3e6){} EV::now_update; $NOW=EV::now; # generate load #d# |
3925 | |
3939 | |
3926 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3940 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3927 | $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; |
3941 | $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; |
3928 | Coro::async_pool { |
3942 | Coro::async_pool { |
3929 | $Coro::current->{desc} = "runtime saver"; |
3943 | $Coro::current->{desc} = "runtime saver"; |
… | |
… | |
3952 | } |
3966 | } |
3953 | |
3967 | |
3954 | { |
3968 | { |
3955 | # configure BDB |
3969 | # configure BDB |
3956 | |
3970 | |
3957 | BDB::min_parallel 8; |
3971 | BDB::min_parallel 16; |
3958 | BDB::max_poll_reqs $TICK * 0.1; |
3972 | BDB::max_poll_reqs $TICK * 0.1; |
3959 | $AnyEvent::BDB::WATCHER->priority (1); |
3973 | $AnyEvent::BDB::WATCHER->priority (1); |
3960 | |
3974 | |
3961 | unless ($DB_ENV) { |
3975 | unless ($DB_ENV) { |
3962 | $DB_ENV = BDB::db_env_create; |
3976 | $DB_ENV = BDB::db_env_create; |